2.2. Other functions provided by `libpam`
Prev | Chapter 2. What can be expected by the module | Next

## 2.2. Other functions provided by `libpam`

### 2.2.1. Strings describing PAM error codes

    #include <security/pam_appl.h>

`const char *pam_strerror(` | pamh, |
| errnum`)`; |

`pam_handle_t *pamh`;
`int errnum`;

#### 2.2.1.1. DESCRIPTION

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.

#### 2.2.1.2. RETURN VALUES

This function returns always a pointer to a string.

### 2.2.2. Request a delay on failure

    #include <security/pam_appl.h>

`int pam_fail_delay(` | pamh, |
| usec`)`; |

`pam_handle_t *pamh`;
`unsigned int usec`;

#### 2.2.2.1. DESCRIPTION

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.

#### 2.2.2.2. RETURN VALUES

PAM_SUCCESS

  Delay was successful adjusted.

PAM_SYSTEM_ERR

  A NULL pointer was submitted as PAM handle.

Prev | Up | Next
2.1. Getting and setting PAM_ITEMs and data | Home | Chapter 3. What is expected of a module