]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Un-spageticize code
authorAlejandro Colomar <alx@kernel.org>
Thu, 14 Nov 2024 12:52:31 +0000 (13:52 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 24 Jan 2025 13:58:13 +0000 (07:58 -0600)
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/addgrps.c
src/newgrp.c

index a52dd55d5056af87695427044ed1ec0f5cd946f5..809b8e702a41da9b5060f8ae755bd95b2ec309dc 100644 (file)
@@ -52,19 +52,15 @@ add_groups(const char *list)
                        return -1;
                }
                ngroups = getgroups (i, grouplist);
-               if (   (   (-1 == ngroups)
-                       && (EINVAL != errno))
-                   || (i > (size_t)ngroups)) {
-                       /* Unexpected failure of getgroups or successful
-                        * reception of the groups */
+               if (ngroups == -1 && errno != EINVAL) {
+                       free(grouplist);
+                       return -1;
+               }
+               if (i > (size_t)ngroups) {
                        break;
                }
                free (grouplist);
        }
-       if (ngroups < 0) {
-               free (grouplist);
-               return -1;
-       }
 
        added = false;
        p = buf;
index 2549c81ed3bf025a514e14d2a269a33607ccfa5a..e5dc2290beb22452e10d3d00d9f48f8da0df0f75 100644 (file)
@@ -558,25 +558,25 @@ int main (int argc, char **argv)
        for (int i = 16; /* void */; i *= 2) {
                grouplist = XMALLOC(i, GETGROUPS_T);
                ngroups = getgroups (i, grouplist);
-               if (i > ngroups && !(ngroups == -1 && errno == EINVAL)) {
+               if (ngroups == -1 && errno != EINVAL) {
+                       perror("getgroups");
+#ifdef WITH_AUDIT
+                       if (group) {
+                               SNPRINTF(audit_buf, "changing new-group=%s", group);
+                               audit_logger(AUDIT_CHGRP_ID, Prog,
+                                            audit_buf, NULL, getuid(), 0);
+                       } else {
+                               audit_logger(AUDIT_CHGRP_ID, Prog,
+                                            "changing", NULL, getuid(), 0);
+                       }
+#endif
+                       exit(EXIT_FAILURE);
+               }
+               if (i > (size_t)ngroups) {
                        break;
                }
                free (grouplist);
        }
-       if (ngroups < 0) {
-               perror ("getgroups");
-#ifdef WITH_AUDIT
-               if (group) {
-                       SNPRINTF(audit_buf, "changing new-group=%s", group);
-                       audit_logger (AUDIT_CHGRP_ID, Prog,
-                                     audit_buf, NULL, getuid (), 0);
-               } else {
-                       audit_logger (AUDIT_CHGRP_ID, Prog,
-                                     "changing", NULL, getuid (), 0);
-               }
-#endif
-               exit (EXIT_FAILURE);
-       }
 
        /*
         * now we put her in the new group. The password file entry for her