|
|
#include <sys/types.h> #include <prot.h>int smp_generate_pw(cleartext, hyphenp, usrp, reasonp) char *cleartext; char **hyphenp; struct smp_user_info *usrp; char **reasonp;
The password is generated by first calculating minimum and maximum password lengths. Then get_seed(S-osr5) is called to get a seed value and finally randomword(S-osr5) is called to generate the password.
smp_generate_pw copies the generated password to a pre-defined array, pointed to by cleartext. A hyphenated version is stored in the pre-defined array pointed to by *hyphenp. usrp points to a smp_user_info structure which has been created by the previous call to smp_check_user.
reasonp is used with certain return values to store a descriptive message.
...
put("login: ");
switch (smp_check_user(SMP_LOGIN, gets(line), ttyname(0), 0, &usrp,
&pwtries, &reason)) {
...
case SMP_PWREQ:
put("\nmust set password now\n");
if ((pwtype=smp_pw_choice(usrp, &reason)) == SMP_CHOOSE) {
put("generate a password? ");
if (tolower(*gets(line))=='y')
pwtype = SMP_GENERATE;
else
pwtype = SMP_PICK;
} else if (pwtype == SMP_EXTFAIL) {
put(reason);
put("\n");
exit(1);
}
noecho();
for (;;) {
if (pwtries < 1) {
put("too many tries\n");
echo();
smp_audit_fail(usrp);
exit(1);
}
noecho();
switch (pwtype) {
case SMP_PICK:
...
break;
case SMP_GENERATE:
put("generating a password");
for (;;) {
char *hyphen;
if (smp_generate_pw(newpw, &hyphen, usrp, &reason)
== SMP_EXTFAIL) {
echo();
put(reason);
put("\n");
exit(1);
}
put("\npassword: "); put(newpw);
put(" hyphenated: "); put(hyphen);
put(" enter password:");
if (strcmp(newpw, gets(line)) == 0)
break; /* user takes this one */
if (strcmp(line, "quit") == 0) {
put("\n");
echo();
smp_audit_fail(usrp);
exit(1);
}
if (*line == '\0')
continue; /* just return gets another one */
put("\nno match"); /* and go around again */
}
put("\n");
break;
}
put("re-enter password: ");
switch (smp_set_pw(gets(line), newpw, usrp, &pwtries, &reason)) {
...
}
break;
}
...
}