PAM is designed to provide the system administrator with a great deal of flexibility in configuration of the privilege granting applications of their system. The local configuration of system security controlled by PAM is contained in one of two places: either the single system file, /etc/pam.conf , or the /etc/pam.d/ directory.
24.2.1 PAM Configuration Syntax
In this section we discuss the correct syntax of and generic options respected by entries to these files. PAM-specific tokens in the configuration file are case insensitive. The module paths, however, are case sensitive since they indicate a file's name and reflect the case dependence of typical file systems. The case-sensitivity of the arguments to any given module is defined for each module in turn .
In addition to the lines described below, there are two special characters provided for the convenience of the system administrator: comments are preceded by a " # " and extend to the next end-of-line; also, module specification lines may be extended with a " \ " escaped newline.
If the PAM authentication module (loadable link library file) is located in the default location, then it is not necessary to specify the path . In the case of Linux, the default location is /lib/security . If the module is located outside the default, then the path must be specified as:
auth required /other_path/pam_strange_module.so
126.96.36.199 Anatomy of /etc/pam.d Entries
The remaining information in this subsection was taken from the documentation of the Linux-PAM project. For more information on PAM, see The Official Linux-PAM home page. 
A general configuration line of the /etc/pam.conf file has the following form:
service-name module-type control-flag module-path args
Below, we explain the meaning of each of these tokens. The second (and more recently adopted) way of configuring Linux-PAM is via the contents of the /etc/pam.d/ directory. Once we have explained the meaning of the above tokens, we will describe this method.
service-name ” The name of the service associated with this entry. Frequently, the service name is the conventional name of the given application. For example, ftpd , rlogind and su , and so on.
module-type ” One of (currently) four types of module. The four types are as follows :
control-flag ” The control-flag is used to indicate how the PAM library will react to the success or failure of the module it is associated with. Since modules can be stacked (modules of the same type execute in series, one after another), the control-flags determine the relative importance of each module. The application is not made aware of the individual success or failure of modules listed in the /etc/pam.conf file. Instead, it receives a summary success or fail response from the Linux-PAM library. The order of execution of these modules is that of the entries in the /etc/pam.conf file; earlier entries are executed before later ones. As of Linux-PAM v0.60, this control-flag can be defined with one of two syntaxes.
The simpler (and historical) syntax for the control-flag is a single keyword defined to indicate the severity of concern associated with the success or failure of a specific module. There are four such keywords: required , requisite , sufficient and optional .
The Linux-PAM library interprets these keywords in the following manner:
The more elaborate ( newer ) syntax is much more specific and gives the administrator a great deal of control over how the user is authenticated. This form of the control flag is delimited with square brackets and consists of a series of value=action tokens:
[value1=action1 value2=action2 ...]
Here, value1 is one of the following return values:
success; open_err; symbol_err; service_err; system_err; buf_err; perm_denied; auth_err; cred_insufficient; authinfo_unavail; user_unknown; maxtries; new_authtok_reqd; acct_expired; session_err; cred_unavail; cred_expired; cred_err; no_module_data; conv_err; authtok_err; authtok_recover_err; authtok_lock_busy; authtok_disable_aging; try_again; ignore; abort; authtok_expired; module_unknown; bad_item; and default.
The last of these (default) can be used to set the action for those return values that are not explicitly defined.
The action1 can be a positive integer or one of the following tokens: ignore; ok; done; bad; die; and reset . A positive integer, J, when specified as the action, can be used to indicate that the next J modules of the current module-type will be skipped . In this way, the administrator can develop a moderately sophisticated stack of modules with a number of different paths of execution. Which path is taken can be determined by the reactions of individual modules.
Each of the four keywords: required; requisite; sufficient; and optional , have an equivalent expression in terms of the [...] syntax. They are as follows:
Just to get a feel for the power of this new syntax, here is a taste of what you can do with it. With Linux-PAM-0.63, the notion of client plug-in agents was introduced. This is something that makes it possible for PAM to support machine-machine authentication using the transport protocol inherent to the client/server application. With the [... value=action ...] control syntax, it is possible for an application to be configured to support binary prompts with compliant clients , but to gracefully fall over into an alternative authentication mode for older, legacy applications.
module-path ” The path-name of the dynamically loadable object file; the pluggable module itself. If the first character of the module path is " / " it is assumed to be a complete path. If this is not the case, the given module path is appended to the default module path: /lib/security (but see the notes above).
The arguments are a list of tokens that are passed to the module when it is invoked, much like arguments to a typical Linux shell command. Generally , valid arguments are optional and are specific to any given module. Invalid arguments are ignored by a module, however, when encountering an invalid argument, the module is required to write an error to syslog(3). For a list of generic options, see the next section.
If you wish to include spaces in an argument, you should surround that argument with square brackets. For example:
squid auth required pam_mysql.so user=passwd_query passwd=mada \ db=eminence [query=select user_name from internet_service where \ user_name=%u and password=PASSWORD(%p) and service=web_proxy]
When using this convention, you can include " [ " characters inside the string, and if you wish to have a " / " character inside the string that will survive the argument parsing, you should use " \/ ". In other words:
[..[..\]..] --> ..[..]..
24.2.2 Example System Configurations
The following is an example /etc/pam.d/login configuration file. This example had all options uncommented and is probably not usable because it stacks many conditions before allowing successful completion of the login process. Essentially all conditions can be disabled by commenting them out, except the calls to pam_pwdb.so .
188.8.131.52 PAM: Original Login Config
#%PAM-1.0 # The PAM configuration file for the login service # auth required pam_securetty.so auth required pam_nologin.so # auth required pam_dialup.so # auth optional pam_mail.so auth required pam_pwdb.so shadow md5 # account requisite pam_time.so account required pam_pwdb.so session required pam_pwdb.so # session optional pam_lastlog.so # password required pam_cracklib.so retry =3 password required pam_pwdb.so shadow md5
184.108.40.206 PAM: Login Using pam_smbpass
PAM allows use of replaceable modules. Those available on a sample system include:
$/bin/ls /lib/security pam_access.so pam_ftp.so pam_limits.so pam_ncp_auth.so pam_rhosts_auth.so pam_stress.so pam_cracklib.so pam_group.so pam_listfile.so pam_nologin.so pam_rootok.so pam_tally.so pam_deny.so pam_issue.so pam_mail.so pam_permit.so pam_securetty.so pam_time.so pam_dialup.so pam_lastlog.so pam_mkhomedir.so pam_pwdb.so pam_shells.so pam_unix.so pam_env.so pam_ldap.so pam_motd.so pam_radius.so pam_smbpass.so pam_unix_acct.so pam_wheel.so pam_unix_auth.so pam_unix_passwd.so pam_userdb.so pam_warn.so pam_unix_session.so
The following example for the login program replaces the use of the pam_pwdb.so module that uses the system password database ( /etc/passwd , /etc/shadow , /etc/group ) with the module pam_smbpass.so , which uses the Samba database which contains the Microsoft MD4 encrypted password hashes. This database is stored in either /usr/local/samba/private/smbpasswd , /etc/samba/smbpasswd , or in /etc/samba.d/smbpasswd , depending on the Samba implementation for your UNIX/Linux system. The pam_smbpass.so module is provided by Samba version 2.2.1 or later. It can be compiled by specifying the --with-pam_smbpass options when running Samba's configure script. For more information on the pam_smbpass module, see the documentation in the source/pam_smbpass directory of the Samba source distribution.
#%PAM-1.0 # The PAM configuration file for the login service # auth required pam_smbpass.so nodelay account required pam_smbpass.so nodelay session required pam_smbpass.so nodelay password required pam_smbpass.so nodelay
The following is the PAM configuration file for a particular Linux system. The default condition uses pam_pwdb.so .
#%PAM-1.0 # The PAM configuration file for the samba service # auth required pam_pwdb.so nullok nodelay shadow audit account required pam_pwdb.so audit nodelay session required pam_pwdb.so nodelay password required pam_pwdb.so shadow md5
In the following example, the decision has been made to use the smbpasswd database even for basic Samba authentication. Such a decision could also be made for the passwd program and would thus allow the smbpasswd passwords to be changed using the passwd program:
#%PAM-1.0 # The PAM configuration file for the samba service # auth required pam_smbpass.so nodelay account required pam_pwdb.so audit nodelay session required pam_pwdb.so nodelay password required pam_smbpass.so nodelay smbconf=/etc/samba.d/smb.conf
24.2.3 smb.conf PAM Configuration
There is an option in smb.conf called obey pam restrictions . The following is from the online help for this option in SWAT;
When Samba is configured to enable PAM support (i.e., --with-pam ), this parameter will control whether or not Samba should obey PAM's account and session management directives. The default behavior is to use PAM for cleartext authentication only and to ignore any account or session management. Samba always ignores PAM for authentication in the case of encrypt passwords = yes. The reason is that PAM modules cannot support the challenge/response authentication mechanism needed in the presence of SMB password encryption.
Default: obey pam restrictions = no
24.2.4 Remote CIFS Authentication Using winbindd .so
All operating systems depend on the provision of users credentials acceptable to the platform. UNIX requires the provision of a user identifier (UID) as well as a group identifier (GID). These are both simple integer type numbers that are obtained from a password backend such as /etc/passwd .
Users and groups on a Windows NT server are assigned a relative ID (RID) which is unique for the domain when the user or group is created. To convert the Windows NT user or group into a UNIX user or group, a mapping between RIDs and UNIX user and group IDs is required. This is one of the jobs that winbind performs.
As Winbind users and groups are resolved from a server, user and group IDs are allocated from a specified range. This is done on a first come, first served basis, although all existing users and groups will be mapped as soon as a client performs a user or group enumeration command. The allocated UNIX IDs are stored in a database file under the Samba lock directory and will be remembered .
The astute administrator will realize from this that the combination of pam_smbpass.so , winbindd and a distributed passdb backend , such as ldap , will allow the establishment of a centrally managed, distributed user/password database that can also be used by all PAM-aware (e.g., Linux) programs and applications. This arrangement can have particularly potent advantages compared with the use of Microsoft Active Directory Service (ADS) in so far as the reduction of wide area network authentication traffic.
24.2.5 Password Synchronization Using pam_smbpass.so
pam_smbpass is a PAM module that can be used on conforming systems to keep the smbpasswd (Samba password) database in sync with the UNIX password file. PAM (Pluggable Authentication Modules) is an API supported under some UNIX operating systems, such as Solaris, HPUX and Linux, that provides a generic interface to authentication mechanisms.
This module authenticates a local smbpasswd user database. If you require support for authenticating against a remote SMB server, or if you are concerned about the presence of SUID root binaries on your system, it is recommended that you use pam_winbind instead.
Options recognized by this module are shown in Table 24.1.
Table 24.1. Options recognized by pam_smbpass
The following are examples of the use of pam_smbpass.so in the format of Linux /etc/pam.d/ files structure. Those wishing to implement this tool on other platforms will need to adapt this appropriately.
220.127.116.11 Password Synchronization Configuration
A sample PAM configuration that shows the use of pam_smbpass to make sure private/smbpasswd is kept in sync when /etc/passwd (/etc/shadow) is changed. Useful when an expired password might be changed by an application (such as ssh ).
#%PAM-1.0 # password-sync # auth requisite pam_nologin.so auth required pam_unix.so account required pam_unix.so password requisite pam_cracklib.so retry=3 password requisite pam_unix.so shadow md5 use_authtok try_first_pass password required pam_smbpass.so nullok use_authtok try_first_pass session required pam_unix.so
18.104.22.168 Password Migration Configuration
A sample PAM configuration that shows the use of pam_smbpass to migrate from plaintext to encrypted passwords for Samba. Unlike other methods , this can be used for users who have never connected to Samba shares: password migration takes place when users ftp in, login using ssh , pop their mail, and so on.
#%PAM-1.0 # password-migration # auth requisite pam_nologin.so # pam_smbpass is called IF pam_unix succeeds. auth requisite pam_unix.so auth optional pam_smbpass.so migrate account required pam_unix.so password requisite pam_cracklib.so retry=3 password requisite pam_unix.so shadow md5 use_authtok try_first_pass password optional pam_smbpass.so nullok use_authtok try_first_pass session required pam_unix.so
22.214.171.124 Mature Password Configuration
A sample PAM configuration for a mature smbpasswd installation. private/smbpasswd is fully populated , and we consider it an error if the SMB password does not exist or does not match the UNIX password.
#%PAM-1.0 # password-mature # auth requisite pam_nologin.so auth required pam_unix.so account required pam_unix.so password requisite pam_cracklib.so retry=3 password requisite pam_unix.so shadow md5 use_authtok try_first_pass password required pam_smbpass.so use_authtok use_first_pass session required pam_unix.so
126.96.36.199 Kerberos Password Integration Configuration
A sample PAM configuration that shows pam_smbpass used together with pam_krb5 . This could be useful on a Samba PDC that is also a member of a Kerberos realm.
#%PAM-1.0 # kdc-pdc # auth requisite pam_nologin.so auth requisite pam_krb5.so auth optional pam_smbpass.so migrate account required pam_krb5.so password requisite pam_cracklib.so retry=3 password optional pam_smbpass.so nullok use_authtok try_first_pass password required pam_krb5.so use_authtok try_first_pass session required pam_krb5.so