head	1.16;
access;
symbols;
locks; strict;
comment	@# @;


1.16
date	97.04.05.06.49.14;	author morgan;	state Exp;
branches;
next	1.15;

1.15
date	97.02.15.18.31.49;	author morgan;	state Exp;
branches;
next	1.14;

1.14
date	97.01.04.18.46.56;	author morgan;	state Exp;
branches;
next	1.13;

1.13
date	96.11.30.20.57.28;	author morgan;	state Exp;
branches;
next	1.12;

1.12
date	96.11.10.19.38.30;	author morgan;	state Exp;
branches;
next	1.11;

1.11
date	96.06.24.05.43.19;	author morgan;	state Exp;
branches;
next	1.10;

1.10
date	96.06.02.07.55.17;	author morgan;	state Exp;
branches;
next	1.9;

1.9
date	96.05.26.05.17.46;	author morgan;	state Exp;
branches;
next	1.8;

1.8
date	96.05.26.03.46.18;	author morgan;	state Exp;
branches;
next	1.7;

1.7
date	96.05.21.04.25.49;	author morgan;	state Exp;
branches;
next	1.6;

1.6
date	96.05.11.07.37.17;	author morgan;	state Exp;
branches;
next	1.5;

1.5
date	96.05.11.07.05.00;	author morgan;	state Exp;
branches;
next	1.4;

1.4
date	96.05.02.04.40.29;	author morgan;	state Exp;
branches;
next	1.3;

1.3
date	96.03.17.02.45.12;	author morgan;	state Exp;
branches;
next	1.2;

1.2
date	96.03.10.02.39.29;	author morgan;	state Exp;
branches;
next	1.1;

1.1
date	96.03.09.06.47.49;	author morgan;	state Exp;
branches;
next	;


desc
@The Linux-PAM application developers' guide. If you want
to make an application use PAM you had better read this.
@


1.16
log
@update for .57
@
text
@<!doctype linuxdoc system>

<!--

 $Id: pam_appl.sgml,v 1.15 1997/02/15 18:31:49 morgan Exp morgan $

    Copyright (C) Andrew G. Morgan 1996, 1997.  All rights reserved.

Redistribution and use in source (sgml) and binary (derived) forms,
with or without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright
   notice, and the entire permission notice in its entirety,
   including the disclaimer of warranties.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

3. The name of the author may not be used to endorse or promote
   products derived from this software without specific prior
   written permission.

ALTERNATIVELY, this product may be distributed under the terms of the
GNU General Public License, in which case the provisions of the GNU
GPL are required INSTEAD OF the above restrictions.  (This clause is
necessary due to a potential bad interaction between the GNU GPL and
the restrictions contained in a BSD-style copyright.)

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

 -->

<article>

<title>The Linux-PAM Application Developers' Guide
<author>Andrew G. Morgan, <tt>morgan@@parc.power.net</tt>
<date>DRAFT v0.57 1997/3/4
<abstract>
This manual documents what an application developer needs to know
about the <bf>Linux-PAM</bf> library. It describes how an application
might use the <bf>Linux-PAM</bf> library to authenticate users. In
addition it contains a description of the funtions to be found in
<tt/libpam_misc/ library, that can be used in general applications.
Finally, it contains some comments on PAM related security issues for
the application developer.
</abstract>

<toc>

<sect>Introduction

<sect1>Synopsis

<p>
For general applications that wish to use the services provided by
<bf/Linux-PAM/ the following is a summary of the relevant linking
information:
<tscreen>
<verb>
#include <security/pam_appl.h>

cc -o application .... -lpam
</verb>
</tscreen>

<p>
In addition to <tt/libpam/, there is a library of miscellaneous
functions that make the job of writing <em/PAM-aware/ applications
easier (this library is not covered in the DCE-RFC for PAM):
<tscreen>
<verb>
...
#include <security/pam_misc.h>

cc -o application .... -lpam -lpam_misc
</verb>
</tscreen>

<sect1> Description

<p>
<bf>Linux-PAM</bf> (Pluggable Authentication Modules for Linux) is a
library that enables the local system administrator to choose how
individual applications authenticate users.  For an overview of the
<bf>Linux-PAM</bf> library see the <bf/Linux-PAM/ System
Administrators' Guide.

<p>
It is the purpose of the <bf>Linux-PAM</bf> project to liberate the
development of privilege granting software from the development of
secure and appropriate authentication schemes.  This is accomplished
by providing a documented library of functions that an application may
use for all forms of user authentication management. This library
dynamically loads locally configured authentication modules that
actually perform the authentication tasks.

<p>
From the perspective of an application developer the information
contained in the local configuration of the PAM library should not be
important.  Indeed it is intended that an application treat the
functions documented here as a ``black box'' that will deal with all
aspects of user authentication. ``All aspects'' includes user
verification, account management, session initialization/termination
and also the resetting of passwords (<em/authentication tokens/).

<sect>The public interface to <bf>Linux-PAM</bf>
 
<p>
Firstly, the relevant include file for the <bf>Linux-PAM</bf> library
is <tt>&lt;security/pam_appl.h&gt;</tt>. It contains the definitions
for a number of functions. After listing these functions, we collect
some guiding remarks for programmers.

<sect1>What can be expected by the application

<p>
Here we document those functions in the <bf/Linux-PAM/ library that
may be called from an application.

<sect2>Initialization of Linux-PAM
<label id="pam-start-section">

<p>
<tscreen>
<verb>
extern int pam_start(const char *service_name, const char *user,
		     const struct pam_conv *pam_conversation,
		     pam_handle_t **pamh);
</verb>
</tscreen>

