#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    118
    Rep Power
    13

    PAM aware application


    Anyone have examples of making an application "PAM aware"? I need to modify some login code to use the PAM modules on Solaris and hope there is a simple example out there. I don't need to write a module, as I will use the standard one(s).

    I found this simple code here...

    http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/pam_appl-8.html

    but it is for Linux and doesn't pass a password.

    THanks for any help, I'm a Java programmer and have some difficulty with C. :confused:
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,547
    Rep Power
    2337
    Hi,

    This site might be helpful, but you may have already known that. I also remember printing out a few of the man pages.

    Here's some old test source code from when I was messing around with it a few years ago (on Solaris). It just takes the user name and password as command line parameters and authenticates via PAM.

    Hope this helps.

    Code:
    #include <security/pam_appl.h>
    #include <ostream>
    
    int main (int argc, char *argv[])
    {
        pam_handle_t *pamHandle = NULL;
    
        if (argc < 3)
            return -1;
     
        int pamResult = pam_start (argv[0], NULL, NULL, &pamHandle);
        if (pamResult != PAM_SUCCESS)
        {
            std::cerr << "pam_start error: " 
                      << pam_strerror (NULL, pamResult) << std::endl;
            return -1;
        }
        
        pam_set_item (pamHandle, PAM_USER, argv[1]);
        pam_set_item (pamHandle, PAM_AUTHTOK, argv[2]);
        pamResult = pam_authenticate (pamHandle, 0);
        std::cerr << "Authentication result: " 
                  << pam_strerror (pamHandle, pamResult) << std::endl;
        pam_end (pamHandle, pamResult);
    
        return 0;
    }
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    118
    Rep Power
    13

    Thanks!


    THanks, this is what I was looking for. :)

IMN logo majestic logo threadwatch logo seochat tools logo