Next: , Previous: Iterator, Up: libmailbox


3.1.11 Authenticator

     /* Prefixes mu_authority_, mu_ticket_, and mu_wicket_ are reserved. */
     #include <mailutils/auth.h>
     

There are many ways to authenticate to a server. To be flexible the authentication process is provided by three objects mu_authority_t, mu_ticket_t, and mu_wicket_t. The mu_authority_t can implement different protocol like APOP, MD5-AUTH, One Time Passwd, etc. By default if a mailbox does not understand or know how to authenticate it falls back to user/passwd authentication. The mu_ticket_t is a way for Mailboxes and Mailers provide a way to authenticate when the URL does not contain enough information. The default action is to call the function mu_authority_authenticate() which will get the user and passwd if not set, this function can be overridden by a custom method.

— Function: int mu_ticket_create (mu_ticket_t *, void *owner)
— Function: void mu_ticket_destroy (mu_ticket_t *, void *owner)
— Function: int mu_ticket_set_destroy (mu_ticket_t, void (*) (mu_ticket_t), void *owner)
— Function: void* mu_ticket_get_owner (mu_ticket_t)
— Function: int mu_ticket_set_pop (mu_ticket_t, int (*_pop) (mu_ticket_t, url_t, const char *, char **), void *)
— Function: int mu_ticket_pop (mu_ticket_t, url_t, const char *, char **)
— Function: int mu_ticket_set_data (mu_ticket_t, void *, void *owner)
— Function: int mu_ticket_get_data (mu_ticket_t, void **)

— Function: int mu_authority_create (mu_authority_t *, mu_ticket_t, void *)
— Function: void mu_authority_destroy (mu_authority_t *, void *)
— Function: void* mu_authority_get_owner (mu_authority_t)
— Function: int mu_authority_set_ticket (mu_authority_t, mu_ticket_t)
— Function: int mu_authority_get_ticket (mu_authority_t, mu_ticket_t *)
— Function: int mu_authority_authenticate (mu_authority_t)
— Function: int mu_authority_set_authenticate (mu_authority_t, int (*_authenticate) (mu_authority_t), void *)
— Function: int mu_authority_create_null (mu_authority_t *authority, void *owner)

— Function: int mu_wicket_create (mu_wicket_t *, const char *)
— Function: void mu_wicket_destroy (mu_wicket_t *)
— Function: int mu_wicket_set_filename (mu_wicket_t, const char *)
— Function: int mu_wicket_get_filename (mu_wicket_t, char *, size_t, size_t *)
— Function: int mu_wicket_set_ticket (mu_wicket_t, int (*) (mu_wicket_t, const char *, const char *, mu_ticket_t *))
— Function: int mu_wicket_get_ticket (mu_wicket_t, mu_ticket_t *, const char *, const char *)

A simple example of an authenticate function:
     #include <stdio.h>
     #include <string.h>
     #include <mailutils/auth.h>
     
     int
     my_authenticate (auth_t auth, char **user, char **passwd)
     {
       char u[128] = "";
       char p[128] = "";
     
       /* prompt the user name */
       printf ("User: ");
       fflush (stdout);
       fgets (u, sizeof (u), stdin);
       u[strlen (u) - 1] = '\0'; /* nuke the trailing NL */
     
       /* prompt the passwd */
       printf ("Passwd: "); fflush (stdout);
       echo_off ();
       fgets (p, sizeof(p), stdin);
       echo_on ();
       p[strlen (p) - 1] = '\0';
     
       /* duplicate */
       *user = strdup (u);
       *passwd = strdup (p);
       return 0;
     }