auth.texi 1.68 KB
Mailboxes and Mailers provide a way to authenticate when the URL does not
contain enough information.  The default action is to call function
@code{auth_authenticate} who will get the @emph{user} and @emph{passwd}
if not set, this function can be override by a custom method.

@deftypefun int auth_create (auth_t *@var{pauth}, void *@var{owner})
@end deftypefun

@deftypefun void auth_destroy (auth_t *@var{pauth}, void *@var{owner})
@end deftypefun

@deftypefun int auth_prologue (auth_t @var{auth})
@end deftypefun

@deftypefun int auth_set_prologue (auth_t @var{auth}, int (*@var{_prologue})(auth_t), void *@var{owner})
@end deftypefun

@deftypefun int auth_authenticate (auth_t @var{auth}, char **@var{user}, char **@var{passwd})
@end deftypefun

@deftypefun int auth_set_authenticate (auth_t auth, int (*@var{_authenticate}) (auth_t, char **, char **), void *@var{owner})
@end deftypefun

@deftypefun int auth_epilogue (auth_t @var{auth})
@end deftypefun

@deftypefun int auth_set_epilogue (auth_t @var{auth}, int (*@var{_epilogue})(auth_t), void *@var{owner})
@end deftypefun

A simple example of an authenticate function:
@example
#include <mailutils/auth.h>
#include <stdio.h>
#include <string.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;
@}
@end example