use sysconf instead of NGROUPS_MAX

Jeremy Allison jeremy at valinux.com
Tue Feb 15 00:19:14 GMT 2000


Sven Rudolph wrote:
> 
> Currently samba (2.0.6) relies on the NGROUPS_MAX define. This makes
> the number of allowed simultaneous (per-user) secondary groups a
> compile-time decision.
> 
> $ find . -name \*.c | xargs grep NGROUPS
> /source/lib/system.c:  if (setlen > NGROUPS_MAX) {
> /source/lib/replace.c: gid_t  grouplst[NGROUPS_MAX];
> /source/lib/replace.c: while (i < NGROUPS_MAX &&
> /source/smbd/password.c:#ifdef NGROUPS_MAX
> /source/smbd/password.c:       if((groups = (gid_t *)malloc(sizeof(gid_t)*NGROUPS_MAX)) == NULL)
> 
> POSIX defined sysconf in order to avoid this.
> 
> By using sysconf(_SC_NGROUPS_MAX) this value is determined at
> run-time.
> 
> OTOH NGROUPS_MAX seems to be used incorrectly anyway:
> 
> source/smbd/password.c
> #ifdef NGROUPS_MAX
>         if((groups = (gid_t *)malloc(sizeof(gid_t)*NGROUPS_MAX)) == NULL)
> #else /* NGROUPS_MAX */
>         if((groups = (gid_t *)malloc(sizeof(gid_t)*ngroups)) == NULL)
> #endif /* NGROUPS_MAX */
> 
> As Donald Lewine's POSIX book says: "The values returned by these
> functions should be thought of as minimum guarantees. ... The values
> returned by sysconf() and pathconf() are not suitable for allocating
> memory."
> 
> Running samba on Linux only above-showed source/smbd/password.c seems
> to be a problem since the other NGROUPS_MAX occurences only matter
> when things like a sane initgroups are missing.

I have fixed this in the HEAD and 2.0.x source trees
so that Samba now uses sysconf(_SC_NGROUPS_MAX) as
appropriate.

Thanks for pointing this out.

Regards,

	Jeremy Allison,
	Samba Team.

-- 
--------------------------------------------------------
Buying an operating system without source is like buying
a self-assembly Space Shuttle with no instructions.
--------------------------------------------------------


More information about the samba mailing list