Skip to content

Commit a49d2ac

Browse files
alejandro-colomarikerexxe
authored andcommitted
src/usermod.c: -U: Report E_PASSWORDLESS on error due to passwordless account
Reproducer: $ useradd foo $ grep foo /etc/passwd /etc/shadow /etc/passwd:foo:x:1001:1001::/home/foo:/usr/bin/bash /etc/shadow:foo:!:20458:0:99999:7::: $ usermod -U testuser usermod: unlocking the user's password would result in a passwordless account. You should set a password with usermod -p to unlock this user's password. $ echo $? 0 $ grep foo /etc/passwd /etc/shadow /etc/passwd:foo:x:1001:1001::/home/foo:/usr/bin/bash /etc/shadow:foo:!:20458:0:99999:7::: The program failed (didn't change anything, and reported the problem to stderr) but reported success (0). After this patch, the error is reported as E_PASSWORDLESS (20). Closes: <#1479> Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org> Acked-by: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
1 parent b43089b commit a49d2ac

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/usermod.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#endif /* ACCT_TOOLS_SETUID */
2929
#include <paths.h>
3030
#include <stdio.h>
31+
#include <stdlib.h>
3132
#include <string.h>
3233
#include <strings.h>
3334
#include <sys/stat.h>
@@ -97,6 +98,7 @@
9798
#define E_SUB_UID_UPDATE 16 /* can't update the subordinate uid file */
9899
#define E_SUB_GID_UPDATE 18 /* can't update the subordinate gid file */
99100
#endif /* ENABLE_SUBIDS */
101+
#define E_PASSWORDLESS 20 /* would result in a passwordless account */
100102

101103
#define VALID(s) (!strpbrk(s, ":\n"))
102104

@@ -437,7 +439,8 @@ usage (int status)
437439
* update encrypted password string (for both shadow and non-shadow
438440
* passwords)
439441
*/
440-
static char *new_pw_passwd (char *pw_pass)
442+
static char *
443+
new_pw_passwd(char *pw_pass, bool process_selinux)
441444
{
442445
if (Lflg && ('!' != pw_pass[0])) {
443446
#ifdef WITH_AUDIT
@@ -452,7 +455,7 @@ static char *new_pw_passwd (char *pw_pass)
452455
_("%s: unlocking the user's password would result in a passwordless account.\n"
453456
"You should set a password with usermod -p to unlock this user's password.\n"),
454457
Prog);
455-
return pw_pass;
458+
fail_exit(E_PASSWORDLESS, process_selinux);
456459
}
457460

458461
#ifdef WITH_AUDIT
@@ -507,7 +510,7 @@ static void new_pwent (struct passwd *pwent, bool process_selinux)
507510
*/
508511
if ( (!is_shadow_pwd)
509512
|| !streq(pwent->pw_passwd, SHADOW_PASSWD_STRING)) {
510-
pwent->pw_passwd = new_pw_passwd (pwent->pw_passwd);
513+
pwent->pw_passwd = new_pw_passwd(pwent->pw_passwd, process_selinux);
511514
}
512515

513516
if (uflg) {
@@ -622,7 +625,7 @@ static void new_spent (struct spwd *spent, bool process_selinux)
622625
* + there were already both entries
623626
* + aging has been requested
624627
*/
625-
spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp);
628+
spent->sp_pwdp = new_pw_passwd(spent->sp_pwdp, process_selinux);
626629

627630
if (pflg) {
628631
spent->sp_lstchg = gettime () / DAY;

0 commit comments

Comments
 (0)