<p>
This is the first of the <bf>Linux-PAM</bf> functions that must be
called by an application. It initializes the interface and reads the
system configuration file, <tt>/etc/pam.conf</tt> (see the
<bf/Linux-PAM/ System Administrators' Guide).  Following a successful
return (<tt/PAM_SUCCESS/) the contents of <tt/*pamh/ is a handle that
provides continuity for successive calls to the <bf/Linux-PAM/
library.  The arguments expected by <tt/pam_start/ are as follows: the
<tt/service_name/ of the program, the <tt/user/name of the individual
to be authenticated, a pointer to an application-supplied
<tt/pam_conv/ structure and a pointer to a <tt/pam_handle_t/
<em/pointer/.

<p>
The <tt>pam_conv</tt> structure is discussed more fully in the section
<ref id="the-conversation-function" name="below">.  The
<tt>pam_handle_t</tt> is a <em>blind</em> structure and the
application should not attempt to probe it directly for information.
Instead the <bf>Linux-PAM</bf> library provides the functions
<tt>pam_set_item</tt> and <tt>pam_get_item</tt>.  These functions are
documented below.

<sect2>Termination of the library
<label id="pam-end-section">

<p>
<tscreen>
<verb>
extern int pam_end(pam_handle_t *pamh, int pam_status);
</verb>
</tscreen>

<p>
This function is the last function an application should call in the
<bf>Linux-PAM</bf> library.  Upon return the handle <tt/pamh/ is no
longer valid and all memory associated with it will be invalid (likely
to cause a segmentation fault if accessed).

<p>
Under normal conditions the argument <tt/pam_status/ has the value
PAM_SUCCESS, but in the event of an unsuccessful service application
the approprite <bf/Linux-PAM/ error-return value should be used
here.
attempt its purpose is to be passed as an argument to the
module specific function <tt/cleanup()/ (see the <bf/Linux-PAM/
<htmlurl url="pam_modules.html" name="Module Developers' Guide">).

<sect2>Setting PAM items
<label id="pam-set-item-section">

<p>
<tscreen>
<verb>
extern int pam_set_item(pam_handle_t *pamh, int item_type,
			const void *item);
</verb>
</tscreen>

<p>This function is used to (re)set the value of one of the following
<bf/item_type/s:

<p><descrip>
<tag><tt/PAM_SERVICE/</tag>
     	The service name

<tag><tt/PAM_USER/</tag>
	The user name

<tag><tt/PAM_TTY/</tag>
	The terminal name: prefixed by <tt>/dev/</tt> if it is a
device file; for graphical, X-based, applications the value for this
item should be the <tt/&dollar;DISPLAY/ variable.

<tag><tt/PAM_RHOST/</tag>
	The remote host name

<tag><tt/PAM_CONV/</tag>
	The conversation structure (see section <ref
id="the-conversation-function" name="below">)

<tag><tt/PAM_RUSER/</tag>
	The remote user name

<tag><tt/PAM_USER_PROMPT/</tag>
	The string used when prompting for a user's name. The default
value for this string is ``Please enter username: ''.

</descrip>

<p>
For all <tt/item_type/s, other than <tt/PAM_CONV/, <tt/item/ is a
pointer to a <tt>&lt;NUL&gt;</tt> terminated character string.  In the
case of <tt/PAM_CONV/, <tt/item/ points to an initialized
<tt/pam_conv/ structure (see section <ref
id="the-conversation-function" name="below">).

<p>
A successful call to this function returns <tt/PAM_SUCCESS/.  However,
the application should expect one of the following errors:

<p>
<descrip>
<tag><tt/PAM_PERM_DENIED/</tag>
	An attempt was made to replace the conversation structure with
a <tt/NULL/ value.
<tag><tt/PAM_BUF_ERR/</tag>
	The function ran out of memory making a copy of the item.
<tag><tt/PAM_BAD_ITEM/</tag>
	The application attempted to set an undefined item.
</descrip>

<sect2>Getting PAM items
<label id="pam-get-item-section">

<p>
<tscreen>
<verb>
extern int pam_get_item(const pam_handle_t *pamh, int item_type,
			const void **item);
</verb>
</tscreen>

<p>
This function is used to obtain the value of the indicated
<tt/item_type/.  Upon successful return, <tt/*item/ contains a pointer
to the value of the corresponding item.  Note, this is a pointer to
the <em/actual/ data and should <em/not/ be <tt/free()/'ed or
over-written!  A successful call is signaled by a return value of
<tt/PAM_SUCCESS/.  If an attempt is made to get an undefined item,
<tt/PAM_BAD_ITEM/ is returned.

<sect2>Understanding errors
<label id="pam-strerror-section">

<p>
<tscreen>
<verb>
extern const char *pam_strerror(int errnum);
</verb>
</tscreen>

<p>
This function returns some text describing the <bf>Linux-PAM</bf>
error associated with the argument <tt/errnum/.  If the error is not
recognized ``<tt/Unknown Linux-PAM error/'' is returned.

<sect2>Planning for delays

<p>
<tscreen>
<verb>
extern int pam_fail_delay(pam_handle_t *pamh, unsigned int micro_sec);
</verb>
</tscreen>

<p>
This function is offered by <bf/Linux-PAM/ to facilitate time delays
following a failed call to <tt/pam_authenticate()/ and before control
is returned to the application. When using this function the
application programmer should check if it is available with,
<tscreen>
<verb>
#ifdef HAVE_PAM_FAIL_DELAY
    ....
#endif /* HAVE_PAM_FAIL_DELAY */
</verb>
</tscreen>


<p>
Generally, an application requests that a user is authenticated by
<bf/Linux-PAM/ through a call to <tt/pam_authenticate()/ or
<tt/pam_chauthtok()/.  These functions calls each of the <em/stacked/
authentication modules listed in the <tt>/etc/pam.conf</tt> file.  As
directed by this file, one of more of the modules may fail causing the
<tt/pam_...()/ call to return an error.  It is desirable for there to
also be a pause before the application continues. The principal reason
for such a delay is security: a delay acts to discourage <em/brute
force/ dictionary attacks primarily, but also helps hinder
<em/timed/ (covert channel) attacks.

<p>
The <tt/pam_fail_delay()/ function provides the mechanism by which an
application or module can suggest a minimum delay (of <tt/micro_sec/
<em/micro-seconds/). <bf/Linux-PAM/ keeps a record of the longest time
requested with this function. Should <tt/pam_authenticate()/ fail,
the failing return to the application is delayed by an amount of time
randomly distributed (by up to 25%) about this longest value.

<p>
Independent of success, the delay time is reset to its zero default
value when <bf/Linux-PAM/ returns control to the application.

<sect2>Authenticating the user

<p>
<tscreen>
<verb>
extern int pam_authenticate(pam_handle_t *pamh, int flags);
</verb>
</tscreen>

<p>
This function serves as an interface to the authentication mechanisms
of the loaded modules.  The single <em/optional/ flag, which may be
logically OR'd with <tt/PAM_SILENT/, takes the following value,

<p><descrip>

<tag><tt/PAM_DISALLOW_NULL_AUTHTOK/</tag>
	Instruct the authentication modules to return
<tt/PAM_AUTH_ERR/ if the user does not have a registered
authorization token---it is set to <tt/NULL/ in the system database.
</descrip>

<p>
The value returned by this function is one of the following:

<p><descrip>

<tag><tt/PAM_AUTH_ERR/</tag>
	The user was not authenticated
<tag><tt/PAM_CRED_INSUFFICIENT/</tag>
	For some reason the application does not have sufficient
credentials to authenticate the user.
<tag><tt/PAM_AUTHINFO_UNAVAIL/</tag>
	The modules were not able to access the authentication
information. This might be due to a network or hardware failure etc.
<tag><tt/PAM_USER_UNKNOWN/</tag>
	The supplied username is not known to the authentication
service
<tag><tt/PAM_MAXTRIES/</tag>
	One or more of the authentication modules has reached its
limit of tries authenticating the user. Do not try again.

</descrip>

<p>
If one or more of the authentication modules fails to load, for
whatever reason, this function will return <tt/PAM_ABORT/.

<sect2>Setting user credentials
<label id="pam-setcred-section">

<p>
<tscreen>
<verb>
extern int pam_setcred(pam_handle_t *pamh, int flags);
</verb>
</tscreen>

<p>
This function is used to set the module-specific credentials of the
user.  It is usually called after the user has been authenticated,
after the account management function has been called and after a
session has been opened for the user.

<p>
A credential is something that the user possesses.  It is some
property, such as a <em>Kerberos</em> ticket, or a supplementary group
membership that make up the uniqueness of a given user.  On a Linux
(or UN*X system) the user's <tt>UID</tt> and <tt>GID</tt>'s are
credentials too.  However, it has been decided that these properties
(along with the default supplementary groups of which the user is a
member) are credentials that should be set directly by the application
and not by PAM.

<p>
This function simply calls the <tt/pam_sm_setcred/ functions of each
of the loaded modules.  Valid <tt/flags/, any one of which, may be
logically OR'd with <tt/PAM_SILENT/, are:

<p><descrip>
<tag><tt/PAM_CRED_ESTABLISH/</tag>
	Set the credentials for the authentication service,
<tag><tt/PAM_CRED_DELETE/</tag>
	Delete the credentials associated with the authentication service,
<tag><tt/PAM_CRED_REINITIALIZE/</tag>
	Reinitialize the user credentials, and
<tag><tt/PAM_CRED_REFRESH/</tag>
	Extend the lifetime of the user credentials.
</descrip>

<p>
A successful return is signalled with <tt/PAM_SUCCESS/. Errors that
are especially relevant to this function are the following:

<p><descrip>
<tag><tt/PAM_CRED_UNAVAIL/</tag>
	A module cannot retrieve the user's credentials.
<tag><tt/PAM_CRED_EXPIRED/</tag>
	The user's credentials have expired.
<tag><tt/PAM_USER_UNKNOWN/</tag>
	The user is not known to an authentication module.
<tag><tt/PAM_CRED_ERR/</tag>
	A module was unable to set the credentials of the user.
</descrip>

<sect2>Account management

<p>
<tscreen>
<verb>
extern int pam_acct_mgmt(pam_handle_t *pamh, int flags);
</verb>
</tscreen>

<p>
This function is typically called after the user has been
authenticated.  It establishes whether the user's account is healthy.
That is to say, whether the user's account is still active and whether
the user is permitted to gain access to the system at this time.
Valid flags, any one of which, may be logically OR'd with
<tt/PAM_SILENT/, and are the same as those applicable to the
<tt/flags/ argument of <tt/pam_authenticate/.

<p>
This function simply calls the corresponding functions of each of the
loaded modules, as instructed by the configuration file,
<tt>/etc/pam.conf</tt>.

<p>
The normal response from this function is <tt/PAM_SUCCESS/, however,
specific failures are indicated by the following error returns:

<descrip>
<tag><tt/PAM_AUTHTOKEN_REQD/</tag>
The user <bf/is/ valid but their authentication token has
<em/expired/.  The correct response to this return-value is to require
that the user satisfies the <tt/pam_chauthtok()/ function before
obtaining service.  It may not be possible for some applications to do
this.  In such cases, the user should be denied access until such time
as they can update their password.

<tag><tt/PAM_ACCT_EXPIRED/</tag>
	The user is no longer permitted access to the system.
<tag><tt/PAM_AUTH_ERR/</tag>
	There was an authentication error.

<tag><tt/PAM_PERM_DENIED/</tag>
	The user is not permitted to gain access at this time.
<tag><tt/PAM_USER_UNKNOWN/</tag>
	The user is not known to a module's account management
component.

</descrip>

<sect2>Updating authentication tokens
<label id="pam-chauthtok-section">

<p>
<tscreen>
<verb>
extern int pam_chauthtok(pam_handle_t *pamh, const int flags);
</verb>
</tscreen>

<p>
This function is used to change the authentication token for a given
user (as indicated by the state associated with the handle,
<tt/pamh/). The following is a valid but optional flag which may be
logically OR'd with <tt/PAM_SILENT/,

<descrip>
<tag><tt/PAM_CHANGE_EXPIRED_AUTHTOK/</tag>
	This argument indicates to the modules that the users
authentication token (password) should only be changed if it has
expired.
</descrip>

<p>
Note, if this argument is not passed, the application requires that
<em/all/ authentication tokens are to be changed.

<p>
<tt/PAM_SUCCESS/ is the only successful return value, valid
error-returns are:

<descrip>
<tag><tt/PAM_AUTHTOK_ERR/</tag>
	A module was unable to obtain the new authentication token.
	
<tag><tt/PAM_AUTHTOK_RECOVERY_ERR/</tag>
	A module was unable to obtain the old authentication token.

<tag><tt/PAM_AUTHTOK_LOCK_BUSY/</tag>
	One or more of the modules was unable to change the
authentication token since it is currently locked.
	
<tag><tt/PAM_AUTHTOK_DISABLE_AGING/</tag>
	Authentication token aging has been disabled for at least one
of the modules.

<tag><tt/PAM_PERM_DENIED/</tag>
	Permission denied.

<tag><tt/PAM_TRY_AGAIN/</tag>
	Not all of the modules were in a position to update the
authentication token(s). In such a case none of the user's
authentication tokens are updated.

<tag><tt/PAM_USER_UNKNOWN/</tag>
	The user is not known to the authentication token changing
service.

</descrip>

<sect2>Session initialization
<label id="pam-open-session-section">

<p>
<tscreen>
<verb>
extern int pam_open_session(pam_handle_t *pamh, int flags);
</verb>
</tscreen>

<p>
This function is used to indicate that an authenticated session has
begun.  It is used to inform the module that the user is currently in
a session.  It should be possible for the <bf>Linux-PAM</bf> library
to open a session and close the same session (see section <ref
id="pam-close-session-section" name="below">) from different
applications.

<p>
Currently, this function simply calls each of the corresponding
functions of the loaded modules. The only valid flag is
<tt/PAM_SILENT/ and this is, of course, <em/optional/.

<p>
If any of the <em/required/ loaded modules are unable to open a
session for the user, this function will return <tt/PAM_SESSION_ERR/.

<sect2>Terminating sessions
<label id="pam-close-session-section">

<p>
<tscreen>
<verb>
extern int pam_close_session(pam_handle_t *pamh, int flags);
</verb>
</tscreen>

<p>
This function is used to indicate that an authenticated session has
ended. It is used to inform the module that the user is exiting a
session. It should be possible for the <bf>Linux-PAM</bf> library to
open a session and close the same session from different applications.

<p>
Currently, this function simply calls each of the corresponding
functions of the loaded modules.  The only valid flag is
<tt/PAM_SILENT/ and this is, of course, <em/optional/.

<p>
If any of the <em/required/ loaded modules are unable to close a
session for the user, this function will return <tt/PAM_SESSION_ERR/.

<sect2>Setting PAM environment variables
<label id="pam-putenv-section">

<p>
<tscreen>
<verb>
extern int pam_putenv(pam_handle_t *pamh, const char *name_value);
</verb>
</tscreen>

<p>
<em>
Warning, the environment support in <bf/Linux-PAM/ is based solely
on a six line email from the developers at Sun. Its interface is
likely to be generally correct, however, the details are likely to be
changed as more information becomes available.
</em>

<p>
This function attempts to (re)set a <bf/Linux-PAM/ environment
variable. The <tt/name_value/ argument is a single <tt/NUL/ terminated
string of one of the following forms:
<descrip>
<tag>``<tt/NAME=value of variable/''</tag>

In this case the environment variable of the given <tt/NAME/ is set to
the indicated value: ``<tt/value of variable/''.  If this variable is
already known, it is overwritten. Otherwise it is added to the
<bf/Linux-PAM/ environment.

<tag>``<tt/NAME=/''</tag>

This function sets the variable to an empty value. It is listed
separately to indicate that this is the correct way to achieve such a
setting.

<tag>``<tt/NAME/''</tag>

Without an `<tt/=/' the <tt/pam_putenv()/ function will delete the
correspoding variable from the <bf/Linux-PAM/ environment.

</descrip>

<p>
Success is indicated with a return value of <tt/PAM_SUCCESS/. Failure
is indicated by one of the following returns:

<descrip>
<tag><tt/PAM_PERM_DENIED/</tag>
	name given is a <tt/NULL/ pointer

<tag><tt/PAM_BAD_ITEM/</tag>
	variable requested (for deletion) is not currently set

<tag><tt/PAM_ABORT/</tag>
	the <bf/Linux-PAM/ handle, <tt/pamh/, is corrupt

<tag><tt/PAM_BUF_ERR/</tag>
	failed to allocate memory when attempting update

</descrip>

<sect2>Getting a PAM environment variable
<label id="pam-getenv-section">

<p>
<tscreen>
<verb>
extern const char *pam_getenv(pam_handle_t *pamh, const char *name);
</verb>
</tscreen>

<p>
<em>
Warning, the environment support in <bf/Linux-PAM/ is based solely
on a six-line email from the developers at Sun. Its interface is
likely to be generally correct, however, the details are likely to be
changed as more information becomes available.
</em>

<p>
Obtain the value of the indicated <bf/Linux-PAM/ environment
variable. On error, internal failure or the unavailability of the
given variable (unspecified), this function simply returns <tt/NULL/.

<sect2>Getting the PAM environment
<label id="pam-getenvlist-section">

<p>
<tscreen>
<verb>
extern const char * const *pam_getenvlist(pam_handle_t *pamh);
</verb>
</tscreen>

<p>
<em>
Warning, the environment support in <bf/Linux-PAM/ is based solely
on a six line email from the developers at Sun. Its interface is
likely to be generally correct, however, the details are likely to be
changed as more information becomes available.
</em>

<p>
This function returns a pointer to the complete <tt/Linux-PAM/
environment.  It is a pointer to a <em/read-only/ list of
<em/read-only/ environment variables.  It should be noted that this
memory will become invalid after a call to <tt/pam_end()/ (see the
section <ref id="pam-end-section" name="above">).  If application
wishes to make use of this list after such a call, it should first
make a copy of all the set variables. (A function that performs such a
transcription is to be found in <tt/libpam_misc/.)

<sect1>What is expected of an application

<sect2>The conversation function
<label id="the-conversation-function">

<p>
An application must provide a ``conversation function''. It is used
for direct communication between a loaded module and the application
and will typically provide a means for the module to prompt the user
for a password etc. . The structure, <tt/pam_conv/, is defined by
including <tt>&lt;security/pam_appl.h&gt</tt>; to be,

<p>
<tscreen>
<verb>
struct pam_conv {
    int (*conv)(int num_msg,
        const struct pam_message **msg,
        struct pam_response **resp,
        void *appdata_ptr);
    void *appdata_ptr;
};
</verb>
</tscreen>

<p>
It is initialized by the application before it is passed to the
library.  The <em/contents/ of this structure are attached to the
<tt/*pamh/ handle.  The point of this argument is to provide a
mechanism for any loaded module to interact directly with the
application program. This is why it is called a <em/conversation/
structure.

<p>
When a module calls the referenced <tt/conv()/ function, the argument
<tt/*appdata_ptr/ is set to the second element of this structure.

<p>
The other arguments of a call to <tt/conv()/ concern the information
exchanged by module and application. That is to say, <tt/num_msg/
holds the length of the array of pointers, <tt/msg/. After a
successful return, the pointer <tt/*resp/ points to an array of
<tt/pam_response/ structures, holding the application supplied text.
Note, <tt/*resp/ is an <tt/struct pam_response/ array and <em/not/ an
array of pointers.

<p>
The message (from the module to the application) passing structure is
defined by <tt>&lt;security/pam_appl.h&gt;</tt> as:

<p>
<tscreen>
<verb>
struct pam_message {
    int msg_style;
    const char *msg;
};
</verb>
</tscreen>

<p>
Valid choices for <tt/msg_style/ are:

<p><descrip>
<tag><tt/PAM_PROMPT_ECHO_OFF/</tag>
	Obtain a string without echoing any text
<tag><tt/PAM_PROMPT_ECHO_ON/</tag>
	Obtain a string whilst echoing text
<tag><tt/PAM_ERROR_MSG/</tag>
	Display an error
<tag><tt/PAM_TEXT_INFO/</tag>
	Display some text.
</descrip>

<p>
The point of having an array of messages is that it becomes possible
to pass a number of things to the application in a single call from
the module. It can also be convenient for the application that related
things come at once: a windows based application can then present a
single form with many messages/prompts on at once.

<p>
The response (from the application to the module) passing structure is
defined by including <tt>&lt;security/pam_appl.h&gt;</tt> as:

<p><tscreen><verb>
struct pam_response {
    char *resp;
    int resp_retcode;
};
</verb></tscreen>

<p>
Currently, there are no definitions for <tt/resp_retcode/ values; the
normal value is <tt/0/. The length of the <tt/*resp/ array is known in
advance by the module, since it is dependent on the number of prompts
sent in the <tt/msg/ array. The memory for this array and its string
elements should be <em/dynamically/ allocated with one of the
<tt/malloc()/ library of functions. <em>It will be <tt/free()/'d by
the module.</em>

<p>
The maximum length of the <tt/pam_msg.msg/ and <tt/pam_response.resp/
character strings is <tt/PAM_MAX_MSG_SIZE/.

<p>
<tt/PAM_SUCCESS/ is the expected return value of this
function. However, should an error occur the application should not
set <tt/*resp/ but simply return <tt/PAM_CONV_ERR/.

<p>
Note, if an application wishes to use two conversation functions, it
should activate the second with a call to <tt/pam_set_item()/.

<sect1>Programming notes

<p>
Note, all of the authentication service function calls accept the
token <tt/PAM_SILENT/, which instructs the modules to not send
messages to the application. This token can be logically OR'd with any
one of the permitted tokens specific to the individual function calls.
<tt/PAM_SILENT/ does not override the prompting of the user for
passwords etc., it only stops informative messages from being
generated.

<sect>Security issues of <bf>Linux-PAM</bf>

<p>
A poorly (or maliciously) written application can defeat any
<bf/Linux-PAM/ module's authentication mechanisms by simply ignoring
it's return values.  It is the applications task and responsibility to
grant privileges and access to services.  The <bf/Linux-PAM/ library
simply assumes the responsibility of <em/authenticating/ the user;
ascertaining that the user <em/is/ who they say they are.  Care should
be taken to anticipate all of the documented behavior of the
<bf/Linux-PAM/ library functions.  A failure to do this will most
certainly lead to a future security breach.

<sect1>Care about standard library calls

<p>
In general, writers of authorization-granting applications should
assume that each module is likely to call any or <em/all/ `libc'
functions.  For `libc' functions that return pointers to
static/dynamically allocated structures (ie. the library allocates the
memory and the user is not expected to `<tt/free()/' it) any module
call to this function is likely to corrupt a pointer previously
obtained by the application.  The application programmer should either
re-call such a `libc' function after a call to the <bf/Linux-PAM/
library, or copy the structure contents to some safe area of memory
before passing control to the <bf/Linux-PAM/ library.

<sect1>Choice of a service name

<p>
When picking the <em/service-name/ that corresponds to the first entry
in the <tt>/etc/pam.conf</tt> file, the application programmer should
<bf/avoid/ the temptation of choosing something related to
<tt/argv[0]/.  It is a trivial matter for any user to invoke any
application on a system under a different name -- this should not be
permitted to cause a security breach.

<p>
To invoke some <tt/target/ application by another name, the user may
symbolically link the target application with the desired name.  To be
precise all the user need do is,
<tscreen>
<verb>
ln -s /target/application ./preferred_name
</verb>
</tscreen>
and then <em/run/ <tt>./preferred_name</tt>

<p>
By studying the <bf/Linux-PAM/ configuration file,
<tt>/etc/pam.conf</tt>, an attacker can choose the <tt/preferred_name/
to be that of a service enjoying minimal protection; for example a
game which uses <bf/Linux-PAM/ to restrict access to certain hours of
the day.  If the service-name were to be linked to the filename under
which the service was invoked, it is clear that the user is
effectively in the position of dictating which authentication scheme
the service uses.  Needless to say, this is not a secure situation.

<p>
The conclusion is that the application developer should carefully
define the service-name of an application. The safest thing is to make
it a single hard-wired name.

<sect1>The conversation function

<p>
Care should be taken to ensure that the <tt/conv()/ function is
robust. Such a function is provided in the library <tt/libpam_misc/
(see <ref id="libpam-misc-section" name="below">).

<sect1>The identity of the user

<p>
The <bf/Linux-PAM/ modules will need to determine the identity of the
user who requests a service, and the identity of the user who grants
the service.  These two users will seldom be the same.  Indeed there
is generally a third user identity to be considered, the new (assumed)
identity of the user once the service is granted.

<p>
The need for keeping tabs on these identities is clearly an issue of
security.  Basically, the identity of the user requesting a service
should be the current <tt/uid/ (userid) of the running process; the
identity of the privilege granting user is the <tt/euid/ (effective
userid) of the running process; the identity of the user, under whose
name the service will be executed, is given by the contents of the
<tt/PAM_USER/ <tt/pam_get_item(2)/.

<p>
In addition the identity of a remote user, requesting the service from
a distant location, will be placed in the <tt/PAM_RUSER/ item.

<sect1>Sufficient resources

<p>
Care should be taken to ensure that the proper execution of an
application is not compromised by a lack of system resources.  If an
application is unable to open sufficient files to perform its service,
it should fail gracefully, or request additional resources.
Specifically, the quantities manipulated by the <tt/setrlimit(2)/
family of commands should be taken into consideration.

<sect>A library of miscellaneous helper functions
<label id="libpam-misc-section">

<p>
To aid the work of the application developer a library of
miscellaneous functions is provided.  It is called <tt/libpam_misc/,
and contains functions for allocating memory (securely), a text based
conversation function, and routines for enhancing the standard
PAM-environment variable support.

<sect1>Requirements

<p>
The functions, structures and macros, made available by this library
can be defined by including <tt>&lt;security/pam_misc.h&gt;</tt>.  It
should be noted that this library is specific to <bf/Linux-PAM/ and is
not referred to in the defining DCE-RFC (see <ref id="bibliography"
name="the bibliography">) below.

<sect1>Functions supplied

<sect2>Safe string duplication

<p>
<tscreen>
<verb>
extern char *xstrdup(const char *s)
</verb>
</tscreen>
Return a duplicate copy of the <tt/NUL/ terminated string,
<tt/s/. <tt/NULL/ is returned if there is insufficient memory
available for the duplicate or if <tt/s=NULL/.

<sect2>A text based conversation function

<p>
<tscreen>
<verb>
extern int misc_conv(int num_msg, const struct pam_message **msgm,
		     struct pam_response **response, void *appdata_ptr);
</verb>
</tscreen>

<p>
This is a function that will prompt the user with the appropriate
comments and obtain the appropriate inputs as directed by
authentication modules.

<p>
In addition to simply slotting into the appropriate <tt/struct
pam_conv/, this function provides some time-out facilities.  The
function exports five variables that can be used by an application
programmer to limit the amount of time this conversation function will
spend waiting for the user to type something.

<p>
The five variables are as follows:
<descrip>
<tag><tt>extern time_t pam_misc_conv_warn_time;</tt></tag>

This variable contains the <em/time/ (as returned by <tt/time()/) that
the user should be first warned that the clock is ticking. By default
it has the value <tt/0/, which indicates that no such warning will be
given. The application may set its value to sometime in the future,
but this should be done prior to passing control to the <bf/Linux-PAM/
library.

<tag><tt>extern const char *pam_misc_conv_warn_line;</tt></tag>

Used in conjuction with <tt/pam_misc_conv_warn_time/, this variable is
a pointer to the string that will be displayed when it becomes time to
warn the user that the timeout is approaching. Its default value is
``..&bsol;a.Time is running out...&bsol;n'', but this can be changed
by the application prior to passing control to <bf/Linux-PAM/.

<tag><tt>extern time_t pam_misc_conv_die_time;</tt></tag>

This variable contains the <em/time/ (as returned by <tt/time()/) that
the conversation will time out. By default it has the value <tt/0/,
which indicates that the conversation function will not timeout. The
application may set its value to sometime in the future, this should
be done prior to passing control to the <bf/Linux-PAM/ library.

<tag><tt>extern const char *pam_misc_conv_die_line;</tt></tag>

Used in conjuction with <tt/pam_misc_conv_die_time/, this variable is
a pointer to the string that will be displayed when the conversation
times out. Its default value is ``..&bsol;a.Sorry, your time is
up!&bsol;n'', but this can be changed by the application prior to
passing control to <bf/Linux-PAM/.

<tag><tt>extern int pam_misc_conv_died;</tt></tag>

Following a return from the <bf/Linux-PAM/ libraray, the value of this
variable indicates whether the conversation has timed out. A value of
<tt/1/ indicates the time-out occurred.

</descrip>

<sect2>Transcribing an environment to that of Linux-PAM
<p>
<tscreen>
<verb>
extern int pam_misc_paste_env(pam_handle_t *pamh,
			      const char * const * user_env);
</verb>
</tscreen>

This function takes the supplied list of environment pointers and
<em/uploads/ its contents to the <bf/Linux-PAM/ environment. Success
is indicated by <tt/PAM_SUCCESS/.

<sect2>Saving the Linux-PAM environment for later use
<p>
<tscreen>
<verb>
extern char **pam_misc_copy_env(pam_handle_t *pamh);
</verb>
</tscreen>

This function returns a pointer to a list of environment variables
that are a direct copy of the <bf/Linux-PAM/ environment.  The memory
associated with these variables are the responsibility of the
application and should be liberated with a call to
<tt/pam_misc_drop_env()/.

<sect2>Liberating a locally saved environment
<p>
<tscreen>
<verb>
extern char **pam_misc_drop_env(char **env);
</verb>
</tscreen>

This function is defined to complement the <tt/pam_misc_copy_env()/
function.  It liberates the memory associated with <tt/env/,
<em/overwriting/ with <tt/0/ all memory before <tt/free()/ing it.

<sect2>BSD like Linux-PAM environment variable setting
<p>
<tscreen>
<verb>
extern int pam_misc_setenv(pam_handle_t *pamh, const char *name,
			   const char *value, int readonly);
</verb>
</tscreen>

This function performs a task equivalent to <tt/pam_putenv()/, its
syntax is, however, more like the BSD style function; <tt/setenv()/.
The <tt/name/ and <tt/value/ are concatenated with an ``<tt/=/'' to
form a <tt/name_value/ and passed to <tt/pam_putenv()/. If, however,
the <bf/Linux-PAM/ variable is already set, the replacement will only
be applied if the last argument, <tt/readonly/, is zero.

<sect>Glossary of PAM related terms

<p>
The following are a list of terms used within this document.

<p>
<descrip>

<tag>Authentication token</tag>
Generally, this is a password.  However, a user can authenticate
him/herself in a variety of ways.  Updating the user's authentication
token thus corresponds to <em>refreshing</em> the object they use to
authenticate themself with the system.  The word password is avoided
to keep open the possibility that the authentication involves a
retinal scan or other non-textual mode of challenge/response.

<tag>Credentials</tag>
Having successfully authenticated the user, PAM is able to establish
certain characteristics/attributes of the user.  These are termed
<em>credentials</em>.  Examples of which are group memberships to
perform privileged tasks with, and <em>tickets</em> in the form of
environment variables etc. .  Some user-credentials, such as the
user's UID and GID (plus default group memberships) are not deemed to
be PAM-credentials.  It is the responsibility of the application to
grant these directly.

</descrip>

<sect>An example application

<p>
To get a flavor of the way a <tt/Linux-PAM/ application is written we
include the following example. It prompts the user for their password
and indicates whether their account is valid on the standard output,
its return code also indicates the success (<tt/0/ for success; <tt/1/
for failure).

<p>
<tscreen>
<verb>
/*
  This program was contributed by Shane Watts
  [modifications by AGM]

  You need to add the following (or equivalent) to the /etc/pam.conf file.
  # check authorization
  check_user   auth       required     /usr/lib/security/pam_unix_auth.so
  check_user   account    required     /usr/lib/security/pam_unix_acct.so
 */

#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <stdio.h>

static struct pam_conv conv = {
    misc_conv,
    NULL
};

int main(int argc, char *argv[])
{
    pam_handle_t *pamh=NULL;
    int retval;
    const char *user="nobody";

    if(argc == 2) {
	user = argv[1];
    }

    if(argc > 2) {
	fprintf(stderr, "Usage: check_user [username]\n");
	exit(1);
    }

    retval = pam_start("check_user", user, &ero;conv, &ero;pamh);
	
    if (retval == PAM_SUCCESS)
        retval = pam_authenticate(pamh, 0);    /* is user really user? */

    if (retval == PAM_SUCCESS)
        retval = pam_acct_mgmt(pamh, 0);       /* permitted access? */

    /* This is where we have been authorized or not. */

    if (retval == PAM_SUCCESS) {
	fprintf(stdout, "Authenticated\n");
    } else {
	fprintf(stdout, "Not Authenticated\n");
    }

    if (pam_end(pamh,retval) != PAM_SUCCESS) {     /* close Linux-PAM */
	pamh = NULL;
	fprintf(stderr, "check_user: failed to release authenticator\n");
	exit(1);
    }

    return ( retval == PAM_SUCCESS ? 0:1 );       /* indicate success */
}
</verb>
</tscreen>

<sect>Files

<p><descrip>

<tag><tt>/usr/include/security/pam_appl.h</tt></tag>

header file for <bf/Linux-PAM/ applications interface

<tag><tt>/usr/include/security/pam_misc.h</tt></tag>

header file for useful library functions for making applications
easier to write

<tag><tt>/usr/lib/libpam.so.*</tt></tag>

the shared library providing applications with access to
<bf/Linux-PAM/.

<tag><tt>/etc/pam.conf</tt></tag>

the <bf/Linux-PAM/ configuration file.

<tag><tt>/usr/lib/security/pam_*.so</tt></tag>

the primary location for <bf/Linux-PAM/ dynamically loadable object
files; the modules.

</descrip>

<sect>See also
<label id="bibliography">

<p><itemize>

<item>The <bf/Linux-PAM/
<htmlurl url="pam.html" name="System Administrators' Guide">.

<item>The <bf/Linux-PAM/
<htmlurl url="pam_modules.html" name="Module Writers' Guide">.

<item>The V. Samar and R. Schemers (SunSoft), ``UNIFIED LOGIN WITH
PLUGGABLE AUTHENTICATION MODULES'', Open Software Foundation Request
For Comments 86.0, October 1995.

</itemize>

<sect>Notes

<p>
I intend to put development comments here... like ``at the moment
this isn't actually supported''. At release time what ever is in
this section will be placed in the Bugs section below! :)

<p>
<itemize>

<item> <tt/pam_strerror()/ should be internationalized....

<item>
Note, the <tt/resp_retcode/ of struct <tt/pam_message/, has no
purpose at the moment. Ideas/suggestions welcome!

<item> more security issues are required....

</itemize>

<sect>Author/acknowledgments

<p>
This document was written by Andrew G. Morgan
(morgan@@parc.power.net) with many contributions from
<!-- insert credits here -->
<!--
 an sgml list of people to credit for their contributions to Linux-PAM
  -->
Craig S. Bell,
Derrick J. Brashear,
Oliver Crow,
Marc Ewing,
Cristian Gafton,
Eric Hester,
Michael K. Johnson,
Elliot Lee,
Al Longyear,
Marek Michalkiewicz,
Aleph One,
Sean Reifschneider,
Eric Troan,
Theodore Ts'o,
Jeff Uphoff,
Ronald Wahl,
John Wilmes,
Joseph S. D. Yao
and
Alex O.  Yuriev.

<p>
Thanks are also due to Sun Microsystems, especially to Vipin Samar and
Charlie Lai for their advice. At an early stage in the development of
<bf/Linux-PAM/, Sun graciously made the documentation for their
implementation of PAM available. This act greatly accelerated the
development of <bf/Linux-PAM/.

<sect>Bugs/omissions

<p>
This manual is hopelessly unfinished. Only a partial list of people is
credited for all the good work they have done.

<sect>Copyright information for this document

<p>
Copyright (c) Andrew G. Morgan 1996.  All rights reserved.
<newline>
Email: <tt>&lt;morgan@@parc.power.net&gt;</tt>

<p>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

<p>
<itemize>

<item>
1. Redistributions of source code must retain the above copyright
   notice, and the entire permission notice in its entirety,
   including the disclaimer of warranties.

<item>
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

<item>
3. The name of the author may not be used to endorse or promote
   products derived from this software without specific prior
   written permission.

</itemize>

<p>
<bf/Alternatively/, this product may be distributed under the terms of
the GNU General Public License (GPL), in which case the provisions of
the GNU GPL are required <bf/instead of/ the above restrictions.
(This clause is necessary due to a potential bad interaction between
the GNU GPL and the restrictions contained in a BSD-style copyright.)

<p>
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

<p>
<tt>$Id: pam_appl.sgml,v 1.15 1997/02/15 18:31:49 morgan Exp morgan $</tt>

</article>
@


1.15
log
@update for .56
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.14 1997/01/04 18:46:56 morgan Exp morgan $
d49 1
a49 1
<date>DRAFT v0.56 1997/2/15
d302 10
a311 1
is returned to the application.
d397 15
a411 1
user.  It is usually called after the user has been authenticated.
d1097 28
d1360 1
a1360 1
<tt>$Id: pam_appl.sgml,v 1.14 1997/01/04 18:46:56 morgan Exp morgan $</tt>
@


1.14
log
@update for .55
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.13 1996/11/30 20:57:28 morgan Exp morgan $
d7 1
a7 1
    Copyright (C) Andrew G. Morgan 1996.  All rights reserved.
d9 3
a11 3
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
d49 1
a49 1
<date>DRAFT v0.55 1996/12/5
d290 38
d1309 1
a1309 1
<tt>$Id: pam_appl.sgml,v 1.13 1996/11/30 20:57:28 morgan Exp morgan $</tt>
@


1.13
log
@updated for .54.
added info about environment variables and pam_misc stuff
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.12 1996/11/10 19:38:30 morgan Exp morgan $
d49 1
a49 1
<date>DRAFT v0.54 1996/11/30
d213 3
a215 1
	The terminal name
d228 3
a230 1
	The string used when prompting for a user's name.
d793 2
d796 1
a796 1
In general writers of authorization-granting applications should
d803 1
a803 1
re-call such a `libc' function after any call to the <bf/Linux-PAM/
d807 2
d810 1
a810 1
When picking the <em/service name/ that corresponds to the first entry
d812 32
a843 5
avoid the temptation of choosing, <tt/argv[0]/. Since a user can
always establish the service that uses the weakest authentication
service.  By symbolically linking the targeted application to a link
of that name, the user assumes power to choose the authentication
method for any application.
d850 32
d895 2
a896 2
The functions, structures and macros made available by this library
can be defined by including <tt>&lt;security/pam_misc.h&gt;</tt>. It
d930 51
d1082 1
a1082 1
    retval = pam_start("check_user", user, &amp;conv, &amp;pamh);
d1179 25
a1203 3
(morgan@@parc.power.net) with many contributions from Marc Ewing,
Michael K. Johnson, Al Longyear, Marek Michalkiewicz, Theodore Ts'o,
Jeff Uphoff, Joseph S. D. Yao and Alex O.  Yuriev.
d1217 55
@


1.12
log
@updated for .53
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.11 1996/06/24 05:43:19 morgan Exp morgan $
d48 2
a49 2
<author>Andrew G. Morgan, <tt>morgan@@physics.ucla.edu</tt>
<date>DRAFT v0.53 1996/10/24
d53 5
a57 3
might use the <bf>Linux-PAM</bf> library to authenticate users. It also
contains some comments on PAM related security issues for the
application developer.
d64 2
a65 1
<sect1> SYNOPSIS
d67 3
d78 13
d94 5
a98 4
<bf>Linux-PAM</bf> (Pluggable Authentication Modules) is a library that
enables the local system administrator to choose how individual
applications authenticate users.  For an overview of the <bf>Linux-PAM</bf>
library see the <bf/Linux-PAM/ System Administrators' Guide.
d107 1
a107 1
actually perform the task of user authentication.
d112 5
a116 4
important. Indeed it is intended that an application treat the
functions documented in this file as a ``black box'' that will deal
with all aspects of user authentication. ``All aspects'' includes user
verification and also the resetting of passwords etc. .
d132 3
d136 7
a142 4
<itemize>
<item>
<tt>extern int pam_start(const char *service_name, const char *user,
const struct pam_conv *pam_conversation, pam_handle_t **pamh);</tt>
d148 1
a148 1
<bf/Linux-PAM/ System Administrators' Guide). Following a successful
d151 1
a151 1
library. The arguments expected by <tt/pam_start/ are as follows: the
d158 2
a159 2
The <tt>pam_conv</tt> structure is discussed more fully below in the
section covering ``What is expected of an application''. The
d161 7
a167 4
application should not attempt to probe it directly for
information. Instead the <bf>Linux-PAM</bf> library provides the
functions <tt>pam_set_item</tt> and <tt>pam_get_item</tt>. These
functions are documented below.
d170 5
a174 2
<item>
<tt>extern int pam_end(pam_handle_t *pamh, int pam_status);</tt>
d178 15
a192 5
<bf>Linux-PAM</bf> library. Upon return the handle <tt/pamh/ is no
longer valid. Under normal conditions the argument <tt/pam_status/ has
the value PAM_SUCCESS, but its purpose is to be passed as an argument
to the module specific function <tt/cleanup()/ (see the <bf/Linux-PAM/
Module Developers' Guide).
d195 6
a200 3
<item>
<tt>extern int pam_set_item(pam_handle_t *pamh, int item_type, const
void *item);</tt>
d208 1
d211 1
d214 1
d217 1
d219 3
a221 1
	The pam_conv structure (see below)
d224 1
d230 5
a234 4
For all <tt/item_type/s, but <tt/PAM_CONV/, <tt/item/ is a pointer to
a <tt>&lt;NUL&gt;</tt> terminated character string. In the case of
<tt/PAM_CONV/, <tt/item/ points to an initialized <tt/pam_conv/
structure (see below).
d237 2
a238 2
A successful call to this function returns <tt/PAM_SUCCESS/. However
the application can expect one of the following errors:
d248 1
a248 1
	The application attempted to set an un-defined item.
d251 3
d255 6
a260 3
<item>
<tt>extern int pam_get_item(const pam_handle_t *pamh, int item_type,
const void **item);</tt>
d265 3
a267 3
to the value of the corresponding item. Note, this is a pointer to the
<em/actual/ data and should <em/not/ be <tt/free()/'ed or
over-written! A successful call is signaled by a return value of
d271 3
d275 10
a284 2
<item>
<tt>extern const char *pam_strerror(int errnum);</tt>
d286 1
a286 3
<p>This function returns some text describing the <bf>Linux-PAM</bf>
error associated with the argument <tt/errnum/. If the error is not
recognized <tt/``Unknown Linux-PAM error''/ is returned.
d289 5
a293 2
<item>
<tt>extern int pam_authenticate(pam_handle_t *pamh, int flags);</tt>
d297 1
a297 1
of the loaded modules. The single <em/optional/ flag, which may be
d334 3
d338 5
a342 2
<item>
<tt>extern int pam_setcred(pam_handle_t *pamh, int flags);</tt>
d346 4
a349 4
user. It is usually called after the user has been authenticated. This
function simply calls the <tt/pam_sm_setcred/ functions of each of the
loaded modules.  Valid <tt/flags/, any one of which, may be logically
OR'd with <tt/PAM_SILENT/, are:
d363 2
a364 2
Return values that the application should look out for are the
following:
d377 2
d380 5
a384 2
<item>
<tt>extern int pam_acct_mgmt(pam_handle_t *pamh, int flags);</tt>
d388 4
a391 4
authenticated. It establishes whether the user's account is
healthy. That is to say, whether the user's account is still active
and whether the user is permitted to gain access to the system at this
time. Valid flags, any one of which, may be logically OR'd with
d396 2
a397 2
Currently, this function simply calls the corresponding functions of
each of the loaded modules, as instructed by the configuration file,
d405 8
d417 1
a417 4
<tag><tt/PAM_AUTHTOKEN_REQD/</tag>
	The user's authentication token has expired. Before calling
this function again the application should arrange for a new one to be
given. This is accomplished via a call to <tt/pam_chauthtok()/.
d426 3
d430 5
a434 2
<item>
<tt>extern int pam_chauthtok(pam_handle_t *pamh, const int flags);</tt>
d477 2
a478 1
authentication token(s).
d486 3
d490 5
a494 2
<item>
<tt>extern int pam_open_session(pam_handle_t *pamh, int flags);</tt>
d498 4
a501 3
begun. It is used to inform the module that the user is currently in a
session. It should be possible for the <bf>Linux-PAM</bf> library to
open a session and close the same session (see below) from different
d513 3
d517 5
a521 2
<item>
<tt>extern int pam_close_session(pam_handle_t *pamh, int flags);</tt>
d531 1
a531 1
functions of the loaded modules. The only valid flag is
d538 112
a649 1
</itemize>
d653 3
d678 5
a682 4
library. The contents of this structure are attached to the <tt/*pamh/
handle.  The point of this argument is to provide a mechanism for any
loaded module to interact directly with the application program. This
is why it is called a <em/conversation/ structure.
d759 5
a763 1
return set <tt/*resp/ and simply return <tt/PAM_CONV_ERR/.
d781 2
a782 2
it's return values. It is the applications task and responsibility to
grant privileges and access to services. The <bf/Linux-PAM/ library
d784 1
a784 1
ascertaining that the user <em/is/ who they say they are. Care should
d786 1
a786 1
<bf/Linux-PAM/ library functions. A failure to do this will most
d792 1
a792 1
functions. For `libc' functions that return pointers to
d796 1
a796 1
obtained by the application. The application programmer should either
d806 3
a808 3
service. By symbolically linking the targeted application to a link of
that name, the user assumes power to choose the authentication method
for any application.
d812 105
a916 1
robust.
d920 70
a989 6
<p><em>
It would be nice to give a simple template for a PAM-aware application
here. I guess it need not grant any privileges, but rather just print
``authentication succeeded/failed''. It would also be rather useful
for developing modules.
</em>
d995 9
d1021 1
d1025 2
a1026 1
<item>The <bf/Linux-PAM/ System Administrators' Guide.
d1028 2
a1029 1
<item>The <bf/Linux-PAM/ Module Writers' Guide.
a1046 7
<item>
the <tt/pam_status/ argument of <tt/pam_end()/ is passed to
<tt/cleanup()/? This seems dangerously close to making applications
module specific...? Perhaps someone can clarify this for me? Is
there going to be a recognized list of valid pam_status arguments? I
guess it should be in &lt;security/pam_appl.h&gt;?

a1048 22
<item> need a simple example application?

<item> <tt>pam_setcred</tt>, this function will get a better write up
once I appreciate it better!

<item> <tt/pam_conv/.. This seems to be a good way for the module to
set application environment variables etc. from the module . Might I
suggest that (see rfc86.0 pp26-27) we have a special action for the
conv function when the <tt/num_msg/ argument is <em/negative/. For
example, if <tt/num_mesg==PAM_EXPORT_ENV( = -1 )/, then the <tt/msg/
pointer points at an array of two <tt/pam_message/ structures holding
the name of the environment variable and its value. While we are at it
the <tt/*resp/ pointer can be directed at a pam_response holding the
<em/previous/ value of this variable (or <tt/NULL/). Thoughts?

<p> another thing that we might think about is multiple responses from
an application, I have inserted it into the code and documented it
here in the hope that no-one objects too strongly. My motivation is
simply that it seems desirable to get username and password with a
single call to <tt/conv()/. Wouldn't this be easier for windows based
applications to do logging in type things?

d1061 1
a1061 1
(morgan@@physics.ucla.edu) with many contributions from Marc Ewing,
d1074 1
a1074 1
<p>Few PAM modules currently exist. Few PAM-aware applications exist.
@


1.11
log
@added return value of PAM_PERM_DENIED to those of pam_acct_mgmt()
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.10 1996/06/02 07:55:17 morgan Exp morgan $
d47 1
a47 1
<title>The <bf>Linux-PAM</bf> Application Developers' Guide
d49 1
a49 1
<date>DRAFT v0.43 1996/6/23
@


1.10
log
@fixed copyright, names and pam_get_item definition
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.9 1996/05/26 05:17:46 morgan Exp morgan $
d49 1
a49 1
<date>DRAFT v0.42 1996/5/31
d330 2
@


1.9
log
@updated for .40
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.8 1996/05/26 03:46:18 morgan Exp morgan $
d7 1
a7 1
    Copyright Andrew G. Morgan 1996.  All rights reserved.
d26 4
a29 4
GNU Public License, in which case the provisions of the GPL are
required INSTEAD OF the above restrictions.  (This clause is necessary
due to a potential bad interaction between the GPL and the
restrictions contained in a BSD-style copyright.)
d49 1
a49 1
<date>DRAFT v0.40 1996/5/25
d200 1
a200 1
void **item);</tt>
d680 4
a683 4
This document was written by Andrew Morgan (morgan@@physics.ucla.edu)
with many contributions from Marc Ewing, Michael Johnson, Al Longyear,
Marek Michalkiewicz, Theodore Ts'o, Jeff Uphoff, Joseph Yao and Alex
Yuriev.
@


1.8
log
@added Michael and Joseph to credits
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.7 1996/05/21 04:25:49 morgan Exp morgan $
d49 1
a49 1
<date>DRAFT v0.34 1996/5/8
@


1.7
log
@fixed a couple of typos and corrected Marek's name
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.6 1996/05/11 07:37:17 morgan Exp morgan $
d680 4
a683 3
This manual was written by Andrew Morgan (morgan@@physics.ucla.edu)
with many contributions from Marc Ewing, Al Longyear, Marek
Michalkiewicz, Theodore Ts'o, Jeff Uphoff and Alex Yuriev.
@


1.6
log
@*** empty log message ***
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.5 1996/05/11 07:05:00 morgan Exp morgan $
d49 1
a49 1
<date>DRAFT v0.33 1996/5/8
d354 1
a354 1
Note, if this argument is not passed the application requires that
d436 2
a437 2
for a password etc. . The structure <tt/pam_conv/ is defined in
<tt>&lt;security/pam_appl.h&gt</tt>; to be,
d474 1
a474 1
defined in <tt>&lt;security/pam_appl.h&gt;</tt> as:
d509 1
a509 1
defined in <tt>&lt;security/pam_appl.h&gt;</tt> as:
d543 3
d570 1
a570 3
before passing control to the <bf/Linux-PAM/ library. <tt/PAM_SILENT/
does not override the prompting of the user for passwords etc., only
stops informative messages from being generated.
d598 5
a603 1
	the <bf/Linux-PAM/ configuration file
d605 6
a610 2
<tag><tt>/usr/lib/security/pam_*_*.so</tt></tag>
	Authentication modules.
d682 1
a682 1
Mickalchiewicz, Theodore Ts'o, Jeff Uphoff and Alex Yuriev.
d685 5
a689 4
Thanks are also due to Sun Microsystems. At an early stage in the
development of <bf/Linux-PAM/, Sun graciously made the documentation
for their implementation of PAM available. This act greatly
accelerated the development of <bf/Linux-PAM/.
@


1.5
log
@corrected Jeff's name!
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.4 1996/05/02 04:40:29 morgan Exp morgan $
d49 1
a49 1
<date>DRAFT v0.3 1996/3/16
@


1.4
log
@added credits
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.3 1996/03/17 02:45:12 morgan Exp morgan $
d673 1
a673 1
Mickalchiewicz, Theodore Ts'o, Jeoff Uphoff and Alex Yuriev.
@


1.3
log
@update for 0.3
@
text
@d5 1
a5 1
 $Id: pam_appl.sgml,v 1.2 1996/03/10 02:39:29 morgan Exp morgan $
d672 2
a673 2
with many contributions from Marc Ewing, Marek Mickalchiewicz,
Theodore Ts'o, Jeoff Uphoff and Alex Yuriev.
d683 1
a683 1
<p>No PAM modules currently exist. No PAM-aware applications exist.
@


1.2
log
@added some return values
@
text
@d5 1
a5 1
 $Id$
d49 1
a49 1
<date>DRAFT v0.2 1996/3/6
d58 2
d78 1
a78 1
library see pam.html.
d102 1
a102 1
for a number of functions. Before listing these functions, we collect
a104 18
<sect1>Programming notes

<p>
In general writers of authorization-granting applications should
assume that each module is likely to call any or <em/all/ `libc'
functions. For `libc' functions that return pointers to
static/dynamically allocated structures (ie. the library allocates the
memory and the user is not expected to `<tt/free()/' it) any module
call to this function is likely to corrupt a pointer previously
obtained by the application. The application programmer should either
re-call such a libc function after any call to the <bf/Linux-PAM/
library, or copy the structure contents to some safe area of memory
before passing control to the <bf/Linux-PAM/ library.

<p>
All of the authentication services accept the token <tt/PAM_SILENT/,
which instructs the modules to not send messages to the application.

d114 2
a115 2
<tt>extern int pam_start(char *service_name, char *user, struct
pam_conv *pam_conversation, pam_handle_t **pamh);</tt>
d120 7
a126 7
system configuration file, <tt>/etc/pam.conf</tt> (see
pam.html). Following a successful return (<tt/PAM_SUCCESS/)
the contents of <tt/*pamh/ is a handle that provides continuity
for successive calls to the <bf/Linux-PAM/ library. The arguments
expected by <tt/pam_start/ are as follows: the
<tt/service_name/ of the program, the <tt/user/name of the
individual to be authenticated, a pointer to an application-supplied
d139 1
d148 2
a149 2
to the module specific function <tt/cleanup()/ (see
pam_modules.html. [XXX -- see notes]
d151 1
d178 3
a180 3
a <tt/'\\0'/ terminated character string. In the case of <tt/PAM_CONV/,
<tt/item/ points to an initialized <tt/pam_conv/ structure (see
below).
d182 16
d207 2
a208 1
over-written!  If an attempt is made to get an undefined item,
d211 1
d216 2
a217 1
error associated with the argument <tt/errnum/. [ XXX - see notes ]
d219 1
d225 2
a226 1
of the loaded modules. Valid flags, which may be logically OR'd, are
a229 2
<tag><tt/PAM_SILENT/</tag>
	Instruct the authentication modules to not generate any messages, and
d232 1
a232 1
<tt/PAM_AUTH_ERROR/ if the user does not have a registered
a233 1

d262 1
d268 4
a271 4
user. It is usually called after the user has been
authenticated. Currently, this function simply calls the
<tt/pam_sm_setcred/ functions of each of the loaded modules.  Valid
<tt/flags/, which may be logically OR'd, are:
d284 16
d308 3
a310 2
time. Valid flags, which may be logically OR'd, are the same as those
applicable to the <tt/flags/ argument of <tt/pam_authenticate/.
d318 3
a320 2
Besides the normal authentication failure returns, this function may
return the following error,
d324 63
d389 1
d402 2
a403 1
functions of the loaded modules. [ XXX - see notes ]
d409 1
d421 2
a422 1
functions of the loaded modules. [ XXX - see notes ]
a427 9
<item>
<tt>extern int pam_chauthtok(pam_handle_t *pamh, const int flags);</tt>

<p>
This function is used to change the authentication token for a given
user (as indicated by the state associated with the handle,
<tt/pamh/). Valid flags, which may be logically OR'd, are those
associated with a call to <tt/pam_authenticate/ above.

d439 3
a441 1
<p><tscreen><verb>
d449 2
a450 1
</verb></tscreen>
d467 4
a470 2
successful return, the pointer <tt/*resp/ points to a
<tt/pam_response/ structure, holding the application supplied text.
d476 3
a478 1
<p><tscreen><verb>
d481 1
a481 1
    char *msg;
d483 2
a484 1
</verb></tscreen>
d502 4
a505 6
to pass a number of things to the application in a single call
from the module. It can also be convenient for the application that
related things come at once: a windows based application can then
present a single form with many messages on at once. Currently, there
is no mechanism for returning more than one string from the
application. [ see NOTES ].
d519 24
a542 2
Currently, there are no definitions for <tt/resp_retcode/ values. The
normal response is <tt/0/. [ XXX - see notes ]
d547 9
a555 2
This section will discuss good practices for applications
programmers... 
d558 21
a578 2
Clearly it is a good idea to always check the return value of a call
to any function of <bf>Linux-PAM</bf>.
d582 1
a582 1
robust. [ XXX - see notes ]
d609 1
a609 1
<item>The <bf/Linux-PAM/ system administrators' guide; pam.html.
d611 1
a611 1
<item>The <bf/Linux-PAM/ module writers' guide pam_modules.html.
d638 1
a638 1
<item> need a simple example application.
d640 2
a641 2
<item> <tt>pam_open/close_session</tt>, these functions will get a
better write up once I appreciate them better!
d654 5
a658 3
an application. Say getting username,password with a single call to
<tt/conv()/. Would this be easier for windows based applications to do
loging in type things?
d664 1
a664 13
<item>
perhaps this comment should be in the pam_modules manual (too)? On
return from a call to <tt/conv()/ the <em/response/ should be copied
to some allocated memory. This will ensure that no static variables
etc. in the application cause problems when used repeatedly!

<item>
more work needs to be done, documenting valid responses of the
various function calls. The security issues bit is currently rather
pathetic.

<item>
Does <tt/PAM_SILENT/, mean the user is not ``prompted'' for a password?
d673 1
a673 1
Theodore Ts'o and Jeoff Uphoff.
d678 2
a679 2
for their implementation of PAM availible. This act greatly
accelerated the developement of <bf/Linux-PAM/.
@


1.1
log
@Initial revision
@
text
@d3 5
a7 1
<!--    Copyright Andrew G. Morgan 1996.  All rights reserved.
d117 4
d217 3
a219 3
<p>This function serves as an interface to the authentication
mechanisms of the loaded modules. Valid flags, which may be logically
OR'd, are
d222 1
d227 25
a251 2
<tt/PAM_AUTHTOKEN_REQD/ if the <em/item/, <tt/PAM_AUTHTOK/, is set to
<tt/NULL/.
d295 8
d356 1
a356 1
&lt;security/pam_appl.h&gt; to be,
d412 9
d518 5
d537 3
@
