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