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