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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Sun May 25 20:58:19 UTC 2008


Author: nekral-guest
Date: 2008-05-25 20:58:16 +0000 (Sun, 25 May 2008)
New Revision: 2019

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/libmisc/chkname.c
   upstream/trunk/libmisc/chkname.h
   upstream/trunk/src/groupadd.c
   upstream/trunk/src/groupmod.c
   upstream/trunk/src/grpck.c
   upstream/trunk/src/newusers.c
   upstream/trunk/src/pwck.c
   upstream/trunk/src/useradd.c
   upstream/trunk/src/usermod.c
Log:
	* libmisc/chkname.h, libmisc/chkname.c: check_group_name (resp.
	check_user_name) renamed to is_valid_user_name (resp.
	is_valid_group_name). is_valid_user_name and is_valid_group_name
	return a bool.
	* src/grpck.c, src/newusers.c, src/usermod.c, src/useradd.c,
	src/groupmod.c, src/pwck.c, src/groupadd.c: Use is_valid_user_name
	and is_valid_group_name, following above change.
	* libmisc/chkname.c: Avoid implicit conversion of chars to
	booleans. Add brackets and parenthesis.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/ChangeLog	2008-05-25 20:58:16 UTC (rev 2019)
@@ -1,5 +1,17 @@
 2008-05-25  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* libmisc/chkname.h, libmisc/chkname.c: check_group_name (resp.
+	check_user_name) renamed to is_valid_user_name (resp.
+	is_valid_group_name). is_valid_user_name and is_valid_group_name
+	return a bool.
+	* src/grpck.c, src/newusers.c, src/usermod.c, src/useradd.c,
+	src/groupmod.c, src/pwck.c, src/groupadd.c: Use is_valid_user_name
+	and is_valid_group_name, following above change.
+	* libmisc/chkname.c: Avoid implicit conversion of chars to
+	booleans. Add brackets and parenthesis.
+
+2008-05-25  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* libmisc/xmalloc.c: Avoid implicit conversion of integers /
 	pointers to booleans.
 	* libmisc/xgetXXbyYY.c: Likewise.

Modified: upstream/trunk/libmisc/chkname.c
===================================================================
--- upstream/trunk/libmisc/chkname.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/libmisc/chkname.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -31,8 +31,11 @@
  */
 
 /*
- * check_user_name(), check_group_name() - check the new user/group
- * name for validity; return value: 1 - OK, 0 - bad name
+ * is_valid_user_name(), is_valid_group_name() - check the new user/group
+ * name for validity;
+ * return values:
+ *   true  - OK
+ *   false - bad name
  */
 
 #include <config.h>
@@ -47,26 +50,32 @@
 #else
 #include <utmp.h>
 #endif
