trying to get HEAD building again. If you want the code
[tprouty/samba.git] / docs / docbook / projdoc / PAM-Authentication-And-Samba.xml
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>
12  
13 <title>PAM based Distributed Authentication</title>
14
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>
22
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>
27
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>
31
32 <sect1>
33 <title>Features and Benefits</title>
34
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>
44
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>
51
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>
58
59 <para>
60 PAM support modules are available for:
61 </para>
62
63 <variablelist>
64         <varlistentry><term><filename>/etc/passwd</filename></term><listitem><para>-</para>
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>
71
72         <varlistentry><term>Kerberos</term><listitem><para>-</para>
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>
79
80         <varlistentry><term>LDAP</term><listitem><para>-</para>
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>
87
88         <varlistentry><term>NetWare Bindery</term><listitem><para>-</para>
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>
94
95         <varlistentry><term>SMB Password</term><listitem><para>-</para>
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>
101
102         <varlistentry><term>SMB Server</term><listitem><para>-</para>
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>
108
109         <varlistentry><term>Winbind</term><listitem><para>-</para>
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>
116
117         <varlistentry><term>RADIUS</term><listitem><para>-</para>
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>
126
127 <para>
128 Of the above, Samba provides the pam_smbpasswd.so and the pam_winbind.so modules alone.
129 </para>
130
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>
138
139 </sect1>
140
141 <sect1>
142 <title>Technical Discussion</title>
143
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>
150
151 <sect2>
152 <title>PAM Configuration Syntax</title>
153
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>
160
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>
166
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>
173
174 <para>
175 <screen>
176 auth  required  /other_path/pam_strange_module.so
177 </screen>
178 </para>
179
180 <sect3>
181 <title>Anatomy of <filename>/etc/pam.d</filename> Entries</title>
182
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/">
187 http://ftp.kernel.org/pub/linux/libs/pam</ulink> The Official Linux-PAM home page.
188 </para>
189
190 <para>
191 A general configuration line of the /etc/pam.conf file has the following form:
192 </para>
193
194 <para>
195 <screen>
196 service-name   module-type   control-flag   module-path   args
197 </screen>
198 </para>
199
200 <para>
201 Below, we explain the meaning of each of these tokens. The second (and more recently adopted)
202 way of configuring Linux-PAM is via the contents of the <filename>/etc/pam.d/</filename> directory.
203 Once we have explained the meaning of the above tokens, we will describe this method.
204 </para>
205
206 <variablelist>
207         <varlistentry><term>service-name</term><listitem><para>-</para>
208                 <para>
209                 The name of the service associated with this entry. Frequently the service name is the conventional
210                 name of the given application. For example, `ftpd', `rlogind' and `su', etc. .
211                 </para>
212
213                 <para>
214                 There is a special service-name, reserved for defining a default authentication mechanism. It has
215                 the name `OTHER' and may be specified in either lower or upper case characters. Note, when there
216                 is a module specified for a named service, the `OTHER' entries are ignored.
217                 </para></listitem>
218         </varlistentry>
219
220         <varlistentry><term>module-type</term><listitem><para>-</para>
221                 <para>
222                 One of (currently) four types of module. The four types are as follows:
223                 </para>
224
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>
233
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>
240
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>
247
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></listitem>
254         </varlistentry>
255
256         <varlistentry><term>control-flag</term><listitem><para>-</para>
257                 <para>
258                 The control-flag is used to indicate how the PAM library will react to the success or failure of the
259                 module it is associated with. Since modules can be stacked (modules of the same type execute in series,
260                 one after another), the control-flags determine the relative importance of each module. The application
261                 is not made aware of the individual success or failure of modules listed in the
262                 <filename>/etc/pam.conf</filename> file. Instead, it receives a summary success or fail response from
263                 the Linux-PAM library. The order of execution of these modules is that of the entries in the
264                 <filename>/etc/pam.conf</filename> file; earlier entries are executed before later ones.
265                 As of Linux-PAM v0.60, this control-flag can be defined with one of two syntaxes.
266                 </para>
267
268                 <para>
269                 The simpler (and historical) syntax for the control-flag is a single keyword defined to indicate the
270                 severity of concern associated with the success or failure of a specific module. There are four such
271                 <emphasis>keywords: required, requisite, sufficient and optional</emphasis>.
272                 </para>
273
274                 <para>
275                 The Linux-PAM library interprets these keywords in the following manner:
276                 </para>
277
278                 <itemizedlist>
279                         <listitem><para>
280                         <emphasis>required:</emphasis> this indicates that the success of the module is required for the
281                         module-type facility to succeed. Failure of this module will not be apparent to the user until all
282                         of the remaining modules (of the same module-type) have been executed.
283                         </para></listitem>
284
285                         <listitem><para>
286                         <emphasis>requisite:</emphasis> like required, however, in the case that such a module returns a
287                         failure, control is directly returned to the application. The return value is that associated with
288                         the first required or requisite module to fail. Note, this flag can be used to protect against the
289                         possibility of a user getting the opportunity to enter a password over an unsafe medium. It is
290                         conceivable that such behavior might inform an attacker of valid accounts on a system. This
291                         possibility should be weighed against the not insignificant concerns of exposing a sensitive
292                         password in a hostile environment.
293                         </para></listitem>
294
295                         <listitem><para>
296                         <emphasis>sufficient:</emphasis> the success of this module is deemed `sufficient' to satisfy
297                         the Linux-PAM library that this module-type has succeeded in its purpose. In the event that no
298                         previous required module has failed, no more `stacked' modules of this type are invoked. (Note,
299                         in this case subsequent required modules are not invoked.). A failure of this module is not deemed
300                         as fatal to satisfying the application that this module-type has succeeded.
301                         </para></listitem>
302
303                         <listitem><para>
304                         <emphasis>optional:</emphasis> as its name suggests, this control-flag marks the module as not
305                         being critical to the success or failure of the user's application for service. In general,
306                         Linux-PAM ignores such a module when determining if the module stack will succeed or fail.
307                         However, in the absence of any definite successes or failures of previous or subsequent stacked
308                         modules this module will determine the nature of the response to the application. One example of
309                         this latter case, is when the other modules return something like PAM_IGNORE.
310                         </para></listitem>
311                 </itemizedlist>
312
313                 <para>
314                 The more elaborate (newer) syntax is much more specific and gives the administrator a great deal of control
315                 over how the user is authenticated. This form of the control flag is delimited with square brackets and
316                 consists of a series of value=action tokens:
317                 </para>
318
319                 <para><screen>
320                 [value1=action1 value2=action2 ...]
321                 </screen></para>
322
323                 <para>
324                 Here, value1 is one of the following return values: success; open_err; symbol_err; service_err;
325                 system_err; buf_err; perm_denied; auth_err; cred_insufficient; authinfo_unavail; user_unknown; maxtries;
326                 new_authtok_reqd; acct_expired; session_err; cred_unavail; cred_expired; cred_err; no_module_data; conv_err;
327                 authtok_err; authtok_recover_err; authtok_lock_busy; authtok_disable_aging; try_again; ignore; abort;
328                 authtok_expired; module_unknown; bad_item; and default. The last of these (default) can be used to set
329                 the action for those return values that are not explicitly defined.
330                 </para>
331
332                 <para>
333                 The action1 can be a positive integer or one of the following tokens: ignore; ok; done; bad; die; and reset.
334                 A positive integer, J, when specified as the action, can be used to indicate that the next J modules of the
335                 current module-type will be skipped. In this way, the administrator can develop a moderately sophisticated
336                 stack of modules with a number of different paths of execution. Which path is taken can be determined by the
337                 reactions of individual modules.
338                 </para>
339
340                 <itemizedlist>
341                         <listitem><para>
342                         <emphasis>ignore:</emphasis> when used with a stack of modules, the module's return status will not
343                         contribute to the return code the application obtains.
344                         </para></listitem>
345
346                         <listitem><para>
347                         <emphasis>bad:</emphasis> this action indicates that the return code should be thought of as indicative
348                         of the module failing. If this module is the first in the stack to fail, its status value will be used
349                         for that of the whole stack.
350                         </para></listitem>
351
352                         <listitem><para>
353                         <emphasis>die:</emphasis> equivalent to bad with the side effect of terminating the module stack and
354                         PAM immediately returning to the application.
355                         </para></listitem>
356
357                         <listitem><para>
358                         <emphasis>ok:</emphasis> this tells PAM that the administrator thinks this return code should
359                         contribute directly to the return code of the full stack of modules. In other words, if the former
360                         state of the stack would lead to a return of PAM_SUCCESS, the module's return code will override
361                         this value. Note, if the former state of the stack holds some value that is indicative of a modules
362                         failure, this 'ok' value will not be used to override that value.
363                         </para></listitem>
364
365                         <listitem><para>
366                         <emphasis>done:</emphasis> equivalent to ok with the side effect of terminating the module stack and
367                         PAM immediately returning to the application.
368                         </para></listitem>
369
370                         <listitem><para>
371                         <emphasis>reset:</emphasis> clear all memory of the state of the module stack and start again with
372                         the next stacked module.
373                         </para></listitem>
374                 </itemizedlist>
375
376                 <para>
377                 Each of the four keywords: required; requisite; sufficient; and optional, have an equivalent expression in
378                 terms of the [...] syntax. They are as follows:
379                 </para>
380
381                 <para>
382                 <itemizedlist>
383                         <listitem><para>
384                         required is equivalent to [success=ok new_authtok_reqd=ok ignore=ignore default=bad]
385                         </para></listitem>
386
387                         <listitem><para>
388                         requisite is equivalent to [success=ok new_authtok_reqd=ok ignore=ignore default=die]
389                         </para></listitem>
390
391                         <listitem><para>
392                         sufficient is equivalent to [success=done new_authtok_reqd=done default=ignore]
393                         </para></listitem>
394
395                         <listitem><para>
396                         optional is equivalent to [success=ok new_authtok_reqd=ok default=ignore]
397                         </para></listitem>
398                 </itemizedlist>
399                 </para>
400
401                 <para>
402                 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,
403                 the notion of client plug-in agents was introduced. This is something that makes it possible for PAM to support
404                 machine-machine authentication using the transport protocol inherent to the client/server application. With the
405                 <emphasis>[ ... value=action ... ]</emphasis> control syntax, it is possible for an application to be configured
406                 to support binary prompts with compliant clients, but to gracefully fall over into an alternative authentication
407                 mode for older, legacy, applications.
408                 </para>
409                 </listitem>
410         </varlistentry>
411
412         <varlistentry><term>module-path</term><listitem><para>-</para>
413                 <para>
414                 The path-name of the dynamically loadable object file; the pluggable module itself. If the first character of the
415                 module path is `/', it is assumed to be a complete path. If this is not the case, the given module path is appended
416                 to the default module path: <filename>/lib/security</filename> (but see the notes above).
417                 </para>
418
419                 <para>
420                 The args are a list of tokens that are passed to the module when it is invoked. Much like arguments to a typical
421                 Linux shell command. Generally, valid arguments are optional and are specific to any given module. Invalid arguments
422                 are ignored by a module, however, when encountering an invalid argument, the module is required to write an error
423                 to syslog(3). For a list of generic options see the next section.
424                 </para>
425
426                 <para>
427                 Note, if you wish to include spaces in an argument, you should surround that argument with square brackets. For example:
428                 </para>
429
430 <para><screen>
431 squid auth required pam_mysql.so user=passwd_query passwd=mada \
432         db=eminence [query=select user_name from internet_service where \
433                      user_name='%u' and password=PASSWORD('%p') and \
434                      service='web_proxy']
435 </screen></para>
436
437                 <para>
438                 Note, when using this convention, you can include `[' characters inside the string, and if you wish to include a `]'
439                 character inside the string that will survive the argument parsing, you should use `\['. In other words:
440                 </para>
441
442 <para><screen>
443 [..[..\]..]    -->   ..[..]..
444 </screen></para>
445
446                 <para>
447                 Any line in (one of) the configuration file(s), that is not formatted correctly, will generally tend (erring on the
448                 side of caution) to make the authentication process fail. A corresponding error is written to the system log files
449                 with a call to syslog(3). 
450                 </para></listitem>
451         </varlistentry>
452 </variablelist>
453
454 </sect3>
455
456 </sect2>
457
458 <sect2>
459 <title>Example System Configurations</title>
460
461 <para>
462 The following is an example <filename>/etc/pam.d/login</filename> configuration file. 
463 This example had all options been uncommented is probably not usable 
464 as it stacks many conditions before allowing successful completion 
465 of the login process. Essentially all conditions can be disabled 
466 by commenting them out except the calls to <filename>pam_pwdb.so</filename>.
467 </para>
468
469 <sect3>
470 <title>PAM: original login config</title>
471
472 <para><screen>
473 #%PAM-1.0
474 # The PAM configuration file for the `login' service
475 #
476 auth         required    pam_securetty.so
477 auth         required    pam_nologin.so
478 # auth       required    pam_dialup.so
479 # auth       optional    pam_mail.so
480 auth         required    pam_pwdb.so shadow md5
481 # account    requisite   pam_time.so
482 account      required    pam_pwdb.so
483 session      required    pam_pwdb.so
484 # session    optional    pam_lastlog.so
485 # password   required    pam_cracklib.so retry=3
486 password     required    pam_pwdb.so shadow md5
487 </screen></para>
488
489 </sect3>
490
491 <sect3>
492 <title>PAM: login using pam_smbpass</title>
493
494 <para>
495 PAM allows use of replaceable modules. Those available on a sample system include:
496 </para>
497
498 <para><prompt>$</prompt><userinput>/bin/ls /lib/security</userinput>
499 <screen>
500 pam_access.so    pam_ftp.so          pam_limits.so     
501 pam_ncp_auth.so  pam_rhosts_auth.so  pam_stress.so     
502 pam_cracklib.so  pam_group.so        pam_listfile.so   
503 pam_nologin.so   pam_rootok.so       pam_tally.so      
504 pam_deny.so      pam_issue.so        pam_mail.so       
505 pam_permit.so    pam_securetty.so    pam_time.so       
506 pam_dialup.so    pam_lastlog.so      pam_mkhomedir.so  
507 pam_pwdb.so      pam_shells.so       pam_unix.so       
508 pam_env.so       pam_ldap.so         pam_motd.so       
509 pam_radius.so    pam_smbpass.so      pam_unix_acct.so  
510 pam_wheel.so     pam_unix_auth.so    pam_unix_passwd.so
511 pam_userdb.so    pam_warn.so         pam_unix_session.so
512 </screen></para>
513
514 <para>
515 The following example for the login program replaces the use of 
516 the <filename>pam_pwdb.so</filename> module which uses the system 
517 password database (<filename>/etc/passwd</filename>,
518 <filename>/etc/shadow</filename>, <filename>/etc/group</filename>) with 
519 the module <filename>pam_smbpass.so</filename> which uses the Samba 
520 database which contains the Microsoft MD4 encrypted password 
521 hashes. This database is stored in either 
522 <filename>/usr/local/samba/private/smbpasswd</filename>, 
523 <filename>/etc/samba/smbpasswd</filename>, or in 
524 <filename>/etc/samba.d/smbpasswd</filename>, depending on the 
525 Samba implementation for your Unix/Linux system. The 
526 <filename>pam_smbpass.so</filename> module is provided by 
527 Samba version 2.2.1 or later. It can be compiled by specifying the 
528 <option>--with-pam_smbpass</option> options when running Samba's
529 <command>configure</command> script.  For more information
530 on the <filename>pam_smbpass</filename> module, see the documentation
531 in the <filename>source/pam_smbpass</filename> directory of the Samba 
532 source distribution.
533 </para>
534
535 <para><screen>
536 #%PAM-1.0
537 # The PAM configuration file for the `login' service
538 #
539 auth        required    pam_smbpass.so nodelay
540 account     required    pam_smbpass.so nodelay
541 session     required    pam_smbpass.so nodelay
542 password    required    pam_smbpass.so nodelay
543 </screen></para>
544
545 <para>
546 The following is the PAM configuration file for a particular 
547 Linux system. The default condition uses <filename>pam_pwdb.so</filename>.
548 </para>
549
550 <para><screen>
551 #%PAM-1.0
552 # The PAM configuration file for the `samba' service
553 #
554 auth       required     pam_pwdb.so nullok nodelay shadow audit
555 account    required     pam_pwdb.so audit nodelay
556 session    required     pam_pwdb.so nodelay
557 password   required     pam_pwdb.so shadow md5
558 </screen></para>
559
560 <para>
561 In the following example the decision has been made to use the 
562 smbpasswd database even for basic samba authentication. Such a 
563 decision could also be made for the passwd program and would 
564 thus allow the smbpasswd passwords to be changed using the passwd 
565 program.
566 </para>
567
568 <para><screen>
569 #%PAM-1.0
570 # The PAM configuration file for the `samba' service
571 #
572 auth       required     pam_smbpass.so nodelay
573 account    required     pam_pwdb.so audit nodelay
574 session    required     pam_pwdb.so nodelay
575 password   required     pam_smbpass.so nodelay smbconf=/etc/samba.d/smb.conf
576 </screen></para>
577
578 <note><para>PAM allows stacking of authentication mechanisms. It is 
579 also possible to pass information obtained within one PAM module through 
580 to the next module in the PAM stack. Please refer to the documentation for 
581 your particular system implementation for details regarding the specific 
582 capabilities of PAM in this environment. Some Linux implementations also 
583 provide the <filename>pam_stack.so</filename> module that allows all 
584 authentication to be configured in a single central file. The 
585 <filename>pam_stack.so</filename> method has some very devoted followers 
586 on the basis that it allows for easier administration. As with all issues in 
587 life though, every decision makes trade-offs, so you may want examine the 
588 PAM documentation for further helpful information.
589 </para></note>
590
591 </sect3>
592
593 </sect2>
594
595 <sect2>
596 <title>smb.conf PAM Configuration</title>
597
598 <para>
599 There is an option in smb.conf called <ulink 
600 url="smb.conf.5.html#OBEYPAMRESTRICTIONS">obey pam restrictions</ulink>. 
601 The following is from the on-line help for this option in SWAT;
602 </para>
603
604 <para>
605 When Samba-3 is configured to enable PAM support (i.e. 
606 <option>--with-pam</option>), this parameter will 
607 control whether or not Samba should obey PAM's account 
608 and session management directives. The default behavior 
609 is to use PAM for clear text authentication only and to 
610 ignore any account or session management. Note that Samba always 
611 ignores PAM for authentication in the case of 
612 <ulink url="smb.conf.5.html#ENCRYPTPASSWORDS">encrypt passwords = yes</ulink>. 
613 The reason is that PAM modules cannot support the challenge/response 
614 authentication mechanism needed in the presence of SMB 
615 password encryption. 
616 </para>
617
618 <para>Default: <parameter>obey pam restrictions = no</parameter></para>
619
620 </sect2>
621
622 <sect2>
623 <title>Remote CIFS Authentication using winbindd.so</title>
624
625 <para>
626 All operating systems depend on the provision of users credentials acceptable to the platform.
627 Unix requires the provision of a user identifier (UID) as well as a group identifier (GID).
628 These are both simple integer type numbers that are obtained from a password backend such
629 as <filename>/etc/passwd</filename>.
630 </para>
631
632 <para>
633 Users and groups on a Windows NT server are assigned a relative id (rid) which is unique for
634 the domain when the user or group is created. To convert the Windows NT user or group into
635 a  unix user or group, a mapping between rids and unix user and group ids is required. This
636 is one of the jobs that winbind performs.
637 </para>
638
639 <para>
640 As winbind users and groups are resolved from a server, user and group ids are allocated
641 from a specified range. This is done on a first come, first served basis, although all
642 existing users and groups will be mapped as soon as a client performs a user or  group 
643 enumeration command.  The allocated unix ids are stored in a database file under the Samba
644 lock directory and will be remembered.
645 </para>
646
647 <para>
648 The astute administrator will realize from this that the combination of <filename>pam_smbpass.so</filename>, 
649 <command>winbindd</command>, and a distributed passdb backend, such as ldap, will allow the establishment of a
650 centrally managed, distributed user/password database that can also be used by all PAM (eg: Linux) aware
651 programs and applications. This arrangement can have particularly potent advantages compared with the use of
652 Microsoft Active Directory Service (ADS) in so far as reduction of wide area network authentication traffic.
653 </para>
654
655 <warning><para>
656 The rid to unix id database is the only location where the user and group  mappings are 
657 stored by winbindd.  If this file is deleted or corrupted, there is no way for winbindd
658 to determine which user and group ids correspond to Windows NT user and group rids.
659 </para></warning>
660
661 </sect2>
662
663 <sect2>
664 <title>Password Synchronization using pam_smbpass.so</title>
665
666 <para>
667 pam_smbpass is a PAM module which can be used on conforming systems to
668 keep the smbpasswd (Samba password) database in sync with the unix
669 password file. PAM (Pluggable Authentication Modules) is an API supported
670 under some Unices, such as Solaris, HPUX and Linux, that provides a
671 generic interface to authentication mechanisms.
672 </para>
673
674 <para>
675 This module authenticates a local smbpasswd user database.  If you require
676 support for authenticating against a remote SMB server, or if you're
677 concerned about the presence of suid root binaries on your system, it is
678 recommended that you use pam_winbind instead.
679 </para>
680
681 <para>
682 Options recognized by this module are as follows:
683 <table frame="all">
684         <title>Options recognized by pam_smbpass</title>
685         <tgroup cols="2" align="left">
686         <tbody>
687                 <row><entry>debug</entry><entry>log more debugging info</entry></row>
688                 <row><entry>audit</entry><entry>like debug, but also logs unknown usernames</entry></row>
689                 <row><entry>use_first_pass</entry><entry>don't prompt the user for passwords; take them from PAM_ items instead</entry></row>
690                 <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>
691                 <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>
692                 <row><entry>not_set_pass</entry><entry>don't make passwords used by this module available to other modules.</entry></row>
693                 <row><entry>nodelay</entry><entry>don't insert ~1 second delays on authentication failure.</entry></row>
694                 <row><entry>nullok</entry><entry>null passwords are allowed.</entry></row>
695                 <row><entry>nonull</entry><entry>null passwords are not allowed. Used to override the Samba configuration.</entry></row>
696                 <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>
697                 <row><entry>smbconf=<replaceable>file</replaceable></entry><entry>specify an alternate path to the &smb.conf; file.</entry></row>
698         </tbody>
699 </tgroup>
700 </table>
701 </para>
702
703 <para>
704 Thanks go to the following people:
705 <simplelist>
706         <member><ulink url="mailto:morgan@transmeta.com">Andrew Morgan</ulink>, for providing the Linux-PAM
707         framework, without which none of this would have happened</member>
708
709         <member><ulink url="gafton@redhat.com">Christian Gafton</ulink> and Andrew Morgan again, for the
710         pam_pwdb module upon which pam_smbpass was originally based</member>
711
712         <member><ulink url="lkcl@switchboard.net">Luke Leighton</ulink> for being receptive to the idea,
713         and for the occasional good-natured complaint about the project's status
714         that keep me working on it :)</member>
715 </simplelist>.
716 </para>
717
718 <para>
719 The following are examples of the use of pam_smbpass.so in the format of Linux
720 <filename>/etc/pam.d/</filename> files structure. Those wishing to implement this
721 tool on other platforms will need to adapt this appropriately.
722 </para>
723
724 <sect3>
725 <title>Password Synchronisation Configuration</title>
726
727 <para>
728 A sample PAM configuration that shows the use of pam_smbpass to make
729 sure private/smbpasswd is kept in sync when /etc/passwd (/etc/shadow)
730 is changed.  Useful when an expired password might be changed by an
731 application (such as ssh).
732 </para>
733
734 <para><screen>
735 #%PAM-1.0
736 # password-sync
737 #
738 auth       requisite    pam_nologin.so
739 auth       required     pam_unix.so
740 account    required     pam_unix.so
741 password   requisite    pam_cracklib.so retry=3
742 password   requisite    pam_unix.so shadow md5 use_authtok try_first_pass
743 password   required     pam_smbpass.so nullok use_authtok try_first_pass
744 session    required     pam_unix.so
745 </screen></para>
746 </sect3>
747
748 <sect3>
749 <title>Password Migration Configuration</title>
750
751 <para>
752 A sample PAM configuration that shows the use of pam_smbpass to migrate
753 from plaintext to encrypted passwords for Samba.  Unlike other methods,
754 this can be used for users who have never connected to Samba shares:
755 password migration takes place when users ftp in, login using ssh, pop
756 their mail, etc.
757 </para>
758
759 <para><screen>
760 #%PAM-1.0
761 # password-migration
762 #
763 auth       requisite   pam_nologin.so
764 # pam_smbpass is called IF pam_unix succeeds.
765 auth       requisite   pam_unix.so
766 auth       optional    pam_smbpass.so migrate
767 account    required    pam_unix.so
768 password   requisite   pam_cracklib.so retry=3
769 password   requisite   pam_unix.so shadow md5 use_authtok try_first_pass
770 password   optional    pam_smbpass.so nullok use_authtok try_first_pass
771 session    required    pam_unix.so
772 </screen></para>
773 </sect3>
774
775 <sect3>
776 <title>Mature Password Configuration</title>
777
778 <para>
779 A sample PAM configuration for a 'mature' smbpasswd installation.
780 private/smbpasswd is fully populated, and we consider it an error if
781 the smbpasswd doesn't exist or doesn't match the Unix password.
782 </para>
783
784 <para><screen>
785 #%PAM-1.0
786 # password-mature
787 #
788 auth       requisite    pam_nologin.so
789 auth       required     pam_unix.so
790 account    required     pam_unix.so
791 password   requisite    pam_cracklib.so retry=3
792 password   requisite    pam_unix.so shadow md5 use_authtok try_first_pass
793 password   required     pam_smbpass.so use_authtok use_first_pass
794 session    required     pam_unix.so
795 </screen></para>
796 </sect3>
797
798 <sect3>
799 <title>Kerberos Password Integration Configuration</title>
800
801 <para>
802 A sample PAM configuration that shows pam_smbpass used together with
803 pam_krb5.  This could be useful on a Samba PDC that is also a member of
804 a Kerberos realm.
805 </para>
806
807 <para><screen>
808 #%PAM-1.0
809 # kdc-pdc
810 #
811 auth       requisite   pam_nologin.so
812 auth       requisite   pam_krb5.so
813 auth       optional    pam_smbpass.so migrate
814 account    required    pam_krb5.so
815 password   requisite   pam_cracklib.so retry=3
816 password   optional    pam_smbpass.so nullok use_authtok try_first_pass
817 password   required    pam_krb5.so use_authtok try_first_pass
818 session    required    pam_krb5.so
819 </screen></para>
820
821 </sect3>
822
823 </sect2>
824
825 </sect1>
826
827 <sect1>
828 <title>Common Errors</title>
829
830 <para>
831 PAM can be a very fickle and sensitive to configuration glitches. Here we look at a few cases from
832 the Samba mailing list.
833 </para>
834
835         <sect2>
836         <title>pam_winbind problem</title>
837
838         <para>
839         I have the following PAM configuration:
840         </para>
841
842 <para>
843 <screen>
844 auth required /lib/security/pam_securetty.so
845 auth sufficient /lib/security/pam_winbind.so
846 auth sufficient /lib/security/pam_unix.so use_first_pass nullok
847 auth required /lib/security/pam_stack.so service=system-auth
848 auth required /lib/security/pam_nologin.so
849 account required /lib/security/pam_stack.so service=system-auth
850 account required /lib/security/pam_winbind.so
851 password required /lib/security/pam_stack.so service=system-auth
852 </screen>
853 </para>
854
855         <para>
856         When I open a new console with [ctrl][alt][F1], then I cant log in with my user "pitie".
857         I've tried with user "scienceu+pitie" also.
858         </para>
859
860         <para>
861         Answer: The problem may lie with your inclusion of <parameter>pam_stack.so
862         service=system-auth</parameter>. That file often contains a lot of stuff that may
863         duplicate what you're already doing. Try commenting out the pam_stack lines
864         for auth and account and see if things work. If they do, look at
865         <filename>/etc/pam.d/system-auth</filename> and copy only what you need from it into your
866         <filename>/etc/pam.d/login</filename> file.  Alternatively, if you want all services to use
867         winbind, you can put the winbind-specific stuff in <filename>/etc/pam.d/system-auth</filename>.
868         </para>
869
870         </sect2>
871
872 </sect1>
873
874 </chapter>