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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Sat Dec 29 14:48:33 UTC 2007


Author: nekral-guest
Date: 2007-12-29 14:48:33 +0000 (Sat, 29 Dec 2007)
New Revision: 1557

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/newusers.c
Log:
Avoid assignments in comparisons.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2007-12-29 14:34:39 UTC (rev 1556)
+++ upstream/trunk/ChangeLog	2007-12-29 14:48:33 UTC (rev 1557)
@@ -6,6 +6,7 @@
 	* src/newusers.c: Before pam_end(), the return value of the previous
 	pam API was already checked. No need to validate it again.
 	* src/newusers.c: Avoid implicit brackets.
+	* src/newusers.c: Avoid assignments in comparisons.
 
 2007-12-29  Nicolas François  <nicolas.francois at centraliens.net>
 

Modified: upstream/trunk/src/newusers.c
===================================================================
--- upstream/trunk/src/newusers.c	2007-12-29 14:34:39 UTC (rev 1556)
+++ upstream/trunk/src/newusers.c	2007-12-29 14:48:33 UTC (rev 1557)
@@ -115,7 +115,8 @@
 	 * Start by seeing if the named group already exists. This will be
 	 * very easy to deal with if it does.
 	 */
-	if ((grp = gr_locate (gid))) {
+	grp = gr_locate (gid);
+	if (NULL != grp) {
 	      add_member:
 		grent = *grp;
 		*ngid = grent.gr_gid;
@@ -209,7 +210,7 @@
  */
 static int add_user (const char *name, const char *uid, uid_t * nuid, gid_t gid)
 {
-	const struct passwd *pwd;
+	const struct passwd *pwd = NULL;
 	struct passwd pwent;
 	uid_t i;
 
@@ -219,15 +220,21 @@
 	 */
 	if ((uid[0] >= '0') && (uid[0] <= '9')) {
 		i = atoi (uid);
-	} else if (('\0' != uid[0]) && (pwd = pw_locate (uid))) {
-		i = pwd->pw_uid;
 	} else {
-		/* Start with gid, either the specified GID, or an ID
-		 * greater than all the group and user IDs */
-		i = gid;
-		for (pw_rewind (); (pwd = pw_next ());) {
-			if (pwd->pw_uid >= i) {
-				i = pwd->pw_uid + 1;
+		if ('\0' != uid[0]) {
+			pwd = pw_locate (uid);
+		}
+
+		if (NULL != pwd) {
+			i = pwd->pw_uid;
+		} else {
+			/* Start with gid, either the specified GID, or an ID
+			 * greater than all the group and user IDs */
+			i = gid;
+			for (pw_rewind (); (pwd = pw_next ());) {
+				if (pwd->pw_uid >= i) {
+					i = pwd->pw_uid + 1;
+				}
 			}
 		}
 	}
@@ -295,7 +302,8 @@
 	 * Do the first and easiest shadow file case. The user already
 	 * exists in the shadow password file.
 	 */
-	if ((sp = spw_locate (pwd->pw_name))) {
+	sp = spw_locate (pwd->pw_name);
+	if (NULL != sp) {
 		spent = *sp;
 		spent.sp_pwdp = pw_encrypt (passwd,
 		                            crypt_make_salt (crypt_method,
@@ -573,7 +581,8 @@
 	 */
 	while (fgets (buf, sizeof buf, stdin) != (char *) 0) {
 		line++;
-		if ((cp = strrchr (buf, '\n'))) {
+		cp = strrchr (buf, '\n');
+		if (NULL != cp) {
 			*cp = '\0';
 		} else {
 			fprintf (stderr, _("%s: line %d: line too long\n"),
@@ -589,7 +598,8 @@
 		 */
 		for (cp = buf, nfields = 0; nfields < 7; nfields++) {
 			fields[nfields] = cp;
-			if ((cp = strchr (cp, ':'))) {
+			cp = strchr (cp, ':');
+			if (NULL != cp) {
 				*cp++ = '\0';
 			} else {
 				break;
@@ -611,8 +621,9 @@
 		 * new group, if that group ID exists, a whole new group ID
 		 * will be made up.
 		 */
-		if (!(pw = pw_locate (fields[0])) &&
-		    add_group (fields[0], fields[3], &gid)) {
+		pw = pw_locate (fields[0]);
+		if (   (NULL == pw)
+		    && (add_group (fields[0], fields[3], &gid) != 0)) {
 			fprintf (stderr,
 			         _("%s: line %d: can't create GID\n"),
 			         Prog, line);
@@ -640,7 +651,8 @@
 		 * The password, gecos field, directory, and shell fields
 		 * all come next.
 		 */
-		if (!(pw = pw_locate (fields[0]))) {
+		pw = pw_locate (fields[0]);
+		if (NULL == pw) {
 			fprintf (stderr,
 			         _("%s: line %d: cannot find user %s\n"),
 			         Prog, line, fields[0]);




More information about the Pkg-shadow-commits mailing list