21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Most modern Unix systems provide support for PAM and even use it for system-wide<br />

authentication (for example, for interactive user login for shell access). Many popular<br />

and widely deployed services that use authentication are also capable of using<br />

PAM.<br />

Every application that makes use of PAM uses a service name, such as “login” or<br />

“ftpd”. PAM uses the service name along with a configuration file (often /etc/pam.conf)<br />

or files (one for each service, named after the service, and usually located in /etc/pam.d).<br />

PAM uses configuration information gleaned from the appropriate configuration file to<br />

determine which modules to use, how to treat successes and failures, and other miscellaneous<br />

information.<br />

Modules are implemented as shared libraries that are dynamically loaded into your<br />

application as required. Each module is expected to export several standard functions<br />

in order to interact with the PAM infrastructure. Implementation of PAM modules<br />

is outside the scope of this book, but our web site contains more information on<br />

this topic.<br />

PAM and its modules handle the drudgery of obtaining passwords from users if<br />

required, exchanging keys, or doing whatever must be done to authenticate. All that<br />

you need to do in your code is make the proper sequence of calls with the necessary<br />

information to PAM, and the details of authentication are handled for you, allowing<br />

you to concentrate on the rest of your application.<br />

Unfortunately, the PAM API is somewhat clumsy, and the steps necessary for performing<br />

basic authentication with PAM are not necessarily as straightforward as they<br />

could be. The functions presented in this recipe, spc_pam_login( ) and spc_pam_<br />

logout( ), work together to perform the necessary steps properly.<br />

To use PAM in your own code, you will need to include the header files security/<br />

pam_appl.h and security/pam_misc.h in your program, and link against the PAM<br />

library, usually by specifying -lpam on the linker command line.<br />

To authenticate a user, call spc_pam_login( ), which has the following signature:<br />

pam_handle_t *spc_pam_login(const char *service, const char *user, int **rc);<br />

This function has the following arguments:<br />

service<br />

Name of the service to use. PAM uses the service name to find the appropriate<br />

module configuration information in its configuration file or files. You will typically<br />

want to use a service name that does not conflict with anything else, though<br />

if you are writing an FTP server, for example, you will want to use “ftpd” as the<br />

service.<br />

user<br />

Name of the user to authenticate.<br />

412 | Chapter 8: Authentication and Key Exchange<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!