Developing PAM modules?

Michael Chang miranda at uranus.com
Wed Jun 2 23:27:52 UTC 2004


On Wed, 2 Jun 2004, Jason Gerfen wrote:

|> I have been trying to get a working PAM module written.  It doesn't do 
|> anything real fancy just creates a file so I know that I am working with 
|> the functions correctly, as of yet I have not been able to get it to do 
|> anything.

I'm going to assume that you mean that you haven't been able to write
to /tmp/log.  What is fopen() returning?

See below...


|> [SNIP]
|> #include <stdio.h>

#include <errno.h>

|> 
|> #define PAM_SM_AUTH
|> #define PAM_SM_ACCOUNT
|> #define PAM_SM_SESSION
|> #define PAM_SM_PASSWORD
|> 
|> #include <pam_modules.h>
|> 
|> PAM_EXTERN
|> int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
|>                                                 const char **argv)
|> {
|>    const char *user;
|>    const char prompt;
|>    FILE *fp;
|>    int i;
|> 
|>    pam_get_user(pamh, &user, &prompt);
|> 

if ( (fp = fopen("/tmp/log", "a")) == NULL) {
	# appropriate syslog logging and error return here
}

|>    fprintf(fp, "\nSample code\n\n");
|>    for(i = 1; i <= 10; i++)
|>     fprintf(fp, "i = %d\n", i);

if (fp != NULL) {
    if (fclose(fp) == EOF) {
		# appropriate syslog logging and error return here
	}
}

|>    return PAM_IGNORE;
|> }


[snip...]


|> Am I missing something?  The PAM module writters guide is kinda vague on 
|> details, and I have only been able to google up a couple of tutorials on 
|> this subject so any help, pointers, howto's are definately appreciated.

It's true, there should be more information about valid return values, for
example.


HTH,
Michael


-- 
/* BEGIN SIG
 *
 * "Afraid of change, afraid of staying the same,
 *  when temptation calls, we just look away."
 *  - Barenaked Ladies
 *
 *-----------------------------
 * Michael Chang
 * miranda [at] uranus dot com
 * AIM: Solempathe
 * http://www.syndetic.org/
 */





More information about the Pam-list mailing list