use sysconf instead of NGROUPS_MAX

Sven Rudolph rudsve at drewag.de
Thu Feb 3 14:01:37 GMT 2000


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.

Suggestions etc. ?

	Sven


More information about the samba mailing list