--- source3/lib/system.c.orig 2021-09-13 08:42:07.000000000 -0500 +++ source3/lib/system.c 2022-01-11 20:30:07.000000000 -0600 @@ -758,7 +758,25 @@ int setgroups_max(void) { -#if defined(SYSCONF_SC_NGROUPS_MAX) +#if defined(DARWINOS) + /* + * Fixes the Grouplimit of 16 users os OS X + * + * Bug has been raised upstream: https://bugzilla.samba.org/show_bug.cgi?id=8773 + * "https://raw.github.com/gist/1892831/af9ac310b5bd2ffafc79a6ae04d6f9e23e3593ee/samba.3.6.3.osx-getgrouplist.patch" + * + * On OS X, sysconf(_SC_NGROUPS_MAX) returns 16 due to OS X's group nesting + * and getgrouplist will return a flat list; users do almost always exceed the + * maximum of 16 groups. + * + * https://bugzilla.samba.org/show_bug.cgi?id=8773 + * https://github.com/mxcl/homebrew/issues/5954 + * https://serverfault.com/questions/414908/osx-10-7-4-samba3-6-6-get-user-groups-failed-to-get-the-unix-group-list + * https://gist.github.com/lasombra/1888778 + * https://github.com/Homebrew/legacy-homebrew/pull/10311 + */ + return 128; +#elif defined(SYSCONF_SC_NGROUPS_MAX) int ret = sysconf(_SC_NGROUPS_MAX); return (ret == -1) ? NGROUPS_MAX : ret; #else --- source3/lib/system_smbd.c.orig 2021-09-13 08:42:07.000000000 -0500 +++ source3/lib/system_smbd.c 2022-01-11 20:32:02.000000000 -0600 @@ -205,7 +205,27 @@ gid_t primary_gid, gid_t **ret_groups, uint32_t *p_ngroups) { +#if defined(DARWINOS) + /* + * Fixes the Grouplimit of 16 users os OS X + * + * Bug has been raised upstream: https://bugzilla.samba.org/show_bug.cgi?id=8773 + * "https://raw.github.com/gist/1892831/af9ac310b5bd2ffafc79a6ae04d6f9e23e3593ee/samba.3.6.3.osx-getgrouplist.patch" + * + * On OS X, sysconf(_SC_NGROUPS_MAX) returns 16 due to OS X's group nesting + * and getgrouplist will return a flat list; users do almost always exceed the + * maximum of 16 groups. + * + * https://bugzilla.samba.org/show_bug.cgi?id=8773 + * https://github.com/mxcl/homebrew/issues/5954 + * https://serverfault.com/questions/414908/osx-10-7-4-samba3-6-6-get-user-groups-failed-to-get-the-unix-group-list + * https://gist.github.com/lasombra/1888778 + * https://github.com/Homebrew/legacy-homebrew/pull/10311 + */ + int max_grp = 128; +#else int max_grp = MIN(128, getgroups_max()); +#endif gid_t stack_groups[max_grp]; uint32_t ngrp; gid_t *temp_groups = stack_groups;