Previous: Existing Modules, Up: libmuauth


3.2.6 Using libmuauth in Your Programs

To link your program against libmuauth, obtain loader arguments by running mailutils-config as follows:

     mailutils-config --link auth

See mailutils-config, for more information about this utility.

Here is a sample Makefile fragment:

     MU_LDFLAGS=`mailutils-config --link auth`
     MU_INCLUDES=`mailutils-config --include`
     
     myprog: myprog.c
             $(CC) -omyprog $(CFLAGS) $(MU_INCLUDES) myprog.c $(MU_LDFLAGS)

If your program will be using only default modules provided by the library, then it will suffice to call MU_AUTH_REGISTER_ALL_MODULES() somewhere near the start of your program. As an example, consider the following code fragment (it is taken from the imap4d daemon):

     int
     main (int argc, char **argv)
     {
       struct group *gr;
       int status = EXIT_SUCCESS;
     
       state = STATE_NONAUTH; /* Starting state in non-auth.  */
     
       MU_AUTH_REGISTER_ALL_MODULES ();
       mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa,
                      NULL, &daemon_param);
       ...

Otherwise, if your program will use it's own modules, first register them with mu_auth_register_module and then call mu_auth_init(), e.g.:

     struct mu_auth_module radius_module = {
       ...
     };
     
     struct mu_auth_module ext_module = {
       ...
     };
     
     int
     main (int argc, char **argv)
     {
       mu_auth_register_module (&radius_module);
       mu_auth_register_module (&ext_module);
       mu_auth_init ();
     
       ...

These two approaches may be combined, allowing you to use both your modules and the ones provided by Mailutils. Consider the example below:

     int
     main (int argc, char **argv)
     {
       mu_auth_register_module (&radius_module);
       mu_auth_register_module (&ext_module);
       MU_AUTH_REGISTER_ALL_MODULES ();
     
       ...
     }