add_groups(const char *list)
{
GETGROUPS_T *grouplist;
- size_t i;
int ngroups;
bool added;
char *g, *p;
char buf[1024];
- int ret;
FILE *shadow_logfd = log_get_logfd();
if (strlen (list) >= sizeof (buf)) {
}
strcpy (buf, list);
- i = 16;
- for (;;) {
+ for (size_t i = 16; /* void */; i *= 2) {
grouplist = MALLOC(i, GETGROUPS_T);
if (NULL == grouplist) {
return -1;
* reception of the groups */
break;
}
- /* not enough room, so try allocating a larger buffer */
free (grouplist);
- i *= 2;
}
if (ngroups < 0) {
free (grouplist);
added = false;
p = buf;
while (NULL != (g = strsep(&p, ",:"))) {
- struct group *grp;
+ size_t i;
+ struct group *grp;
grp = getgrnam(g); /* local, no need for xgetgrnam */
if (NULL == grp) {
}
if (added) {
+ int ret;
+
ret = setgroups (ngroups, grouplist);
free (grouplist);
return ret;
int main (int argc, char **argv)
{
bool initflag = false;
- int i;
bool is_member = false;
bool cflag = false;
int err = 0;
* set.
*/
/* don't use getgroups(0, 0) - it doesn't work on some systems */
- i = 16;
- for (;;) {
+ for (int i = 16; /* void */; i *= 2) {
grouplist = XMALLOC(i, GETGROUPS_T);
ngroups = getgroups (i, grouplist);
if (i > ngroups && !(ngroups == -1 && errno == EINVAL)) {
break;
}
- /* not enough room, so try allocating a larger buffer */
free (grouplist);
- i *= 2;
}
if (ngroups < 0) {
perror ("getgroups");
* database. However getgroups() will return the group. So
* if she is listed there already it is ok to grant membership.
*/
- for (i = 0; i < ngroups; i++) {
+ for (int i = 0; i < ngroups; i++) {
if (grp->gr_gid == grouplist[i]) {
is_member = true;
break;
* If the group doesn't fit, I'll complain loudly and skip this
* part.
*/
+ int i;
for (i = 0; i < ngroups; i++) {
if (gid == grouplist[i]) {
break;