]> granicus.if.org Git - linux-pam/blob - doc/pam_source.sgml
Relevant BUGIDs: 476963
[linux-pam] / doc / pam_source.sgml
1 <!doctype linuxdoc system>
2
3 <!--
4
5  $Id$
6
7     Copyright (c) Andrew G. Morgan 1996-2002.  All rights reserved.
8
9 Redistribution and use in source (sgml) and binary (derived) forms,
10 with or without modification, are permitted provided that the
11 following conditions are met:
12
13 1. Redistributions of source code must retain the above copyright
14    notice, and the entire permission notice in its entirety,
15    including the disclaimer of warranties.
16
17 2. Redistributions in binary form must reproduce the above copyright
18    notice, this list of conditions and the following disclaimer in the
19    documentation and/or other materials provided with the distribution.
20
21 3. The name of the author may not be used to endorse or promote
22    products derived from this software without specific prior
23    written permission.
24
25 ALTERNATIVELY, this product may be distributed under the terms of the
26 GNU General Public License, in which case the provisions of the GNU
27 GPL are required INSTEAD OF the above restrictions.  (This clause is
28 necessary due to a potential bad interaction between the GNU GPL and
29 the restrictions contained in a BSD-style copyright.)
30
31 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
32 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
36 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
37 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
40 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41 DAMAGE.
42
43  -->
44
45 <article>
46
47 <title>The Linux-PAM System Administrators' Guide
48 <author>Andrew G. Morgan, <tt>morgan@kernel.org</tt>
49 <date>DRAFT v0.77 2002/07/10
50 <abstract>
51 This manual documents what a system-administrator needs to know about
52 the <bf>Linux-PAM</bf> library. It covers the correct syntax of the
53 PAM configuration file and discusses strategies for maintaining a
54 secure system.
55 </abstract>
56
57 <!-- Table of contents -->
58 <toc>
59
60 <!-- Begin the document -->
61
62 <sect>Introduction
63
64 <p><bf/Linux-PAM/ (Pluggable Authentication Modules for Linux) is a
65 suite of shared libraries that enable the local system administrator
66 to choose how applications authenticate users.
67
68 <p>In other words, without (rewriting and) recompiling a PAM-aware
69 application, it is possible to switch between the authentication
70 mechanism(s) it uses. Indeed, one may entirely upgrade the local
71 authentication system without touching the applications themselves.
72
73 <p>Historically an application that has required a given user to be
74 authenticated, has had to be compiled to use a specific authentication
75 mechanism.  For example, in the case of traditional UN*X systems, the
76 identity of the user is verified by the user entering a correct
77 password.  This password, after being prefixed by a two character
78 ``salt'', is encrypted (with crypt(3)). The user is then authenticated
79 if this encrypted password is identical to the second field of the
80 user's entry in the system password database (the <tt>/etc/passwd</tt>
81 file).  On such systems, most if not all forms of privileges are
82 granted based on this single authentication scheme. Privilege comes in
83 the form of a personal user-identifier (<tt/uid/) and membership of
84 various groups. Services and applications are available based on the
85 personal and group identity of the user. Traditionally, group
86 membership has been assigned based on entries in the
87 <tt>/etc/group</tt> file.
88
89 <p>
90 Unfortunately, increases in the speed of computers and the
91 widespread introduction of network based computing, have made once
92 secure authentication mechanisms, such as this, vulnerable to
93 attack. In the light of such realities, new methods of authentication
94 are continuously being developed.
95
96 <p>
97 It is the purpose of the <bf/Linux-PAM/ project to separate the
98 development of privilege granting software from the development of
99 secure and appropriate authentication schemes.  This is accomplished
100 by providing a library of functions that an application may use to
101 request that a user be authenticated. This PAM library is configured
102 locally with a system file, <tt>/etc/pam.conf</tt> (or a series of
103 configuration files located in <tt>/etc/pam.d/</tt>) to authenticate a
104 user request via the locally available authentication modules. The
105 modules themselves will usually be located in the directory
106 <tt>/lib/security</tt> and take the form of dynamically loadable
107 object files (see <tt/dlopen(3)/).
108
109 <sect>Some comments on the text<label id="text-conventions">
110
111 <p>
112 Before proceeding to read the rest of this document, it should be
113 noted that the text assumes that certain files are placed in certain
114 directories.  Where they have been specified, the conventions we adopt
115 here for locating these files are those of the relevant RFC (RFC-86.0,
116 see <ref id="see-also-sec" name="bibliography">).  If you are using a
117 distribution of Linux (or some other operating system) that supports
118 PAM but chooses to distribute these files in a diferent way you should
119 be careful when copying examples directly from the text.
120
121 <p>
122 As an example of the above, where it is explicit, the text assumes
123 that PAM loadable object files (the <em/modules/) are to be located in
124 the following directory: <tt>/lib/security/</tt>. This is generally
125 the location that seems to be compatible with the Linux File System
126 Standard (the FSSTND). On Solaris, which has its own licensed version
127 of PAM, and some other implementations of UN*X, these files can be
128 found in <tt>/usr/lib/security</tt>. Please be careful to perform the
129 necessary transcription when using the examples from the text.
130
131 <sect>Overview<label id="overview-section">
132
133 <p>
134 For the uninitiated, we begin by considering an example.  We take an
135 application that grants some service to users; <em/login/ is one such
136 program. <em/Login/ does two things, it first establishes that the
137 requesting user is whom they claim to be and second provides them with
138 the requested service: in the case of <em/login/ the service is a
139 command shell (<em>bash, tcsh, zsh, etc.</em>) running with the
140 identity of the user.
141
142 <p>
143 Traditionally, the former step is achieved by the <em/login/
144 application prompting the user for a password and then verifying that
145 it agrees with that located on the system; hence verifying that
146 as far as the system is concerned the user is who they claim to be.
147 This is the task that is delegated to <bf/Linux-PAM/.
148
149 <p>
150 From the perspective of the application programmer (in this case the
151 person that wrote the <em/login/ application), <bf/Linux-PAM/ takes
152 care of this authentication task -- verifying the identity of the user.
153
154 <p>
155 The flexibility of <bf/Linux-PAM/ is that <em/you/, the system
156 administrator, have the freedom to stipulate which authentication
157 scheme is to be used.  You have the freedom to set the scheme for
158 any/all PAM-aware applications on your Linux system.  That is, you can
159 authenticate from anything as naive as <em/simple trust/
160 (<tt/pam_permit/) to something as paranoid as a combination of a
161 retinal scan, a voice print and a one-time password!
162
163 <p>
164 To illustrate the flexibility you face, consider the following
165 situation: a system administrator (parent) wishes to improve the
166 mathematical ability of her users (children). She can configure their
167 favorite ``Shoot 'em up game'' (PAM-aware of course) to authenticate
168 them with a request for the product of a couple of random numbers less
169 than 12. It is clear that if the game is any good they will soon learn
170 their <em/multiplication tables/.   As they mature, the authentication
171 can be upgraded to include (long) division!
172
173 <p>
174 <bf/Linux-PAM/ deals with four separate types of (management)
175 task. These are: <em/authentication management/; <em/account
176 management/; <em/session management/; and <em/password management/.
177 The association of the preferred management scheme with the behavior
178 of an application is made with entries in the relevant <bf/Linux-PAM/
179 configuration file.  The management functions are performed by
180 <em/modules/ specified in the configuration file. The syntax for this
181 file is discussed in the section <ref id="configuration"
182 name="below">.
183
184 <p>
185 Here is a figure that describes the overall organization of
186 <bf/Linux-PAM/.
187 <tscreen>
188 <verb>
189          +----------------+
190          | application: X |
191          +----------------+       /  +----------+     +================+
192          | authentication-[---->--\--] Linux-   |--<--| PAM config file|
193          |       +        [----<--/--]   PAM    |     |================|
194          |[conversation()][--+    \  |          |     | X auth .. a.so |
195          +----------------+  |    /  +-n--n-----+     | X auth .. b.so |
196          |                |  |       __|  |           |           _____/
197          |  service user  |  A      |     |           |____,-----' 
198          |                |  |      V     A                        
199          +----------------+  +------|-----|---------+ -----+------+
200                                 +---u-----u----+    |      |      |
201                                 |   auth....   |--[ a ]--[ b ]--[ c ]
202                                 +--------------+
203                                 |   acct....   |--[ b ]--[ d ]
204                                 +--------------+
205                                 |   password   |--[ b ]--[ c ]
206                                 +--------------+
207                                 |   session    |--[ e ]--[ c ]
208                                 +--------------+
209 </verb>
210 </tscreen>
211 By way of explanation, the left of the figure represents the
212 application; application X.  Such an application interfaces with the
213 <bf/Linux-PAM/ library and knows none of the specifics of its
214 configured authentication method.  The <bf/Linux-PAM/ library (in the
215 center) consults the contents of the PAM configuration file and loads
216 the modules that are appropriate for application-X. These modules fall
217 into one of four management groups (lower-center) and are stacked in
218 the order they appear in the configuration file. These modules, when
219 called by <bf/Linux-PAM/, perform the various authentication tasks for
220 the application. Textual information, required from/or offered to the
221 user, can be exchanged through the use of the application-supplied
222 <em/conversation/ function.
223
224 <sect1>Getting started
225
226 <p>
227 The following text was contributed by Seth Chaiklin:
228 <tscreen>
229 <verb>
230 To this point, we have described how PAM should work in an
231 ideal world, in which all applications are coded properly.
232 However, at the present time (October 1998), this is far
233 from the case.  Therefore, here are some practical considerations
234 in trying to use PAM in your system.
235
236 Why bother, is it really worth all the trouble?  
237
238 If you running Linux as a single user system, or in an
239 environment where all the users are trusted, then there 
240 is no real advantage for using PAM.
241 </verb>
242 </tscreen>
243
244 <p>
245 <BF>Ed:</BF> there is actually an advantage since you can <em/dummy
246 down/ the authentication to the point where you don't have
247 any... Almost like Win95.
248 <p>
249 In a networked environment, it is clear that you need to think a
250 little more about how users etc., are authenticated:]
251
252 <p>
253 <tscreen>
254 <verb>
255 If you are running Linux as a server, where several different
256 services are being provided (e.g., WWW with areas restricted by
257 password control, PPP), then there can be some real and interesting
258 value for PAM.  In particular, through the use of modules, PAM can
259 enable a program to search through several different password
260 databases, even if that program is not explicitly coded for
261 that particular database.  Here are some examples of the possibilities
262 that this enables.
263
264    o  Apache has a module that provides PAM services.  Now
265    authentication
266       to use particular directories can be conducted by PAM, which
267       means that the range of modules that are available to PAM can
268       be used, including RADIUS, NIS, NCP (which means that Novell
269       password databases can be used).
270
271    o  pppd has a PAMified version (available from RedHat)  Now it is
272       possible to use a series of databases to authenticate ppp users.
273       In addition to the normal Linux-based password databases (such
274       as /etc/passwd and /etc/shadow), you can use PAM modules to 
275       authenticate against Novell password databases or NT-based 
276       password databases. 
277
278    o  The preceding two examples can be combined.  Imagaine that the
279       persons in your office/department are already registered with a
280       username and password in a Novell or NT LAN.  If you wanted to
281       use this database on your Linux server (for PPP access, for 
282       web access, or even for normal shell access), you can use PAM
283       to authenticate against this existing database, rather than
284       maintain a separate database on both Linux and the LAN server.
285
286
287 Can I use PAM for any program that requires authentication?
288
289 Yes and no.   Yes, if you have access to the source code, and can
290 add the appropriate PAM functions.  No, if you do not have access 
291 to the source code, and the binary does not have the PAM functions
292 included.
293
294 In other words, if a program is going to use PAM, then it has to
295 have PAM functions explicitly coded into the program.  If they
296 are not, then it is not possible to use PAM. 
297
298 How can I tell whether a program has PAM coded into it or not?
299
300 A quick-and-dirty (but not always reliable) method is to ldd
301 <programname>
302 If libpam and libpam_misc are not among the libraries that the program
303 uses, then it is not going to work with PAM.  However, it is possible
304 that the libraries are included, but there are still problems, because
305 the PAM coding in the program does not work as it should.  So a
306 more reliable method is to make the follow tests.
307
308 In the /etc/pam.d directory, one needs to make a configuration file
309 for the program that one wants to run.  The exact name of the
310 configuration
311 file is hard-coded into the program.  Usually, it is the same name as
312 the
313 program, but not always.  For sake of illustration, let's assume that
314 the program is named "pamprog" and the name of the configuration file
315 is /etc/pam.d/pamprog.
316
317 In the /etc/pam.d/pamprog but the following two lines:
318
319 auth    required  pam_permit.so
320 auth    required  pam_warn.so
321
322
323 Now try to use pamprog.  The first line in the configuration file 
324 says that all users are permitted.  The second line will write a
325 warning to your syslog file (or whether you syslog is writing
326
327 messages).  If this test succeeds, then you know that you have
328 a program that can understand pam, and you can start the more
329 interesting work of deciding how to stack modules in your
330 /etc/pam.d/pamprog  file.
331 </verb>
332 </tscreen>
333
334 <sect>The Linux-PAM configuration file
335 <label id="configuration">
336
337 <p>
338 <bf/Linux-PAM/ is designed to provide the system administrator with a
339 great deal of flexibility in configuring the privilege granting
340 applications of their system. The local configuration of those aspects
341 of system security controlled by <tt/Linux-PAM/ is contained in one of
342 two places: either the single system file, <tt>/etc/pam.conf</tt>; or
343 the <tt>/etc/pam.d/</tt> directory.  In this section we discuss the
344 correct syntax of and generic options respected by entries to these
345 files.
346
347 <sect1>Configuration file syntax
348
349 <p>
350 The reader should note that the <bf/Linux-PAM/ specific tokens in this
351 file are case <em/insensitive/. The module paths, however, are case
352 sensitive since they indicate a file's <em/name/ and reflect the case
353 dependence of typical Linux file-systems. The case-sensitivity of the
354 arguments to any given module is defined for each module in turn.
355
356 <p>
357 In addition to the lines described below, there are two <em/special/
358 characters provided for the convenience of the system administrator:
359 comments are preceded by a `<tt/&num;/' and extend to the
360 next end-of-line; also, module specification lines may be extended
361 with a `<tt/&bsol;/' escaped newline.
362
363 <p>
364 A general configuration line of the <tt>/etc/pam.conf</tt> file has
365 the following form:
366 <tscreen>
367 <verb>
368 service-name   module-type   control-flag   module-path   args
369 </verb>
370 </tscreen>
371 Below, we explain the meaning of each of these tokens. The second (and
372 more recently adopted) way of configuring <bf/Linux-PAM/ is via the
373 contents of the <tt>/etc/pam.d/</tt> directory. Once we have explained
374 the meaning of the above tokens, we will describe this method.
375
376 <p>
377 <descrip>
378 <tag><tt/service-name/</tag>
379 The name of the service associated with this entry. Frequently the
380 service name is the conventional name of the given application. For
381 example, `<tt/ftpd/', `<tt/rlogind/' and `<tt/su/', <em/etc./ .
382
383 <p>
384 There is a special <tt/service-name/, reserved for defining a default
385 authentication mechanism. It has the name `<tt/OTHER/' and may be
386 specified in either lower or upper case characters. Note, when there
387 is a module specified for a named service, the `<tt/OTHER/' entries
388 are ignored.
389
390 <tag><tt/module-type/</tag>
391 One of (currently) four types of module. The four types are as
392 follows:
393 <itemize>
394 <item> <tt/auth/; this module type provides two aspects of
395 authenticating the user. Firstly, it establishes that the user is who
396 they claim to be, by instructing the application to prompt the user
397 for a password or other means of identification. Secondly, the module
398 can grant <tt/group/ membership (independently of the
399 <tt>/etc/groups</tt> file discussed above) or other privileges through
400 its <em/credential/ granting properties.
401
402 <item> <tt/account/; this module performs non-authentication based
403 account management. It is typically used to restrict/permit access to
404 a service based on the time of day, currently available system
405 resources (maximum number of users) or perhaps the location of the
406 applicant user---`<tt/root/' login only on the console.
407
408 <item> <tt/session/; primarily, this module is associated with doing
409 things that need to be done for the user before/after they can be
410 given service.  Such things include the logging of information
411 concerning the opening/closing of some data exchange with a user,
412 mounting directories, etc. .
413
414 <item> <tt/password/; this last module type is required for updating the
415 authentication token associated with the user. Typically, there is one
416 module for each `challenge/response' based authentication (<tt/auth/)
417 module-type.
418
419 </itemize>
420
421 <tag><tt/control-flag/</tag>
422
423 The control-flag is used to indicate how the PAM library will react to
424 the success or failure of the module it is associated with.  Since
425 modules can be <em/stacked/ (modules of the same type execute in
426 series, one after another), the control-flags determine the relative
427 importance of each module.  The application is not made aware of the
428 individual success or failure of modules listed in the
429 `<tt>/etc/pam.conf</tt>' file.  Instead, it receives a summary
430 <em/success/ or <em/fail/ response from the <bf/Linux-PAM/ library.
431 The order of execution of these modules is that of the entries in the
432 <tt>/etc/pam.conf</tt> file; earlier entries are executed before later
433 ones.  As of Linux-PAM v0.60, this <em/control-flag/ can be defined
434 with one of two syntaxes.
435
436 <p>
437 The simpler (and historical) syntax for the control-flag is a single
438 keyword defined to indicate the severity of concern associated with
439 the success or failure of a specific module.  There are four such
440 keywords: <tt/required/, <tt/requisite/, <tt/sufficient/ and
441 <tt/optional/.
442
443 <p>
444 The Linux-PAM library interprets these keywords in the following
445 manner:
446
447 <itemize>
448
449 <item> <tt/required/; this indicates that the success of the module is
450 required for the <tt/module-type/ facility to succeed. Failure of this
451 module will not be apparent to the user until all of the remaining
452 modules (of the same <tt/module-type/) have been executed.
453
454 <item> <tt/requisite/; like <tt/required/, however, in the case that
455 such a module returns a failure, control is directly returned to the
456 application.  The return value is that associated with the <em/first/
457 <tt/required/ or <tt/requisite/ module to fail.  Note, this flag can be
458 used to protect against the possibility of a user getting the
459 opportunity to enter a password over an unsafe medium.  It is
460 conceivable that such behavior might inform an attacker of valid
461 accounts on a system. This possibility should be weighed against the
462 not insignificant concerns of exposing a sensitive password in a
463 hostile environment.
464
465 <item> <tt/sufficient/; the success of this module is deemed
466 `<em/sufficient/' to satisfy the <bf/Linux-PAM/ library that this
467 module-type has succeeded in its purpose. In the event that no
468 previous <tt/required/ module has failed, no more `<em/stacked/'
469 modules of this type are invoked. (Note, in this case subsequent
470 <tt/required/ modules are <bf/not/ invoked.). A failure of this module
471 is not deemed as fatal to satisfying the application that this
472 <tt/module-type/ has succeeded.
473
474 <item> <tt/optional/; as its name suggests, this <tt/control-flag/
475 marks the module as not being critical to the success or failure of
476 the user's application for service.  In general, <bf/Linux-PAM/
477 ignores such a module when determining if the module stack will
478 succeed or fail.  However, in the absence of any definite successes or
479 failures of previous or subsequent stacked modules this module will
480 determine the nature of the response to the application.  One example
481 of this latter case, is when the other modules return something like
482 <tt/PAM_IGNORE/.
483
484 </itemize>
485
486 <p>
487 The more elaborate (newer) syntax is much more specific and gives the
488 administrator a great deal of control over how the user is
489 authenticated.  This form of the control flag is delimeted with square
490 brackets and consists of a series of <tt/value=action/ tokens:
491 <tscreen>
492 <verb>
493     [value1=action1 value2=action2 ...]
494 </verb>
495 </tscreen>
496
497 <p>
498 Here, <tt/valueI/ is one of the following <em/return values/:
499 <tt/success/; <tt/open_err/; <tt/symbol_err/; <tt/service_err/;
500 <tt/system_err/; <tt/buf_err/; <tt/perm_denied/; <tt/auth_err/;
501 <tt/cred_insufficient/; <tt/authinfo_unavail/; <tt/user_unknown/;
502 <tt/maxtries/; <tt/new_authtok_reqd/; <tt/acct_expired/;
503 <tt/session_err/; <tt/cred_unavail/; <tt/cred_expired/; <tt/cred_err/;
504 <tt/no_module_data/; <tt/conv_err/; <tt/authtok_err/;
505 <tt/authtok_recover_err/; <tt/authtok_lock_busy/;
506 <tt/authtok_disable_aging/; <tt/try_again/; <tt/ignore/; <tt/abort/;
507 <tt/authtok_expired/; <tt/module_unknown/; <tt/bad_item/; and
508 <tt/default/.  The last of these (<tt/default/) can be used to set the
509 action for those return values that are not explicitly defined.
510
511 <p>
512 The <tt/actionI/ can be a positive integer or one of the following
513 tokens: <tt/ignore/; <tt/ok/; <tt/done/; <tt/bad/; <tt/die/; and
514 <tt/reset/.  A positive integer, <tt/J/, when specified as the action,
515 can be used to indicate that the next <em/J/ modules of the current
516 module-type will be skipped.  In this way, the administrator can
517 develop a moderately sophisticated stack of modules with a number of
518 different paths of execution.  Which path is taken can be determined
519 by the reactions of individual modules.
520
521 <p>
522 <itemize>
523 <item><tt/ignore/ - when used with a stack of modules, the module's
524   return status will not contribute to the return code the application
525   obtains.
526 <item><tt/bad/ - this action indicates that the return code should be
527   thought of as indicative of the module failing. If this module is
528   the first in the stack to fail, its status value will be used for
529   that of the whole stack.
530 <item><tt/die/ - equivalent to <tt/bad/ with the side effect of
531   terminating the module stack and PAM immediately returning to the
532   application.
533 <item><tt/ok/ - this tells <bf/PAM/ that the administrator thinks this
534   return code should contribute directly to the return code of the full
535   stack of modules. In other words, if the former state of the stack
536   would lead to a return of <tt/PAM_SUCCESS/, the module's return code
537   will override this value.  Note, if the former state of the stack
538   holds some value that is indicative of a modules failure, this 'ok'
539   value will not be used to override that value.
540 <item><tt/done/ - equivalent to <tt/ok/ with the side effect of
541   terminating the module stack and PAM immediately returning to the
542   application.
543 <item><tt/reset/ - clear all memory of the state of the module stack and
544   start again with the next stacked module.
545 </itemize>
546
547 <p>
548 Each of the four keywords: <tt/required/; <tt/requisite/;
549 <tt/sufficient/; and <tt/optional/, have an equivalent expression in
550 terms of the <tt/[...]/ syntax. They are as follows:
551 <itemize>
552 <item><tt/required/ is equivalent to
553 <tt/[success=ok new_authtok_reqd=ok ignore=ignore default=bad]/
554 <item><tt/requisite/ is equivalent to
555 <tt/[success=ok new_authtok_reqd=ok ignore=ignore default=die]/
556 <item><tt/sufficient/ is equivalent to
557 <tt/[success=done new_authtok_reqd=done default=ignore]/
558 <item><tt/optional/ is equivalent to 
559 <tt/[success=ok new_authtok_reqd=ok default=ignore]/
560 </itemize>
561
562 <p>
563 Just to get a feel for the power of this new syntax, here is a taste
564 of what you can do with it.  With <bf/Linux-PAM-0.63/, the notion of
565 client plug-in agents was introduced.  This is something that makes it
566 possible for PAM to support machine-machine authentication using the
567 transport protocol inherent to the client/server application.  With
568 the ``<tt/[ ... value=action ... ]/'' control syntax, it is possible
569 for an application to be configured to support binary prompts with
570 compliant clients, but to gracefully fall over into an alternative
571 authentication mode for older, legacy, applications.
572
573 <tag> <tt/module-path/</tag>
574
575 The path-name of the dynamically loadable object file; <em/the
576 pluggable module/ itself. If the first character of the module path is
577 `<tt>/</tt>', it is assumed to be a complete path. If this is not the
578 case, the given module path is appended to the default module path:
579 <tt>/lib/security</tt> (but see the notes <ref id="text-conventions"
580 name="above">).
581
582 <tag> <tt/args/</tag>
583
584 The <tt/args/ are a list of tokens that are passed to the module when
585 it is invoked. Much like arguments to a typical Linux shell command.
586 Generally, valid arguments are optional and are specific to any given
587 module. Invalid arguments are ignored by a module, however, when
588 encountering an invalid argument, the module is required to write an
589 error to <tt/syslog(3)/. For a list of <em/generic/ options see the
590 next section.
591
592 Note, if you wish to include spaces in an argument, you should
593 surround that argument with square brackets. For example:
594 <tscreen>
595 <verb>
596 squid auth required pam_mysql.so user=passwd_query passwd=mada \
597         db=eminence [query=select user_name from internet_service where \
598                      user_name='%u' and password=PASSWORD('%p') and \
599                      service='web_proxy']
600 </verb>
601 </tscreen>
602 Note, when using this convention, you can include `<tt/[/' characters
603 inside the string, and if you wish to include a `<tt/]/' character
604 inside the string that will survive the argument parsing, you should
605 use `<tt/\[/'. In other words:
606 <tscreen>
607 <verb>
608 [..[..\]..]    -->   ..[..]..
609 </verb>
610 </tscreen>
611
612 </descrip>
613
614 <p>
615 Any line in (one of) the configuration file(s), that is not formatted
616 correctly, will generally tend (erring on the side of caution) to make
617 the authentication process fail.  A corresponding error is written to
618 the system log files with a call to <tt/syslog(3)/.
619
620 <sect1>Directory based configuration
621
622 <p>
623 More flexible than the single configuration file, as of version 0.56,
624 it is possible to configure <tt>libpam</tt> via the contents of the
625 <tt>/etc/pam.d/</tt> directory.  In this case the directory is filled
626 with files each of which has a filename equal to a service-name (in
627 lower-case): it is the personal configuration file for the named
628 service.
629
630 <p>
631 <bf/Linux-PAM/ can be compiled in one of two modes.  The preferred
632 mode uses either <tt>/etc/pam.d/</tt> or <tt>/etc/pam.conf</tt>
633 configuration but not both.  That is to say, if there is a
634 <tt>/etc/pam.d/</tt> directory then libpam only uses the files
635 contained in this directory.  However, in the absence of the
636 <tt>/etc/pam.d/</tt> directory the <tt>/etc/pam.conf</tt> file is used
637 (this is likely to be the mode your preferred distribution uses).  The
638 other mode is to use both <tt>/etc/pam.d/</tt> and
639 <tt>/etc/pam.conf</tt> in sequence.  In this mode, entries in
640 <tt>/etc/pam.d/</tt> override those of <tt>/etc/pam.conf</tt>.
641
642 The syntax of each file in <tt>/etc/pam.d/</tt> is similar to that of
643 the <tt>/etc/pam.conf</tt> file and is made up of lines of the
644 following form:
645 <tscreen>
646 <verb>
647 module-type   control-flag   module-path   arguments
648 </verb>
649 </tscreen>
650 The only difference being that the <tt>service-name</tt> is not
651 present.   The service-name is of course the name of the given
652 configuration file.  For example, <tt>/etc/pam.d/login</tt> contains
653 the configuration for the <em>login</em> service.
654
655 <p>
656 This method of configuration has a number of advantages over the
657 single file approach. We list them here to assist the reader in
658 deciding which scheme to adopt:
659
660 <p>
661 <itemize>
662
663 <item>A lower chance of misconfiguring an application. There is one
664 less field to mis-type when editing the configuration files by hand.
665
666 <item>Easier to maintain. One application may be reconfigured without
667 risk of interfering with other applications on the system.
668
669 <item>It is possible to symbolically link different services
670 configuration files to a single file. This makes it easier to keep the
671 system policy for access consistent across different applications.
672 (It should be noted, to conserve space, it is equally possible to
673 <em>hard</em> link a number of configuration files.  However, care
674 should be taken when administering this arrangement as editing a hard
675 linked file is likely to break the link.)
676
677 <item>A potential for quicker configuration file parsing. Only the
678 relevant entries are parsed when a service gets bound to its modules.
679
680 <item>It is possible to limit read access to individual <bf/Linux-PAM/
681 configuration files using the file protections of the filesystem.
682
683 <item>Package management becomes simpler.  Every time a new
684 application is installed, it can be accompanied by an
685 <tt>/etc/pam.d/</tt><em>xxxxxx</em> file.
686
687 </itemize>
688
689 <sect1>Generic optional arguments
690
691 <p>
692 The following are optional arguments which are likely to be understood
693 by any module. Arguments (including these) are in general
694 <em/optional/.
695
696 <p>
697 <descrip>
698 <tag><tt/debug/</tag>
699
700 Use the <tt/syslog(3)/ call to log debugging information to the system
701 log files.
702
703 <tag> <tt/no_warn/</tag>
704
705 Instruct module to not give warning messages to the application.
706
707 <tag> <tt/use_first_pass/</tag>
708
709 The module should not prompt the user for a password. Instead, it
710 should obtain the previously typed password (from the preceding
711 <tt/auth/ module), and use that. If that doesn't work, then the user
712 will not be authenticated. (This option is intended for <tt/auth/
713 and <tt/password/ modules only).
714
715 <tag> <tt/try_first_pass/</tag>
716
717 The module should attempt authentication with the previously typed
718 password (from the preceding <tt/auth/ module). If that doesn't work,
719 then the user is prompted for a password. (This option is intended for
720 <tt/auth/ modules only).
721
722 <tag> <tt/use_mapped_pass/</tag>
723
724 This argument is not currently supported by any of the modules in the
725 <bf/Linux-PAM/ distribution because of possible consequences
726 associated with U.S. encryption exporting restrictions. Within the
727 U.S., module developers are, of course, free to implement it (as are
728 developers in other countries). For compatibility reasons we describe
729 its use as suggested in the <bf/DCE-RFC 86.0/, see section <ref
730 id="see-also-sec" name="bibliography"> for a pointer to this document.
731
732 <p>
733 The <tt/use_mapped_pass/ argument instructs the module to take the
734 clear text authentication token entered by a previous module (that
735 requests such a token) and use it to generate an encryption/decryption
736 key with which to safely store/retrieve the authentication token
737 required for this module. In this way the user can enter a single
738 authentication token and be quietly authenticated by a number of
739 stacked modules.  Obviously a convenient feature that necessarily
740 requires some reliably strong encryption to make it secure.
741 This argument is intended for the <tt/auth/ and <tt/password/ module
742 types only.
743
744 <tag><tt/expose_account/</tag>
745
746 <p>
747 In general the leakage of some information about user accounts is not
748 a secure policy for modules to adopt. Sometimes information such as
749 users names or home directories, or preferred shell, can be used to
750 attack a user's account. In some circumstances, however, this sort of
751 information is not deemed a threat: displaying a user's full name when
752 asking them for a password in a secured environment could also be
753 called being 'friendly'. The <tt/expose_account/ argument is a
754 standard module argument to encourage a module to be less discrete
755 about account information as it is deemed appropriate by the local
756 administrator.
757
758 </descrip>
759
760 <sect1>Example configuration file entries
761
762 <p>
763 In this section, we give some examples of entries that can be present
764 in the <bf/Linux-PAM/ configuration file. As a first attempt at
765 configuring your system you could do worse than to implement these.
766
767 <sect2>Default policy
768
769 <p>
770 If a system is to be considered secure, it had better have a
771 reasonably secure `<tt/OTHER/' entry. The following is a paranoid
772 setting (which is not a bad place to start!):
773 <tscreen>
774 <verb>
775 #
776 # default; deny access
777 #
778 OTHER   auth     required       pam_deny.so
779 OTHER   account  required       pam_deny.so
780 OTHER   password required       pam_deny.so
781 OTHER   session  required       pam_deny.so
782 </verb>
783 </tscreen>
784 Whilst fundamentally a secure default, this is not very sympathetic to
785 a misconfigured system. For example, such a system is vulnerable to
786 locking everyone out should the rest of the file become badly written.
787
788 <p>
789 The module <tt/pam_deny/ (documented in a later section) is not very
790 sophisticated. For example, it logs no information when it is invoked
791 so unless the users of a system contact the administrator when failing
792 to execute a service application, the administrator may go for a long
793 while in ignorance of the fact that his system is misconfigured.
794
795 <p>
796 The addition of the following line before those in the above example
797 would provide a suitable warning to the administrator.
798 <tscreen>
799 <verb>
800 #
801 # default; wake up! This application is not configured
802 #
803 OTHER   auth     required       pam_warn.so
804 OTHER   password required       pam_warn.so
805 </verb>
806 </tscreen>
807 Having two ``<tt/OTHER auth/'' lines is an example of stacking.
808
809 <p>
810 On a system that uses the <tt>/etc/pam.d/</tt> configuration, the
811 corresponding default setup would be achieved with the following file:
812 <tscreen>
813 <verb>
814 #
815 # default configuration: /etc/pam.d/other
816 #
817 auth     required       pam_warn.so
818 auth     required       pam_deny.so
819 account  required       pam_deny.so
820 password required       pam_warn.so
821 password required       pam_deny.so
822 session  required       pam_deny.so
823 </verb>
824 </tscreen>
825 This is the only explicit example we give for an <tt>/etc/pam.d/</tt>
826 file. In general, it should be clear how to transpose the remaining
827 examples to this configuration scheme.
828
829 <p>
830 On a less sensitive computer, one on which the system administrator
831 wishes to remain ignorant of much of the power of <tt/Linux-PAM/, the
832 following selection of lines (in <tt>/etc/pam.conf</tt>) is likely to
833 mimic the historically familiar Linux setup.
834 <tscreen>
835 <verb>
836 #
837 # default; standard UN*X access
838 #
839 OTHER   auth     required       pam_unix.so
840 OTHER   account  required       pam_unix.so
841 OTHER   password required       pam_unix.so
842 OTHER   session  required       pam_unix.so
843 </verb>
844 </tscreen>
845 In general this will provide a starting place for most applications.
846 Unfortunately, most is not all. One application that might require
847 additional lines is <em/ftpd/ if you wish to enable
848 <em/anonymous-ftp/.
849
850 <p>
851 To enable anonymous-ftp, the following lines might be used to replace
852 the default (<tt/OTHER/) ones. (<bf/*WARNING*/ as of 1996/12/28 this
853 does not work correctly with any ftpd. Consequently, this description
854 may be subject to change or the application will be fixed.)
855 <tscreen>
856 <verb>
857 #
858 # ftpd; add ftp-specifics. These lines enable anonymous ftp over
859 #       standard UN*X access (the listfile entry blocks access to
860 #       users listed in /etc/ftpusers)
861 #
862 ftpd    auth    sufficient  pam_ftp.so
863 ftpd    auth    required    pam_unix_auth.so use_first_pass
864 ftpd    auth    required    pam_listfile.so \
865         onerr=succeed item=user sense=deny file=/etc/ftpusers
866 </verb>
867 </tscreen>
868 Note, the second line is necessary since the default entries are
869 ignored by a service application (here <em/ftpd/) if there are
870 <em/any/ entries in <tt>/etc/pam.conf</tt> for that specified service.
871 Again, this is an example of authentication module stacking.  Note the
872 use of the <tt/sufficient/ control-flag. It says that ``if this module
873 authenticates the user, ignore the subsequent <tt/auth/
874 modules''. Also note the use of the ``<tt/use_first_pass/''
875 module-argument, this instructs the UN*X authentication module that it
876 is not to prompt for a password but rely on one already having been
877 obtained by the <tt/pam_ftp/ module.
878
879 <sect>Security issues of Linux-PAM
880
881 <p>
882 This section will discuss good practices for using PAM in a secure
883 manner.  <em>It is currently sadly lacking...suggestions are
884 welcome!</em>
885
886 <sect1>If something goes wrong
887
888 <p>
889 <bf/Linux-PAM/ has the potential to seriously change the security of
890 your system.  You can choose to have no security or absolute security
891 (no access permitted).  In general, <bf/Linux-PAM/ errs towards the
892 latter.  Any number of configuration errors can dissable access to
893 your system partially, or completely.
894
895 <p>
896 The most dramatic problem that is likely to be encountered when
897 configuring <bf/Linux-PAM/ is that of <em>deleting</em> the
898 configuration file(s): <tt>/etc/pam.d/*</tt> and/or
899 <tt>/etc/pam.conf</tt>.  This will lock you out of your own system!
900
901 <p>
902 To recover, your best bet is to reboot the system in single user mode
903 and set about correcting things from there.  The following has been
904 <em>adapted</em> from a life-saving email on the subject from David
905 Wood:
906 <verb>
907 > What the hell do I do now?
908
909 OK, don't panic. The first thing you have to realize is that
910 this happens to 50% of users who ever do anything with PAM.
911 It happened here, not once, not twice, but three times, all
912 different, and in the end, the solution was the same every
913 time.
914
915 First, I hope you installed LILO with a delay. If you can,
916 reboot, hit shift or tab or something and type:
917
918     LILO boot: linux single
919
920 (Replace 'linux' with 'name-of-your-normal-linux-image').
921 This will let you in without logging in.  Ever wondered how
922 easy it is to break into a linux machine from the console?
923 Now you know.
924
925 If you can't do that, then get yourself a bootkernel floppy
926 and a root disk a-la slackware's rescue.gz.  (Red Hat's
927 installation disks can be used in this mode too.)
928
929 In either case, the point is to get back your root prompt.
930
931 Second, I'm going to assume that you haven't completely
932 nuked your pam installation - just your configuration files.
933 Here's how you make your configs nice again:
934
935     cd /etc
936     mv pam.conf pam.conf.orig
937     mv pam.d pam.d.orig
938     mkdir pam.d
939     cd pam.d
940
941 and then use vi to create a file called "other" in this
942 directory.  It should contain the following four lines:
943
944     auth     required       pam_unix.so
945     account  required       pam_unix.so
946     password required       pam_unix.so
947     session  required       pam_unix.so
948
949 Now you have the simplest possible PAM configuration that
950 will work the way you're used to.  Everything should
951 magically start to work again.  Try it out by hitting ALT-F2
952 and logging in on another virtual console.  If it doesn't
953 work, you have bigger problems, or you've mistyped
954 something.  One of the wonders of this system (seriously,
955 perhaps) is that if you mistype anything in the conf files,
956 you usually get no error reporting of any kind on the
957 console - just some entries in the log file.  So look there!
958 (Try 'tail /var/log/messages'.)
959
960 From here you can go back and get a real configuration
961 going, hopefully after you've tested it first on a machine
962 you don't care about screwing up.  :/
963
964 Some pointers (to make everything "right" with Red Hat...):
965
966     Install the newest pam, pamconfig, and pwdb from the
967     redhat current directory, and do it all on the same
968     command line with rpm...
969
970         rpm -Uvh [maybe --force too] pam-* pamconfig-* pwdb-*
971
972     Then make sure you install (or reinstall) the newest
973     version of libc, util-linux, wuftp, and NetKit. For
974     kicks you might try installing the newest versions of
975     the affected x apps, like xlock, but I haven't gotten
976     those to work at all yet.
977
978 </verb>
979
980 <sect1>Avoid having a weak `other' configuration
981
982 <p>
983 It is not a good thing to have a weak default (<tt/OTHER/) entry.
984 This service is the default configuration for all PAM aware
985 applications and if it is weak, your system is likely to be vulnerable
986 to attack.
987
988 <p>
989 Here is a sample "other" configuration file. The <em/pam_deny/ module will
990 deny access and the <em/pam_warn/ module will send a syslog message to
991 <tt/auth.notice/:
992
993 <p>
994 <tscreen>
995 <verb>
996 #
997 # The PAM configuration file for the `other' service 
998
999 auth      required   pam_deny.so 
1000 auth      required   pam_warn.so 
1001 account   required   pam_deny.so 
1002 account   required   pam_warn.so 
1003 password  required   pam_deny.so 
1004 password  required   pam_warn.so 
1005 session   required   pam_deny.so 
1006 session   required   pam_warn.so
1007 </verb>
1008 </tscreen>
1009
1010 <sect>A reference guide for available modules
1011
1012 <p>
1013 Here, we collect together some descriptions of the various modules
1014 available for <bf/Linux-PAM/.  In general these modules should be
1015 freely available.  Where this is not the case, it will be indicated.
1016
1017 <p>
1018 Also please note the comments contained in the section <ref 
1019 id="text-conventions" name="on text conventions above"> when copying
1020 the examples listed below.
1021
1022 <!-- insert-file MODULES-SGML -->
1023
1024 <sect>Files
1025
1026 <p><descrip>
1027
1028 <tag><tt>/lib/libpam.so.*</tt></tag>
1029
1030 the shared library providing applications with access to
1031 <bf/Linux-PAM/.
1032
1033 <tag><tt>/etc/pam.conf</tt></tag>
1034
1035 the <bf/Linux-PAM/ configuration file.
1036
1037 <tag><tt>/lib/security/pam_*.so</tt></tag>
1038
1039 the primary location for <bf/Linux-PAM/ dynamically loadable object
1040 files; the modules.
1041
1042 </descrip>
1043
1044 <sect>See also<label id="see-also-sec">
1045
1046 <p><itemize>
1047
1048 <item>The <bf/Linux-PAM/ Application Writers' Guide.
1049
1050 <item>The <bf/Linux-PAM/ Module Writers' Guide.
1051
1052 <item>The V. Samar and R. Schemers (SunSoft), ``UNIFIED LOGIN WITH
1053 PLUGGABLE AUTHENTICATION MODULES'', Open Software Foundation Request
1054 For Comments 86.0, October 1995. See this url:
1055 <tt><htmlurl
1056 url="http://www.kernel.org/pub/linux/libs/pam/pre/doc/rfc86.0.txt.gz"
1057 name="http://www.kernel.org/pub/linux/libs/pam/pre/doc/rfc86.0.txt.gz"></tt>
1058
1059 </itemize>
1060
1061 <sect>Notes
1062
1063 <p>
1064 I intend to put development comments here... like ``at the moment
1065 this isn't actually supported''. At release time what ever is in
1066 this section will be placed in the Bugs section below! :)
1067
1068 <p>
1069 Are we going to be able to support the <tt/use_mapped_pass/ module
1070 argument? Anyone know a cheap (free) good lawyer?!
1071
1072 <p>
1073 <itemize>
1074 <item>
1075 This issue may go away, as Sun have investigated adding a new
1076 management group for mappings. In this way, libpam would have mapping
1077 modules that could securely store passwords using strong cryptography
1078 and in such a way that they need not be distributed with Linux-PAM.
1079 </itemize>
1080
1081 <sect>Author/acknowledgments
1082
1083 <p>
1084 This document was written by Andrew G. Morgan (morgan@kernel.org)
1085 with many contributions from
1086 <!-- insert-file CREDITS -->
1087
1088 <p>
1089 Thanks are also due to Sun Microsystems, especially to Vipin Samar and
1090 Charlie Lai for their advice. At an early stage in the development of
1091 <bf/Linux-PAM/, Sun graciously made the documentation for their
1092 implementation of PAM available. This act greatly accelerated the
1093 development of <bf/Linux-PAM/.
1094
1095 <sect>Bugs/omissions
1096
1097 <p>
1098 More PAM modules are being developed all the time. It is unlikely that
1099 this document will ever be truely up to date!
1100
1101 <p>
1102 This manual is unfinished. Only a partial list of people is credited
1103 for all the good work they have done.
1104
1105 <sect>Copyright information for this document
1106
1107 <p>
1108 Copyright (c) Andrew G. Morgan 1996-2002.  All rights reserved.
1109 <newline>
1110 Email: <tt>&lt;morgan@kernel.org&gt;</tt>
1111
1112 <p>
1113 Redistribution and use in source and binary forms, with or without
1114 modification, are permitted provided that the following conditions are
1115 met:
1116
1117 <p>
1118 <itemize>
1119
1120 <item>
1121 1. Redistributions of source code must retain the above copyright
1122    notice, and the entire permission notice in its entirety,
1123    including the disclaimer of warranties.
1124
1125 <item>
1126 2. Redistributions in binary form must reproduce the above copyright
1127    notice, this list of conditions and the following disclaimer in the
1128    documentation and/or other materials provided with the distribution.
1129
1130 <item>
1131 3. The name of the author may not be used to endorse or promote
1132    products derived from this software without specific prior
1133    written permission.
1134
1135 </itemize>
1136
1137 <p>
1138 <bf/Alternatively/, this product may be distributed under the terms of
1139 the GNU General Public License (GPL), in which case the provisions of
1140 the GNU GPL are required <bf/instead of/ the above restrictions.
1141 (This clause is necessary due to a potential bad interaction between
1142 the GNU GPL and the restrictions contained in a BSD-style copyright.)
1143
1144 <p>
1145 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
1146 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1147 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1148 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1149 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1150 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
1151 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1152 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
1153 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
1154 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1155 DAMAGE.
1156
1157 <p>
1158 <tt>$Id$</tt>
1159
1160 </article>