-static int good_name (const char *name)
+
+static bool is_valid_name (const char *name)
 {
 	/*
 	 * User/group names must match [a-z_][a-z0-9_-]*[$]
 	 */
-	if (!*name || !((*name >= 'a' && *name <= 'z') || *name == '_'))
-		return 0;
+	if (('\0' == *name) ||
+	    !((('a' <= *name) && ('z' >= *name)) || ('_' == *name))) {
+		return false;
+	}
 
-	while (*++name) {
-		if (!((*name >= 'a' && *name <= 'z') ||
-		      (*name >= '0' && *name <= '9') ||
-		      *name == '_' || *name == '-' ||
-		      (*name == '$' && *(name + 1) == '\0')))
-			return 0;
+	while ('\0' != *++name) {
+		if (!(( ('a' <= *name) && ('z' >= *name) ) ||
+		      ( ('0' <= *name) && ('9' >= *name) ) ||
+		      ('_' == *name) ||
+		      ('-' == *name) ||
+		      ( ('$' == *name) && ('\0' == *(name + 1)) )
+		     )) {
+			return false;
+		}
 	}
 
-	return 1;
+	return true;
 }
 
-int check_user_name (const char *name)
+bool is_valid_user_name (const char *name)
 {
 #if HAVE_UTMPX_H
 	struct utmpx ut;
@@ -78,21 +87,23 @@
 	 * User names are limited by whatever utmp can
 	 * handle (usually max 8 characters).
 	 */
-	if (strlen (name) > sizeof (ut.ut_user))
-		return 0;
+	if (strlen (name) > sizeof (ut.ut_user)) {
+		return false;
+	}
 
-	return good_name (name);
+	return is_valid_name (name);
 }
 
-int check_group_name (const char *name)
+bool is_valid_group_name (const char *name)
 {
 	/*
 	 * Arbitrary limit for group names - max 16
 	 * characters (same as on HP-UX 10).
 	 */
-	if (strlen (name) > 16)
-		return 0;
+	if (strlen (name) > 16) {
+		return false;
+	}
 
-	return good_name (name);
+	return is_valid_name (name);
 }
 

Modified: upstream/trunk/libmisc/chkname.h
===================================================================
--- upstream/trunk/libmisc/chkname.h	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/libmisc/chkname.h	2008-05-25 20:58:16 UTC (rev 2019)
@@ -34,13 +34,16 @@
 #define _CHKNAME_H_
 
 /*
- * check_user_name(), check_group_name() - check the new user/group
- * name for validity; return value: 1 - OK, 0 - bad name
+ * is_valid_user_name(), is_valid_group_name() - check the new user/group
+ * name for validity;
+ * return values:
+ *   true  - OK
+ *   false - bad name
  */
 
 #include "defines.h"
 
-extern int check_user_name (const char *);
-extern int check_group_name (const char *name);
+extern bool is_valid_user_name (const char *name);
+extern bool is_valid_group_name (const char *name);
 
 #endif

Modified: upstream/trunk/src/groupadd.c
===================================================================
--- upstream/trunk/src/groupadd.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/src/groupadd.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -220,7 +220,7 @@
  */
 static void check_new_name (void)
 {
-	if (check_group_name (group_name)) {
+	if (is_valid_group_name (group_name)) {
 		return;
 	}
 

Modified: upstream/trunk/src/groupmod.c
===================================================================
--- upstream/trunk/src/groupmod.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/src/groupmod.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -328,7 +328,7 @@
 		return;
 	}
 
-	if (check_group_name (group_newname)) {
+	if (is_valid_group_name (group_newname)) {
 
 		/*
 		 * If the entry is found, too bad.

Modified: upstream/trunk/src/grpck.c
===================================================================
--- upstream/trunk/src/grpck.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/src/grpck.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -497,7 +497,7 @@
 		/*
 		 * Check for invalid group names.  --marekm
 		 */
-		if (!check_group_name (grp->gr_name)) {
+		if (!is_valid_group_name (grp->gr_name)) {
 			*errors += 1;
 			printf (_("invalid group name '%s'\n"), grp->gr_name);
 		}

Modified: upstream/trunk/src/newusers.c
===================================================================
--- upstream/trunk/src/newusers.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/src/newusers.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -214,7 +214,7 @@
 	}
 
 	/* Check if this is a valid group name */
-	if (check_group_name (grent.gr_name) == 0) {
+	if (!is_valid_group_name (grent.gr_name)) {
 		fprintf (stderr,
 		         _("%s: invalid group name `%s'\n"),
 		         Prog, grent.gr_name);
@@ -318,7 +318,7 @@
 	struct passwd pwent;
 
 	/* Check if this is a valid user name */
-	if (check_user_name (name) == 0) {
+	if (!is_valid_user_name (name)) {
 		fprintf (stderr,
 		         _("%s: invalid user name `%s'\n"),
 		         Prog, name);

Modified: upstream/trunk/src/pwck.c
===================================================================
--- upstream/trunk/src/pwck.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/src/pwck.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -354,7 +354,7 @@
 		/*
 		 * Check for invalid usernames.  --marekm
 		 */
-		if (!check_user_name (pwd->pw_name)) {
+		if (!is_valid_user_name (pwd->pw_name)) {
 			printf (_("invalid user name '%s'\n"), pwd->pw_name);
 			*errors += 1;
 		}

Modified: upstream/trunk/src/useradd.c
===================================================================
--- upstream/trunk/src/useradd.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/src/useradd.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -1123,7 +1123,7 @@
 			usage ();
 
 		user_name = argv[optind];
-		if (!check_user_name (user_name)) {
+		if (!is_valid_user_name (user_name)) {
 			fprintf (stderr,
 				 _
 				 ("%s: invalid user name '%s'\n"),

Modified: upstream/trunk/src/usermod.c
===================================================================
--- upstream/trunk/src/usermod.c	2008-05-25 20:41:13 UTC (rev 2018)
+++ upstream/trunk/src/usermod.c	2008-05-25 20:58:16 UTC (rev 2019)
@@ -917,7 +917,7 @@
 				Gflg++;
 				break;
 			case 'l':
-				if (!check_user_name (optarg)) {
+				if (!is_valid_user_name (optarg)) {
 					fprintf (stderr,
 						 _("%s: invalid field '%s'\n"),
 						 Prog, optarg);




More information about the Pkg-shadow-commits mailing list