]> granicus.if.org Git - linux-pam/blob - doc/pam_source.sgml
Relevant BUGIDs: 408961
[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.75 2001/03/18
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>/usr/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>/usr/lib/security/</tt>. However, Red Hat
126 Linux, in agreement with the Linux File System Standard (the FSSTND),
127 places these files in <tt>/lib/security</tt>. Please be careful to
128 perform the necessary transcription when using the examples from the
129 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   arguments
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 type will be skipped.  In this way, the administrator can develop a
517 moderately sophisticated stack of modules with a number of different
518 paths of execution.  Which path is taken can be determined by the
519 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 Just to get a feel for the power of this new syntax, here is a taste
549 of what you can do with it.  With <bf/Linux-PAM-0.63/, the notion of
550 client plug-in agents was introduced.  This is something that makes it
551 possible for PAM to support machine-machine authentication using the
552 transport protocol inherent to the client/server application.  With
553 the ``<tt/[ ... value=action ... ]/'' control syntax, it is possible
554 for an application to be configured to support binary prompts with
555 compliant clients, but to gracefully fall over into an alternative
556 authentication mode for older, legacy, applications.  Flexible eh?
557
558 <tag> <tt/module-path/</tag>
559
560 The path-name of the dynamically loadable object file; <em/the
561 pluggable module/ itself. If the first character of the module path is
562 `<tt>/</tt>', it is assumed to be a complete path. If this is not the
563 case, the given module path is appended to the default module path:
564 <tt>/usr/lib/security</tt> (but see the notes <ref
565 id="text-conventions" name="above">).
566
567 <tag> <tt/args/</tag>
568
569 The <tt/args/ are a list of tokens that are passed to the module when
570 it is invoked. Much like arguments to a typical Linux shell command.
571 Generally, valid arguments are optional and are specific to any given
572 module. Invalid arguments are ignored by a module, however, when
573 encountering an invalid argument, the module is required to write an
574 error to <tt/syslog(3)/. For a list of <em/generic/ options see the
575 next section.
576
577 </descrip>
578
579 <p>
580 Any line in (one of) the configuration file(s), that is not formatted
581 correctly, will generally tend (erring on the side of caution) to make
582 the authentication process fail.  A corresponding error is written to
583 the system log files with a call to <tt/syslog(3)/.
584
585 <sect1>Directory based configuration
586
587 <p>
588 More flexible than the single configuration file, as of version 0.56,
589 it is possible to configure <tt>libpam</tt> via the contents of the
590 <tt>/etc/pam.d/</tt> directory.  In this case the directory is filled
591 with files each of which has a filename equal to a service-name (in
592 lower-case): it is the personal configuration file for the named
593 service.
594
595 <p>
596 <bf/Linux-PAM/ can be compiled in one of two modes.  The preferred
597 mode uses either <tt>/etc/pam.d/</tt> or <tt>/etc/pam.conf</tt>
598 configuration but not both.  That is to say, if there is a
599 <tt>/etc/pam.d/</tt> directory then libpam only uses the files
600 contained in this directory.  However, in the absence of the
601 <tt>/etc/pam.d/</tt> directory the <tt>/etc/pam.conf</tt> file is
602 used.  The other mode (and the one currently supported by Red Hat 4.2
603 and higher) is to use both <tt>/etc/pam.d/</tt> and
604 <tt>/etc/pam.conf</tt> in sequence.  In this mode, entries in
605 <tt>/etc/pam.d/</tt> override those of <tt>/etc/pam.conf</tt>.
606
607 The syntax of each file in <tt>/etc/pam.d/</tt> is similar to that of
608 the <tt>/etc/pam.conf</tt> file and is made up of lines of the
609 following form:
610 <tscreen>
611 <verb>
612 module-type   control-flag   module-path   arguments
613 </verb>
614 </tscreen>
615 The only difference being that the <tt>service-name</tt> is not
616 present.   The service-name is of course the name of the given
617 configuration file.  For example, <tt>/etc/pam.d/login</tt> contains
618 the configuration for the <em>login</em> service.
619
620 <p>
621 This method of configuration has a number of advantages over the
622 single file approach. We list them here to assist the reader in
623 deciding which scheme to adopt:
624
625 <p>
626 <itemize>
627
628 <item>A lower chance of misconfiguring an application. There is one
629 less field to mis-type when editing the configuration files by hand.
630
631 <item>Easier to maintain. One application may be reconfigured without
632 risk of interfering with other applications on the system.
633
634 <item>It is possible to symbolically link different services
635 configuration files to a single file. This makes it easier to keep the
636 system policy for access consistent across different applications.
637 (It should be noted, to conserve space, it is equally possible to
638 <em>hard</em> link a number of configuration files.  However, care
639 should be taken when administering this arrangement as editing a hard
640 linked file is likely to break the link.)
641
642 <item>A potential for quicker configuration file parsing. Only the
643 relevant entries are parsed when a service gets bound to its modules.
644
645 <item>It is possible to limit read access to individual <bf/Linux-PAM/
646 configuration files using the file protections of the filesystem.
647
648 <item>Package management becomes simpler.  Every time a new
649 application is installed, it can be accompanied by an
650 <tt>/etc/pam.d/</tt><em>xxxxxx</em> file.
651
652 </itemize>
653
654 <sect1>Generic optional arguments
655
656 <p>
657 The following are optional arguments which are likely to be understood
658 by any module. Arguments (including these) are in general
659 <em/optional/.
660
661 <p>
662 <descrip>
663 <tag><tt/debug/</tag>
664
665 Use the <tt/syslog(3)/ call to log debugging information to the system
666 log files.
667
668 <tag> <tt/no_warn/</tag>
669
670 Instruct module to not give warning messages to the application.
671
672 <tag> <tt/use_first_pass/</tag>
673
674 The module should not prompt the user for a password. Instead, it
675 should obtain the previously typed password (from the preceding
676 <tt/auth/ module), and use that. If that doesn't work, then the user
677 will not be authenticated. (This option is intended for <tt/auth/
678 and <tt/password/ modules only).
679
680 <tag> <tt/try_first_pass/</tag>
681
682 The module should attempt authentication with the previously typed
683 password (from the preceding <tt/auth/ module). If that doesn't work,
684 then the user is prompted for a password. (This option is intended for
685 <tt/auth/ modules only).
686
687 <tag> <tt/use_mapped_pass/</tag>
688
689 This argument is not currently supported by any of the modules in the
690 <bf/Linux-PAM/ distribution because of possible consequences
691 associated with U.S. encryption exporting restrictions. Within the
692 U.S., module developers are, of course, free to implement it (as are
693 developers in other countries). For compatibility reasons we describe
694 its use as suggested in the <bf/DCE-RFC 86.0/, see section <ref
695 id="see-also-sec" name="bibliography"> for a pointer to this document.
696
697 <p>
698 The <tt/use_mapped_pass/ argument instructs the module to take the
699 clear text authentication token entered by a previous module (that
700 requests such a token) and use it to generate an encryption/decryption
701 key with which to safely store/retrieve the authentication token
702 required for this module. In this way the user can enter a single
703 authentication token and be quietly authenticated by a number of
704 stacked modules.  Obviously a convenient feature that necessarily
705 requires some reliably strong encryption to make it secure.
706 This argument is intended for the <tt/auth/ and <tt/password/ module
707 types only.
708
709 <tag><tt/expose_account/</tag>
710
711 <p>
712 In general the leakage of some information about user accounts is not
713 a secure policy for modules to adopt. Sometimes information such as
714 users names or home directories, or preferred shell, can be used to
715 attack a user's account. In some circumstances, however, this sort of
716 information is not deemed a threat: displaying a user's full name when
717 asking them for a password in a secured environment could also be
718 called being 'friendly'. The <tt/expose_account/ argument is a
719 standard module argument to encourage a module to be less discrete
720 about account information as it is deemed appropriate by the local
721 administrator.
722
723 </descrip>
724
725 <sect1>Example configuration file entries
726
727 <p>
728 In this section, we give some examples of entries that can be present
729 in the <bf/Linux-PAM/ configuration file. As a first attempt at
730 configuring your system you could do worse than to implement these.
731
732 <sect2>Default policy
733
734 <p>
735 If a system is to be considered secure, it had better have a
736 reasonably secure `<tt/OTHER/' entry. The following is a paranoid
737 setting (which is not a bad place to start!):
738 <tscreen>
739 <verb>
740 #
741 # default; deny access
742 #
743 OTHER   auth     required       /usr/lib/security/pam_deny.so
744 OTHER   account  required       /usr/lib/security/pam_deny.so
745 OTHER   password required       /usr/lib/security/pam_deny.so
746 OTHER   session  required       /usr/lib/security/pam_deny.so
747 </verb>
748 </tscreen>
749 Whilst fundamentally a secure default, this is not very sympathetic to
750 a misconfigured system. For example, such a system is vulnerable to
751 locking everyone out should the rest of the file become badly written.
752
753 <p>
754 The module <tt/pam_deny/ (documented in a later section) is not very
755 sophisticated. For example, it logs no information when it is invoked
756 so unless the users of a system contact the administrator when failing
757 to execute a service application, the administrator may go for a long
758 while in ignorance of the fact that his system is misconfigured.
759
760 <p>
761 The addition of the following line before those in the above example
762 would provide a suitable warning to the administrator.
763 <tscreen>
764 <verb>
765 #
766 # default; wake up! This application is not configured
767 #
768 OTHER   auth     required       /usr/lib/security/pam_warn.so
769 OTHER   password required       /usr/lib/security/pam_warn.so
770 </verb>
771 </tscreen>
772 Having two ``<tt/OTHER auth/'' lines is an example of stacking.
773
774 <p>
775 On a system that uses the <tt>/etc/pam.d/</tt> configuration, the
776 corresponding default setup would be achieved with the following file:
777 <tscreen>
778 <verb>
779 #
780 # default configuration: /etc/pam.d/other
781 #
782 auth     required       /usr/lib/security/pam_warn.so
783 auth     required       /usr/lib/security/pam_deny.so
784 account  required       /usr/lib/security/pam_deny.so
785 password required       /usr/lib/security/pam_warn.so
786 password required       /usr/lib/security/pam_deny.so
787 session  required       /usr/lib/security/pam_deny.so
788 </verb>
789 </tscreen>
790 This is the only explicit example we give for an <tt>/etc/pam.d/</tt>
791 file. In general, it should be clear how to transpose the remaining
792 examples to this configuration scheme.
793
794 <p>
795 On a less sensitive computer, one on which the system administrator
796 wishes to remain ignorant of much of the power of <tt/Linux-PAM/, the
797 following selection of lines (in <tt>/etc/pam.conf</tt>) is likely to
798 mimic the historically familiar Linux setup.
799 <tscreen>
800 <verb>
801 #
802 # default; standard UNIX access
803 #
804 OTHER   auth     required       /usr/lib/security/pam_unix_auth.so
805 OTHER   account  required       /usr/lib/security/pam_unix_acct.so
806 OTHER   password required       /usr/lib/security/pam_unix_passwd.so
807 OTHER   session  required       /usr/lib/security/pam_unix_session.so
808 </verb>
809 </tscreen>
810 In general this will provide a starting place for most applications.
811 Unfortunately, most is not all. One application that might require
812 additional lines is <em/ftpd/ if you wish to enable
813 <em/anonymous-ftp/.
814
815 <p>
816 To enable anonymous-ftp, the following lines might be used to replace
817 the default (<tt/OTHER/) ones. (<bf/*WARNING*/ as of 1996/12/28 this
818 does not work correctly with any ftpd. Consequently, this description
819 may be subject to change or the application will be fixed.)
820 <tscreen>
821 <verb>
822 #
823 # ftpd; add ftp-specifics. These lines enable anonymous ftp over
824 #       standard UNIX access (the listfile entry blocks access to
825 #       users listed in /etc/ftpusers)
826 #
827 ftpd    auth    sufficient  /usr/lib/security/pam_ftp.so
828 ftpd    auth    required    /usr/lib/security/pam_unix_auth.so use_first_pass
829 ftpd    auth    required    /usr/lib/security/pam_listfile.so \
830                         onerr=succeed item=user sense=deny file=/etc/ftpusers
831 </verb>
832 </tscreen>
833 Note, the second line is necessary since the default entries are
834 ignored by a service application (here <em/ftpd/) if there are
835 <em/any/ entries in <tt>/etc/pam.conf</tt> for that specified service.
836 Again, this is an example of authentication module stacking.  Note the
837 use of the <tt/sufficient/ control-flag. It says that ``if this module
838 authenticates the user, ignore the subsequent <tt/auth/
839 modules''. Also note the use of the ``<tt/use_first_pass/''
840 module-argument, this instructs the UNIX authentication module that it
841 is not to prompt for a password but rely one already having been
842 obtained by the ftp module.
843
844 <sect>Security issues of Linux-PAM
845
846 <p>
847 This section will discuss good practices for using Linux-PAM in a
848 secure manner.  <em>It is currently sadly lacking...suggestions are
849 welcome!</em>
850
851 <sect1>If something goes wrong
852
853 <p>
854 <bf/Linux-PAM/ has the potential to seriously change the security of
855 your system.  You can choose to have no security or absolute security
856 (no access permitted).  In general, <bf/Linux-PAM/ errs towards the
857 latter.  Any number of configuration errors can dissable access to
858 your system partially, or completely.
859
860 <p>
861 The most dramatic problem that is likely to be encountered when
862 configuring <bf/Linux-PAM/ is that of <em>deleting</em> the
863 configuration file(s): <tt>/etc/pam.d/*</tt> and/or
864 <tt>/etc/pam.conf</tt>.  This will lock you out of your own system!
865
866 <p>
867 To recover, your best bet is to reboot the system in single user mode
868 and set about correcting things from there.  The following has been
869 <em>adapted</em> from a life-saving email on the subject from David
870 Wood:
871 <verb>
872 > What the hell do I do now?
873
874 OK, don't panic. The first thing you have to realize is that
875 this happens to 50% of users who ever do anything with PAM.
876 It happened here, not once, not twice, but three times, all
877 different, and in the end, the solution was the same every
878 time.
879
880 First, I hope you installed LILO with a delay. If you can,
881 reboot, hit shift or tab or something and type:
882
883     LILO boot: linux single
884
885 (Replace 'linux' with 'name-of-your-normal-linux-image').
886 This will let you in without logging in.  Ever wondered how
887 easy it is to break into a linux machine from the console?
888 Now you know.
889
890 If you can't do that, then get yourself a bootkernel floppy
891 and a root disk a-la slackware's rescue.gz.  (Red Hat's
892 installation disks can be used in this mode too.)
893
894 In either case, the point is to get back your root prompt.
895
896 Second, I'm going to assume that you haven't completely
897 nuked your pam installation - just your configuration files.
898 Here's how you make your configs nice again:
899
900     cd /etc
901     mv pam.conf pam.conf.orig
902     mv pam.d pam.d.orig
903     mkdir pam.d
904     cd pam.d
905
906 and then use vi to create a file called "other" in this
907 directory.  It should contain the following four lines:
908
909     auth     required       pam_unix_auth.so
910     account  required       pam_unix_acct.so
911     password required       pam_unix_passwd.so
912     session  required       pam_unix_session.so
913
914 Now you have the simplest possible PAM configuration that
915 will work the way you're used to.  Everything should
916 magically start to work again.  Try it out by hitting ALT-F2
917 and logging in on another virtual console.  If it doesn't
918 work, you have bigger problems, or you've mistyped
919 something.  One of the wonders of this system (seriously,
920 perhaps) is that if you mistype anything in the conf files,
921 you usually get no error reporting of any kind on the
922 console - just some entries in the log file.  So look there!
923 (Try 'tail /var/log/messages'.)
924
925 From here you can go back and get a real configuration
926 going, hopefully after you've tested it first on a machine
927 you don't care about screwing up.  :/
928
929 Some pointers (to make everything "right" with Red Hat...):
930
931     Install the newest pam, pamconfig, and pwdb from the
932     redhat current directory, and do it all on the same
933     command line with rpm...
934
935         rpm -Uvh [maybe --force too] pam-* pamconfig-* pwdb-*
936
937     Then make sure you install (or reinstall) the newest
938     version of libc, util-linux, wuftp, and NetKit. For
939     kicks you might try installing the newest versions of
940     the affected x apps, like xlock, but I haven't gotten
941     those to work at all yet.
942
943 </verb>
944
945 <sect1>Avoid having a weak `other' configuration
946
947 <p>
948 It is not a good thing to have a weak default (<tt/OTHER/) entry.
949 This service is the default configuration for all PAM aware
950 applications and if it is weak, your system is likely to be vulnerable
951 to attack.
952
953 <p>
954 Here is a sample "other" configuration file. The <em/pam_deny/ module will
955 deny access and the <em/pam_warn/ module will send a syslog message to
956 <tt/auth.notice/:
957
958 <p>
959 <tscreen>
960 <verb>
961 #
962 # The PAM configuration file for the `other' service 
963
964 auth      required   pam_deny.so 
965 auth      required   pam_warn.so 
966 account   required   pam_deny.so 
967 account   required   pam_warn.so 
968 password  required   pam_deny.so 
969 password  required   pam_warn.so 
970 session   required   pam_deny.so 
971 session   required   pam_warn.so
972 </verb>
973 </tscreen>
974
975 <sect>A reference guide for available modules
976
977 <p>
978 Here, we collect together some descriptions of the various modules
979 available for <bf/Linux-PAM/.  In general these modules should be
980 freely available.  Where this is not the case, it will be indicated.
981
982 <p>
983 Also please note the comments contained in the section <ref 
984 id="text-conventions" name="on text conventions above"> when copying
985 the examples listed below.
986
987 <!-- insert-file MODULES-SGML -->
988
989 <sect>Files
990
991 <p><descrip>
992
993 <tag><tt>/usr/lib/libpam.so.*</tt></tag>
994
995 the shared library providing applications with access to
996 <bf/Linux-PAM/.
997
998 <tag><tt>/etc/pam.conf</tt></tag>
999
1000 the <bf/Linux-PAM/ configuration file.
1001
1002 <tag><tt>/usr/lib/security/pam_*.so</tt></tag>
1003
1004 the primary location for <bf/Linux-PAM/ dynamically loadable object
1005 files; the modules.
1006
1007 </descrip>
1008
1009 <sect>See also<label id="see-also-sec">
1010
1011 <p><itemize>
1012
1013 <item>The <bf/Linux-PAM/ Application Writers' Guide.
1014
1015 <item>The <bf/Linux-PAM/ Module Writers' Guide.
1016
1017 <item>The V. Samar and R. Schemers (SunSoft), ``UNIFIED LOGIN WITH
1018 PLUGGABLE AUTHENTICATION MODULES'', Open Software Foundation Request
1019 For Comments 86.0, October 1995. See this url:
1020 <tt><htmlurl
1021 url="http://www.kernel.org/pub/linux/libs/pam/pre/doc/rfc86.0.txt.gz"
1022 name="http://www.kernel.org/pub/linux/libs/pam/pre/doc/rfc86.0.txt.gz"></tt>
1023
1024 </itemize>
1025
1026 <sect>Notes
1027
1028 <p>
1029 I intend to put development comments here... like ``at the moment
1030 this isn't actually supported''. At release time what ever is in
1031 this section will be placed in the Bugs section below! :)
1032
1033 <p>
1034 Are we going to be able to support the <tt/use_mapped_pass/ module
1035 argument? Anyone know a cheap (free) good lawyer?!
1036
1037 <p>
1038 <itemize>
1039 <item>
1040 This issue may go away, as Sun have investigated adding a new
1041 management group for mappings. In this way, libpam would have mapping
1042 modules that could securely store passwords using strong cryptography
1043 and in such a way that they need not be distributed with Linux-PAM.
1044 </itemize>
1045
1046 <sect>Author/acknowledgments
1047
1048 <p>
1049 This document was written by Andrew G. Morgan (morgan@kernel.org)
1050 with many contributions from
1051 <!-- insert-file CREDITS -->
1052
1053 <p>
1054 Thanks are also due to Sun Microsystems, especially to Vipin Samar and
1055 Charlie Lai for their advice. At an early stage in the development of
1056 <bf/Linux-PAM/, Sun graciously made the documentation for their
1057 implementation of PAM available. This act greatly accelerated the
1058 development of <bf/Linux-PAM/.
1059
1060 <sect>Bugs/omissions
1061
1062 <p>
1063 More PAM modules are being developed all the time. It is unlikely that
1064 this document will ever be truely up to date!
1065
1066 <p>
1067 This manual is unfinished. Only a partial list of people is credited
1068 for all the good work they have done.
1069
1070 <sect>Copyright information for this document
1071
1072 <p>
1073 Copyright (c) Andrew G. Morgan 1996-9.  All rights reserved.
1074 <newline>
1075 Email: <tt>&lt;morgan@linux.kernel.org&gt;</tt>
1076
1077 <p>
1078 Redistribution and use in source and binary forms, with or without
1079 modification, are permitted provided that the following conditions are
1080 met:
1081
1082 <p>
1083 <itemize>
1084
1085 <item>
1086 1. Redistributions of source code must retain the above copyright
1087    notice, and the entire permission notice in its entirety,
1088    including the disclaimer of warranties.
1089
1090 <item>
1091 2. Redistributions in binary form must reproduce the above copyright
1092    notice, this list of conditions and the following disclaimer in the
1093    documentation and/or other materials provided with the distribution.
1094
1095 <item>
1096 3. The name of the author may not be used to endorse or promote
1097    products derived from this software without specific prior
1098    written permission.
1099
1100 </itemize>
1101
1102 <p>
1103 <bf/Alternatively/, this product may be distributed under the terms of
1104 the GNU General Public License (GPL), in which case the provisions of
1105 the GNU GPL are required <bf/instead of/ the above restrictions.
1106 (This clause is necessary due to a potential bad interaction between
1107 the GNU GPL and the restrictions contained in a BSD-style copyright.)
1108
1109 <p>
1110 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
1111 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1112 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1113 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1114 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1115 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
1116 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1117 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
1118 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
1119 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1120 DAMAGE.
1121
1122 <p>
1123 <tt>$Id$</tt>
1124
1125 </article>