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