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;
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