#include <security/pam_appl.h>
int pam_start( | service_name, | |
user, | ||
pam_conversation, | ||
pamh) ; |
const char *service_name
;const char *user
;const struct pam_conv *pam_conversation
;pam_handle_t **pamh
;
The pam_start
function creates the PAM context
and initiates the PAM transaction. It is the first of the PAM
functions that needs to be called by an application. The transaction
state is contained entirely within the structure identified by this
handle, so it is possible to have multiple transactions in parallel.
But it is not possible to use the same handle for different
transactions, a new one is needed for every new context.
The service_name argument specifies the name
of the service to apply and will be stored as PAM_SERVICE item in
the new context. The policy for the service will be read from the
file /etc/pam.d/service_name
or, if that file
does not exist, from /etc/pam.conf
.
The user argument can specify the name of the target user and will be stored as PAM_USER item. If the argument is NULL, the module has to ask for this item if necessary.
The pam_conversation argument points to a struct pam_conv describing the conversation function to use. An application must provide this for direct communication between a loaded module and the application.
Following a successful return (PAM_SUCCESS) the contents of pamh is a handle that contains the PAM context for successive calls to the PAM functions. In an error case is the content of pamh undefined.
The pam_handle_t is a blind structure and
the application should not attempt to probe it directly for
information. Instead the PAM library provides the functions
pam_set_item(3) and
pam_get_item(3).
The PAM handle cannot be used for mulitiple authentications at the
same time as long as pam_end
was not called on
it before.
#include <security/pam_appl.h>
int pam_end( | pamh, | |
pam_status) ; |
pam_handle_t *pamh
;int pam_status
;
The pam_end
function terminates the PAM
transaction and is the last function an application should call
in the PAM context. Upon return the handle pamh
is no longer valid and all memory associated with it will be
invalid.
The pam_status argument should be set to the value returned to the application by the last PAM library call.
The value taken by pam_status is used as
an argument to the module specific callback function,
cleanup()
(See pam_set_data(3) and
pam_get_data(3)). In this way the module can be given notification
of the pass/fail nature of the tear-down process, and perform any
last minute tasks that are appropriate to the module before it is
unlinked. This argument can be logically OR'd with
PAM_DATA_SILENT to indicate to indicate that
the module should not treat the call too seriously. It is generally
used to indicate that the current closing of the library is in a
fork(2)ed
process, and that the parent will take care of cleaning up things
that exist outside of the current process space (files etc.).
This function free's all memory for items
associated with the
pam_set_item(3) and
pam_get_item(3) functions. Pointers associated with such objects
are not valid anymore after pam_end
was called.
#include <security/pam_modules.h>
int pam_set_item( | pamh, | |
item_type, | ||
item) ; |
pam_handle_t *pamh
;int item_type
;const void *item
;
The pam_set_item
function allows applications
and PAM service modules to access and to update PAM informations
of item_type. For this a copy
of the object pointed to by the item argument
is created. The following item_types are
supported:
The service name (which identifies that PAM stack that the PAM functions will use to authenticate the program).
The username of the entity under whose identity service will be given. That is, following authentication, PAM_USER identifies the local entity that gets to use the service. Note, this value can be mapped from something (eg., "anonymous") to something else (eg. "guest119") by any module in the PAM stack. As such an application should consult the value of PAM_USER after each call to a PAM function.
The string used when prompting for a user's name. The default value for this string is a localized version of "login: ".
The terminal name: prefixed by /dev/
if
it is a device file; for graphical, X-based, applications the
value for this item should be the
$DISPLAY variable.
The requesting user name: local name for a locally requesting user or a remote user name for a remote requesting user.
Generally an application or module will attempt to supply the value that is most strongly authenticated (a local account before a remote one. The level of trust in this value is embodied in the actual authentication stack associated with the application, so it is ultimately at the discretion of the system administrator.
PAM_RUSER@PAM_RHOST should always identify the requesting user. In some cases, PAM_RUSER may be NULL. In such situations, it is unclear who the requesting entity is.
The requesting hostname (the hostname of the machine from which the PAM_RUSER entity is requesting service). That is PAM_RUSER@PAM_RHOST does identify the requesting user. In some applications, PAM_RHOST may be NULL. In such situations, it is unclear where the authentication request is originating from.
The authentication token (often a password). This token should be ignored by all module functions besides pam_sm_authenticate(3) and pam_sm_chauthtok(3). In the former function it is used to pass the most recent authentication token from one stacked module to another. In the latter function the token is used for another purpose. It contains the currently active authentication token.
The old authentication token. This token should be ignored by all module functions except pam_sm_chauthtok(3).
The pam_conv structure. See pam_conv(3).
The following additional items are specific to Linux-PAM and should not be used in portable applications:
A function pointer to redirect centrally managed failure delays. See pam_fail_delay(3).
The name of the X display. For graphical, X-based applications the value for this item should be the $DISPLAY variable. This value may be used independently of PAM_TTY for passing the name of the display.
A pointer to a structure containing the X authentication data required to make a connection to the display specified by PAM_XDISPLAY, if such information is necessary. See pam_xauth_data(3).
The default action is for the module to use the following prompts when requesting passwords: "New UNIX password: " and "Retype UNIX password: ". The example word UNIX can be replaced with this item, by default it is empty. This item is used by pam_get_authtok(3).
For all item_types, other than PAM_CONV and
PAM_FAIL_DELAY, item is a pointer to a <NUL>
terminated character string. In the case of PAM_CONV,
item points to an initialized
pam_conv structure. In the case of
PAM_FAIL_DELAY, item is a function pointer:
void (*delay_fn)(int retval, unsigned usec_delay, void *appdata_ptr)
Both, PAM_AUTHTOK and PAM_OLDAUTHTOK, will be reseted before returning to the application. Which means an application is not able to access the authentication tokens.
#include <security/pam_modules.h>
int pam_get_item( | pamh, | |
item_type, | ||
item) ; |
const pam_handle_t *pamh
;int item_type
;const void **item
;
The pam_get_item
function allows applications
and PAM service modules to access and retrieve PAM informations
of item_type. Upon successful return,
item contains a pointer to the value of the
corresponding item. Note, this is a pointer to the
actual data and should
not be free()'ed or
over-written! The following values are supported for
item_type:
The service name (which identifies that PAM stack that the PAM functions will use to authenticate the program).
The username of the entity under whose identity service will be given. That is, following authentication, PAM_USER identifies the local entity that gets to use the service. Note, this value can be mapped from something (eg., "anonymous") to something else (eg. "guest119") by any module in the PAM stack. As such an application should consult the value of PAM_USER after each call to a PAM function.
The string used when prompting for a user's name. The default value for this string is a localized version of "login: ".
The terminal name: prefixed by /dev/
if
it is a device file; for graphical, X-based, applications the
value for this item should be the
$DISPLAY variable.
The requesting user name: local name for a locally requesting user or a remote user name for a remote requesting user.
Generally an application or module will attempt to supply the value that is most strongly authenticated (a local account before a remote one. The level of trust in this value is embodied in the actual authentication stack associated with the application, so it is ultimately at the discretion of the system administrator.
PAM_RUSER@PAM_RHOST should always identify the requesting user. In some cases, PAM_RUSER may be NULL. In such situations, it is unclear who the requesting entity is.
The requesting hostname (the hostname of the machine from which the PAM_RUSER entity is requesting service). That is PAM_RUSER@PAM_RHOST does identify the requesting user. In some applications, PAM_RHOST may be NULL. In such situations, it is unclear where the authentication request is originating from.
The authentication token (often a password). This token should be ignored by all module functions besides pam_sm_authenticate(3) and pam_sm_chauthtok(3). In the former function it is used to pass the most recent authentication token from one stacked module to another. In the latter function the token is used for another purpose. It contains the currently active authentication token.
The old authentication token. This token should be ignored by all module functions except pam_sm_chauthtok(3).
The pam_conv structure. See pam_conv(3).
The following additional items are specific to Linux-PAM and should not be used in portable applications:
A function pointer to redirect centrally managed failure delays. See pam_fail_delay(3).
The name of the X display. For graphical, X-based applications the value for this item should be the $DISPLAY variable. This value may be used independently of PAM_TTY for passing the name of the display.
A pointer to a structure containing the X authentication data required to make a connection to the display specified by PAM_XDISPLAY, if such information is necessary. See pam_xauth_data(3).
The default action is for the module to use the following prompts when requesting passwords: "New UNIX password: " and "Retype UNIX password: ". The example word UNIX can be replaced with this item, by default it is empty. This item is used by pam_get_authtok(3).
If a service module wishes to obtain the name of the user, it should not use this function, but instead perform a call to pam_get_user(3).
Only a service module is privileged to read the authentication tokens, PAM_AUTHTOK and PAM_OLDAUTHTOK.
#include <security/pam_appl.h>
const char *pam_strerror( | pamh, | |
errnum) ; |
pam_handle_t *pamh
;int errnum
;
The pam_strerror
function returns a pointer to
a string describing the error code passed in the argument
errnum, possibly using the LC_MESSAGES part of
the current locale to select the appropriate language. This string
must not be modified by the application. No library function will
modify this string.
#include <security/pam_appl.h>
int pam_fail_delay( | pamh, | |
usec) ; |
pam_handle_t *pamh
;unsigned int usec
;
The pam_fail_delay
function provides a
mechanism by which an application or module can suggest a minimum
delay of usec micro-seconds. The
function keeps a record of the longest time requested with this
function. Should
pam_authenticate(3) fail, the failing return to the application is
delayed by an amount of time randomly distributed (by up to 50%)
about this longest value.
Independent of success, the delay time is reset to its zero default value when the PAM service module returns control to the application. The delay occurs after all authentication modules have been called, but before control is returned to the service application.
When using this function the programmer should check if it is available with:
#ifdef HAVE_PAM_FAIL_DELAY .... #endif /* HAVE_PAM_FAIL_DELAY */
For applications written with a single thread that are event driven in nature, generating this delay may be undesirable. Instead, the application may want to register the delay in some other way. For example, in a single threaded server that serves multiple authentication requests from a single event loop, the application might want to simply mark a given connection as blocked until an application timer expires. For this reason the delay function can be changed with the PAM_FAIL_DELAY item. It can be queried and set with pam_get_item(3) and pam_set_item (3) respectively. The value used to set it should be a function pointer of the following prototype:
void (*delay_fn)(int retval, unsigned usec_delay, void *appdata_ptr);
The arguments being the retval return code of the module stack, the usec_delay micro-second delay that libpam is requesting and the appdata_ptr that the application has associated with the current pamh. This last value was set by the application when it called pam_start(3) or explicitly with pam_set_item(3). Note, if PAM_FAIL_DELAY item is unset (or set to NULL), then no delay will be performed.
#include <security/pam_appl.h>
int pam_authenticate( | pamh, | |
flags) ; |
pam_handle_t *pamh
;int flags
;
The pam_authenticate
function is used to
authenticate the user. The user is required to provide an
authentication token depending upon the authentication service,
usually this is a password, but could also be a finger print.
The PAM service module may request that the user enter their username vio the the conversation mechanism (see pam_start(3) and pam_conv(3)). The name of the authenticated user will be present in the PAM item PAM_USER. This item may be recovered with a call to pam_get_item(3).
The pamh argument is an authentication handle obtained by a prior call to pam_start(). The flags argument is the binary or of zero or more of the following values:
Do not emit any messages.
The PAM module service should return PAM_AUTH_ERR if the user does not have a registered authentication token.
The application should exit immediately after calling pam_end(3) first.
The user was not authenticated.
For some reason the application does not have sufficient credentials to authenticate the user.
The modules were not able to access the authentication information. This might be due to a network or hardware failure etc.
One or more of the authentication modules has reached its limit of tries authenticating the user. Do not try again.
The user was successfully authenticated.
User unknown to authentication service.
#include <security/pam_appl.h>
int pam_setcred( | pamh, | |
flags) ; |
pam_handle_t *pamh
;int flags
;
The pam_setcred
function is used to establish,
maintain and delete the credentials of a user. It should be called
to set the credentials after a user has been authenticated and before
a session is opened for the user (with
pam_open_session(3)). The credentials should be deleted after the session
has been closed (with
pam_close_session(3)).
A credential is something that the user possesses. It is some property, such as a Kerberos ticket, or a supplementary group membership that make up the uniqueness of a given user. On a Linux system the user's UID and GID's are credentials too. However, it has been decided that these properties (along with the default supplementary groups of which the user is a member) are credentials that should be set directly by the application and not by PAM. Such credentials should be established, by the application, prior to a call to this function. For example, initgroups(2) (or equivalent) should have been performed.
Valid flags, any one of which, may be
logically OR'd with PAM_SILENT
, are:
Initialize the credentials for the user.
Delete the user's credentials.
Fully reinitialize the user's credentials.
Extend the lifetime of the existing credentials.
Memory buffer error.
Failed to set user credentials.
User credentials are expired.
Failed to retrieve user credentials.
Data was successful stored.
A NULL pointer was submitted as PAM handle, the function was called by a module or another system error occured.
User is not known to an authentication module.
#include <security/pam_appl.h>
int pam_acct_mgmt( | pamh, | |
flags) ; |
pam_handle_t *pamh
;int flags
;
The pam_acct_mgmt
function is used to determine
if the users account is valid. It checks for authentication token
and account expiration and verifies access restrictions. It is
typically called after the user has been authenticated.
The pamh argument is an authentication handle obtained by a prior call to pam_start(). The flags argument is the binary or of zero or more of the following values:
Do not emit any messages.
The PAM module service should return PAM_NEW_AUTHTOK_REQD if the user has a null authentication token.
User account has expired.
Authentication failure.
The user account is valid but their authentication token
is expired. The correct response to
this return-value is to require that the user satisfies
the pam_chauthtok()
function before
obtaining service. It may not be possible for some
applications to do this. In such cases, the user should be
denied access until such time as they can update their password.
Permission denied.
The authentication token was successfully updated.
User unknown to password service.
#include <security/pam_appl.h>
int pam_chauthtok( | pamh, | |
flags) ; |
pam_handle_t *pamh
;int flags
;
The pam_chauthtok
function is used to change the
authentication token for a given user (as indicated by the state
associated with the handle pamh).
The pamh argument is an authentication handle obtained by a prior call to pam_start(). The flags argument is the binary or of zero or more of the following values:
Do not emit any messages.
This argument indicates to the modules that the users authentication token (password) should only be changed if it has expired. If this argument is not passed, the application requires that all authentication tokens are to be changed.
A module was unable to obtain the new authentication token.
A module was unable to obtain the old authentication token.
One or more of the modules was unable to change the authentication token since it is currently locked.
Authentication token aging has been disabled for at least one of the modules.
Permission denied.
The authentication token was successfully updated.
Not all of the modules were in a position to update the authentication token(s). In such a case none of the user's authentication tokens are updated.
User unknown to password service.
#include <security/pam_appl.h>
int pam_open_session( | pamh, | |
flags) ; |
pam_handle_t *pamh
;int flags
;
The pam_open_session
function sets up a
user session for a previously successful authenticated user.
The session should later be terminated with a call to
pam_close_session(3).
It should be noted that the effective uid, geteuid(2). of the application should be of sufficient privilege to perform such tasks as creating or mounting the user's home directory for example.
The flags argument is the binary or of zero or more of the following values:
Do not emit any messages.
#include <security/pam_appl.h>
int pam_close_session( | pamh, | |
flags) ; |
pam_handle_t *pamh
;int flags
;
The pam_close_session
function is used
to indicate that an authenticated session has ended.
The session should have been created with a call to
pam_open_session(3).
It should be noted that the effective uid, geteuid(2). of the application should be of sufficient privilege to perform such tasks as unmounting the user's home directory for example.
The flags argument is the binary or of zero or more of the following values:
Do not emit any messages.
#include <security/pam_appl.h>
int pam_putenv( | pamh, | |
name_value) ; |
pam_handle_t *pamh
;const char *name_value
;
The pam_putenv
function is used to
add or change the value of PAM environment variables as
associated with the pamh handle.
The pamh argument is an authentication handle obtained by a prior call to pam_start(). The name_value argument is a single NUL terminated string of one of the following forms:
In this case the environment variable of the given NAME is set to the indicated value: value of variable. If this variable is already known, it is overwritten. Otherwise it is added to the PAM environment.
This function sets the variable to an empty value. It is listed separately to indicate that this is the correct way to achieve such a setting.
Without an '=' the pam_putenv
() function
will delete the
corresponding variable from the PAM environment.
pam_putenv
() operates on a copy of
name_value, which means in contrast to
putenv(3), the application is responsible to free the data.
#include <security/pam_appl.h>
const char *pam_getenv( | pamh, | |
name) ; |
pam_handle_t *pamh
;const char *name
;
The pam_getenv
function searches the
PAM environment list as associated with the handle
pamh for an item that matches the string
pointed to by name and returns a pointer
to the value of the environment variable. The application is
not allowed to free the data.
#include <security/pam_appl.h>
char **pam_getenvlist( | pamh) ; |
pam_handle_t *pamh
;
The pam_getenvlist
function returns a complete
copy of the PAM environment as associated with the handle
pamh. The PAM environment variables
represent the contents of the regular environment variables of the
authenticated user when service is granted.
The format of the memory is a malloc()'d array of char pointers, the last element of which is set to NULL. Each of the non-NULL entries in this array point to a NUL terminated and malloc()'d char string of the form: "name=value".
It should be noted that this memory will never be free()'d by
libpam. Once obtained by a call to
pam_getenvlist
, it is the responsibility of
the calling application to free() this memory.
It is by design, and not a coincidence, that the format and contents of the returned array matches that required for the third argument of the execle(3) function call.