Match Samba 2.2, and make ACB_NORMAL the default ACB value.
[Samba.git] / docs / docbook / projdoc / PAM-Authentication-And-Samba.xml
blob2f8383aae265dce78997036856eca5b393ac97be
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"/>, 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><programlisting>
488 #%PAM-1.0
489 # The PAM configuration file for the <quote>login</quote> service
491 auth         required    pam_securetty.so
492 auth         required    pam_nologin.so
493 # auth       required    pam_dialup.so
494 # auth       optional    pam_mail.so
495 auth         required    pam_pwdb.so shadow md5
496 # account    requisite   pam_time.so
497 account      required    pam_pwdb.so
498 session      required    pam_pwdb.so
499 # session    optional    pam_lastlog.so
500 # password   required    pam_cracklib.so retry=3
501 password     required    pam_pwdb.so shadow md5
502 </programlisting></para>
504 </sect3>
506 <sect3>
507 <title>PAM: Login Using <filename>pam_smbpass</filename></title>
509 <para>
510 PAM allows use of replaceable modules. Those available on a sample system include:
511 </para>
513 <para><prompt>$</prompt><userinput>/bin/ls /lib/security</userinput>
514 <programlisting>
515 pam_access.so    pam_ftp.so          pam_limits.so     
516 pam_ncp_auth.so  pam_rhosts_auth.so  pam_stress.so     
517 pam_cracklib.so  pam_group.so        pam_listfile.so   
518 pam_nologin.so   pam_rootok.so       pam_tally.so      
519 pam_deny.so      pam_issue.so        pam_mail.so       
520 pam_permit.so    pam_securetty.so    pam_time.so       
521 pam_dialup.so    pam_lastlog.so      pam_mkhomedir.so  
522 pam_pwdb.so      pam_shells.so       pam_UNIX.so       
523 pam_env.so       pam_ldap.so         pam_motd.so       
524 pam_radius.so    pam_smbpass.so      pam_UNIX_acct.so  
525 pam_wheel.so     pam_UNIX_auth.so    pam_UNIX_passwd.so
526 pam_userdb.so    pam_warn.so         pam_UNIX_session.so
527 </programlisting></para>
529 <para>
530 The following example for the login program replaces the use of 
531 the <filename>pam_pwdb.so</filename> module that uses the system 
532 password database (<filename>/etc/passwd</filename>,
533 <filename>/etc/shadow</filename>, <filename>/etc/group</filename>) with 
534 the module <filename>pam_smbpass.so</filename>, which uses the Samba 
535 database which contains the Microsoft MD4 encrypted password 
536 hashes. This database is stored in either 
537 <filename>/usr/local/samba/private/smbpasswd</filename>, 
538 <filename>/etc/samba/smbpasswd</filename>, or in 
539 <filename>/etc/samba.d/smbpasswd</filename>, depending on the 
540 Samba implementation for your UNIX/Linux system. The 
541 <filename>pam_smbpass.so</filename> module is provided by 
542 Samba version 2.2.1 or later. It can be compiled by specifying the 
543 <option>--with-pam_smbpass</option> options when running Samba's
544 <command>configure</command> script. For more information
545 on the <filename>pam_smbpass</filename> module, see the documentation
546 in the <filename>source/pam_smbpass</filename> directory of the Samba 
547 source distribution.
548 </para>
550 <para><programlisting>
551 #%PAM-1.0
552 # The PAM configuration file for the <quote>login</quote> service
554 auth        required    pam_smbpass.so nodelay
555 account     required    pam_smbpass.so nodelay
556 session     required    pam_smbpass.so nodelay
557 password    required    pam_smbpass.so nodelay
558 </programlisting></para>
560 <para>
561 The following is the PAM configuration file for a particular 
562 Linux system. The default condition uses <filename>pam_pwdb.so</filename>.
563 </para>
565 <para><programlisting>
566 #%PAM-1.0
567 # The PAM configuration file for the <quote>samba</quote> service
569 auth       required     pam_pwdb.so nullok nodelay shadow audit
570 account    required     pam_pwdb.so audit nodelay
571 session    required     pam_pwdb.so nodelay
572 password   required     pam_pwdb.so shadow md5
573 </programlisting></para>
575 <para>
576 In the following example, the decision has been made to use the 
577 <command>smbpasswd</command> database even for basic Samba authentication. Such a 
578 decision could also be made for the <command>passwd</command> program and would 
579 thus allow the <command>smbpasswd</command> passwords to be changed using the
580 <command>passwd</command> program:
581 </para>
583 <para><programlisting>
584 #%PAM-1.0
585 # The PAM configuration file for the <quote>samba</quote> service
587 auth       required     pam_smbpass.so nodelay
588 account    required     pam_pwdb.so audit nodelay
589 session    required     pam_pwdb.so nodelay
590 password   required     pam_smbpass.so nodelay smbconf=/etc/samba.d/smb.conf
591 </programlisting></para>
593 <note><para>PAM allows stacking of authentication mechanisms. It is 
594 also possible to pass information obtained within one PAM module through 
595 to the next module in the PAM stack. Please refer to the documentation for 
596 your particular system implementation for details regarding the specific 
597 capabilities of PAM in this environment. Some Linux implementations also 
598 provide the <filename>pam_stack.so</filename> module that allows all 
599 authentication to be configured in a single central file. The 
600 <filename>pam_stack.so</filename> method has some devoted followers 
601 on the basis that it allows for easier administration. As with all issues in 
602 life though, every decision makes trade-offs, so you may want to examine the 
603 PAM documentation for further helpful information.
604 </para></note>
606 </sect3>
608 </sect2>
610 <sect2>
611 <title>&smb.conf; PAM Configuration</title>
613 <para>
614         There is an option in &smb.conf; called <smbconfoption><name>obey pam restrictions</name></smbconfoption>.
615 The following is from the online help for this option in SWAT;
616 </para>
618 <para>
619 When Samba is configured to enable PAM support (i.e., <option>--with-pam</option>), this parameter will 
620 control whether or not Samba should obey PAM's account and session management directives. The default behavior 
621 is to use PAM for cleartext authentication only and to ignore any account or session management. Samba always 
622 ignores PAM for authentication in the case of <smbconfoption><name>encrypt passwords</name><value>yes</value></smbconfoption>. 
623 The reason is that PAM modules cannot support the challenge/response authentication mechanism needed in the presence of SMB 
624 password encryption. 
625 </para>
627 <para>Default: <smbconfoption><name>obey pam restrictions</name><value>no</value></smbconfoption></para>
629 </sect2>
631 <sect2>
632 <title>Remote CIFS Authentication Using <filename>winbindd.so</filename></title>
634 <para>
635 All operating systems depend on the provision of users credentials acceptable to the platform.
636 UNIX requires the provision of a user identifier (UID) as well as a group identifier (GID).
637 These are both simple integer type numbers that are obtained from a password backend such
638 as <filename>/etc/passwd</filename>.
639 </para>
641 <para>
642 Users and groups on a Windows NT server are assigned a relative ID (RID) which is unique for
643 the domain when the user or group is created. To convert the Windows NT user or group into
644 a  UNIX user or group, a mapping between RIDs and UNIX user and group IDs is required. This
645 is one of the jobs that winbind performs.
646 </para>
648 <para>
649 As Winbind users and groups are resolved from a server, user and group IDs are allocated
650 from a specified range. This is done on a first come, first served basis, although all
651 existing users and groups will be mapped as soon as a client performs a user or  group 
652 enumeration command. The allocated UNIX IDs are stored in a database file under the Samba
653 lock directory and will be remembered.
654 </para>
656 <para>
657 The astute administrator will realize from this that the combination of <filename>pam_smbpass.so</filename>, 
658 <command>winbindd</command> and a distributed <smbconfoption><name>passdb backend</name><value></value></smbconfoption>,
659 such as <parameter>ldap</parameter>, will allow the establishment of a centrally managed, distributed user/password
660 database that can also be used by all PAM-aware (e.g., Linux) programs and applications. This arrangement can have
661 particularly potent advantages compared with the use of Microsoft Active Directory Service (ADS) in so far as
662 the reduction of wide area network authentication traffic.
663 </para>
665 <warning><para>
666 The RID to UNIX ID database is the only location where the user and group  mappings are 
667 stored by <command>winbindd</command>. If this file is deleted or corrupted, there is no way for <command>winbindd</command>
668 to determine which user and group IDs correspond to Windows NT user and group RIDs.
669 </para></warning>
671 </sect2>
673 <sect2>
674 <title>Password Synchronization Using <filename>pam_smbpass.so</filename></title>
676 <para>
677 <filename>pam_smbpass</filename> is a PAM module that can be used on conforming systems to
678 keep the <filename>smbpasswd</filename> (Samba password) database in sync with the UNIX
679 password file. PAM (Pluggable Authentication Modules) is an API supported
680 under some UNIX operating systems, such as Solaris, HPUX and Linux, that provides a
681 generic interface to authentication mechanisms.
682 </para>
684 <para>
685 This module authenticates a local <filename>smbpasswd</filename> user database. If you require
686 support for authenticating against a remote SMB server, or if you are
687 concerned about the presence of SUID root binaries on your system, it is
688 recommended that you use <filename>pam_winbind</filename> instead.
689 </para>
691 <para>
692 Options recognized by this module are shown in <link linkend="smbpassoptions"/>.
693 <table frame="all" id="smbpassoptions">
694         <title>Options recognized by <parameter>pam_smbpass</parameter></title>
695         <tgroup cols="2" align="left">
696                 <colspec align="left"/>
697                 <colspec align="justify" colwidth="1*"/>
698         <tbody>
699                 <row><entry>debug</entry><entry>log more debugging info.</entry></row>
700                 <row><entry>audit</entry><entry>like debug, but also logs unknown usernames.</entry></row>
701                 <row><entry>use_first_pass</entry><entry>do not prompt the user for passwords; take them from PAM_ items instead.</entry></row>
702                 <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>
703                 <row><entry>use_authtok</entry>
704                         <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>
705                 <row><entry>not_set_pass</entry><entry>do not make passwords used by this module available to other modules.</entry></row>
706                 <row><entry>nodelay</entry><entry>do not insert ~1 second delays on authentication failure.</entry></row>
707                 <row><entry>nullok</entry><entry>null passwords are allowed.</entry></row>
708                 <row><entry>nonull</entry><entry>null passwords are not allowed. Used to override the Samba configuration.</entry></row>
709                 <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>
710                 <row><entry>smbconf=<replaceable>file</replaceable></entry><entry>specify an alternate path to the &smb.conf; file.</entry></row>
711         </tbody>
712 </tgroup>
713 </table>
714 </para>
716 <para>
717 The following are examples of the use of <filename>pam_smbpass.so</filename> in the format of Linux
718 <filename>/etc/pam.d/</filename> files structure. Those wishing to implement this
719 tool on other platforms will need to adapt this appropriately.
720 </para>
722 <sect3>
723 <title>Password Synchronization Configuration</title>
725 <para>
726 A sample PAM configuration that shows the use of pam_smbpass to make
727 sure <filename>private/smbpasswd</filename> is kept in sync when <filename>/etc/passwd (/etc/shadow)</filename>
728 is changed. Useful when an expired password might be changed by an
729 application (such as <command>ssh</command>).
730 </para>
732 <para><programlisting>
733 #%PAM-1.0
734 # password-sync
736 auth       requisite    pam_nologin.so
737 auth       required     pam_UNIX.so
738 account    required     pam_UNIX.so
739 password   requisite    pam_cracklib.so retry=3
740 password   requisite    pam_UNIX.so shadow md5 use_authtok try_first_pass
741 password   required     pam_smbpass.so nullok use_authtok try_first_pass
742 session    required     pam_UNIX.so
743 </programlisting></para>
744 </sect3>
746 <sect3>
747 <title>Password Migration Configuration</title>
749 <para>
750 A sample PAM configuration that shows the use of <filename>pam_smbpass</filename> to migrate
751 from plaintext to encrypted passwords for Samba. Unlike other methods,
752 this can be used for users who have never connected to Samba shares:
753 password migration takes place when users <command>ftp</command> in, login using <command>ssh</command>, pop
754 their mail, and so on.
755 </para>
757 <para><programlisting>
758 #%PAM-1.0
759 # password-migration
761 auth       requisite   pam_nologin.so
762 # pam_smbpass is called IF pam_UNIX succeeds.
763 auth       requisite   pam_UNIX.so
764 auth       optional    pam_smbpass.so migrate
765 account    required    pam_UNIX.so
766 password   requisite   pam_cracklib.so retry=3
767 password   requisite   pam_UNIX.so shadow md5 use_authtok try_first_pass
768 password   optional    pam_smbpass.so nullok use_authtok try_first_pass
769 session    required    pam_UNIX.so
770 </programlisting></para>
771 </sect3>
773 <sect3>
774 <title>Mature Password Configuration</title>
776 <para>
777 A sample PAM configuration for a mature <filename>smbpasswd</filename> installation.
778 <filename>private/smbpasswd</filename> is fully populated, and we consider it an error if
779 the SMB password does not exist or does not match the UNIX password.
780 </para>
782 <para><programlisting>
783 #%PAM-1.0
784 # password-mature
786 auth       requisite    pam_nologin.so
787 auth       required     pam_UNIX.so
788 account    required     pam_UNIX.so
789 password   requisite    pam_cracklib.so retry=3
790 password   requisite    pam_UNIX.so shadow md5 use_authtok try_first_pass
791 password   required     pam_smbpass.so use_authtok use_first_pass
792 session    required     pam_UNIX.so
793 </programlisting></para>
794 </sect3>
796 <sect3>
797 <title>Kerberos Password Integration Configuration</title>
799 <para>
800 A sample PAM configuration that shows <parameter>pam_smbpass</parameter> used together with
801 <parameter>pam_krb5</parameter>. This could be useful on a Samba PDC that is also a member of
802 a Kerberos realm.
803 </para>
805 <para><programlisting>
806 #%PAM-1.0
807 # kdc-pdc
809 auth       requisite   pam_nologin.so
810 auth       requisite   pam_krb5.so
811 auth       optional    pam_smbpass.so migrate
812 account    required    pam_krb5.so
813 password   requisite   pam_cracklib.so retry=3
814 password   optional    pam_smbpass.so nullok use_authtok try_first_pass
815 password   required    pam_krb5.so use_authtok try_first_pass
816 session    required    pam_krb5.so
817 </programlisting></para>
819 </sect3>
821 </sect2>
823 </sect1>
825 <sect1>
826 <title>Common Errors</title>
828 <para>
829 PAM can be fickle and sensitive to configuration glitches. Here we look at a few cases from
830 the Samba mailing list.
831 </para>
833         <sect2>
834         <title>pam_winbind Problem</title>
836         <para>
837         A user reported: I have the following PAM configuration:
838         </para>
840 <para>
841 <programlisting>
842 auth required /lib/security/pam_securetty.so
843 auth sufficient /lib/security/pam_winbind.so
844 auth sufficient /lib/security/pam_UNIX.so use_first_pass nullok
845 auth required /lib/security/pam_stack.so service=system-auth
846 auth required /lib/security/pam_nologin.so
847 account required /lib/security/pam_stack.so service=system-auth
848 account required /lib/security/pam_winbind.so
849 password required /lib/security/pam_stack.so service=system-auth
850 </programlisting>
851 </para>
853         <para>
854         When I open a new console with [ctrl][alt][F1], I can't log in with my user <quote>pitie</quote>.
855         I have tried with user <quote>scienceu+pitie</quote> also.
856         </para>
858         <para>
859         <emphasis>Answer:</emphasis> The problem may lie with your inclusion of <parameter>pam_stack.so
860         service=system-auth</parameter>. That file often contains a lot of stuff that may
861         duplicate what you are already doing. Try commenting out the <parameter>pam_stack</parameter> lines
862         for <parameter>auth</parameter> and <parameter>account</parameter> and see if things work. If they do, look at
863         <filename>/etc/pam.d/system-auth</filename> and copy only what you need from it into your
864         <filename>/etc/pam.d/login</filename> file. Alternately, if you want all services to use
865         Winbind, you can put the Winbind-specific stuff in <filename>/etc/pam.d/system-auth</filename>.
866         </para>
868         </sect2>
870         <sect2>
871         <title>Winbind Is Not Resolving Users and Groups</title>
873         <para>
874         <quote>
875         My &smb.conf; file is correctly configured. I have specified 
876         <smbconfoption><name>idmap uid</name><value>12000</value></smbconfoption>, 
877         and <smbconfoption><name>idmap gid</name><value>3000-3500</value></smbconfoption>
878         and <command>winbind</command> is running. When I do the following it all works fine.
879         </quote>
880         </para>
882 <para><screen>
883 &rootprompt;<userinput>wbinfo -u</userinput>
884 MIDEARTH+maryo
885 MIDEARTH+jackb
886 MIDEARTH+ameds
888 MIDEARTH+root
890 &rootprompt;<userinput>wbinfo -g</userinput>
891 MIDEARTH+Domain Users
892 MIDEARTH+Domain Admins
893 MIDEARTH+Domain Guests
895 MIDEARTH+Accounts
897 &rootprompt;<userinput>getent passwd</userinput>
898 root:x:0:0:root:/root:/bin/bash
899 bin:x:1:1:bin:/bin:/bin/bash
901 maryo:x:15000:15003:Mary Orville:/home/MIDEARTH/maryo:/bin/false
902 </screen></para>
904         <para>
905         <quote>
906         But this command fails:
907         </quote>
908 <screen>
909 &rootprompt;<userinput>chown maryo a_file</userinput>
910 chown: 'maryo': invalid user
911 </screen>
912         <quote>This is driving me nuts! What can be wrong?</quote>
913         </para>
915         <para>
916         <emphasis>Answer:</emphasis> Your system is likely running <command>nscd</command>, the name service
917         caching daemon. Shut it down, do not restart it! You will find your problem resolved.
918         </para>
920         </sect2>
921 </sect1>
923 </chapter>