2 * Marc Ewing (marc@redhat.com) - original test code
3 * Alexander O. Yuriev (alex@bach.cis.temple.edu)
4 * Andrew Morgan (morgan@physics.ucla.edu)
11 #include <security/pam_appl.h>
13 /* this program is not written to the PAM spec: it tests the
14 * pam_[sg]et_data() functions. Which is usually reserved for modules */
16 #include <security/pam_modules.h>
17 #include <security/pam_misc.h>
19 #define USERNAMESIZE 1024
21 static int test_conv( int num_msg,
22 const struct pam_message **msgm,
23 struct pam_response **response,
29 static struct pam_conv conv = {
34 static int cleanup_func(pam_handle_t *pamh, void *data, int error_status)
36 printf("Cleaning up!\n");
43 char *name = ( char *) malloc( USERNAMESIZE + 1 );
49 perror( "Ouch, don't have enough memory");
56 fprintf( stdout, "Enter a name of a user to authenticate : ");
57 name = fgets( name , USERNAMESIZE, stdin );
60 perror ( "Hey, how can authenticate "
61 "someone whos name I don't know?" );
65 *( name + strlen ( name ) - 1 ) = 0;
67 pam_start( "login", name, &conv, &pamh );
69 p = x_strdup( getpass ("Password: ") );
72 perror ( "You love NULL pointers, "
73 "don't you? I don't ");
76 pam_set_item ( pamh, PAM_AUTHTOK, p );
77 pam_get_item ( pamh, PAM_USER, (void**) &s);
78 pam_set_data(pamh, "DATA", "Hi there! I'm data!", cleanup_func);
79 pam_get_data(pamh, "DATA", (void **) &s);
82 fprintf( stdout, "*** Attempting to perform "
83 "PAM authentication...\n");
84 fprintf( stdout, "%s\n",
85 pam_strerror( pam_authenticate( pamh, 0 ) ) ) ;
87 pam_end(pamh, PAM_SUCCESS);