kern/113398: [libc] initgroups fails rather than truncates if

Denis Barov dindin at yandex-team.ru
Wed Feb 27 20:10:05 UTC 2008


The following reply was made to PR kern/113398; it has been noted by GNATS.

From: Denis Barov <dindin at yandex-team.ru>
To: bug-followup at FreeBSD.org, dean.povey at quest.com
Cc:  
Subject: Re: kern/113398: [libc] initgroups fails rather than truncates if
Date: Wed, 27 Feb 2008 23:06:54 +0300

 number of groups > NGROUPS_MAX meaning the user can no longer login
 Message-ID: <20080227170342.GE1139 at sepulca.yandex.ru>
 MIME-Version: 1.0
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 X-Operating-System: FreeBSD sepulca.yandex.ru 6.3-STABLE FreeBSD 6.3-STABLE
 User-Agent: mutt-ng/devel-r804 (FreeBSD)
 Status: RO
 
 I'm sorry, previous patch just  increases number of groups to 64, and this
 one fixes problem.
 
 -- 
 Cheers
 Denis Barov
 
 diff -urN src/lib/libc/gen/initgroups.c.orig src/lib/libc/gen/initgroups.c
 --- src/lib/libc/gen/initgroups.c.orig  2003-11-19 18:51:26.000000000 +0300
 +++ src/lib/libc/gen/initgroups.c   2008-02-27 22:59:13.000000000 +0300
 @@ -42,6 +42,7 @@
  #include <stdio.h>
  #include "namespace.h"
  #include <err.h>
 +#include <errno.h>
  #include "un-namespace.h"
  #include <unistd.h>
 
 @@ -51,6 +52,7 @@
     gid_t agroup;
  {
     int ngroups;
 +    int result;
     /*
      * Provide space for one group more than NGROUPS to allow
      * setgroups to fail and set errno.
 @@ -59,5 +61,10 @@
 
     ngroups = NGROUPS + 1;
     getgrouplist(uname, agroup, groups, &ngroups);
 -   return (setgroups(ngroups, groups));
 +
 +    do
 +      result = setgroups (ngroups, groups);
 +    while (result == -1 && errno == EINVAL && --ngroups > 0);
 +
 +   return result;
  }
 
 
 


More information about the freebsd-bugs mailing list