[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Newbie app-writing question



amount of examples and references I've found [1], I *think* I need to write a
new conversation function and pass that to pam_start(), but I haven't figured
out the propper syntax to do that [2].

Correct.. kind of.


int static_conv(int n, const struct pam_message **msg,
            struct pam_response **resp, void *data)

the void * here is for your "custom" data. I usually define a structure like:


// The structure used to pass a username and password to pam
typedef struct auth_struct
{
  // Username to authenticate
  const char *username;
  // Password to use
  const char *password;
} auth_struct;

Then setup a conversation structure for PAM:

static struct pam_conv myauthconv = {
auth_conv, // conversation function


    NULL
  };

And finally, fill in and provide the auth structure:

struct auth_struct buffer;
buffer.username = username;
buffer.password = password;
myauthconv.appdata_ptr = &buffer; // This is the meat of the idea here - we need to tell PAM to pass our structure as the 'user defined data' in the last argument of our conversation function


Now when your conv callback gets hit, pam will pass it the appdata_ptr as the last argument and you can cast it back to a structure and get whatever info you needed out of it.

Hope that helps!
Nate Yocom

Also - Note that I have written an entire section on writing PAM aware applications for use with network programming in my (co-authored) upcoming title: http://www.apress.com/book/bookDisplay.html?bID=309 - The Definitive Guide to Linux Network Programming - pre-order your copy today!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]