Allow the user to change from an empty password

Default to SHA-512.
This commit is contained in:
sin 2014-06-05 17:12:21 +01:00
parent abbb8fffc7
commit f628b72747

View File

@ -21,7 +21,8 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *pass, *cryptpass1, *cryptpass2, *cryptpass3; char *pass;
char *cryptpass1 = NULL, *cryptpass2 = NULL, *cryptpass3 = NULL;
char *p; char *p;
char template[] = "/tmp/pw.XXXXXX"; char template[] = "/tmp/pw.XXXXXX";
struct passwd *pw; struct passwd *pw;
@ -49,8 +50,11 @@ main(int argc, char *argv[])
eprintf("denied\n"); eprintf("denied\n");
} }
if (pw->pw_passwd[0] == '\0') if (pw->pw_passwd[0] == '\0') {
/* Default to SHA-512 for empty passwords */
pw->pw_passwd = "$6$";
goto newpass; goto newpass;
}
if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '\0') if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '\0')
eprintf("no shadow support\n"); eprintf("no shadow support\n");
@ -62,6 +66,8 @@ main(int argc, char *argv[])
putchar('\n'); putchar('\n');
if (!pass) if (!pass)
eprintf("getpass:"); eprintf("getpass:");
if (pass[0] == '\0')
eprintf("no password supplied\n");
p = crypt(pass, pw->pw_passwd); p = crypt(pass, pw->pw_passwd);
if (!p) if (!p)
eprintf("crypt:"); eprintf("crypt:");
@ -77,11 +83,13 @@ newpass:
putchar('\n'); putchar('\n');
if (!pass) if (!pass)
eprintf("getpass:"); eprintf("getpass:");
if (pass[0] == '\0')
eprintf("no password supplied\n");
p = crypt(pass, pw->pw_passwd); p = crypt(pass, pw->pw_passwd);
if (!p) if (!p)
eprintf("crypt:"); eprintf("crypt:");
cryptpass2 = estrdup(p); cryptpass2 = estrdup(p);
if (strcmp(cryptpass1, cryptpass2) == 0) if (cryptpass1 && strcmp(cryptpass1, cryptpass2) == 0)
eprintf("password left unchanged\n"); eprintf("password left unchanged\n");
/* Flush pending input */ /* Flush pending input */
@ -91,6 +99,8 @@ newpass:
putchar('\n'); putchar('\n');
if (!pass) if (!pass)
eprintf("getpass:"); eprintf("getpass:");
if (pass[0] == '\0')
eprintf("no password supplied\n");
p = crypt(pass, pw->pw_passwd); p = crypt(pass, pw->pw_passwd);
if (!p) if (!p)
eprintf("crypt:"); eprintf("crypt:");