Author Alexander.Belopolsky
Recipients Alexander.Belopolsky, l0nwlf, loewis, michael.foord, orsenthil, ronaldoussoren
Date 2010-02-22.22:50:28
SpamBayes Score 6.00899e-11
Marked as misclassified No
Message-id <1266879031.04.0.329078170686.issue7900@psf.upfronthosting.co.za>
In-reply-to
Content
After some head-scratching, I figured out how to reproduce stock python2.5 behavior.  It turns out that defining _DARWIN_C_SOURCE not only allows getgroups() output to exceed NGROUPS_MAX (as documented), but also effectively disables setgroups() which is not documented.

With no-darwin-ext.diff patch and previously attached tg.py, I see

$ cat tg.py
import os
g = os.getgroups()
print(g)
os.setgroups(g[:5])
print(os.getgroups())

$ sudo ./python.exe tg.py
[0, 101, 204, 100, 98, 80, 61, 29, 20, 12, 9, 8, 5, 4, 3, 2]
[0, 101, 204, 100, 98]

which is the same as with stock python2.5:

$ sudo python2.5 tg.py
[0, 101, 204, 100, 98, 80, 61, 29, 20, 12, 9, 8, 5, 4, 3, 2]
[0, 101, 204, 100, 98]

Note that root is a member of 18 groups on my system, but the last two are truncated by os.getgroups().

It is tempting to adopt no-darwin-ext.diff as a solution to this issue because allowing more than NGROUPS_MAX (or sysconf(_SC_NGROUPS_MAX) which should be the same) groups is really a Mac OS bug.

In order to have both working os.setgroups() and os.getgroups() supporting more than NGROUPS_MAX results, it appears that the two functions should be compiled in separate compilation units which is probably too big of a price to pay for the functionality.

Also, my issue7900.diff, while likely to work in most practical situation is vulnerable to a race condition if group membership is expanded between two calls to getgroups.
History
Date User Action Args
2010-02-22 22:50:31Alexander.Belopolskysetrecipients: + Alexander.Belopolsky, loewis, ronaldoussoren, orsenthil, michael.foord, l0nwlf
2010-02-22 22:50:31Alexander.Belopolskysetmessageid: <1266879031.04.0.329078170686.issue7900@psf.upfronthosting.co.za>
2010-02-22 22:50:29Alexander.Belopolskylinkissue7900 messages
2010-02-22 22:50:29Alexander.Belopolskycreate