add 'html' to release target so as to include output/devel/*
[Samba.git] / docs / howto / PAM.xml
blob7e5911bb19e93eee8fbfa144d2acd6ea18e5ec46
1 <chapter id="pam">
2 <chapterinfo>
3         &author.jht;
4         <author>
5                 <firstname>Stephen</firstname><surname>Langasek</surname>
6                 <affiliation>
7                         <address><email>vorlon@netexpress.net</email></address>
8                 </affiliation>
9         </author>
10     <pubdate>May 31, 2003</pubdate>
11 </chapterinfo>
13 <title>PAM-Based Distributed Authentication</title>
15 <para>
16 This chapter should help you to deploy Winbind-based authentication on any PAM-enabled
17 UNIX/Linux system. Winbind can be used to enable User-Level application access authentication
18 from any MS Windows NT Domain, MS Windows 200x Active Directory-based
19 domain, or any Samba-based domain environment. It will also help you to configure PAM-based local host access
20 controls that are appropriate to your Samba configuration.
21 </para>
23 <para>
24 In addition to knowing how to configure Winbind into PAM, you will learn generic PAM management
25 possibilities and in particular how to deploy tools like <filename>pam_smbpass.so</filename> to your advantage.
26 </para>
28 <note><para>
29 The use of Winbind requires more than PAM configuration alone.
30 Please refer to <link linkend="winbind">Winbind: Use of Domain Accounts</link>, for further information regarding Winbind.
31 </para></note>
33 <sect1>
34 <title>Features and Benefits</title>
36 <para>
37 A number of UNIX systems (e.g., Sun Solaris), as well as the xxxxBSD family and Linux,
38 now utilize the Pluggable Authentication Modules (PAM) facility to provide all authentication, 
39 authorization and resource control services. Prior to the introduction of PAM, a decision
40 to use an alternative to the system password database (<filename>/etc/passwd</filename>) 
41 would require the provision of alternatives for all programs that provide security services.
42 Such a choice would involve provision of alternatives to programs such as: <command>login</command>, 
43 <command>passwd</command>, <command>chown</command>, and so on.
44 </para>
46 <para>
47 PAM provides a mechanism that disconnects these security programs from the underlying
48 authentication/authorization infrastructure. PAM is configured by making appropriate modifications to  one file
49 <filename>/etc/pam.conf</filename> (Solaris), or by editing individual control files that are
50 located in <filename>/etc/pam.d</filename>.
51 </para>
53 <para>
54 On PAM-enabled UNIX/Linux systems, it is an easy matter to configure the system to use any
55 authentication backend so long as the appropriate dynamically loadable library modules
56 are available for it. The backend may be local to the system, or may be centralized on a
57 remote server.
58 </para>
60 <para>
61 PAM support modules are available for:
62 </para>
64 <variablelist>
65         <varlistentry><term><filename>/etc/passwd</filename></term><listitem>
66                 <para>
67                 There are several PAM modules that interact with this standard UNIX user
68                 database. The most common are called: <filename>pam_unix.so</filename>, <filename>pam_unix2.so</filename>, <filename>pam_pwdb.so</filename>
69                 and <filename>pam_userdb.so</filename>.
70                 </para>
71         </listitem></varlistentry>
73         <varlistentry><term>Kerberos</term><listitem>
74                 <para>
75                 The <filename>pam_krb5.so</filename> module allows the use of any Kerberos compliant server.
76                 This tool is used to access MIT Kerberos, Heimdal Kerberos, and potentially
77                 Microsoft Active Directory (if enabled).
78                 </para>
79         </listitem></varlistentry>
81         <varlistentry><term>LDAP</term><listitem>
82                 <para>
83                 The <filename>pam_ldap.so</filename> module allows the use of any LDAP v2 or v3 compatible backend
84                 server. Commonly used LDAP backend servers include: OpenLDAP v2.0 and v2.1,
85                 Sun ONE iDentity server, Novell eDirectory server, Microsoft Active Directory.
86                 </para>
87         </listitem></varlistentry>
89         <varlistentry><term>NetWare Bindery</term><listitem>
90                 <para>
91                 The <filename>pam_ncp_auth.so</filename> module allows authentication off any bindery-enabled
92                 NetWare Core Protocol-based server.
93                 </para>
94         </listitem></varlistentry>
96         <varlistentry><term>SMB Password</term><listitem>
97                 <para>
98                 This module, called <filename>pam_smbpass.so</filename>, will allow user authentication off
99                 the passdb backend that is configured in the Samba &smb.conf; file.
100                 </para>
101         </listitem></varlistentry>
103         <varlistentry><term>SMB Server</term><listitem>
104                 <para>
105                 The <filename>pam_smb_auth.so</filename> module is the original MS Windows networking authentication
106                 tool. This module has been somewhat outdated by the Winbind module.
107                 </para>
108         </listitem></varlistentry>
110         <varlistentry><term>Winbind</term><listitem>
111                 <para>
112                 The <filename>pam_winbind.so</filename> module allows Samba to obtain authentication from any
113                 MS Windows Domain Controller. It can just as easily be used to authenticate
114                 users for access to any PAM-enabled application.
115                 </para>
116         </listitem></varlistentry>
118         <varlistentry><term>RADIUS</term><listitem>
119                 <para>
120                 There is a PAM RADIUS (Remote Access Dial-In User Service) authentication
121                 module. In most cases, administrators will need to locate the source code
122                 for this tool and compile and install it themselves. RADIUS protocols are
123                 used by many routers and terminal servers.
124                 </para>
125         </listitem></varlistentry>
126 </variablelist>
128 <para>
129 Of the above, Samba provides the <filename>pam_smbpasswd.so</filename> and the <filename>pam_winbind.so</filename> modules alone.
130 </para>
132 <para>
133 Once configured, these permit a remarkable level of flexibility in the location and use
134 of distributed Samba Domain Controllers that can provide wide area network bandwidth
135 efficient authentication services for PAM-capable systems. In effect, this allows the
136 deployment of centrally managed and maintained distributed authentication from a
137 single-user account database.
138 </para>
140 </sect1>
142 <sect1>
143 <title>Technical Discussion</title>
145 <para>
146 PAM is designed to provide the system administrator with a great deal of flexibility in
147 configuration of the privilege granting applications of their system. The local
148 configuration of system security controlled by PAM is contained in one of two places:
149 either the single system file, <filename>/etc/pam.conf</filename>, or the
150 <filename>/etc/pam.d/</filename> directory.
151 </para>
153 <sect2>
154 <title>PAM Configuration Syntax</title>
156 <para>
157 In this section we discuss the correct syntax of and generic options respected by entries to these files.
158 PAM-specific tokens in the configuration file are case insensitive. The module paths, however, are case
159 sensitive since they indicate a file's name and reflect the case
160 dependence of typical file systems.
161 The case-sensitivity of the arguments to any given module is defined for each module in turn.
162 </para>
164 <para>
165 In addition to the lines described below, there are two special characters provided for the convenience
166 of the system administrator: comments are preceded by a <quote>#</quote> and extend to the next end-of-line; also,
167 module specification lines may be extended with a <quote>\</quote> escaped newline. 
168 </para>
170 <para>
171 If the PAM authentication module (loadable link library file) is located in the
172 default location, then it is not necessary to specify the path. In the case of
173 Linux, the default location is <filename>/lib/security</filename>. If the module
174 is located outside the default, then the path must be specified as:
175 </para>
177 <para>
178 <programlisting>
179 auth  required  /other_path/pam_strange_module.so
180 </programlisting>
181 </para>
183 <sect3>
184 <title>Anatomy of <filename>/etc/pam.d</filename> Entries</title>
186 <para>
187 The remaining information in this subsection was taken from the documentation of the Linux-PAM
188 project. For more information on PAM, see 
189 <ulink url="http://ftp.kernel.org/pub/linux/libs/pam/">The Official Linux-PAM home page.</ulink>
190 </para>
192 <para>
193 A general configuration line of the <filename>/etc/pam.conf</filename> file has the following form:
194 </para>
196 <para>
197 <programlisting>
198 service-name   module-type   control-flag   module-path   args
199 </programlisting>
200 </para>
202 <para>
203 Below, we explain the meaning of each of these tokens. The second (and more recently adopted)
204 way of configuring Linux-PAM is via the contents of the <filename>/etc/pam.d/</filename> directory.
205 Once we have explained the meaning of the above tokens, we will describe this method.
206 </para>
208 <variablelist>
209         <varlistentry><term>service-name</term><listitem>
210                 <para>
211                 The name of the service associated with this entry. Frequently, the service name is the conventional
212                 name of the given application. For example, <command>ftpd</command>, <command>rlogind</command> and
213                 <command>su</command>, and so on.
214                 </para>
216                 <para>
217                 There is a special service-name reserved for defining a default authentication mechanism. It has
218                 the name <parameter>OTHER</parameter> and may be specified in either lower- or upper-case characters.
219                 Note, when there is a module specified for a named service, the <parameter>OTHER</parameter>
220                 entries are ignored.
221                 </para>
222                 </listitem>
223         </varlistentry>
225         <varlistentry><term>module-type</term><listitem>
226                 <para>
227                 One of (currently) four types of module. The four types are as follows:
228                 </para>
230                 <itemizedlist>
231                         <listitem><para>
232                         <parameter>auth:</parameter> This module type provides two aspects of authenticating the user.
233                         It establishes that the user is who he claims to be by instructing the application
234                         to prompt the user for a password or other means of identification. Secondly, the module can
235                         grant group membership (independently of the <filename>/etc/groups</filename> file discussed
236                         above) or other privileges through its credential granting properties.
237                         </para></listitem>
239                         <listitem><para>
240                         <parameter>account:</parameter> This module performs non-authentication-based account management.
241                         It is typically used to restrict/permit access to a service based on the time of day, currently
242                         available system resources (maximum number of users) or perhaps the location of the applicant
243                         user <quote>root</quote> login only on the console.
244                         </para></listitem>
246                         <listitem><para>
247                         <parameter>session:</parameter> Primarily, this module is associated with doing things that need
248                         to be done for the user before and after they can be given service. Such things include the logging
249                         of information concerning the opening and closing of some data exchange with a user, mounting
250                         directories, and so on.
251                         </para></listitem>
253                         <listitem><para>
254                         <parameter>password:</parameter> This last module type is required for updating the authentication
255                         token associated with the user. Typically, there is one module for each <quote>challenge/response</quote>
256                         -based authentication <parameter>(auth)</parameter> module type.
257                         </para></listitem>
258                 </itemizedlist>
259                 </listitem>
260         </varlistentry>
262         <varlistentry><term>control-flag</term><listitem>
263                 <para>
264                 The control-flag is used to indicate how the PAM library will react to the success or failure of the
265                 module it is associated with. Since modules can be stacked (modules of the same type execute in series,
266                 one after another), the control-flags determine the relative importance of each module. The application
267                 is not made aware of the individual success or failure of modules listed in the
268                 <filename>/etc/pam.conf</filename> file. Instead, it receives a summary success or fail response from
269                 the Linux-PAM library. The order of execution of these modules is that of the entries in the
270                 <filename>/etc/pam.conf</filename> file; earlier entries are executed before later ones.
271                 As of Linux-PAM v0.60, this control-flag can be defined with one of two syntaxes.
272                 </para>
274                 <para>
275                 The simpler (and historical) syntax for the control-flag is a single keyword defined to indicate the
276                 severity of concern associated with the success or failure of a specific module. There are four such
277                 keywords: <parameter>required, requisite, sufficient and optional</parameter>.
278                 </para>
280                 <para>
281                 The Linux-PAM library interprets these keywords in the following manner:
282                 </para>
284                 <itemizedlist>
285                         <listitem><para>
286                         <parameter>required:</parameter> This indicates that the success of the module is required for the
287                         module-type facility to succeed. Failure of this module will not be apparent to the user until all
288                         of the remaining modules (of the same module-type) have been executed.
289                         </para></listitem>
291                         <listitem><para>
292                         <parameter>requisite:</parameter> Like required, however, in the case that such a module returns a
293                         failure, control is directly returned to the application. The return value is that associated with
294                         the first required or requisite module to fail. This flag can be used to protect against the
295                         possibility of a user getting the opportunity to enter a password over an unsafe medium. It is
296                         conceivable that such behavior might inform an attacker of valid accounts on a system. This
297                         possibility should be weighed against the not insignificant concerns of exposing a sensitive
298                         password in a hostile environment.
299                         </para></listitem>
301                         <listitem><para>
302                         <parameter>sufficient:</parameter> The success of this module is deemed <parameter>sufficient</parameter> to satisfy
303                         the Linux-PAM library that this module-type has succeeded in its purpose. In the event that no
304                         previous required module has failed, no more <quote>stacked</quote> modules of this type are invoked.
305                         (In this case, subsequent required modules are not invoked). A failure of this module is not deemed
306                         as fatal to satisfying the application that this module-type has succeeded.
307                         </para></listitem>
309                         <listitem><para>
310                         <parameter>optional:</parameter> As its name suggests, this control-flag marks the module as not
311                         being critical to the success or failure of the user's application for service. In general,
312                         Linux-PAM ignores such a module when determining if the module stack will succeed or fail.
313                         However, in the absence of any definite successes or failures of previous or subsequent stacked
314                         modules, this module will determine the nature of the response to the application. One example of
315                         this latter case, is when the other modules return something like PAM_IGNORE.
316                         </para></listitem>
317                 </itemizedlist>
319                 <para>
320                 The more elaborate (newer) syntax is much more specific and gives the administrator a great deal of control
321                 over how the user is authenticated. This form of the control flag is delimited with square brackets and
322                 consists of a series of <parameter>value=action</parameter> tokens:
323                 </para>
325 <para><programlisting>
326 [value1=action1 value2=action2 ...]
327 </programlisting></para>
329                 <para>
330                 Here, <parameter>value1</parameter> is one of the following return values:
331 <screen>
332 <parameter>success; open_err; symbol_err; service_err; system_err; buf_err;</parameter>
333 <parameter>perm_denied; auth_err; cred_insufficient; authinfo_unavail;</parameter>
334 <parameter>user_unknown; maxtries; new_authtok_reqd; acct_expired; session_err;</parameter>
335 <parameter>cred_unavail; cred_expired; cred_err; no_module_data; conv_err;</parameter>
336 <parameter>authtok_err; authtok_recover_err; authtok_lock_busy;</parameter>
337 <parameter>authtok_disable_aging; try_again; ignore; abort; authtok_expired;</parameter>
338 <parameter>module_unknown; bad_item;</parameter> and <parameter>default</parameter>.
339 </screen>
340 </para>
342                 <para>
343                 The last of these <parameter>(default)</parameter> can be used to set the action for those return values that are not explicitly defined.
344                 </para>
346                 <para>
347                 The <parameter>action1</parameter> can be a positive integer or one of the following tokens: 
348                 <parameter>ignore; ok; done; bad; die;</parameter> and <parameter>reset</parameter>.
349                 A positive integer, J, when specified as the action, can be used to indicate that the next J modules of the
350                 current module-type will be skipped. In this way, the administrator can develop a moderately sophisticated
351                 stack of modules with a number of different paths of execution. Which path is taken can be determined by the
352                 reactions of individual modules.
353                 </para>
355                 <itemizedlist>
356                         <listitem><para>
357                         <parameter>ignore:</parameter> When used with a stack of modules, the module's return status will not
358                         contribute to the return code the application obtains.
359                         </para></listitem>
361                         <listitem><para>
362                         <parameter>bad:</parameter> This action indicates that the return code should be thought of as indicative
363                         of the module failing. If this module is the first in the stack to fail, its status value will be used
364                         for that of the whole stack.
365                         </para></listitem>
367                         <listitem><para>
368                         <parameter>die:</parameter> Equivalent to bad with the side effect of terminating the module stack and
369                         PAM immediately returning to the application.
370                         </para></listitem>
372                         <listitem><para>
373                         <parameter>ok:</parameter> This tells PAM that the administrator thinks this return code should
374                         contribute directly to the return code of the full stack of modules. In other words, if the former
375                         state of the stack would lead to a return of PAM_SUCCESS, the module's return code will override
376                         this value. Note, if the former state of the stack holds some value that is indicative of a modules
377                         failure, this <parameter>ok</parameter> value will not be used to override that value.
378                         </para></listitem>
380                         <listitem><para>
381                         <parameter>done:</parameter> Equivalent to <parameter>ok</parameter> with the side effect of terminating the module stack and
382                         PAM immediately returning to the application.
383                         </para></listitem>
385                         <listitem><para>
386                         <parameter>reset:</parameter> Clears all memory of the state of the module stack and starts again with
387                         the next stacked module.
388                         </para></listitem>
389                 </itemizedlist>
391                 <para>
392                 Each of the four keywords: <parameter>required; requisite; sufficient;</parameter> and <parameter>optional</parameter>,
393                 have an equivalent expression in terms of the [...] syntax. They are as follows:
394                 </para>
396                 <para>
397                 <itemizedlist>
398                         <listitem><para>
399                         <parameter>required</parameter> is equivalent to <parameter>[success=ok new_authtok_reqd=ok ignore=ignore default=bad]</parameter>.
400                         </para></listitem>
402                         <listitem><para>
403                         <parameter>requisite</parameter> is equivalent to <parameter>[success=ok new_authtok_reqd=ok ignore=ignore default=die]</parameter>.
404                         </para></listitem>
406                         <listitem><para>
407                                         <parameter>sufficient</parameter> is equivalent to <parameter>[success=done new_authtok_reqd=done<?latex \linebreak ?> default=ignore]</parameter>.
408                         </para></listitem>
410                         <listitem><para>
411                         <parameter>optional</parameter> is equivalent to <parameter>[success=ok new_authtok_reqd=ok default=ignore]</parameter>.
412                         </para></listitem>
413                 </itemizedlist>
414                 </para>
416                 <para>
417                 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,
418                 the notion of client plug-in agents was introduced. This is something that makes it possible for PAM to support
419                 machine-machine authentication using the transport protocol inherent to the client/server application. With the
420                 <parameter>[ ... value=action ... ]</parameter> control syntax, it is possible for an application to be configured
421                 to support binary prompts with compliant clients, but to gracefully fall over into an alternative authentication
422                 mode for older, legacy applications.
423                 </para>
424                 </listitem>
425         </varlistentry>
427         <varlistentry><term>module-path</term><listitem>
428                 <para>
429                 The path-name of the dynamically loadable object file; the pluggable module itself. If the first character of the
430                 module path is <quote>/</quote>, it is assumed to be a complete path. If this is not the case, the given module path is appended
431                 to the default module path: <filename>/lib/security</filename> (but see the notes above).
432                 </para>
434                 <para>
435                 The arguments are a list of tokens that are passed to the module when it is invoked, much like arguments to a typical
436                 Linux shell command. Generally, valid arguments are optional and are specific to any given module. Invalid arguments
437                 are ignored by a module, however, when encountering an invalid argument, the module is required to write an error
438                 to syslog(3). For a list of generic options, see the next section.
439                 </para>
441                 <para>
442                 If you wish to include spaces in an argument, you should surround that argument with square brackets. For example:
443                 </para>
445 <para><programlisting>
446 squid auth required pam_mysql.so user=passwd_query passwd=mada \
447 db=eminence [query=select user_name from internet_service where \
448 user_name=<quote>%u</quote> and password=PASSWORD(<quote>%p</quote>) and service=<quote>web_proxy</quote>]
449 </programlisting></para>
451                 <para>
452                 When using this convention, you can include <quote>[</quote> characters inside the string, and if you wish to have a <quote>]</quote>
453                 character inside the string that will survive the argument parsing, you should use <quote>\[</quote>. In other words:
454                 </para>
456 <para><programlisting>
457 [..[..\]..]    -->   ..[..]..
458 </programlisting></para>
460                 <para>
461                 Any line in one of the configuration files that is not formatted correctly will generally tend (erring on the
462                 side of caution) to make the authentication process fail. A corresponding error is written to the system log files
463                 with a call to syslog(3). 
464                 </para>
465                 </listitem>
466         </varlistentry>
467 </variablelist>
469 </sect3>
471 </sect2>
473 <sect2>
474 <title>Example System Configurations</title>
476 <para>
477 The following is an example <filename>/etc/pam.d/login</filename> configuration file. 
478 This example had all options uncommented and is probably not usable 
479 because it stacks many conditions before allowing successful completion 
480 of the login process. Essentially all conditions can be disabled 
481 by commenting them out, except the calls to <filename>pam_pwdb.so</filename>.
482 </para>
484 <sect3>
485 <title>PAM: Original Login Config</title>
487 <para>
488         <smbfile name="pam-login-default">
489         <programlisting>
490 #%PAM-1.0
491 # The PAM configuration file for the <quote>login</quote> service
493 auth         required    pam_securetty.so
494 auth         required    pam_nologin.so
495 # auth       required    pam_dialup.so
496 # auth       optional    pam_mail.so
497 auth         required    pam_pwdb.so shadow md5
498 # account    requisite   pam_time.so
499 account      required    pam_pwdb.so
500 session      required    pam_pwdb.so
501 # session    optional    pam_lastlog.so
502 # password   required    pam_cracklib.so retry=3
503 password     required    pam_pwdb.so shadow md5
504 </programlisting>
505 </smbfile></para>
507 </sect3>
509 <sect3>
510 <title>PAM: Login Using <filename>pam_smbpass</filename></title>
512 <para>
513 PAM allows use of replaceable modules. Those available on a sample system include:
514 </para>
516 <para><prompt>$</prompt><userinput>/bin/ls /lib/security</userinput>
517 <programlisting>
518 pam_access.so    pam_ftp.so          pam_limits.so     
519 pam_ncp_auth.so  pam_rhosts_auth.so  pam_stress.so     
520 pam_cracklib.so  pam_group.so        pam_listfile.so   
521 pam_nologin.so   pam_rootok.so       pam_tally.so      
522 pam_deny.so      pam_issue.so        pam_mail.so       
523 pam_permit.so    pam_securetty.so    pam_time.so       
524 pam_dialup.so    pam_lastlog.so      pam_mkhomedir.so  
525 pam_pwdb.so      pam_shells.so       pam_unix.so       
526 pam_env.so       pam_ldap.so         pam_motd.so       
527 pam_radius.so    pam_smbpass.so      pam_unix_acct.so  
528 pam_wheel.so     pam_unix_auth.so    pam_unix_passwd.so
529 pam_userdb.so    pam_warn.so         pam_unix_session.so
530 </programlisting></para>
532 <para>
533 The following example for the login program replaces the use of 
534 the <filename>pam_pwdb.so</filename> module that uses the system 
535 password database (<filename>/etc/passwd</filename>,
536 <filename>/etc/shadow</filename>, <filename>/etc/group</filename>) with 
537 the module <filename>pam_smbpass.so</filename>, which uses the Samba 
538 database which contains the Microsoft MD4 encrypted password 
539 hashes. This database is stored in either 
540 <filename>/usr/local/samba/private/smbpasswd</filename>, 
541 <filename>/etc/samba/smbpasswd</filename>, or in 
542 <filename>/etc/samba.d/smbpasswd</filename>, depending on the 
543 Samba implementation for your UNIX/Linux system. The 
544 <filename>pam_smbpass.so</filename> module is provided by 
545 Samba version 2.2.1 or later. It can be compiled by specifying the 
546 <option>--with-pam_smbpass</option> options when running Samba's
547 <command>configure</command> script. For more information
548 on the <filename>pam_smbpass</filename> module, see the documentation
549 in the <filename>source/pam_smbpass</filename> directory of the Samba 
550 source distribution.
551 </para>
553 <para>
554         <smbfile name="pam-login-smbpass">
555         <programlisting>
556 #%PAM-1.0
557 # The PAM configuration file for the <quote>login</quote> service
559 auth        required    pam_smbpass.so nodelay
560 account     required    pam_smbpass.so nodelay
561 session     required    pam_smbpass.so nodelay
562 password    required    pam_smbpass.so nodelay
563 </programlisting></smbfile></para>
565 <para>
566 The following is the PAM configuration file for a particular 
567 Linux system. The default condition uses <filename>pam_pwdb.so</filename>.
568 </para>
570 <para>
571         <smbfile name="pam-samba-default">
572         <programlisting>
573 #%PAM-1.0
574 # The PAM configuration file for the <quote>samba</quote> service
576 auth       required     pam_pwdb.so nullok nodelay shadow audit
577 account    required     pam_pwdb.so audit nodelay
578 session    required     pam_pwdb.so nodelay
579 password   required     pam_pwdb.so shadow md5
580 </programlisting></smbfile></para>
582 <para>
583 In the following example, the decision has been made to use the 
584 <command>smbpasswd</command> database even for basic Samba authentication. Such a 
585 decision could also be made for the <command>passwd</command> program and would 
586 thus allow the <command>smbpasswd</command> passwords to be changed using the
587 <command>passwd</command> program:
588 </para>
590 <para><smbfile name="pam-samba-smbpass">
591                 <programlisting>
592 #%PAM-1.0
593 # The PAM configuration file for the <quote>samba</quote> service
595 auth       required     pam_smbpass.so nodelay
596 account    required     pam_pwdb.so audit nodelay
597 session    required     pam_pwdb.so nodelay
598 password   required     pam_smbpass.so nodelay smbconf=/etc/samba.d/smb.conf
599 </programlisting>
600 </smbfile></para>
602 <note><para>PAM allows stacking of authentication mechanisms. It is 
603 also possible to pass information obtained within one PAM module through 
604 to the next module in the PAM stack. Please refer to the documentation for 
605 your particular system implementation for details regarding the specific 
606 capabilities of PAM in this environment. Some Linux implementations also 
607 provide the <filename>pam_stack.so</filename> module that allows all 
608 authentication to be configured in a single central file. The 
609 <filename>pam_stack.so</filename> method has some devoted followers 
610 on the basis that it allows for easier administration. As with all issues in 
611 life though, every decision makes trade-offs, so you may want to examine the 
612 PAM documentation for further helpful information.
613 </para></note>
615 </sect3>
617 </sect2>
619 <sect2>
620 <title>&smb.conf; PAM Configuration</title>
622 <para>
623         There is an option in &smb.conf; called <smbconfoption><name>obey pam restrictions</name></smbconfoption>.
624 The following is from the online help for this option in SWAT;
625 </para>
627 <para>
628 When Samba is configured to enable PAM support (i.e., <option>--with-pam</option>), this parameter will 
629 control whether or not Samba should obey PAM's account and session management directives. The default behavior 
630 is to use PAM for clear-text authentication only and to ignore any account or session management. Samba always 
631 ignores PAM for authentication in the case of <smbconfoption><name>encrypt passwords</name><value>yes</value></smbconfoption>. 
632 The reason is that PAM modules cannot support the challenge/response authentication mechanism needed in the presence of SMB 
633 password encryption. 
634 </para>
636 <para>Default: <smbconfoption><name>obey pam restrictions</name><value>no</value></smbconfoption></para>
638 </sect2>
640 <sect2>
641 <title>Remote CIFS Authentication Using <filename>winbindd.so</filename></title>
643 <para>
644 All operating systems depend on the provision of users credentials acceptable to the platform.
645 UNIX requires the provision of a user identifier (UID) as well as a group identifier (GID).
646 These are both simple integer type numbers that are obtained from a password backend such
647 as <filename>/etc/passwd</filename>.
648 </para>
650 <para>
651 Users and groups on a Windows NT server are assigned a relative ID (RID) which is unique for
652 the domain when the user or group is created. To convert the Windows NT user or group into
653 a  UNIX user or group, a mapping between RIDs and UNIX user and group IDs is required. This
654 is one of the jobs that winbind performs.
655 </para>
657 <para>
658 As Winbind users and groups are resolved from a server, user and group IDs are allocated
659 from a specified range. This is done on a first come, first served basis, although all
660 existing users and groups will be mapped as soon as a client performs a user or  group 
661 enumeration command. The allocated UNIX IDs are stored in a database file under the Samba
662 lock directory and will be remembered.
663 </para>
665 <para>
666 The astute administrator will realize from this that the combination of <filename>pam_smbpass.so</filename>, 
667 <command>winbindd</command> and a distributed <smbconfoption><name>passdb backend</name><value></value></smbconfoption>,
668 such as <parameter>ldap</parameter>, will allow the establishment of a centrally managed, distributed user/password
669 database that can also be used by all PAM-aware (e.g., Linux) programs and applications. This arrangement can have
670 particularly potent advantages compared with the use of Microsoft Active Directory Service (ADS) in so far as
671 the reduction of wide area network authentication traffic.
672 </para>
674 <warning><para>
675 The RID to UNIX ID database is the only location where the user and group  mappings are 
676 stored by <command>winbindd</command>. If this file is deleted or corrupted, there is no way for <command>winbindd</command>
677 to determine which user and group IDs correspond to Windows NT user and group RIDs.
678 </para></warning>
680 </sect2>
682 <sect2>
683 <title>Password Synchronization Using <filename>pam_smbpass.so</filename></title>
685 <para>
686 <filename>pam_smbpass</filename> is a PAM module that can be used on conforming systems to
687 keep the <filename>smbpasswd</filename> (Samba password) database in sync with the UNIX
688 password file. PAM (Pluggable Authentication Modules) is an API supported
689 under some UNIX operating systems, such as Solaris, HPUX and Linux, that provides a
690 generic interface to authentication mechanisms.
691 </para>
693 <para>
694 This module authenticates a local <filename>smbpasswd</filename> user database. If you require
695 support for authenticating against a remote SMB server, or if you are
696 concerned about the presence of SUID root binaries on your system, it is
697 recommended that you use <filename>pam_winbind</filename> instead.
698 </para>
700 <para>
701 Options recognized by this module are shown in <link linkend="smbpassoptions">next table</link>.
702 <table frame="all" id="smbpassoptions">
703         <title>Options recognized by <parameter>pam_smbpass</parameter></title>
704         <tgroup cols="2" align="left">
705                 <colspec align="left"/>
706                 <colspec align="justify" colwidth="1*"/>
707         <tbody>
708                 <row><entry>debug</entry><entry>log more debugging info.</entry></row>
709                 <row><entry>audit</entry><entry>like debug, but also logs unknown usernames.</entry></row>
710                 <row><entry>use_first_pass</entry><entry>do not prompt the user for passwords; take them from PAM_ items instead.</entry></row>
711                 <row><entry>try_first_pass</entry><entry>try to get the password from a previous PAM module fall back to prompting the user.</entry></row>
712                 <row><entry>use_authtok</entry>
713                         <entry>like try_first_pass, but *fail* if the new PAM_AUTHTOK has not been previously set (intended for stacking password modules only).</entry></row>
714                 <row><entry>not_set_pass</entry><entry>do not make passwords used by this module available to other modules.</entry></row>
715                 <row><entry>nodelay</entry><entry>do not insert ~1 second delays on authentication failure.</entry></row>
716                 <row><entry>nullok</entry><entry>null passwords are allowed.</entry></row>
717                 <row><entry>nonull</entry><entry>null passwords are not allowed. Used to override the Samba configuration.</entry></row>
718                 <row><entry>migrate</entry><entry>only meaningful in an <quote>auth</quote> context; used to update smbpasswd file with a password used for successful authentication.</entry></row>
719                 <row><entry>smbconf=<replaceable>file</replaceable></entry><entry>specify an alternate path to the &smb.conf; file.</entry></row>
720         </tbody>
721 </tgroup>
722 </table>
723 </para>
725 <para>
726 The following are examples of the use of <filename>pam_smbpass.so</filename> in the format of Linux
727 <filename>/etc/pam.d/</filename> files structure. Those wishing to implement this
728 tool on other platforms will need to adapt this appropriately.
729 </para>
731 <sect3>
732 <title>Password Synchronization Configuration</title>
734 <para>
735 A sample PAM configuration that shows the use of pam_smbpass to make
736 sure <filename>private/smbpasswd</filename> is kept in sync when <filename>/etc/passwd (/etc/shadow)</filename>
737 is changed. Useful when an expired password might be changed by an
738 application (such as <command>ssh</command>).
739 </para>
741 <para>
742         <smbfile name="pam-synchronised-password">
743         <programlisting>
744 #%PAM-1.0
745 # password-sync
747 auth       requisite    pam_nologin.so
748 auth       required     pam_unix.so
749 account    required     pam_unix.so
750 password   requisite    pam_cracklib.so retry=3
751 password   requisite    pam_unix.so shadow md5 use_authtok try_first_pass
752 password   required     pam_smbpass.so nullok use_authtok try_first_pass
753 session    required     pam_unix.so
754 </programlisting></smbfile></para>
755 </sect3>
757 <sect3>
758 <title>Password Migration Configuration</title>
760 <para>
761 A sample PAM configuration that shows the use of <filename>pam_smbpass</filename> to migrate
762 from plaintext to encrypted passwords for Samba. Unlike other methods,
763 this can be used for users who have never connected to Samba shares:
764 password migration takes place when users <command>ftp</command> in, login using <command>ssh</command>, pop
765 their mail, and so on.
766 </para>
768 <para><smbfile name="pam-password-migration">
769         <programlisting>
770 #%PAM-1.0
771 # password-migration
773 auth       requisite   pam_nologin.so
774 # pam_smbpass is called IF pam_unix succeeds.
775 auth       requisite   pam_unix.so
776 auth       optional    pam_smbpass.so migrate
777 account    required    pam_unix.so
778 password   requisite   pam_cracklib.so retry=3
779 password   requisite   pam_unix.so shadow md5 use_authtok try_first_pass
780 password   optional    pam_smbpass.so nullok use_authtok try_first_pass
781 session    required    pam_unix.so
782 </programlisting></smbfile></para>
783 </sect3>
785 <sect3>
786 <title>Mature Password Configuration</title>
788 <para>
789 A sample PAM configuration for a mature <filename>smbpasswd</filename> installation.
790 <filename>private/smbpasswd</filename> is fully populated, and we consider it an error if
791 the SMB password does not exist or does not match the UNIX password.
792 </para>
794 <para><smbfile name="pam-fallback">
795 <programlisting>
796 #%PAM-1.0
797 # password-mature
799 auth       requisite    pam_nologin.so
800 auth       required     pam_unix.so
801 account    required     pam_unix.so
802 password   requisite    pam_cracklib.so retry=3
803 password   requisite    pam_unix.so shadow md5 use_authtok try_first_pass
804 password   required     pam_smbpass.so use_authtok use_first_pass
805 session    required     pam_unix.so
806 </programlisting></smbfile></para>
807 </sect3>
809 <sect3>
810 <title>Kerberos Password Integration Configuration</title>
812 <para>
813 A sample PAM configuration that shows <parameter>pam_smbpass</parameter> used together with
814 <parameter>pam_krb5</parameter>. This could be useful on a Samba PDC that is also a member of
815 a Kerberos realm.
816 </para>
818 <para><smbfile name="pam-krb">
819                 <programlisting>
820 #%PAM-1.0
821 # kdc-pdc
823 auth       requisite   pam_nologin.so
824 auth       requisite   pam_krb5.so
825 auth       optional    pam_smbpass.so migrate
826 account    required    pam_krb5.so
827 password   requisite   pam_cracklib.so retry=3
828 password   optional    pam_smbpass.so nullok use_authtok try_first_pass
829 password   required    pam_krb5.so use_authtok try_first_pass
830 session    required    pam_krb5.so
831 </programlisting></smbfile></para>
833 </sect3>
835 </sect2>
837 </sect1>
839 <sect1>
840 <title>Common Errors</title>
842 <para>
843 PAM can be fickle and sensitive to configuration glitches. Here we look at a few cases from
844 the Samba mailing list.
845 </para>
847 <!-- shouldn't this be in the Winbind chapter - Jelmer -->
848         <sect2>
849         <title>pam_winbind Problem</title>
851         <para>
852         A user reported: I have the following PAM configuration:
853         </para>
855 <para>
856         <smbfile name="pam-winbind-erratic">
857 <programlisting>
858 auth required /lib/security/pam_securetty.so
859 auth sufficient /lib/security/pam_winbind.so
860 auth sufficient /lib/security/pam_unix.so use_first_pass nullok
861 auth required /lib/security/pam_stack.so service=system-auth
862 auth required /lib/security/pam_nologin.so
863 account required /lib/security/pam_stack.so service=system-auth
864 account required /lib/security/pam_winbind.so
865 password required /lib/security/pam_stack.so service=system-auth
866 </programlisting></smbfile>
867 </para>
869         <para>
870         When I open a new console with [ctrl][alt][F1], I can't log in with my user <quote>pitie</quote>.
871         I have tried with user <quote>scienceu+pitie</quote> also.
872         </para>
874         <para>
875         <emphasis>Answer:</emphasis> The problem may lie with your inclusion of <parameter>pam_stack.so
876         service=system-auth</parameter>. That file often contains a lot of stuff that may
877         duplicate what you are already doing. Try commenting out the <parameter>pam_stack</parameter> lines
878         for <parameter>auth</parameter> and <parameter>account</parameter> and see if things work. If they do, look at
879         <filename>/etc/pam.d/system-auth</filename> and copy only what you need from it into your
880         <filename>/etc/pam.d/login</filename> file. Alternately, if you want all services to use
881         Winbind, you can put the Winbind-specific stuff in <filename>/etc/pam.d/system-auth</filename>.
882         </para>
884         </sect2>
886         <sect2>
887         <title>Winbind Is Not Resolving Users and Groups</title>
889         <para>
890         <quote>
891         My &smb.conf; file is correctly configured. I have specified 
892         <smbconfoption><name>idmap uid</name><value>12000</value></smbconfoption>, 
893         and <smbconfoption><name>idmap gid</name><value>3000-3500</value></smbconfoption>
894         and <command>winbind</command> is running. When I do the following it all works fine.
895         </quote>
896         </para>
898 <para><screen>
899 &rootprompt;<userinput>wbinfo -u</userinput>
900 MIDEARTH+maryo
901 MIDEARTH+jackb
902 MIDEARTH+ameds
904 MIDEARTH+root
906 &rootprompt;<userinput>wbinfo -g</userinput>
907 MIDEARTH+Domain Users
908 MIDEARTH+Domain Admins
909 MIDEARTH+Domain Guests
911 MIDEARTH+Accounts
913 &rootprompt;<userinput>getent passwd</userinput>
914 root:x:0:0:root:/root:/bin/bash
915 bin:x:1:1:bin:/bin:/bin/bash
917 maryo:x:15000:15003:Mary Orville:/home/MIDEARTH/maryo:/bin/false
918 </screen></para>
920         <para>
921         <quote>
922         But this command fails:
923         </quote>
924 <screen>
925 &rootprompt;<userinput>chown maryo a_file</userinput>
926 chown: 'maryo': invalid user
927 </screen>
928         <quote>This is driving me nuts! What can be wrong?</quote>
929         </para>
931         <para>
932         <emphasis>Answer:</emphasis> Your system is likely running <command>nscd</command>, the name service
933         caching daemon. Shut it down, do not restart it! You will find your problem resolved.
934         </para>
936         </sect2>
937 </sect1>
939 </chapter>