123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <security/pam_appl.h>
- static int in_test;
- static int
- fake_conv (int num_msg, const struct pam_message **msgm UNUSED,
- struct pam_response **response, void *appdata_ptr UNUSED)
- {
- struct pam_response *reply;
- int count;
-
- if (num_msg <= 0)
- return PAM_CONV_ERR;
-
- reply = calloc (num_msg, sizeof (struct pam_response));
- if (reply == NULL)
- return PAM_CONV_ERR;
-
- for (count = 0; count < num_msg; ++count)
- {
- reply[count].resp_retcode = 0;
-
- if (in_test == 1)
- reply[count].resp = strdup ("pamunix01");
- else if (in_test == 2)
- reply[count].resp = strdup ("pamunix0");
- else
- reply[count].resp = strdup ("pamunix11");
- }
-
- *response = reply;
- return PAM_SUCCESS;
- }
- static struct pam_conv conv = {
- fake_conv,
- NULL
- };
- int
- main(int argc, char *argv[])
- {
- pam_handle_t *pamh=NULL;
- const char *user="tstpamunix";
- int retval;
- int debug = 0;
- if (argc > 1 && strcmp (argv[1], "-d") == 0)
- debug = 1;
- retval = pam_start("tst-pam_unix3", user, &conv, &pamh);
- if (retval != PAM_SUCCESS)
- {
- if (debug)
- fprintf (stderr, "unix3: pam_start returned %d\n", retval);
- return 1;
- }
-
- in_test = 1;
- retval = pam_authenticate (pamh, 0);
- if (retval != PAM_SUCCESS)
- {
- if (debug)
- fprintf (stderr, "unix3-1: pam_authenticate returned %d\n", retval);
- return 1;
- }
-
- in_test = 2;
- retval = pam_authenticate (pamh, 0);
- if (retval != PAM_AUTH_ERR)
- {
- if (debug)
- fprintf (stderr, "unix3-2: pam_authenticate returned %d\n", retval);
- return 1;
- }
-
- in_test = 3;
- retval = pam_authenticate (pamh, 0);
- if (retval != PAM_AUTH_ERR)
- {
- if (debug)
- fprintf (stderr, "unix3-3: pam_authenticate returned %d\n", retval);
- return 1;
- }
- retval = pam_end (pamh,retval);
- if (retval != PAM_SUCCESS)
- {
- if (debug)
- fprintf (stderr, "unix3: pam_end returned %d\n", retval);
- return 1;
- }
- return 0;
- }
|