[Pkg-shadow-commits] r2528 - in upstream/trunk: . src

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Sun Mar 15 21:34:21 UTC 2009


Author: nekral-guest
Date: 2009-03-15 21:34:20 +0000 (Sun, 15 Mar 2009)
New Revision: 2528

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/usermod.c
Log:
	* src/usermod.c: get_number() replaced by getlong().
	* src/usermod.c: When the user is renamed, make sure we do not
	override an user with the same name (in passwd or shadow).


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-03-15 21:32:26 UTC (rev 2527)
+++ upstream/trunk/ChangeLog	2009-03-15 21:34:20 UTC (rev 2528)
@@ -1,5 +1,11 @@
 2009-03-15  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/usermod.c: get_number() replaced by getlong().
+	* src/usermod.c: When the user is renamed, make sure we do not
+	override an user with the same name (in passwd or shadow).
+
+2009-03-15  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/gpasswd.c: log_gpasswd_success_gshadow is in the cleanup
 	stack only when the shadow group file is present.
 

Modified: upstream/trunk/src/usermod.c
===================================================================
--- upstream/trunk/src/usermod.c	2009-03-15 21:32:26 UTC (rev 2527)
+++ upstream/trunk/src/usermod.c	2009-03-15 21:34:20 UTC (rev 2528)
@@ -153,7 +153,6 @@
 #endif
 static void grp_update (void);
 
-static long get_number (const char *);
 static void process_flags (int, char **);
 static void close_files (void);
 static void open_files (void);
@@ -400,6 +399,12 @@
 static void new_pwent (struct passwd *pwent)
 {
 	if (lflg) {
+		if (pw_locate (user_newname) != NULL) {
+			fprintf (stderr,
+			         _("%s: user '%s' already exists in %s\n"),
+			         Prog, user_newname, pw_dbname ());
+			fail_exit (E_NAME_IN_USE);
+		}
 #ifdef WITH_AUDIT
 		audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
 		              "changing name",
@@ -410,8 +415,7 @@
 		pwent->pw_name = xstrdup (user_newname);
 	}
 	if (!is_shadow_pwd) {
-		pwent->pw_passwd =
-		    new_pw_passwd (pwent->pw_passwd);
+		pwent->pw_passwd = new_pw_passwd (pwent->pw_passwd);
 	}
 
 	if (uflg) {
@@ -477,6 +481,12 @@
 static void new_spent (struct spwd *spent)
 {
 	if (lflg) {
+		if (spw_locate (user_newname) != NULL) {
+			fprintf (stderr,
+			         _("%s: user '%s' already exists in %s\n"),
+			         Prog, user_newname, spw_dbname ());
+			fail_exit (E_NAME_IN_USE);
+		}
 		spent->sp_namp = xstrdup (user_newname);
 	}
 
@@ -784,20 +794,6 @@
 #endif
 }
 
-static long get_number (const char *numstr)
-{
-	long val;
-	char *endptr;
-
-	val = strtol (numstr, &endptr, 10);
-	if (('\0' != *endptr) || (ERANGE == errno)) {
-		fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
-			 numstr);
-		exit (E_BAD_ARG);
-	}
-	return val;
-}
-
 /*
  * process_flags - perform command line argument setting
  *
@@ -938,7 +934,12 @@
 				eflg = true;
 				break;
 			case 'f':
-				user_newinactive = get_number (optarg);
+				if (getlong (optarg, &user_newinactive) == 0) {
+					fprintf (stderr,
+					         _("%s: invalid numeric argument '%s'\n"),
+					         Prog, optarg);
+					usage ();
+				}
 				fflg = true;
 				break;
 			case 'g':




More information about the Pkg-shadow-commits mailing list