diff options
author | Andrew G. Morgan <morgan@kernel.org> | 2000-06-20 22:10:38 +0000 |
---|---|---|
committer | Andrew G. Morgan <morgan@kernel.org> | 2000-06-20 22:10:38 +0000 |
commit | ea488580c42e8918445a945484de3c8a5addc761 (patch) | |
tree | c992f3ba699caafedfadc16af38e6359c3c24698 /examples/test.c | |
download | pam-ea488580c42e8918445a945484de3c8a5addc761.tar.gz pam-ea488580c42e8918445a945484de3c8a5addc761.tar.bz2 pam-ea488580c42e8918445a945484de3c8a5addc761.zip |
Initial revision
Diffstat (limited to 'examples/test.c')
-rw-r--r-- | examples/test.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/examples/test.c b/examples/test.c new file mode 100644 index 00000000..8fc5e6cd --- /dev/null +++ b/examples/test.c @@ -0,0 +1,105 @@ +/* + * $Log$ + * Revision 1.1 2000/06/20 22:11:13 agmorgan + * Initial revision + * + * Revision 1.1.1.1 1998/07/12 05:17:14 morgan + * Linux PAM sources pre-0.66 + * + * Revision 1.3 1996/03/10 00:14:20 morgan + * made lines less than 80 chars long. + * + * Revision 1.2 1996/03/09 09:16:26 morgan + * changed the header file that it includes. + * + * Revision 1.1 1996/03/09 09:13:34 morgan + * Initial revision + */ + +/* Marc Ewing (marc@redhat.com) - original test code + * Alexander O. Yuriev (alex@bach.cis.temple.edu) + * Andrew Morgan (morgan@physics.ucla.edu) + */ + +#include <stdlib.h> +#include <stdio.h> +#include <pwd.h> + +#include <security/pam_appl.h> + +/* this program is not written to the PAM spec: it tests the + * pam_[sg]et_data() functions. Which is usually reserved for modules */ + +#include <security/pam_modules.h> +#include <security/pam_misc.h> + +#define USERNAMESIZE 1024 + +static int test_conv( int num_msg, + const struct pam_message **msgm, + struct pam_response **response, + void *appdata_ptr ) +{ + return 0; +} + +static struct pam_conv conv = { + test_conv, + NULL +}; + +static int cleanup_func(pam_handle_t *pamh, void *data, int error_status) +{ + printf("Cleaning up!\n"); + return PAM_SUCCESS; +} + +void main( void ) +{ + pam_handle_t *pamh; + char *name = ( char *) malloc( USERNAMESIZE + 1 ); + char *p = NULL; + char *s = NULL; + + if (! name ) + { + perror( "Ouch, don't have enough memory"); + exit( -1 ); + } + + + + + fprintf( stdout, "Enter a name of a user to authenticate : "); + name = fgets( name , USERNAMESIZE, stdin ); + if ( !name ) + { + perror ( "Hey, how can authenticate " + "someone whos name I don't know?" ); + exit ( -1 ); + } + + *( name + strlen ( name ) - 1 ) = 0; + + pam_start( "login", name, &conv, &pamh ); + + p = x_strdup( getpass ("Password: ") ); + if ( !p ) + { + perror ( "You love NULL pointers, " + "don't you? I don't "); + exit ( -1 ); + } + pam_set_item ( pamh, PAM_AUTHTOK, p ); + pam_get_item ( pamh, PAM_USER, (void**) &s); + pam_set_data(pamh, "DATA", "Hi there! I'm data!", cleanup_func); + pam_get_data(pamh, "DATA", (void **) &s); + printf("%s\n", s); + + fprintf( stdout, "*** Attempting to perform " + "PAM authentication...\n"); + fprintf( stdout, "%s\n", + pam_strerror( pam_authenticate( pamh, 0 ) ) ) ; + + pam_end(pamh, PAM_SUCCESS); +} |