| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#include <config.h> |
| 42 |
|
| 43 |
#include <stdio.h> |
| 44 |
#include <stdlib.h> |
| 45 |
#include <string.h> |
| 46 |
#include <security/pam_appl.h> |
| 47 |
#include "pam_inline.h" |
| 48 |
|
| 49 |
static unsigned int in_test; |
| 50 |
|
| 51 |
static const char *passwords[] = { |
| 52 |
"pamhistory01", "pamhistory02", "pamhistory03", |
| 53 |
"pamhistory04", "pamhistory05", "pamhistory06", |
| 54 |
"pamhistory07", "pamhistory08", "pamhistory09", |
| 55 |
"pamhistory10", |
| 56 |
"pamhistory01", "pamhistory02", "pamhistory03", |
| 57 |
"pamhistory04", "pamhistory05", "pamhistory06", |
| 58 |
"pamhistory07", "pamhistory08", "pamhistory09", |
| 59 |
"pamhistory10", |
| 60 |
"pamhistory11", |
| 61 |
"pamhistory01", "pamhistory02", "pamhistory03", |
| 62 |
"pamhistory04", "pamhistory05", "pamhistory06", |
| 63 |
"pamhistory07", "pamhistory08", "pamhistory09", |
| 64 |
"pamhistory10"}; |
| 65 |
|
| 66 |
static int debug; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
static int |
| 71 |
fake_conv (int num_msg, const struct pam_message **msgm, |
| 72 |
struct pam_response **response, void *appdata_ptr UNUSED) |
| 73 |
{ |
| 74 |
struct pam_response *reply; |
| 75 |
int count; |
| 76 |
|
| 77 |
|
| 78 |
if (num_msg <= 0) |
| 79 |
return PAM_CONV_ERR; |
| 80 |
|
| 81 |
if (debug) |
| 82 |
fprintf (stderr, "msg_style=%d, msg=%s\n", msgm[0]->msg_style, |
| 83 |
msgm[0]->msg); |
| 84 |
|
| 85 |
if (msgm[0]->msg_style != 1) |
| 86 |
return PAM_SUCCESS; |
| 87 |
|
| 88 |
|
| 89 |
reply = calloc (num_msg, sizeof (struct pam_response)); |
| 90 |
if (reply == NULL) |
| 91 |
return PAM_CONV_ERR; |
| 92 |
|
| 93 |
|
| 94 |
for (count = 0; count < num_msg; ++count) |
| 95 |
{ |
| 96 |
reply[count].resp_retcode = 0; |
| 97 |
reply[count].resp = strdup (passwords[in_test]); |
| 98 |
if (debug) |
| 99 |
fprintf (stderr, "send password %s\n", reply[count].resp); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
*response = reply; |
| 104 |
return PAM_SUCCESS; |
| 105 |
} |
| 106 |
|
| 107 |
static struct pam_conv conv = { |
| 108 |
fake_conv, |
| 109 |
NULL |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
int |
| 114 |
main(int argc, char *argv[]) |
| 115 |
{ |
| 116 |
pam_handle_t *pamh=NULL; |
| 117 |
const char *user="tstpampwhistory"; |
| 118 |
int retval; |
| 119 |
|
| 120 |
if (argc > 1 && strcmp (argv[1], "-d") == 0) |
| 121 |
debug = 1; |
| 122 |
|
| 123 |
for (in_test = 0; in_test < PAM_ARRAY_SIZE(passwords); in_test++) |
| 124 |
{ |
| 125 |
|
| 126 |
retval = pam_start("tst-pam_pwhistory1", user, &conv, &pamh); |
| 127 |
if (retval != PAM_SUCCESS) |
| 128 |
{ |
| 129 |
if (debug) |
| 130 |
fprintf (stderr, "pwhistory1-%u: pam_start returned %d\n", |
| 131 |
in_test, retval); |
| 132 |
return 1; |
| 133 |
} |
| 134 |
|
| 135 |
retval = pam_chauthtok (pamh, 0); |
| 136 |
if (in_test < 10 || in_test == 20) |
| 137 |
{ |
| 138 |
if (retval != PAM_SUCCESS) |
| 139 |
{ |
| 140 |
if (debug) |
| 141 |
fprintf (stderr, "pwhistory1-%u: pam_chauthtok returned %d\n", |
| 142 |
in_test, retval); |
| 143 |
return 1; |
| 144 |
} |
| 145 |
} |
| 146 |
else if (in_test < 20) |
| 147 |
{ |
| 148 |
if (retval != PAM_MAXTRIES) |
| 149 |
{ |
| 150 |
if (debug) |
| 151 |
fprintf (stderr, "pwhistory1-%u: pam_chauthtok returned %d\n", |
| 152 |
in_test, retval); |
| 153 |
return 1; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
retval = pam_end (pamh,retval); |
| 158 |
if (retval != PAM_SUCCESS) |
| 159 |
{ |
| 160 |
if (debug) |
| 161 |
fprintf (stderr, "pwhistory1: pam_end returned %d\n", retval); |
| 162 |
return 1; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
return 0; |
| 167 |
} |