svn commit: trunk/busybox/loginutils

vda at busybox.net vda at busybox.net
Sat Jul 21 13:54:28 UTC 2007


Author: vda
Date: 2007-07-21 06:54:26 -0700 (Sat, 21 Jul 2007)
New Revision: 19188

Log:
chpasswd: fixes for shadow password handling



Modified:
   trunk/busybox/loginutils/chpasswd.c


Changeset:
Modified: trunk/busybox/loginutils/chpasswd.c
===================================================================
--- trunk/busybox/loginutils/chpasswd.c	2007-07-21 13:27:44 UTC (rev 19187)
+++ trunk/busybox/loginutils/chpasswd.c	2007-07-21 13:54:26 UTC (rev 19188)
@@ -26,13 +26,13 @@
 {
 	char *name, *pass;
 	char salt[sizeof("$N$XXXXXXXX")];
-	int opt;
+	int opt, rc;
 	int rnd = rnd; /* we *want* it to be non-initialized! */
 
 	if (getuid())
 		bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
 
- 	opt_complementary = "?m--e:e--m";
+ 	opt_complementary = "m--e:e--m";
 	USE_GETOPT_LONG(applet_long_options = chpasswd_opts;)
 	opt = getopt32(argc, argv, "em");
 
@@ -53,17 +53,19 @@
 			pass = pw_encrypt(pass, salt);
 		}
 
-		/* LOGMODE_BOTH logs to syslog */
+		/* This is rather complex: if user is not found in /etc/shadow,
+		 * we try to find & change his passwd in /etc/passwd */
+#if ENABLE_FEATURE_SHADOWPASSWDS
+			rc = update_passwd(bb_path_shadow_file, name, pass);
+		if (rc == 0) /* no lines updated, no errors detected */
+#endif
+			rc = update_passwd(bb_path_passwd_file, name, pass);
+		/* LOGMODE_BOTH logs to syslog also */
 		logmode = LOGMODE_BOTH;
-
-		if ((ENABLE_FEATURE_SHADOWPASSWDS 
-			&& !update_passwd(bb_path_shadow_file, name, pass))
-			|| !update_passwd(bb_path_passwd_file, name, pass)
-		) {
+		if (rc < 0)
 			bb_error_msg_and_die("an error occurred updating password for %s", name);
-		} else {
+		if (rc)
 			bb_info_msg("Password for '%s' changed", name);
-		}
 		logmode = LOGMODE_STDIO;
 		free(name);
 	}




More information about the busybox-cvs mailing list