没有合适的资源?快使用搜索试试~ 我知道了~
首页linux pam开发手册
资源详情
资源评论
资源推荐

The Linux-PAM Application
Developers' Guide
Andrew G. Morgan <morgan@kernel.org>
Thorsten Kukuk <kukuk@thkukuk.de>

The Linux-PAM Application Developers' Guide
by Andrew G. Morgan and Thorsten Kukuk
Version 1.1.2, 31. August 2010
Abstract
This manual documents what an application developer needs to know about the Linux-PAM library. It describes how an
application might use the Linux-PAM library to authenticate users. In addition it contains a description of the functions
to be found in libpam_misc library, that can be used in general applications. Finally, it contains some comments
on PAM related security issues for the application developer.

iii
1. Introduction .................................................................................................................... 1
1.1. Description .......................................................................................................... 1
1.2. Synopsis .............................................................................................................. 1
2. Overview ....................................................................................................................... 2
3. The public interface to Linux-PAM ..................................................................................... 4
3.1. What can be expected by the application ................................................................... 4
3.1.1. Initialization of PAM transaction ................................................................... 4
3.1.2. Termination of PAM transaction ................................................................... 5
3.1.3. Setting PAM items ..................................................................................... 5
3.1.4. Getting PAM items ..................................................................................... 7
3.1.5. Strings describing PAM error codes ............................................................... 9
3.1.6. Request a delay on failure ............................................................................ 9
3.1.7. Authenticating the user .............................................................................. 10
3.1.8. Setting user credentials .............................................................................. 11
3.1.9. Account validation management .................................................................. 12
3.1.10. Updating authentication tokens .................................................................. 12
3.1.11. Start PAM session management ................................................................. 13
3.1.12. terminating PAM session management ........................................................ 14
3.1.13. Set or change PAM environment variable .................................................... 14
3.1.14. Get a PAM environment variable ............................................................... 15
3.1.15. Getting the PAM environment ................................................................... 15
3.2. What is expected of an application ......................................................................... 16
3.2.1. The conversation function .......................................................................... 16
3.3. Programming notes .............................................................................................. 18
4. Security issues of Linux-PAM .......................................................................................... 19
4.1. Care about standard library calls ............................................................................ 19
4.2. Choice of a service name ...................................................................................... 19
4.3. The conversation function ..................................................................................... 20
4.4. The identity of the user ........................................................................................ 20
4.5. Sufficient resources ............................................................................................. 20
5. A library of miscellaneous helper functions ........................................................................ 21
5.1. Functions supplied ............................................................................................... 21
5.1.1. Text based conversation function ................................................................. 21
5.1.2. Transcribing an environment to that of PAM ................................................. 22
5.1.3. Liberating a locally saved environment ......................................................... 22
5.1.4. BSD like PAM environment variable setting .................................................. 23
6. Porting legacy applications .............................................................................................. 24
7. Glossary of PAM related terms ........................................................................................ 25
8. An example application .................................................................................................. 26
9. Files ............................................................................................................................ 28
10. See also ...................................................................................................................... 29
11. Author/acknowledgments ............................................................................................... 30
12. Copyright information for this document .......................................................................... 31

1
Chapter 1. Introduction
1.1. Description
Linux-PAM (Pluggable Authentication Modules for Linux) is a library that enables the local system ad-
ministrator to choose how individual applications authenticate users. For an overview of the Linux-PAM
library see the Linux-PAM System Administrators' Guide.
It is the purpose of the Linux-PAM 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 manage-
ment. This library dynamically loads locally configured authentication modules that actually perform the
authentication tasks.
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 docu-
mented 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
(authentication tokens).
1.2. Synopsis
For general applications that wish to use the services provided by Linux-PAM the following is a summary
of the relevant linking information:
#include <security/pam_appl.h>
cc -o application .... -lpam
In addition to libpam, there is a library of miscellaneous functions that make the job of writing PAM-
aware applications easier (this library is not covered in the DCE-RFC for PAM and is specific to the
Linux-PAM distribution):
#include <security/pam_appl.h>
#include <security/pam_misc.h>
cc -o application .... -lpam -lpam_misc

2
Chapter 2. Overview
Most service-giving applications are restricted. In other words, their service is not available to all and
every prospective client. Instead, the applying client must jump through a number of hoops to convince
the serving application that they are authorized to obtain service.
The process of authenticating a client is what PAM is designed to manage. In addition to authentication,
PAM provides account management, credential management, session management and authentication-to-
ken (password changing) management services. It is important to realize when writing a PAM based ap-
plication that these services are provided in a manner that is transparent to the application. That is to say,
when the application is written, no assumptions can be made about how the client will be authenticated.
The process of authentication is performed by the PAM library via a call to pam_authenticate().
The return value of this function will indicate whether a named client (the user) has been authenticated.
If the PAM library needs to prompt the user for any information, such as their name or a password then it
will do so. If the PAM library is configured to authenticate the user using some silent protocol, it will do
this too. (This latter case might be via some hardware interface for example.)
It is important to note that the application must leave all decisions about when to prompt the user at the
discretion of the PAM library.
The PAM library, however, must work equally well for different styles of application. Some applications,
like the familiar login and passwd are terminal based applications, exchanges of information with the client
in these cases is as plain text messages. Graphically based applications, however, have a more sophisticated
interface. They generally interact with the user via specially constructed dialogue boxes. Additionally,
network based services require that text messages exchanged with the client are specially formatted for
automated processing: one such example is ftpd which prefixes each exchanged message with a numeric
identifier.
The presentation of simple requests to a client is thus something very dependent on the protocol that the
serving application will use. In spite of the fact that PAM demands that it drives the whole authentication
process, it is not possible to leave such protocol subtleties up to the PAM library. To overcome this potential
problem, the application provides the PAM library with a conversation function. This function is called
from within the PAM library and enables the PAM to directly interact with the client. The sorts of things
that this conversation function must be able to do are prompt the user with text and/or obtain textual input
from the user for processing by the PAM library. The details of this function are provided in a later section.
For example, the conversation function may be called by the PAM library with a request to prompt the
user for a password. Its job is to reformat the prompt request into a form that the client will understand.
In the case of ftpd, this might involve prefixing the string with the number 331 and sending the request
over the network to a connected client. The conversation function will then obtain any reply and, after
extracting the typed password, will return this string of text to the PAM library. Similar concerns need to
be addressed in the case of an X-based graphical server.
There are a number of issues that need to be addressed when one is porting an existing application to
become PAM compliant. A section below has been devoted to this: Porting legacy applications.
Besides authentication, PAM provides other forms of management. Session management is provided with
calls to pam_open_session() and pam_close_session(). What these functions actually do is
up to the local administrator. But typically, they could be used to log entry and exit from the system or for
mounting and unmounting the user's home directory. If an application provides continuous service for a
period of time, it should probably call these functions, first open after the user is authenticated and then
close when the service is terminated.
剩余33页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0