/[mailutils]/mailutils/mailbox/mu_auth.c
ViewVC logotype

Diff of /mailutils/mailbox/mu_auth.c

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

revision 1.1 by gray, Tue Aug 13 13:25:44 2002 UTC revision 1.2 by gray, Thu Aug 15 12:54:27 2002 UTC
# Line 47  Line 47 
47  #include <mailutils/mu_auth.h>  #include <mailutils/mu_auth.h>
48  #include <mailutils/error.h>  #include <mailutils/error.h>
49    
50  #define DEBUG(c) do { printf c; printf("\n"); } while (0)  /*#define DEBUG(c) do { printf c; printf("\n"); } while (0)*/
51    #define DEBUG(c)
52    
53    static void mu_auth_begin_setup __P((void));
54    static void mu_auth_finish_setup __P((void));
55    
56  /* memory allocation */  /* memory allocation */
57  int  int
# Line 150  mu_auth_nosupport (void *usused_return_d Line 154  mu_auth_nosupport (void *usused_return_d
154    
155  /* II. Authorization: retrieving information about user */  /* II. Authorization: retrieving information about user */
156    
157  static list_t mu_auth_by_name_list;  static list_t mu_auth_by_name_list, _tmp_auth_by_name_list;
158  static list_t mu_auth_by_uid_list;  static list_t mu_auth_by_uid_list, _tmp_auth_by_uid_list;
159    
160  struct mu_auth_data *  struct mu_auth_data *
161  mu_get_auth_by_name (const char *username)  mu_get_auth_by_name (const char *username)
# Line 159  mu_get_auth_by_name (const char *usernam Line 163  mu_get_auth_by_name (const char *usernam
163    struct mu_auth_data *auth = NULL;    struct mu_auth_data *auth = NULL;
164    
165    DEBUG(("mu_get_auth_by_name"));    DEBUG(("mu_get_auth_by_name"));
166      if (!mu_auth_by_name_list)
167        mu_auth_begin_setup ();
168    mu_auth_runlist (mu_auth_by_name_list, &auth, username, NULL);    mu_auth_runlist (mu_auth_by_name_list, &auth, username, NULL);
169    return auth;    return auth;
170  }  }
# Line 169  mu_get_auth_by_uid (uid_t uid) Line 175  mu_get_auth_by_uid (uid_t uid)
175    struct mu_auth_data *auth = NULL;    struct mu_auth_data *auth = NULL;
176    
177    DEBUG(("mu_get_auth_by_uid"));    DEBUG(("mu_get_auth_by_uid"));
178      if (!mu_auth_by_uid_list)
179        mu_auth_begin_setup ();
180    mu_auth_runlist (mu_auth_by_uid_list, &auth, &uid, NULL);    mu_auth_runlist (mu_auth_by_uid_list, &auth, &uid, NULL);
181    return auth;    return auth;
182  }  }
183    
184  /* III. Authentication: determining the authenticity of a user */  /* III. Authentication: determining the authenticity of a user */
185    
186  static list_t mu_authenticate_list;  static list_t mu_authenticate_list, _tmp_authenticate_list;
187    
188  int  int
189  mu_authenticate (struct mu_auth_data *auth_data, char *pass)  mu_authenticate (struct mu_auth_data *auth_data, char *pass)
190  {  {
191    DEBUG(("mu_authenticate"));    DEBUG(("mu_authenticate"));
192      if (!mu_authenticate_list)
193        mu_auth_begin_setup ();
194    return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, pass);    return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, pass);
195  }  }
196    
 /* IV. Implementation functions */  
   
 /* IV a. Authorization */  
   
   
   
197  /* Modules & configuration */  /* Modules & configuration */
198    
199    
# Line 220  struct argp_child mu_auth_argp_child = { Line 224  struct argp_child mu_auth_argp_child = {
224    0    0
225  };  };
226    
 static void mu_auth_finish_setup __P((void));  
   
