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