/[mailutils]/mailutils/imap4d/auth_gsasl.c
ViewVC logotype

Diff of /mailutils/imap4d/auth_gsasl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by gray, Thu Jan 23 09:43:07 2003 UTC revision 1.5 by gray, Mon Feb 3 11:26:22 2003 UTC
# Line 22  Line 22 
22  static Gsasl_ctx *ctx;    static Gsasl_ctx *ctx;  
23  static Gsasl_session_ctx *sess_ctx;  static Gsasl_session_ctx *sess_ctx;
24    
25    static void auth_gsasl_capa_init __P((int disable));
26    
27  static int  static int
28  create_gsasl_stream (stream_t *newstr, stream_t str, int flags)  create_gsasl_stream (stream_t *newstr, int fd, int flags)
29  {  {
30    int rc;    int rc;
31        
32    rc = gsasl_stream_create (newstr, str, sess_ctx, flags);    rc = gsasl_stream_create (newstr, fd, sess_ctx, flags);
33    if (rc)    if (rc)
34      {      {
35        syslog (LOG_ERR, _("cannot create SASL stream: %s"),        syslog (LOG_ERR, _("cannot create SASL stream: %s"),
# Line 47  create_gsasl_stream (stream_t *newstr, s Line 49  create_gsasl_stream (stream_t *newstr, s
49    return RESP_OK;    return RESP_OK;
50  }  }
51    
52  void  int
53  gsasl_replace_streams (void *self, void *data)  gsasl_replace_streams (void *self, void *data)
54  {  {
55    stream_t *s = data;    stream_t *s = data;
# Line 60  gsasl_replace_streams (void *self, void Line 62  gsasl_replace_streams (void *self, void
62    return 0;    return 0;
63  }  }
64    
65    #define AUTHBUFSIZE 512
66    
67    static int
68    auth_step_base64(Gsasl_session_ctx *sess_ctx, char *input,
69                     char **output, size_t *output_len)
70    {
71      int rc;
72    
73      while (1)
74        {
75          rc = gsasl_server_step_base64 (sess_ctx, input, *output, *output_len);
76    
77          if (rc == GSASL_TOO_SMALL_BUFFER)
78            {
79              *output_len += AUTHBUFSIZE;
80              *output = realloc(*output, *output_len);
81              if (output)
82                continue;
83            }
84          break;
85        }
86      return rc;
87    }
88    
89  static int  static int
90  auth_gsasl (struct imap4d_command *command,  auth_gsasl (struct imap4d_command *command,
91               char *auth_type, char *arg, char **username)               char *auth_type, char *arg, char **username)
92  {  {
93    char *input = NULL;    char *input = NULL;
94    char output[512];    char *output;
95    size_t output_len;    size_t output_len;
96    char *s;    char *s;
97    int rc;    int rc;
# Line 84  auth_gsasl (struct imap4d_command *comma Line 109  auth_gsasl (struct imap4d_command *comma
109    
110    gsasl_server_application_data_set (sess_ctx, username);    gsasl_server_application_data_set (sess_ctx, username);
111    
112      output_len = AUTHBUFSIZE;
113      output = malloc (output_len);
114      if (!output)
115        imap4d_bye (ERR_NO_MEM);
116    
117    output[0] = '\0';    output[0] = '\0';
   output_len = sizeof (output);  
118    
119    while ((rc = gsasl_server_step_base64 (sess_ctx, input, output, output_len))    while ((rc = auth_step_base64 (sess_ctx, input, &output, &output_len))
120           == GSASL_NEEDS_MORE)           == GSASL_NEEDS_MORE)
121      {      {
122        util_send ("+ %s\r\n", output);        util_send ("+ %s\r\n", output);
123        input = imap4d_readline_ex ();        input = imap4d_readline_ex ();
124      }      }
125      
126    if (rc != GSASL_OK)    if (rc != GSASL_OK)
127      {      {
128        syslog (LOG_NOTICE, _("GSASL error: %s"), gsasl_strerror (rc));        syslog (LOG_NOTICE, _("GSASL error: %s"), gsasl_strerror (rc));
129          free (output);
130        return RESP_NO;        return RESP_NO;
131      }      }
132    
133      /* Some SASL mechanisms output data when GSASL_OK is returned */
134      if (output[0])
135        util_send ("+ %s\r\n", output);
136      
137      free (output);
138    
139    if (*username == NULL)    if (*username == NULL)
140      {      {
141        syslog (LOG_NOTICE, _("GSASL %s: cannot get username"), auth_type);        syslog (LOG_NOTICE, _("GSASL %s: cannot get username"), auth_type);

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26