227  static error_t  static error_t
228  mu_auth_argp_parser (int key, char *arg, struct argp_state *state)  mu_auth_argp_parser (int key, char *arg, struct argp_state *state)
229  {  {
230    switch (key)    switch (key)
231      {      {
232        case ARGP_KEY_FINI:
233          mu_auth_finish_setup ();
234          break;
235    
236        /* authentication */        /* authentication */
237      case ARG_AUTHORIZATION:      case ARG_AUTHORIZATION:
238        mu_authorization_add_module_list (arg);        mu_authorization_add_module_list (arg);
# Line 236  mu_auth_argp_parser (int key, char *arg, Line 242  mu_auth_argp_parser (int key, char *arg,
242        mu_authentication_add_module_list (arg);        mu_authentication_add_module_list (arg);
243        break;        break;
244                
     case ARGP_KEY_FINI:  
       mu_auth_finish_setup ();  
       break;  
   
245      default:      default:
246        return ARGP_ERR_UNKNOWN;        return ARGP_ERR_UNKNOWN;
247      }      }
# Line 369  mu_authorization_add_module (const char Line 371  mu_authorization_add_module (const char
371        errno = ENOENT;        errno = ENOENT;
372        return 1;        return 1;
373      }      }
374    mu_insert_stack_entry (&mu_auth_by_name_list, &mod->auth_by_name);    mu_insert_stack_entry (&_tmp_auth_by_name_list, &mod->auth_by_name);
375    mu_insert_stack_entry (&mu_auth_by_uid_list, &mod->auth_by_uid);    mu_insert_stack_entry (&_tmp_auth_by_uid_list, &mod->auth_by_uid);
376    return 0;    return 0;
377  }  }
378    
# Line 390  mu_authentication_add_module (const char Line 392  mu_authentication_add_module (const char
392        errno = ENOENT;        errno = ENOENT;
393        return 1;        return 1;
394      }      }
395    mu_insert_stack_entry (&mu_authenticate_list, &mod->authenticate);    mu_insert_stack_entry (&_tmp_authenticate_list, &mod->authenticate);
396    return 0;    return 0;
397  }  }
398    
# Line 400  mu_authentication_add_module_list (const Line 402  mu_authentication_add_module_list (const
402    _add_module_list (modlist, mu_authentication_add_module);    _add_module_list (modlist, mu_authentication_add_module);
403  }  }
404    
   
405  /* ************************************************************************ */  /* ************************************************************************ */
406    
407    /* Setup functions. Note that:
408       1) If libmuath is not linked in, then "generic" and "system" modules
409          are used unconditionally. This provides compatibility with the
410          standard getpw.* functions.
411       2) --authentication and --authorization modify only temporary lists,
412          which get flushed to the main ones when mu_auth_finish_setup() is
413          run. Thus, the default "generic:system" remain in force until
414          argp_parse() exits. */
415      
416  void  void
417  mu_auth_finish_setup ()  mu_auth_begin_setup ()
418  {  {
419    iterator_t itr;    iterator_t itr;
420    
421      if (!module_handler_list)
422        {
423          mu_auth_register_module (&mu_auth_generic_module);
424          mu_auth_register_module (&mu_auth_system_module);
425        }
426      
427    if (!mu_authenticate_list)    if (!mu_authenticate_list)
428      {      {
429        if (iterator_create (&itr, module_handler_list) == 0)        if (iterator_create (&itr, module_handler_list) == 0)
# Line 444  mu_auth_finish_setup () Line 460  mu_auth_finish_setup ()
460  }  }
461    
462  void  void
463    mu_auth_finish_setup ()
464    {
465      list_destroy (&mu_authenticate_list);
466      list_destroy (&mu_auth_by_name_list);
467      list_destroy (&mu_auth_by_uid_list);
468      
469      mu_authenticate_list = _tmp_authenticate_list;
470      _tmp_authenticate_list = NULL;
471      mu_auth_by_name_list = _tmp_auth_by_name_list;
472      _tmp_auth_by_name_list = NULL;
473      mu_auth_by_uid_list = _tmp_auth_by_uid_list;
474      _tmp_auth_by_uid_list = NULL;
475      
476      mu_auth_begin_setup ();
477    }
478    
479    void
480  mu_auth_init ()  mu_auth_init ()
481  {  {
482    if (mu_register_capa ("auth", &mu_auth_argp_child))    if (mu_register_capa ("auth", &mu_auth_argp_child))

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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