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

Diff of /mailutils/imap4d/authenticate.c

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

revision 1.11 by polak, Sun Dec 29 12:52:06 2002 UTC revision 1.12 by gray, Wed Jan 22 13:12:27 2003 UTC
# Line 17  Line 17 
17    
18  #include "imap4d.h"  #include "imap4d.h"
19    
 extern int auth_gssapi __P((struct imap4d_command *, char **username));  
   
20  struct imap_auth {  struct imap_auth {
21    char *name;    char *name;
22    int (*handler) __P((struct imap4d_command *, char **));    imap4d_auth_handler_fp handler;
23  } imap_auth_tab[] = {  };
24  #ifdef WITH_GSSAPI  
25    { "GSSAPI", auth_gssapi },  static list_t imap_auth_list;
26  #endif    
27    { NULL, NULL }  static int
28    comp (const void *item, const void *data)
29    {
30      struct imap_auth *p = item;
31      return strcmp (p->name, (char*) data);
32    }
33    
34    void
35    auth_add (char *name, imap4d_auth_handler_fp handler)
36    {
37      struct imap_auth *p = malloc (sizeof (*p));
38    
39      if (!p)
40        imap4d_bye (ERR_NO_MEM);
41    
42      p->name = name;
43      p->handler = handler;
44      if (!imap_auth_list)
45        {
46          list_create (&imap_auth_list);
47          list_set_comparator (imap_auth_list, comp);
48        }
49      list_append (imap_auth_list, (void*)p);
50    }
51    
52    void
53    auth_remove (char *name)
54    {
55      list_remove (imap_auth_list, (void*) name);
56    }
57    
58    static int
59    _auth_capa (void *item, void *usused)
60    {
61      struct imap_auth *p = item;
62      util_send(" AUTH=%s", p->name);
63      return 0;
64    }
65    
66    struct auth_data {
67      struct imap4d_command *command;
68      char *auth_type;
69      char *arg;
70      char *username;
71      int result;
72  };  };
73    
74    static int
75    _auth_try (void *item, void *data)
76    {
77      struct imap_auth *p = item;
78      struct auth_data *ap = data;
79    
80      if (strcmp (p->name, ap->auth_type) == 0)
81        {
82          ap->result = p->handler (ap->command,
83                                   ap->auth_type, ap->arg, &ap->username);
84          return 1;
85        }
86      return 0;
87    }
88    
89  void  void
90  imap4d_auth_capability ()  imap4d_auth_capability ()
91  {  {
92    struct imap_auth *ap;    list_do (imap_auth_list, _auth_capa, NULL);
   for (ap = imap_auth_tab; ap->name; ap++)  
     util_send(" AUTH=%s", ap->name);  
93  }  }
94    
95  int  int
# Line 42  imap4d_authenticate (struct imap4d_comma Line 97  imap4d_authenticate (struct imap4d_comma
97  {  {
98    char *sp = NULL;    char *sp = NULL;
99    char *auth_type;    char *auth_type;
100    struct imap_auth *ap;    struct auth_data adata;
   char *username = NULL;  
101        
102    auth_type = util_getword (arg, &sp);    auth_type = util_getword (arg, &sp);
103    util_unquote (&auth_type);    util_unquote (&auth_type);
104    if (!auth_type)    if (!auth_type)
105      return util_finish (command, RESP_BAD, "Too few arguments");      return util_finish (command, RESP_BAD, "Too few arguments");
106    
107    for (ap = imap_auth_tab; ap->name; ap++)    adata.command = command;
108      if (strcmp (auth_type, ap->name) == 0)    adata.auth_type = auth_type;
109        {    adata.arg = sp;
110          if (ap->handler (command, &username))    adata.username = NULL;
111            return 1;  
112        }    if (list_do (imap_auth_list, _auth_try, &adata) == 0)
113        return util_finish (command, RESP_NO,
114    if (username)                          "Authentication mechanism not supported");
115      
116      if (adata.result == RESP_OK && adata.username)
117      {      {
118        auth_data = mu_get_auth_by_name (username);        auth_data = mu_get_auth_by_name (adata.username);
119        if (auth_data == NULL)        if (auth_data == NULL)
120          return util_finish (command, RESP_NO,          return util_finish (command, RESP_NO,
121                              "User name or passwd rejected");                              "User name or passwd rejected");
# Line 71  imap4d_authenticate (struct imap4d_comma Line 127  imap4d_authenticate (struct imap4d_comma
127        /* FIXME: Check for errors.  */        /* FIXME: Check for errors.  */
128        chdir (homedir);        chdir (homedir);
129        namespace_init (homedir);        namespace_init (homedir);
130        syslog (LOG_INFO, _("User '%s' logged in"), username);        syslog (LOG_INFO, _("User '%s' logged in"), adata.username);
131        return 0;        
132          return util_finish (command, RESP_OK,
133                              "%s authentication successful", auth_type);
134      }      }
135                
136    return util_finish (command, RESP_NO,    return util_finish (command, adata.result,
137                        "Authentication mechanism not supported");                        "%s authentication failed", auth_type);
138  }  }
139    

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

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