Previous Next Contents

5.3 Added requirements for statically loaded modules.

Modules may be statically linked into libpam. This should be true of all the modules distributed with the basic Linux-PAM distribution. To be statically linked, a module needs to export information about the functions it contains in a manner that does not clash with other modules.

The extra code necessary to build a static module should be delimited with #ifdef PAM_STATIC and #endif. The static code should do the following:

As a simple example, consider the following module code which defines a module that can be compiled to be static or dynamic:

#include <stdio.h>                                    /* for NULL define */

#define PAM_SM_PASSWORD         /* the only pam_sm_... function declared */
#include <security/pam_modules.h>

PAM_EXTERN int pam_sm_chauthtok(pam_handle_t *pamh, int flags,
                                int argc, const char **argv)
{
     return PAM_SUCCESS;
}

#ifdef PAM_STATIC             /* for the case that this module is static */

struct pam_module _pam_modname_modstruct = {       /* static module data */
     "pam_modname",
     NULL,
     NULL,
     NULL,
     NULL,
     NULL,
     pam_sm_chauthtok,
};

#endif                                                 /* end PAM_STATIC */

To be linked with libpam, staticly-linked modules must be built from within the Linux-PAM-X.YY/modules/ subdirectory of the Linux-PAM source directory as part of a normal build of the Linux-PAM system.

The Makefile, for the module in question, must execute the register_static shell script that is located in the Linux-PAM-X.YY/modules/ subdirectory. This is to ensure that the module is properly registered with libpam.

The two manditory arguments to register_static are the title, and the pathname of the object file containing the module's code. The pathname is specified relative to the Linux-PAM-X.YY/modules directory. The pathname may be an empty string---this is for the case that a single object file needs to register more than one struct pam_module. In such a case, exactly one call to register_static must indicate the object file.

Here is an example; a line in the Makefile might look like this:

register:
ifdef STATIC
        (cd ..; ./register_static pam_modname pam_modname/pam_modname.o)
endif

For some further examples, see the modules subdirectory of the current Linux-PAM distribution.


Previous Next Contents