Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libpam / doc / pam_appl.sgml
1 <!doctype linuxdoc system>
2
3 <!--
4
5  $Id: pam_appl.sgml,v 1.16 1997/04/05 06:49:14 morgan Exp morgan $
6  $FreeBSD: src/contrib/libpam/doc/pam_appl.sgml,v 1.1.1.1.6.2 2001/06/11 15:28:10 markm Exp $
7
8     Copyright (C) Andrew G. Morgan 1996, 1997.  All rights reserved.
9
10 Redistribution and use in source (sgml) and binary (derived) forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright
15    notice, and the entire permission notice in its entirety,
16    including the disclaimer of warranties.
17
18 2. Redistributions in binary form must reproduce the above copyright
19    notice, this list of conditions and the following disclaimer in the
20    documentation and/or other materials provided with the distribution.
21
22 3. The name of the author may not be used to endorse or promote
23    products derived from this software without specific prior
24    written permission.
25
26 ALTERNATIVELY, this product may be distributed under the terms of the
27 GNU General Public License, in which case the provisions of the GNU
28 GPL are required INSTEAD OF the above restrictions.  (This clause is
29 necessary due to a potential bad interaction between the GNU GPL and
30 the restrictions contained in a BSD-style copyright.)
31
32 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
33 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
34 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
37 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
38 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
40 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
41 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42 DAMAGE.
43
44  -->
45
46 <article>
47
48 <title>The Linux-PAM Application Developers' Guide
49 <author>Andrew G. Morgan, <tt>morgan@linux.kernel.org</tt>
50 <date>DRAFT v0.63 1998/1/18
51 <abstract>
52 This manual documents what an application developer needs to know
53 about the <bf>Linux-PAM</bf> library. It describes how an application
54 might use the <bf>Linux-PAM</bf> library to authenticate users. In
55 addition it contains a description of the funtions to be found in
56 <tt/libpam_misc/ library, that can be used in general applications.
57 Finally, it contains some comments on PAM related security issues for
58 the application developer.
59 </abstract>
60
61 <toc>
62
63 <sect>Introduction
64
65 <sect1>Synopsis
66
67 <p>
68 For general applications that wish to use the services provided by
69 <bf/Linux-PAM/ the following is a summary of the relevant linking
70 information:
71 <tscreen>
72 <verb>
73 #include <security/pam_appl.h>
74
75 cc -o application .... -lpam
76 </verb>
77 </tscreen>
78
79 <p>
80 In addition to <tt/libpam/, there is a library of miscellaneous
81 functions that make the job of writing <em/PAM-aware/ applications
82 easier (this library is not covered in the DCE-RFC for PAM and is
83 specific to the Linux-PAM distribution):
84 <tscreen>
85 <verb>
86 ...
87 #include <security/pam_misc.h>
88
89 cc -o application .... -lpam -lpam_misc
90 </verb>
91 </tscreen>
92
93 <sect1> Description
94
95 <p>
96 <bf>Linux-PAM</bf> (Pluggable Authentication Modules for Linux) is a
97 library that enables the local system administrator to choose how
98 individual applications authenticate users.  For an overview of the
99 <bf>Linux-PAM</bf> library see the <bf/Linux-PAM/ System
100 Administrators' Guide.
101
102 <p>
103 It is the purpose of the <bf>Linux-PAM</bf> project to liberate the
104 development of privilege granting software from the development of
105 secure and appropriate authentication schemes.  This is accomplished
106 by providing a documented library of functions that an application may
107 use for all forms of user authentication management. This library
108 dynamically loads locally configured authentication modules that
109 actually perform the authentication tasks.
110
111 <p>
112 From the perspective of an application developer the information
113 contained in the local configuration of the PAM library should not be
114 important.  Indeed it is intended that an application treat the
115 functions documented here as a ``black box'' that will deal with all
116 aspects of user authentication. ``All aspects'' includes user
117 verification, account management, session initialization/termination
118 and also the resetting of passwords (<em/authentication tokens/).
119
120 <sect>Overview
121
122 <p>
123 Most service-giving applications are restricted.  In other words,
124 their service is not available to all and every prospective client.
125 Instead, the applying client must jump through a number of hoops to
126 convince the serving application that they are authorized to obtain
127 service.
128
129 The process of <em/authenticating/ a client is what PAM is designed to
130 manage.  In addition to authentication, PAM provides account
131 management, credential management, session management and
132 authentication-token (password changing) management services.  It is
133 important to realize when writing a PAM based application that these
134 services are provided in a manner that is <bf>transparent</bf> to the
135 the application.  That is to say, when the application is written, no
136 assumptions can be made about <em>how</em> the client will be
137 authenticated.
138
139 <p>
140 The process of authentication is performed by the PAM library via a
141 call to <tt>pam_authenticate()</tt>.  The return value of this
142 function will indicate whether a named client (the <em>user</em>) has
143 been authenticated.  If the PAM library needs to prompt the user for
144 any information, such as their <em>name</em> or a <em>password</em>
145 then it will do so.  If the PAM library is configured to authenticate
146 the user using some silent protocol, it will do this too.  (This
147 latter case might be via some hardware interface for example.)
148
149 <p>
150 It is important to note that the application must leave all decisions
151 about when to prompt the user at the discretion of the PAM library.
152
153 <p>
154 The PAM library, however, must work equally well for different styles
155 of application.  Some applications, like the familiar <tt>login</tt>
156 and <tt>passwd</tt> are terminal based applications, exchanges of
157 information with the client in these cases is as plain text messages.
158 Graphically based applications, however, have a more sophisticated
159 interface.  They generally interact with the user via specially
160 constructed dialogue boxes.  Additionally, network based services
161 require that text messages exchanged with the client are specially
162 formatted for automated processing: one such example is <tt>ftpd</tt>
163 which prefixes each exchanged message with a numeric identifier.
164
165 <p>
166 The presentation of simple requests to a client is thus something very
167 dependent on the protocol that the serving application will use.  In
168 spite of the fact that PAM demands that it drives the whole
169 authentication process, it is not possible to leave such protocol
170 subtleties up to the PAM library.  To overcome this potential problem,
171 the application provides the PAM library with a <em>conversation</em>
172 function.  This function is called from <bf>within</bf> the PAM
173 library and enables the PAM to directly interact with the client.  The
174 sorts of things that this conversation function must be able to do are
175 prompt the user with text and/or obtain textual input from the user
176 for processing by the PAM library.  The details of this function are
177 provided in a later section.
178
179 <p>
180 For example, the conversation function may be called by the PAM library
181 with a request to prompt the user for a password.  Its job is to
182 reformat the prompt request into a form that the client will
183 understand.  In the case of <tt>ftpd</tt>, this will involve prefixing
184 the string with the number <tt>331</tt> and sending the request over
185 the network to a connected client.  The conversation function will
186 then obtain any reply and, after extracting the typed password, will
187 return this string of text to the PAM library.  Similar concerns need
188 to be addressed in the case of an X-based graphical server.
189
190 <p>
191 There are a number of issues that need to be addressed when one is
192 porting an existing application to become PAM compliant.  A section
193 below has been devoted to this: Porting legacy applications.
194
195 <p>
196 Besides authentication, PAM provides other forms of management.
197 Session management is provided with calls to
198 <tt>pam_open_session()</tt> and <tt>pam_close_session()</tt>.  What
199 these functions actually do is up to the local administrator.  But
200 typically, they could be used to log entry and exit from the system or
201 for mounting and unmounting the user's home directory.  If an
202 application provides continuous service for a period of time, it
203 should probably call these functions, first open after the user is
204 authenticated and then close when the service is terminated.
205
206 <p>
207 Account management is another area that an application developer
208 should include with a call to <tt/pam_acct_mgmt()/.  This call will
209 perform checks on the good health of the user's account (has it
210 expired etc.). One of the things this function may check is whether
211 the user's authentication token has expired - in such a case the
212 application may choose to attempt to update it with a call to
213 <tt/pam_chauthtok()/, although some applications are not suited to
214 this task (<em>ftp</em> for example) and in this case the application
215 should deny access to the user.
216
217 <p>
218 PAM is also capable of setting and deleting the users credentials with
219 the call <tt>pam_setcred()</tt>.  This function should always be
220 called after the user is authenticated and before service is offered
221 to the user.  By convention, this should be the last call to the PAM
222 library before service is given to the user.  What exactly a
223 credential is, is not well defined.  However, some examples are given
224 in the glossary below.
225
226 <sect>The public interface to <bf>Linux-PAM</bf>
227  
228 <p>
229 Firstly, the relevant include file for the <bf>Linux-PAM</bf> library
230 is <tt>&lt;security/pam_appl.h&gt;</tt>. It contains the definitions
231 for a number of functions. After listing these functions, we collect
232 some guiding remarks for programmers.
233
234 <sect1>What can be expected by the application
235
236 <p>
237 Here we document those functions in the <bf/Linux-PAM/ library that
238 may be called from an application.
239
240 <sect2>Initialization of Linux-PAM
241 <label id="pam-start-section">
242
243 <p>
244 <tscreen>
245 <verb>
246 extern int pam_start(const char *service_name, const char *user,
247                      const struct pam_conv *pam_conversation,
248                      pam_handle_t **pamh);
249 </verb>
250 </tscreen>
251
252 <p>
253 This is the first of the <bf>Linux-PAM</bf> functions that must be
254 called by an application. It initializes the interface and reads the
255 system configuration file, <tt>/etc/pam.conf</tt> (see the
256 <bf/Linux-PAM/ System Administrators' Guide).  Following a successful
257 return (<tt/PAM_SUCCESS/) the contents of <tt/*pamh/ is a handle that
258 provides continuity for successive calls to the <bf/Linux-PAM/
259 library.  The arguments expected by <tt/pam_start/ are as follows: the
260 <tt/service_name/ of the program, the <tt/user/name of the individual
261 to be authenticated, a pointer to an application-supplied
262 <tt/pam_conv/ structure and a pointer to a <tt/pam_handle_t/
263 <em/pointer/.
264
265 <p>
266 The <tt>pam_conv</tt> structure is discussed more fully in the section
267 <ref id="the-conversation-function" name="below">.  The
268 <tt>pam_handle_t</tt> is a <em>blind</em> structure and the
269 application should not attempt to probe it directly for information.
270 Instead the <bf>Linux-PAM</bf> library provides the functions
271 <tt>pam_set_item</tt> and <tt>pam_get_item</tt>.  These functions are
272 documented below.
273
274 <sect2>Termination of the library
275 <label id="pam-end-section">
276
277 <p>
278 <tscreen>
279 <verb>
280 extern int pam_end(pam_handle_t *pamh, int pam_status);
281 </verb>
282 </tscreen>
283
284 <p>
285 This function is the last function an application should call in the
286 <bf>Linux-PAM</bf> library.  Upon return the handle <tt/pamh/ is no
287 longer valid and all memory associated with it will be invalid (likely
288 to cause a segmentation fault if accessed).
289
290 <p>
291 Under normal conditions the argument <tt/pam_status/ has the value
292 PAM_SUCCESS, but in the event of an unsuccessful service application
293 the approprite <bf/Linux-PAM/ error-return value should be used
294 here.
295 attempt its purpose is to be passed as an argument to the
296 module specific function <tt/cleanup()/ (see the <bf/Linux-PAM/
297 <htmlurl url="pam_modules.html" name="Module Developers' Guide">).
298
299 <sect2>Setting PAM items
300 <label id="pam-set-item-section">
301
302 <p>
303 <tscreen>
304 <verb>
305 extern int pam_set_item(pam_handle_t *pamh, int item_type,
306                         const void *item);
307 </verb>
308 </tscreen>
309
310 <p>This function is used to (re)set the value of one of the following
311 <bf/item_type/s:
312
313 <p><descrip>
314 <tag><tt/PAM_SERVICE/</tag>
315         The service name
316
317 <tag><tt/PAM_USER/</tag>
318         The user name
319
320 <tag><tt/PAM_TTY/</tag>
321         The terminal name: prefixed by <tt>/dev/</tt> if it is a
322 device file; for graphical, X-based, applications the value for this
323 item should be the <tt/&dollar;DISPLAY/ variable.
324
325 <tag><tt/PAM_RHOST/</tag>
326         The remote host name
327
328 <tag><tt/PAM_CONV/</tag>
329         The conversation structure (see section <ref
330 id="the-conversation-function" name="below">)
331
332 <tag><tt/PAM_RUSER/</tag>
333         The remote user name
334
335 <tag><tt/PAM_USER_PROMPT/</tag>
336         The string used when prompting for a user's name. The default
337 value for this string is ``Please enter username: ''.
338
339 </descrip>
340
341 <p>
342 For all <tt/item_type/s, other than <tt/PAM_CONV/, <tt/item/ is a
343 pointer to a <tt>&lt;NUL&gt;</tt> terminated character string.  In the
344 case of <tt/PAM_CONV/, <tt/item/ points to an initialized
345 <tt/pam_conv/ structure (see section <ref
346 id="the-conversation-function" name="below">).
347
348 <p>
349 A successful call to this function returns <tt/PAM_SUCCESS/.  However,
350 the application should expect one of the following errors:
351
352 <p>
353 <descrip>
354 <tag><tt/PAM_PERM_DENIED/</tag>
355         An attempt was made to replace the conversation structure with
356 a <tt/NULL/ value.
357 <tag><tt/PAM_BUF_ERR/</tag>
358         The function ran out of memory making a copy of the item.
359 <tag><tt/PAM_BAD_ITEM/</tag>
360         The application attempted to set an undefined item.
361 </descrip>
362
363 <sect2>Getting PAM items
364 <label id="pam-get-item-section">
365
366 <p>
367 <tscreen>
368 <verb>
369 extern int pam_get_item(const pam_handle_t *pamh, int item_type,
370                         const void **item);
371 </verb>
372 </tscreen>
373
374 <p>
375 This function is used to obtain the value of the indicated
376 <tt/item_type/.  Upon successful return, <tt/*item/ contains a pointer
377 to the value of the corresponding item.  Note, this is a pointer to
378 the <em/actual/ data and should <em/not/ be <tt/free()/'ed or
379 over-written!  A successful call is signaled by a return value of
380 <tt/PAM_SUCCESS/.  If an attempt is made to get an undefined item,
381 <tt/PAM_BAD_ITEM/ is returned.
382
383 <sect2>Understanding errors
384 <label id="pam-strerror-section">
385
386 <p>
387 <tscreen>
388 <verb>
389 extern const char *pam_strerror(pam_handle_t *pamh, int errnum);
390 </verb>
391 </tscreen>
392
393 <p>
394 This function returns some text describing the <bf>Linux-PAM</bf>
395 error associated with the argument <tt/errnum/.  If the error is not
396 recognized ``<tt/Unknown Linux-PAM error/'' is returned.
397
398 <sect2>Planning for delays
399
400 <p>
401 <tscreen>
402 <verb>
403 extern int pam_fail_delay(pam_handle_t *pamh, unsigned int micro_sec);
404 </verb>
405 </tscreen>
406
407 <p>
408 This function is offered by <bf/Linux-PAM/ to facilitate time delays
409 following a failed call to <tt/pam_authenticate()/ and before control
410 is returned to the application. When using this function the
411 application programmer should check if it is available with,
412 <tscreen>
413 <verb>
414 #ifdef HAVE_PAM_FAIL_DELAY
415     ....
416 #endif /* HAVE_PAM_FAIL_DELAY */
417 </verb>
418 </tscreen>
419
420
421 <p>
422 Generally, an application requests that a user is authenticated by
423 <bf/Linux-PAM/ through a call to <tt/pam_authenticate()/ or
424 <tt/pam_chauthtok()/.  These functions calls each of the <em/stacked/
425 authentication modules listed in the <tt>/etc/pam.conf</tt> file.  As
426 directed by this file, one of more of the modules may fail causing the
427 <tt/pam_...()/ call to return an error.  It is desirable for there to
428 also be a pause before the application continues. The principal reason
429 for such a delay is security: a delay acts to discourage <em/brute
430 force/ dictionary attacks primarily, but also helps hinder
431 <em/timed/ (covert channel) attacks.
432
433 <p>
434 The <tt/pam_fail_delay()/ function provides the mechanism by which an
435 application or module can suggest a minimum delay (of <tt/micro_sec/
436 <em/micro-seconds/). <bf/Linux-PAM/ keeps a record of the longest time
437 requested with this function. Should <tt/pam_authenticate()/ fail,
438 the failing return to the application is delayed by an amount of time
439 randomly distributed (by up to 25%) about this longest value.
440
441 <p>
442 Independent of success, the delay time is reset to its zero default
443 value when <bf/Linux-PAM/ returns control to the application.
444
445 <sect2>Authenticating the user
446
447 <p>
448 <tscreen>
449 <verb>
450 extern int pam_authenticate(pam_handle_t *pamh, int flags);
451 </verb>
452 </tscreen>
453
454 <p>
455 This function serves as an interface to the authentication mechanisms
456 of the loaded modules.  The single <em/optional/ flag, which may be
457 logically OR'd with <tt/PAM_SILENT/, takes the following value,
458
459 <p><descrip>
460
461 <tag><tt/PAM_DISALLOW_NULL_AUTHTOK/</tag>
462         Instruct the authentication modules to return
463 <tt/PAM_AUTH_ERR/ if the user does not have a registered
464 authorization token---it is set to <tt/NULL/ in the system database.
465 </descrip>
466
467 <p>
468 The value returned by this function is one of the following:
469
470 <p><descrip>
471
472 <tag><tt/PAM_AUTH_ERR/</tag>
473         The user was not authenticated
474 <tag><tt/PAM_CRED_INSUFFICIENT/</tag>
475         For some reason the application does not have sufficient
476 credentials to authenticate the user.
477 <tag><tt/PAM_AUTHINFO_UNAVAIL/</tag>
478         The modules were not able to access the authentication
479 information. This might be due to a network or hardware failure etc.
480 <tag><tt/PAM_USER_UNKNOWN/</tag>
481         The supplied username is not known to the authentication
482 service
483 <tag><tt/PAM_MAXTRIES/</tag>
484         One or more of the authentication modules has reached its
485 limit of tries authenticating the user. Do not try again.
486
487 </descrip>
488
489 <p>
490 If one or more of the authentication modules fails to load, for
491 whatever reason, this function will return <tt/PAM_ABORT/.
492
493 <sect2>Setting user credentials
494 <label id="pam-setcred-section">
495
496 <p>
497 <tscreen>
498 <verb>
499 extern int pam_setcred(pam_handle_t *pamh, int flags);
500 </verb>
501 </tscreen>
502
503 <p>
504 This function is used to set the module-specific credentials of the
505 user.  It is usually called after the user has been authenticated,
506 after the account management function has been called and after a
507 session has been opened for the user.
508
509 <p>
510 A credential is something that the user possesses.  It is some
511 property, such as a <em>Kerberos</em> ticket, or a supplementary group
512 membership that make up the uniqueness of a given user.  On a Linux
513 (or UN*X system) the user's <tt>UID</tt> and <tt>GID</tt>'s are
514 credentials too.  However, it has been decided that these properties
515 (along with the default supplementary groups of which the user is a
516 member) are credentials that should be set directly by the application
517 and not by PAM.
518
519 <p>
520 This function simply calls the <tt/pam_sm_setcred/ functions of each
521 of the loaded modules.  Valid <tt/flags/, any one of which, may be
522 logically OR'd with <tt/PAM_SILENT/, are:
523
524 <p><descrip>
525 <tag><tt/PAM_ESTABLISH_CRED/</tag>
526         Set the credentials for the authentication service,
527 <tag><tt/PAM_DELETE_CRED/</tag>
528         Delete the credentials associated with the authentication service,
529 <tag><tt/PAM_REINITIALIZE_CRED/</tag>
530         Reinitialize the user credentials, and
531 <tag><tt/PAM_REFRESH_CRED/</tag>
532         Extend the lifetime of the user credentials.
533 </descrip>
534
535 <p>
536 A successful return is signalled with <tt/PAM_SUCCESS/. Errors that
537 are especially relevant to this function are the following:
538
539 <p><descrip>
540 <tag><tt/PAM_CRED_UNAVAIL/</tag>
541         A module cannot retrieve the user's credentials.
542 <tag><tt/PAM_CRED_EXPIRED/</tag>
543         The user's credentials have expired.
544 <tag><tt/PAM_USER_UNKNOWN/</tag>
545         The user is not known to an authentication module.
546 <tag><tt/PAM_CRED_ERR/</tag>
547         A module was unable to set the credentials of the user.
548 </descrip>
549
550 <sect2>Account management
551
552 <p>
553 <tscreen>
554 <verb>
555 extern int pam_acct_mgmt(pam_handle_t *pamh, int flags);
556 </verb>
557 </tscreen>
558
559 <p>
560 This function is typically called after the user has been
561 authenticated.  It establishes whether the user's account is healthy.
562 That is to say, whether the user's account is still active and whether
563 the user is permitted to gain access to the system at this time.
564 Valid flags, any one of which, may be logically OR'd with
565 <tt/PAM_SILENT/, and are the same as those applicable to the
566 <tt/flags/ argument of <tt/pam_authenticate/.
567
568 <p>
569 This function simply calls the corresponding functions of each of the
570 loaded modules, as instructed by the configuration file,
571 <tt>/etc/pam.conf</tt>.
572
573 <p>
574 The normal response from this function is <tt/PAM_SUCCESS/, however,
575 specific failures are indicated by the following error returns:
576
577 <descrip>
578 <tag><tt/PAM_AUTHTOKEN_REQD/</tag>
579 The user <bf/is/ valid but their authentication token has
580 <em/expired/.  The correct response to this return-value is to require
581 that the user satisfies the <tt/pam_chauthtok()/ function before
582 obtaining service.  It may not be possible for some applications to do
583 this.  In such cases, the user should be denied access until such time
584 as they can update their password.
585
586 <tag><tt/PAM_ACCT_EXPIRED/</tag>
587         The user is no longer permitted access to the system.
588 <tag><tt/PAM_AUTH_ERR/</tag>
589         There was an authentication error.
590
591 <tag><tt/PAM_PERM_DENIED/</tag>
592         The user is not permitted to gain access at this time.
593 <tag><tt/PAM_USER_UNKNOWN/</tag>
594         The user is not known to a module's account management
595 component.
596
597 </descrip>
598
599 <sect2>Updating authentication tokens
600 <label id="pam-chauthtok-section">
601
602 <p>
603 <tscreen>
604 <verb>
605 extern int pam_chauthtok(pam_handle_t *pamh, const int flags);
606 </verb>
607 </tscreen>
608
609 <p>
610 This function is used to change the authentication token for a given
611 user (as indicated by the state associated with the handle,
612 <tt/pamh/). The following is a valid but optional flag which may be
613 logically OR'd with <tt/PAM_SILENT/,
614
615 <descrip>
616 <tag><tt/PAM_CHANGE_EXPIRED_AUTHTOK/</tag>
617         This argument indicates to the modules that the users
618 authentication token (password) should only be changed if it has
619 expired.
620 </descrip>
621
622 <p>
623 Note, if this argument is not passed, the application requires that
624 <em/all/ authentication tokens are to be changed.
625
626 <p>
627 <tt/PAM_SUCCESS/ is the only successful return value, valid
628 error-returns are:
629
630 <descrip>
631 <tag><tt/PAM_AUTHTOK_ERR/</tag>
632         A module was unable to obtain the new authentication token.
633         
634 <tag><tt/PAM_AUTHTOK_RECOVERY_ERR/</tag>
635         A module was unable to obtain the old authentication token.
636
637 <tag><tt/PAM_AUTHTOK_LOCK_BUSY/</tag>
638         One or more of the modules was unable to change the
639 authentication token since it is currently locked.
640         
641 <tag><tt/PAM_AUTHTOK_DISABLE_AGING/</tag>
642         Authentication token aging has been disabled for at least one
643 of the modules.
644
645 <tag><tt/PAM_PERM_DENIED/</tag>
646         Permission denied.
647
648 <tag><tt/PAM_TRY_AGAIN/</tag>
649         Not all of the modules were in a position to update the
650 authentication token(s). In such a case none of the user's
651 authentication tokens are updated.
652
653 <tag><tt/PAM_USER_UNKNOWN/</tag>
654         The user is not known to the authentication token changing
655 service.
656
657 </descrip>
658
659 <sect2>Session initialization
660 <label id="pam-open-session-section">
661
662 <p>
663 <tscreen>
664 <verb>
665 extern int pam_open_session(pam_handle_t *pamh, int flags);
666 </verb>
667 </tscreen>
668
669 <p>
670 This function is used to indicate that an authenticated session has
671 begun.  It is used to inform the module that the user is currently in
672 a session.  It should be possible for the <bf>Linux-PAM</bf> library
673 to open a session and close the same session (see section <ref
674 id="pam-close-session-section" name="below">) from different
675 applications.
676
677 <p>
678 Currently, this function simply calls each of the corresponding
679 functions of the loaded modules. The only valid flag is
680 <tt/PAM_SILENT/ and this is, of course, <em/optional/.
681
682 <p>
683 If any of the <em/required/ loaded modules are unable to open a
684 session for the user, this function will return <tt/PAM_SESSION_ERR/.
685
686 <sect2>Terminating sessions
687 <label id="pam-close-session-section">
688
689 <p>
690 <tscreen>
691 <verb>
692 extern int pam_close_session(pam_handle_t *pamh, int flags);
693 </verb>
694 </tscreen>
695
696 <p>
697 This function is used to indicate that an authenticated session has
698 ended. It is used to inform the module that the user is exiting a
699 session. It should be possible for the <bf>Linux-PAM</bf> library to
700 open a session and close the same session from different applications.
701
702 <p>
703 Currently, this function simply calls each of the corresponding
704 functions of the loaded modules.  The only valid flag is
705 <tt/PAM_SILENT/ and this is, of course, <em/optional/.
706
707 <p>
708 If any of the <em/required/ loaded modules are unable to close a
709 session for the user, this function will return <tt/PAM_SESSION_ERR/.
710
711 <sect2>Setting PAM environment variables
712 <label id="pam-putenv-section">
713
714 <p>
715 <tscreen>
716 <verb>
717 extern int pam_putenv(pam_handle_t *pamh, const char *name_value);
718 </verb>
719 </tscreen>
720
721 <p>
722 <em>
723 Warning, the environment support in <bf/Linux-PAM/ is based solely
724 on a six line email from the developers at Sun. Its interface is
725 likely to be generally correct, however, the details are likely to be
726 changed as more information becomes available.
727 </em>
728
729 <p>
730 This function attempts to (re)set a <bf/Linux-PAM/ environment
731 variable. The <tt/name_value/ argument is a single <tt/NUL/ terminated
732 string of one of the following forms:
733 <descrip>
734 <tag>``<tt/NAME=value of variable/''</tag>
735
736 In this case the environment variable of the given <tt/NAME/ is set to
737 the indicated value: ``<tt/value of variable/''.  If this variable is
738 already known, it is overwritten. Otherwise it is added to the
739 <bf/Linux-PAM/ environment.
740
741 <tag>``<tt/NAME=/''</tag>
742
743 This function sets the variable to an empty value. It is listed
744 separately to indicate that this is the correct way to achieve such a
745 setting.
746
747 <tag>``<tt/NAME/''</tag>
748
749 Without an `<tt/=/' the <tt/pam_putenv()/ function will delete the
750 correspoding variable from the <bf/Linux-PAM/ environment.
751
752 </descrip>
753
754 <p>
755 Success is indicated with a return value of <tt/PAM_SUCCESS/. Failure
756 is indicated by one of the following returns:
757
758 <descrip>
759 <tag><tt/PAM_PERM_DENIED/</tag>
760         name given is a <tt/NULL/ pointer
761
762 <tag><tt/PAM_BAD_ITEM/</tag>
763         variable requested (for deletion) is not currently set
764
765 <tag><tt/PAM_ABORT/</tag>
766         the <bf/Linux-PAM/ handle, <tt/pamh/, is corrupt
767
768 <tag><tt/PAM_BUF_ERR/</tag>
769         failed to allocate memory when attempting update
770
771 </descrip>
772
773 <sect2>Getting a PAM environment variable
774 <label id="pam-getenv-section">
775
776 <p>
777 <tscreen>
778 <verb>
779 extern const char *pam_getenv(pam_handle_t *pamh, const char *name);
780 </verb>
781 </tscreen>
782
783 <p>
784 <em>
785 Warning, the environment support in <bf/Linux-PAM/ is based solely
786 on a six-line email from the developers at Sun. Its interface is
787 likely to be generally correct, however, the details are likely to be
788 changed as more information becomes available.
789 </em>
790
791 <p>
792 Obtain the value of the indicated <bf/Linux-PAM/ environment
793 variable. On error, internal failure or the unavailability of the
794 given variable (unspecified), this function simply returns <tt/NULL/.
795
796 <sect2>Getting the PAM environment
797 <label id="pam-getenvlist-section">
798
799 <p>
800 <tscreen>
801 <verb>
802 extern const char * const *pam_getenvlist(pam_handle_t *pamh);
803 </verb>
804 </tscreen>
805
806 <p>
807 <em>
808 Warning, the environment support in <bf/Linux-PAM/ is based solely
809 on a six line email from the developers at Sun. Its interface is
810 likely to be generally correct, however, the details are likely to be
811 changed as more information becomes available.
812 </em>
813
814 <p>
815 This function returns a pointer to the complete <tt/Linux-PAM/
816 environment.  It is a pointer to a <em/read-only/ list of
817 <em/read-only/ environment variables.  It should be noted that this
818 memory will become invalid after a call to <tt/pam_end()/ (see the
819 section <ref id="pam-end-section" name="above">).  If application
820 wishes to make use of this list after such a call, it should first
821 make a copy of all the set variables. (A function that performs such a
822 transcription is to be found in <tt/libpam_misc/.)
823
824 <sect1>What is expected of an application
825
826 <sect2>The conversation function
827 <label id="the-conversation-function">
828
829 <p>
830 An application must provide a ``conversation function''. It is used
831 for direct communication between a loaded module and the application
832 and will typically provide a means for the module to prompt the user
833 for a password etc. . The structure, <tt/pam_conv/, is defined by
834 including <tt>&lt;security/pam_appl.h&gt</tt>; to be,
835
836 <p>
837 <tscreen>
838 <verb>
839 struct pam_conv {
840     int (*conv)(int num_msg,
841         const struct pam_message **msg,
842         struct pam_response **resp,
843         void *appdata_ptr);
844     void *appdata_ptr;
845 };
846 </verb>
847 </tscreen>
848
849 <p>
850 It is initialized by the application before it is passed to the
851 library.  The <em/contents/ of this structure are attached to the
852 <tt/*pamh/ handle.  The point of this argument is to provide a
853 mechanism for any loaded module to interact directly with the
854 application program. This is why it is called a <em/conversation/
855 structure.
856
857 <p>
858 When a module calls the referenced <tt/conv()/ function, the argument
859 <tt/*appdata_ptr/ is set to the second element of this structure.
860
861 <p>
862 The other arguments of a call to <tt/conv()/ concern the information
863 exchanged by module and application. That is to say, <tt/num_msg/
864 holds the length of the array of pointers, <tt/msg/. After a
865 successful return, the pointer <tt/*resp/ points to an array of
866 <tt/pam_response/ structures, holding the application supplied text.
867 Note, <tt/*resp/ is an <tt/struct pam_response/ array and <em/not/ an
868 array of pointers.
869
870 <p>
871 The message (from the module to the application) passing structure is
872 defined by <tt>&lt;security/pam_appl.h&gt;</tt> as:
873
874 <p>
875 <tscreen>
876 <verb>
877 struct pam_message {
878     int msg_style;
879     const char *msg;
880 };
881 </verb>
882 </tscreen>
883
884 <p>
885 Valid choices for <tt/msg_style/ are:
886
887 <p><descrip>
888 <tag><tt/PAM_PROMPT_ECHO_OFF/</tag>
889         Obtain a string without echoing any text
890 <tag><tt/PAM_PROMPT_ECHO_ON/</tag>
891         Obtain a string whilst echoing text
892 <tag><tt/PAM_ERROR_MSG/</tag>
893         Display an error
894 <tag><tt/PAM_TEXT_INFO/</tag>
895         Display some text.
896 </descrip>
897
898 <p>
899 The point of having an array of messages is that it becomes possible
900 to pass a number of things to the application in a single call from
901 the module. It can also be convenient for the application that related
902 things come at once: a windows based application can then present a
903 single form with many messages/prompts on at once.
904
905 <p>
906 The response (from the application to the module) passing structure is
907 defined by including <tt>&lt;security/pam_appl.h&gt;</tt> as:
908
909 <p><tscreen><verb>
910 struct pam_response {
911     char *resp;
912     int resp_retcode;
913 };
914 </verb></tscreen>
915
916 <p>
917 Currently, there are no definitions for <tt/resp_retcode/ values; the
918 normal value is <tt/0/.
919
920 <p>
921 Prior to the 0.59 release of Linux-PAM, the length of the returned
922 <tt/pam_response/ array was equal to the number of <em/prompts/ (types
923 <tt/PAM_PROMPT_ECHO_OFF/ and <tt/PAM_PROMPT_ECHO_ON/) in the
924 <tt/pam_message/ array with which the conversation function was
925 called.  This meant that it was not always necessary for the module to
926 <tt/free(3)/ the responses if the conversation function was only used
927 to display some text.
928
929 <p>
930 Post Linux-PAM-0.59 (and in the interests of compatibility with
931 Sunsoft).  The number of resposes is always equal to the <tt/num_msg/
932 conversation function argument.  This is slightly easier to program
933 but does require that the response array is <tt/free(3)/'d after every
934 call to the conversation function.  The index of the responses
935 corresponds directly to the prompt index in the <tt/pam_message/
936 array.
937
938 <p>
939 The maximum length of the <tt/pam_msg.msg/ and <tt/pam_response.resp/
940 character strings is <tt/PAM_MAX_MSG_SIZE/.  (This is not enforced by
941 Linux-PAM.)
942
943 <p>
944 <tt/PAM_SUCCESS/ is the expected return value of this
945 function.  However, should an error occur the application should not
946 set <tt/*resp/ but simply return <tt/PAM_CONV_ERR/.
947
948 <p>
949 Note, if an application wishes to use two conversation functions, it
950 should activate the second with a call to <tt/pam_set_item()/.
951
952 <p>
953 <bf>Notes:</bf> New item types are being added to the conversation
954 protocol.  Currently Linux-PAM supports: <tt>PAM_BINARY_PROMPT</tt>
955 and <tt>PAM_BINARY_MSG</tt>.  These two are intended for server-client
956 hidden information exchange and may be used as an interface for
957 maching-machine authentication.
958
959 <sect1>Programming notes
960
961 <p>
962 Note, all of the authentication service function calls accept the
963 token <tt/PAM_SILENT/, which instructs the modules to not send
964 messages to the application. This token can be logically OR'd with any
965 one of the permitted tokens specific to the individual function calls.
966 <tt/PAM_SILENT/ does not override the prompting of the user for
967 passwords etc., it only stops informative messages from being
968 generated.
969
970 <sect>Security issues of <bf>Linux-PAM</bf>
971
972 <p>
973 A poorly (or maliciously) written application can defeat any
974 <bf/Linux-PAM/ module's authentication mechanisms by simply ignoring
975 it's return values.  It is the applications task and responsibility to
976 grant privileges and access to services.  The <bf/Linux-PAM/ library
977 simply assumes the responsibility of <em/authenticating/ the user;
978 ascertaining that the user <em/is/ who they say they are.  Care should
979 be taken to anticipate all of the documented behavior of the
980 <bf/Linux-PAM/ library functions.  A failure to do this will most
981 certainly lead to a future security breach.
982
983 <sect1>Care about standard library calls
984
985 <p>
986 In general, writers of authorization-granting applications should
987 assume that each module is likely to call any or <em/all/ `libc'
988 functions.  For `libc' functions that return pointers to
989 static/dynamically allocated structures (ie. the library allocates the
990 memory and the user is not expected to `<tt/free()/' it) any module
991 call to this function is likely to corrupt a pointer previously
992 obtained by the application.  The application programmer should either
993 re-call such a `libc' function after a call to the <bf/Linux-PAM/
994 library, or copy the structure contents to some safe area of memory
995 before passing control to the <bf/Linux-PAM/ library.
996
997 <p>
998 Two function classes that fall into this category are
999 <tt>getpwnam(3)</tt> and <tt>syslog(3)</tt>.
1000
1001 <sect1>Choice of a service name
1002
1003 <p>
1004 When picking the <em/service-name/ that corresponds to the first entry
1005 in the <tt>/etc/pam.conf</tt> file, the application programmer should
1006 <bf/avoid/ the temptation of choosing something related to
1007 <tt/argv[0]/.  It is a trivial matter for any user to invoke any
1008 application on a system under a different name -- this should not be
1009 permitted to cause a security breach.
1010
1011 <p>
1012 To invoke some <tt/target/ application by another name, the user may
1013 symbolically link the target application with the desired name.  To be
1014 precise all the user need do is,
1015 <tscreen>
1016 <verb>
1017 ln -s /target/application ./preferred_name
1018 </verb>
1019 </tscreen>
1020 and then <em/run/ <tt>./preferred_name</tt>
1021
1022 <p>
1023 By studying the <bf/Linux-PAM/ configuration file,
1024 <tt>/etc/pam.conf</tt>, an attacker can choose the <tt/preferred_name/
1025 to be that of a service enjoying minimal protection; for example a
1026 game which uses <bf/Linux-PAM/ to restrict access to certain hours of
1027 the day.  If the service-name were to be linked to the filename under
1028 which the service was invoked, it is clear that the user is
1029 effectively in the position of dictating which authentication scheme
1030 the service uses.  Needless to say, this is not a secure situation.
1031
1032 <p>
1033 The conclusion is that the application developer should carefully
1034 define the service-name of an application. The safest thing is to make
1035 it a single hard-wired name.
1036
1037 <sect1>The conversation function
1038
1039 <p>
1040 Care should be taken to ensure that the <tt/conv()/ function is
1041 robust. Such a function is provided in the library <tt/libpam_misc/
1042 (see <ref id="libpam-misc-section" name="below">).
1043
1044 <sect1>The identity of the user
1045
1046 <p>
1047 The <bf/Linux-PAM/ modules will need to determine the identity of the
1048 user who requests a service, and the identity of the user who grants
1049 the service.  These two users will seldom be the same.  Indeed there
1050 is generally a third user identity to be considered, the new (assumed)
1051 identity of the user once the service is granted.
1052
1053 <p>
1054 The need for keeping tabs on these identities is clearly an issue of
1055 security.  Basically, the identity of the user requesting a service
1056 should be the current <tt/uid/ (userid) of the running process; the
1057 identity of the privilege granting user is the <tt/euid/ (effective
1058 userid) of the running process; the identity of the user, under whose
1059 name the service will be executed, is given by the contents of the
1060 <tt/PAM_USER/ <tt/pam_get_item(2)/.
1061
1062 <p>
1063 In addition the identity of a remote user, requesting the service from
1064 a distant location, will be placed in the <tt/PAM_RUSER/ item.
1065
1066 <sect1>Sufficient resources
1067
1068 <p>
1069 Care should be taken to ensure that the proper execution of an
1070 application is not compromised by a lack of system resources.  If an
1071 application is unable to open sufficient files to perform its service,
1072 it should fail gracefully, or request additional resources.
1073 Specifically, the quantities manipulated by the <tt/setrlimit(2)/
1074 family of commands should be taken into consideration.
1075
1076 <sect>A library of miscellaneous helper functions
1077 <label id="libpam-misc-section">
1078
1079 <p>
1080 To aid the work of the application developer a library of
1081 miscellaneous functions is provided.  It is called <tt/libpam_misc/,
1082 and contains functions for allocating memory (securely), a text based
1083 conversation function, and routines for enhancing the standard
1084 PAM-environment variable support.
1085
1086 <sect1>Requirements
1087
1088 <p>
1089 The functions, structures and macros, made available by this library
1090 can be defined by including <tt>&lt;security/pam_misc.h&gt;</tt>.  It
1091 should be noted that this library is specific to <bf/Linux-PAM/ and is
1092 not referred to in the defining DCE-RFC (see <ref id="bibliography"
1093 name="the bibliography">) below.
1094
1095 <sect1>Functions supplied
1096
1097 <sect2>Safe string duplication
1098
1099 <p>
1100 <tscreen>
1101 <verb>
1102 extern char *xstrdup(const char *s)
1103 </verb>
1104 </tscreen>
1105 Return a duplicate copy of the <tt/NUL/ terminated string,
1106 <tt/s/. <tt/NULL/ is returned if there is insufficient memory
1107 available for the duplicate or if <tt/s=NULL/.
1108
1109 <sect2>A text based conversation function
1110
1111 <p>
1112 <tscreen>
1113 <verb>
1114 extern int misc_conv(int num_msg, const struct pam_message **msgm,
1115                      struct pam_response **response, void *appdata_ptr);
1116 </verb>
1117 </tscreen>
1118
1119 <p>
1120 This is a function that will prompt the user with the appropriate
1121 comments and obtain the appropriate inputs as directed by
1122 authentication modules.
1123
1124 <p>
1125 In addition to simply slotting into the appropriate <tt/struct
1126 pam_conv/, this function provides some time-out facilities.  The
1127 function exports five variables that can be used by an application
1128 programmer to limit the amount of time this conversation function will
1129 spend waiting for the user to type something.
1130
1131 <p>
1132 The five variables are as follows:
1133 <descrip>
1134 <tag><tt>extern time_t pam_misc_conv_warn_time;</tt></tag>
1135
1136 This variable contains the <em/time/ (as returned by <tt/time()/) that
1137 the user should be first warned that the clock is ticking. By default
1138 it has the value <tt/0/, which indicates that no such warning will be
1139 given. The application may set its value to sometime in the future,
1140 but this should be done prior to passing control to the <bf/Linux-PAM/
1141 library.
1142
1143 <tag><tt>extern const char *pam_misc_conv_warn_line;</tt></tag>
1144
1145 Used in conjuction with <tt/pam_misc_conv_warn_time/, this variable is
1146 a pointer to the string that will be displayed when it becomes time to
1147 warn the user that the timeout is approaching. Its default value is
1148 ``..&bsol;a.Time is running out...&bsol;n'', but this can be changed
1149 by the application prior to passing control to <bf/Linux-PAM/.
1150
1151 <tag><tt>extern time_t pam_misc_conv_die_time;</tt></tag>
1152
1153 This variable contains the <em/time/ (as returned by <tt/time()/) that
1154 the conversation will time out. By default it has the value <tt/0/,
1155 which indicates that the conversation function will not timeout. The
1156 application may set its value to sometime in the future, this should
1157 be done prior to passing control to the <bf/Linux-PAM/ library.
1158
1159 <tag><tt>extern const char *pam_misc_conv_die_line;</tt></tag>
1160
1161 Used in conjuction with <tt/pam_misc_conv_die_time/, this variable is
1162 a pointer to the string that will be displayed when the conversation
1163 times out. Its default value is ``..&bsol;a.Sorry, your time is
1164 up!&bsol;n'', but this can be changed by the application prior to
1165 passing control to <bf/Linux-PAM/.
1166
1167 <tag><tt>extern int pam_misc_conv_died;</tt></tag>
1168
1169 Following a return from the <bf/Linux-PAM/ libraray, the value of this
1170 variable indicates whether the conversation has timed out. A value of
1171 <tt/1/ indicates the time-out occurred.
1172
1173 <tag><tt>extern int (*pam_binary_handler_fn)(const union pam_u_packet_p send,
1174                      union pam_u_packet_p *receive);</tt></tag>
1175
1176 This function pointer is initialized to <tt/NULL/ but can be filled
1177 with a function that provides machine-machine (hidden) message
1178 exchange.  It is intended for use with hidden authentication protocols
1179 such as RSA or Diffie-Hellman key exchanges.  (This is still under
1180 development.)
1181
1182 </descrip>
1183
1184 <sect2>Transcribing an environment to that of Linux-PAM
1185 <p>
1186 <tscreen>
1187 <verb>
1188 extern int pam_misc_paste_env(pam_handle_t *pamh,
1189                               const char * const * user_env);
1190 </verb>
1191 </tscreen>
1192
1193 This function takes the supplied list of environment pointers and
1194 <em/uploads/ its contents to the <bf/Linux-PAM/ environment. Success
1195 is indicated by <tt/PAM_SUCCESS/.
1196
1197 <sect2>Saving the Linux-PAM environment for later use
1198 <p>
1199 <tscreen>
1200 <verb>
1201 extern char **pam_misc_copy_env(pam_handle_t *pamh);
1202 </verb>
1203 </tscreen>
1204
1205 This function returns a pointer to a list of environment variables
1206 that are a direct copy of the <bf/Linux-PAM/ environment.  The memory
1207 associated with these variables are the responsibility of the
1208 application and should be liberated with a call to
1209 <tt/pam_misc_drop_env()/.
1210
1211 <sect2>Liberating a locally saved environment
1212 <p>
1213 <tscreen>
1214 <verb>
1215 extern char **pam_misc_drop_env(char **env);
1216 </verb>
1217 </tscreen>
1218
1219 This function is defined to complement the <tt/pam_misc_copy_env()/
1220 function.  It liberates the memory associated with <tt/env/,
1221 <em/overwriting/ with <tt/0/ all memory before <tt/free()/ing it.
1222
1223 <sect2>BSD like Linux-PAM environment variable setting
1224 <p>
1225 <tscreen>
1226 <verb>
1227 extern int pam_misc_setenv(pam_handle_t *pamh, const char *name,
1228                            const char *value, int readonly);
1229 </verb>
1230 </tscreen>
1231
1232 This function performs a task equivalent to <tt/pam_putenv()/, its
1233 syntax is, however, more like the BSD style function; <tt/setenv()/.
1234 The <tt/name/ and <tt/value/ are concatenated with an ``<tt/=/'' to
1235 form a <tt/name_value/ and passed to <tt/pam_putenv()/. If, however,
1236 the <bf/Linux-PAM/ variable is already set, the replacement will only
1237 be applied if the last argument, <tt/readonly/, is zero.
1238
1239 <sect>Porting legacy applications
1240
1241 <p>
1242 The following is extracted from an email.  I'll tidy it up later.
1243
1244 <p>
1245 The point of PAM is that the application is not supposed to have any
1246 idea how the attatched authentication modules will choose to
1247 authenticate the user.  So all they can do is provide a conversation
1248 function that will talk directly to the user(client) on the modules'
1249 behalf.
1250
1251 <p>
1252 Consider the case that you plug a retinal scanner into the login
1253 program.  In this situation the user would be prompted: "please look
1254 into the scanner".  No username or password would be needed - all this
1255 information could be deduced from the scan and a database lookup.  The
1256 point is that the retinal scanner is an ideal task for a "module".
1257
1258 <p>
1259 While it is true that a pop-daemon program is designed with the POP
1260 protocol in mind and no-one ever considered attatching a retinal
1261 scanner to it, it is also the case that the "clean" PAM'ification of
1262 such a daemon would allow for the possibility of a scanner module
1263 being be attatched to it.  The point being that the "standard"
1264 pop-authentication protocol(s) [which will be needed to satisfy
1265 inflexible/legacy clients] would be supported by inserting an
1266 appropriate pam_qpopper module(s).  However, having rewritten popd
1267 once in this way any new protocols can be implemented in-situ.
1268
1269 <p>
1270 One simple test of a ported application would be to insert the
1271 <tt/pam_permit/ module and see if the application demands you type a
1272 password...  In such a case, <tt/xlock/ would fail to lock the
1273 terminal - or would at best be a screen-saver, ftp would give password
1274 free access to all etc..  Neither of these is a very secure thing to
1275 do, but they do illustrate how much flexibility PAM puts in the hands
1276 of the local admin.
1277
1278 <p>
1279 The key issue, in doing things correctly, is identifying what is part
1280 of the authentication procedure (how many passwords etc..) the
1281 exchange protocol (prefixes to prompts etc., numbers like 331 in the
1282 case of ftpd) and what is part of the service that the application
1283 delivers.  PAM really needs to have total control in the
1284 authentication "proceedure", the conversation function should only
1285 deal with reformatting user prompts and extracting responses from raw
1286 input.
1287
1288 <sect>Glossary of PAM related terms
1289
1290 <p>
1291 The following are a list of terms used within this document.
1292
1293 <p>
1294 <descrip>
1295
1296 <tag>Authentication token</tag>
1297 Generally, this is a password.  However, a user can authenticate
1298 him/herself in a variety of ways.  Updating the user's authentication
1299 token thus corresponds to <em>refreshing</em> the object they use to
1300 authenticate themself with the system.  The word password is avoided
1301 to keep open the possibility that the authentication involves a
1302 retinal scan or other non-textual mode of challenge/response.
1303
1304 <tag>Credentials</tag>
1305 Having successfully authenticated the user, PAM is able to establish
1306 certain characteristics/attributes of the user.  These are termed
1307 <em>credentials</em>.  Examples of which are group memberships to
1308 perform privileged tasks with, and <em>tickets</em> in the form of
1309 environment variables etc. .  Some user-credentials, such as the
1310 user's UID and GID (plus default group memberships) are not deemed to
1311 be PAM-credentials.  It is the responsibility of the application to
1312 grant these directly.
1313
1314 </descrip>
1315
1316 <sect>An example application
1317
1318 <p>
1319 To get a flavor of the way a <tt/Linux-PAM/ application is written we
1320 include the following example. It prompts the user for their password
1321 and indicates whether their account is valid on the standard output,
1322 its return code also indicates the success (<tt/0/ for success; <tt/1/
1323 for failure).
1324
1325 <p>
1326 <tscreen>
1327 <verb>
1328 /*
1329   This program was contributed by Shane Watts
1330   [modifications by AGM]
1331
1332   You need to add the following (or equivalent) to the /etc/pam.conf file.
1333   # check authorization
1334   check_user   auth       required     /usr/lib/security/pam_unix_auth.so
1335   check_user   account    required     /usr/lib/security/pam_unix_acct.so
1336  */
1337
1338 #include <security/pam_appl.h>
1339 #include <security/pam_misc.h>
1340 #include <stdio.h>
1341
1342 static struct pam_conv conv = {
1343     misc_conv,
1344     NULL
1345 };
1346
1347 int main(int argc, char *argv[])
1348 {
1349     pam_handle_t *pamh=NULL;
1350     int retval;
1351     const char *user="nobody";
1352
1353     if(argc == 2) {
1354         user = argv[1];
1355     }
1356
1357     if(argc > 2) {
1358         fprintf(stderr, "Usage: check_user [username]\n");
1359         exit(1);
1360     }
1361
1362     retval = pam_start("check_user", user, &ero;conv, &ero;pamh);
1363         
1364     if (retval == PAM_SUCCESS)
1365         retval = pam_authenticate(pamh, 0);    /* is user really user? */
1366
1367     if (retval == PAM_SUCCESS)
1368         retval = pam_acct_mgmt(pamh, 0);       /* permitted access? */
1369
1370     /* This is where we have been authorized or not. */
1371
1372     if (retval == PAM_SUCCESS) {
1373         fprintf(stdout, "Authenticated\n");
1374     } else {
1375         fprintf(stdout, "Not Authenticated\n");
1376     }
1377
1378     if (pam_end(pamh,retval) != PAM_SUCCESS) {     /* close Linux-PAM */
1379         pamh = NULL;
1380         fprintf(stderr, "check_user: failed to release authenticator\n");
1381         exit(1);
1382     }
1383
1384     return ( retval == PAM_SUCCESS ? 0:1 );       /* indicate success */
1385 }
1386 </verb>
1387 </tscreen>
1388
1389 <sect>Files
1390
1391 <p><descrip>
1392
1393 <tag><tt>/usr/include/security/pam_appl.h</tt></tag>
1394
1395 header file for <bf/Linux-PAM/ applications interface
1396
1397 <tag><tt>/usr/include/security/pam_misc.h</tt></tag>
1398
1399 header file for useful library functions for making applications
1400 easier to write
1401
1402 <tag><tt>/usr/lib/libpam.so.*</tt></tag>
1403
1404 the shared library providing applications with access to
1405 <bf/Linux-PAM/.
1406
1407 <tag><tt>/etc/pam.conf</tt></tag>
1408
1409 the <bf/Linux-PAM/ configuration file.
1410
1411 <tag><tt>/usr/lib/security/pam_*.so</tt></tag>
1412
1413 the primary location for <bf/Linux-PAM/ dynamically loadable object
1414 files; the modules.
1415
1416 </descrip>
1417
1418 <sect>See also
1419 <label id="bibliography">
1420
1421 <p><itemize>
1422
1423 <item>The <bf/Linux-PAM/
1424 <htmlurl url="pam.html" name="System Administrators' Guide">.
1425
1426 <item>The <bf/Linux-PAM/
1427 <htmlurl url="pam_modules.html" name="Module Writers' Guide">.
1428
1429 <item>The V. Samar and R. Schemers (SunSoft), ``UNIFIED LOGIN WITH
1430 PLUGGABLE AUTHENTICATION MODULES'', Open Software Foundation Request
1431 For Comments 86.0, October 1995.
1432
1433 </itemize>
1434
1435 <sect>Notes
1436
1437 <p>
1438 I intend to put development comments here... like ``at the moment
1439 this isn't actually supported''. At release time what ever is in
1440 this section will be placed in the Bugs section below! :)
1441
1442 <p>
1443 <itemize>
1444
1445 <item> <tt/pam_strerror()/ should be internationalized....
1446
1447 <item>
1448 Note, the <tt/resp_retcode/ of struct <tt/pam_message/, has no
1449 purpose at the moment. Ideas/suggestions welcome!
1450
1451 <item> more security issues are required....
1452
1453 </itemize>
1454
1455 <sect>Author/acknowledgments
1456
1457 <p>
1458 This document was written by Andrew G. Morgan
1459 (morgan@transmeta.com) with many contributions from
1460 <!-- insert credits here -->
1461 <!--
1462  an sgml list of people to credit for their contributions to Linux-PAM
1463  $Id: CREDITS,v 1.4 1997/04/05 06:47:26 morgan Exp morgan $
1464   -->
1465 Peter Allgeyer,
1466 Tim Baverstock,
1467 Craig S. Bell,
1468 Derrick J. Brashear,
1469 Ben Buxton,
1470 Oliver Crow,
1471 Chris Dent,
1472 Marc Ewing,
1473 Cristian Gafton,
1474 Eric Hester,
1475 Roger Hu,
1476 Eric Jacksch,
1477 Michael K. Johnson,
1478 David Kinchlea,
1479 Nicolai Langfeldt,
1480 Elliot Lee,
1481 Al Longyear,
1482 Ingo Luetkebohle,
1483 Marek Michalkiewicz,
1484 Aleph One,
1485 Martin Pool,
1486 Sean Reifschneider,
1487 Erik Troan,
1488 Theodore Ts'o,
1489 Jeff Uphoff,
1490 Myles Uyema,
1491 Savochkin Andrey Vladimirovich,
1492 Ronald Wahl,
1493 David Wood,
1494 John Wilmes,
1495 Joseph S. D. Yao
1496 and
1497 Alex O.  Yuriev.
1498
1499
1500 <p>
1501 Thanks are also due to Sun Microsystems, especially to Vipin Samar and
1502 Charlie Lai for their advice. At an early stage in the development of
1503 <bf/Linux-PAM/, Sun graciously made the documentation for their
1504 implementation of PAM available. This act greatly accelerated the
1505 development of <bf/Linux-PAM/.
1506
1507 <sect>Bugs/omissions
1508
1509 <p>
1510 This manual is hopelessly unfinished. Only a partial list of people is
1511 credited for all the good work they have done.
1512
1513 <sect>Copyright information for this document
1514
1515 <p>
1516 Copyright (c) Andrew G. Morgan 1996, 1997.  All rights reserved.
1517 <newline>
1518 Email: <tt>&lt;morgan@transmeta.com&gt;</tt>
1519
1520 <p>
1521 Redistribution and use in source and binary forms, with or without
1522 modification, are permitted provided that the following conditions are
1523 met:
1524
1525 <p>
1526 <itemize>
1527
1528 <item>
1529 1. Redistributions of source code must retain the above copyright
1530    notice, and the entire permission notice in its entirety,
1531    including the disclaimer of warranties.
1532
1533 <item>
1534 2. Redistributions in binary form must reproduce the above copyright
1535    notice, this list of conditions and the following disclaimer in the
1536    documentation and/or other materials provided with the distribution.
1537
1538 <item>
1539 3. The name of the author may not be used to endorse or promote
1540    products derived from this software without specific prior
1541    written permission.
1542
1543 </itemize>
1544
1545 <p>
1546 <bf/Alternatively/, this product may be distributed under the terms of
1547 the GNU General Public License (GPL), in which case the provisions of
1548 the GNU GPL are required <bf/instead of/ the above restrictions.
1549 (This clause is necessary due to a potential bad interaction between
1550 the GNU GPL and the restrictions contained in a BSD-style copyright.)
1551
1552 <p>
1553 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
1554 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1555 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1556 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1557 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1558 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
1559 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1560 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
1561 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
1562 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1563 DAMAGE.
1564
1565 <p>
1566 <tt>$Id: pam_appl.sgml,v 1.16 1997/04/05 06:49:14 morgan Exp morgan $</tt>
1567
1568 </article>