LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to Linux Subscribe to Newsletters

Writing PAM Modules, Part One
Pages: 1, 2

Requirements

Function Independence

Most applications will call authentication first, then account, open the session, potentially change the authentication token with password, then close the session. This is not guaranteed, however. Modules must be able to be called independently, in any sequence.



The module must ensure that it behaves appropriately regardless of whether or not other sections have been run -- such as if password is called without authentication, or a session is opened without account management.

Module Completeness

It is perfectly acceptable to write a module which is only supposed to be called as one module type. However, for user friendliness, it can be a good idea to write functions that respond to requests for the other module types. These spurious functions should return either PAM_SERVICE_ERR or PAM_IGNORE.

Required Flags

The PAM_SILENT flag must be accepted by any module. It is passed in the flags parameter of all the functions. If the PAM_SILENT flag (which is logically ORed with any other flags) is on, the module must not pass any text errors or warnings to the application.

Argument Passing

PAM reads the configuration file for the application, parses the stack for the module type, parses the line for the specific module, and passes the appropriate arguments to the module. Each function has the parameters argc and argv, which are the count of the number of arguments and an array of pointers to the arguments, respectively.

These are similar to the parameters of the function main() in C, however, argv[0] is an argument and not the name of the module.

Generic Arguments

There are a number of arguments that all modules can expect they might be passed. A module should implement these modules (with one possible exception), but should not react to their absence.

debug
Send debug data to the system logs using syslog().

expose_account
If your module supports it, display appropriate information about user accounts, such as displaying the user's real name rather than the username in messages.

no_warn
Don't send warnings to the application.

try_first_pass
Retrieve a token from PAM_AUTHTOK and try it for this module. If it fails, ask the user for an authentication token.

use_first_pass
Retrieve a token from PAM_AUTHTOK and use it for this module. If it fails, the module fails.

use_mapped_pass
Applying this argument may cause you to break local laws regarding encryption. If so, Do not do it. No one wants anyone to get into legal trouble for writing code. If you can legally do so, the module should use the existing authentication token from the PAM_AUTHTOK item, and use it as a key to retrieve the authentication token for this module.

Learning the Korn Shell

Related Reading

Learning the Korn Shell
By Bill Rosenblatt, Arnold Robbins

Final Words

This is part one of a three-part series on writing PAM modules. Part two discusses managing a Linux-PAM environment, interacting with the user, and getting and setting module data. Part three discusses the functions a module is required to provide, security issues, and response codes.

Further Reading

  • Linux PAM documentation
  • Introduction to PAM
  • PAM Modules

Jennifer Vesperman is the author of Essential CVS. She writes for the O'Reilly Network, the Linux Documentation Project, and occasionally Linux.Com.


Return to the Linux DevCenter.




Tagged Articles

Post to del.icio.us

This article has been tagged:

pam

Articles that share the tag pam:

Writing PAM Modules, Part One (6 tags)

PAM (3 tags)

View All

programming

Articles that share the tag programming:

Rolling with Ruby on Rails (1374 tags)

Very Dynamic Web Interfaces (279 tags)

Ajax on Rails (231 tags)

Understanding MVC in PHP (202 tags)

A Simpler Ajax Path (186 tags)

View All

linux

Articles that share the tag linux:

Managing Disk Space with LVM (74 tags)

Use Your Digital Camera with Linux (60 tags)

mdadm: A New Tool For Linux Software RAID Management (59 tags)

Asterisk: A Bare-Bones VoIP Example (43 tags)

View All

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com