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