mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
sulogin: handle no password and locked account (treated as no pwd)
This patch does two things:
1. A system with a root account that has no password is now
allowed to login without password, as one expects.
2. A systems with a locked root account, is treated as (1).
The latter of the two may very well turn out to be a really bad idea.
Much angst have been poured into it, yet the end decision is to allow
access.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
266e5b30eb
commit
be2ac1d1b1
1 file changed
+18
-5
+18
-5
@@ -56,7 +56,8 @@ static int get_passwd(struct passwd *pw)
|
|||||||
if (!ptr)
|
if (!ptr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (strlen(ptr) > 1)
|
/* x : password in /etc/shadow, see passwd(5) */
|
||||||
|
if (ptr[0] != 'x')
|
||||||
pw->pw_passwd = strdup(ptr);
|
pw->pw_passwd = strdup(ptr);
|
||||||
|
|
||||||
break; /* done, check it */
|
break; /* done, check it */
|
||||||
@@ -131,9 +132,20 @@ int main(void)
|
|||||||
if (get_passwd(&pw))
|
if (get_passwd(&pw))
|
||||||
err(1, "reading credentials for UID 0");
|
err(1, "reading credentials for UID 0");
|
||||||
|
|
||||||
/* is login disabled, not much we can do */
|
switch (pw.pw_passwd[0]) {
|
||||||
if (strlen(pw.pw_passwd) == 1)
|
case '*': case '!': /* login disabled, allow */
|
||||||
goto done; /* likely one of: "x!*" */
|
printf("The %s account is locked, allowing entry.\n", pw.pw_name);
|
||||||
|
/* fallthrough */
|
||||||
|
case 0: /* no password at all? */
|
||||||
|
printf("Press enter for maintenance.");
|
||||||
|
getchar();
|
||||||
|
goto nopass;
|
||||||
|
|
||||||
|
case '$': /* md5/shaN or similar, original DES not supported */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (tcgetattr(1, &old) < 0)
|
if (tcgetattr(1, &old) < 0)
|
||||||
goto done; /* failed reading tty */
|
goto done; /* failed reading tty */
|
||||||
@@ -153,7 +165,7 @@ int main(void)
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char *passwd;
|
char *passwd;
|
||||||
|
|
||||||
printf("Give %s password for maintenance: ", pw.pw_name);
|
printf("Give %s password for maintenance (Ctrl-D to continue): ", pw.pw_name);
|
||||||
do {
|
do {
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
@@ -171,6 +183,7 @@ int main(void)
|
|||||||
passwd = crypt(pwd, pw.pw_passwd);
|
passwd = crypt(pwd, pw.pw_passwd);
|
||||||
if (passwd && !strcmp(passwd, pw.pw_passwd)) {
|
if (passwd && !strcmp(passwd, pw.pw_passwd)) {
|
||||||
tcsetattr(1, TCSANOW, &old); /* restore tty */
|
tcsetattr(1, TCSANOW, &old); /* restore tty */
|
||||||
|
nopass:
|
||||||
freepw(&pw);
|
freepw(&pw);
|
||||||
|
|
||||||
return sh();
|
return sh();
|
||||||
|
|||||||
Reference in new issue
Block a user