Debian Codegraph @

listings/chapter-10/pam.c

raw
1 /***********************************************************************
2 * Code listing from "Advanced Linux Programming," by CodeSourcery LLC *
3 * Copyright (C) 2001 by New Riders Publishing *
4 * See COPYRIGHT for license information. *
5 ***********************************************************************/
6
7 #include <security/pam_appl.h>
8 #include <security/pam_misc.h>
9 #include <stdio.h>
10
11 int main ()
12 {
13 pam_handle_t* pamh;
14 struct pam_conv pamc;
15
16 /* Set up the PAM conversation. */
17 pamc.conv = &misc_conv;
18 pamc.appdata_ptr = NULL;
19 /* Start a new authentication session. */
20 pam_start ("su", getenv ("USER"), &pamc, &pamh);
21 /* Authenticate the user. */
22 if (pam_authenticate (pamh, 0) != PAM_SUCCESS)
23 fprintf (stderr, "Authentication failed!\n");
24 else
25 fprintf (stderr, "Authentication OK.\n");
26 /* All done. */
27 pam_end (pamh, 0);
28 return 0;
29 }