In OpenBSD, the PAG uses the 2nd and 3rd group slots in the task's
group list. If an application sets en empty group list (such as Samba
does), any existing PAG is lost and any new one is NOT set because
the existing code will set the new group count to 2 instead of 3, and
it leaves the first group entry as garbage (whatever random value the
memory contained), thereby totally messing up the task's group list.
This patch fixes it so that it behaves as expected.
Change-Id: Ia718d55cbaad8ed372fba926dbfcb5db52ea684a
Reviewed-on: http://gerrit.openafs.org/1898
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
AFS_STATCNT(setpag);
ngroups = afs_getgroups(*cred, NGROUPS, gidset);
+ /*
+ * If the group list is empty, use the task's primary group as the group
+ * list. Otherwise, when setting the PAG, group 0 will be set to arbitrary
+ * gibberish and the PAG, which starts at group offset 1, will not be
+ * properly set because the group count will be wrong (2 instead of 3).
+ */
+ if (ngroups == 0) {
+ gidset[0] = (*cred)->cr_gid;
+ ngroups = 1;
+ }
if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
/* We will have to shift grouplist to make room for pag */
if (ngroups + 2 > NGROUPS) {