This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients corona10, ned.deily, ronaldoussoren, shihai1991, steve.dower, vstinner
Date 2020-03-23.16:58:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1584982700.06.0.322930820627.issue40014@roundup.psfhosted.org>
In-reply-to
Content
tl; dr os.getgrouplist() is limited to 17 groups and fails with a random OSError if the request user has more groups. PR 19118 fix the issue.

--

On macOS-10.15.1-x86_64-i386-64bit (python -m platform), os.getgrouplist() fails with my user name and group identifier:

>>> os.getgrouplist('haypo', 20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 0] Error

Full example:

macbook:master haypo$ ./python.exe 
Python 3.9.0a4+ (heads/master:da2914d, Mar 20 2020, 09:45:36) 
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, pwd
>>> entry=pwd.getpwuid(os.getuid())

>>> os.getgrouplist(entry.pw_name, entry.pw_gid)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
InterruptedError: [Errno 4] Interrupted system call

>>> os.getgrouplist(entry.pw_name, entry.pw_gid)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 0] Error

>>> entry
pwd.struct_passwd(pw_name='haypo', pw_passwd='********', pw_uid=502, pw_gid=20, pw_gecos='Victor Stinner', pw_dir='/Users/haypo', pw_shell='/bin/bash')


My user has the following groups:

macbook:master haypo$ id
uid=502(haypo) gid=20(staff) groups=20(staff),702(com.apple.sharepoint.group.2),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),701(com.apple.sharepoint.group.1),33(_appstore),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh),400(com.apple.access_remote_ae),703(com.apple.sharepoint.group.3)

My user has 18 groups.

MAX_GROUPS=16, Python uses 1 + MAX_GROUPS.

getgrouplist() manual page says:

RETURN VALUES
     The getgrouplist() function returns 0 on success.  If the size of the group list is too small to hold
     all the user's groups, getgrouplist() returns -1 to indicate failure.  In this case, the group array
     will be filled with as many groups as will fit.


In short, getgrouplist() doesn't set errno on failure.
History
Date User Action Args
2020-03-23 16:58:20vstinnersetrecipients: + vstinner, ronaldoussoren, ned.deily, steve.dower, corona10, shihai1991
2020-03-23 16:58:20vstinnersetmessageid: <1584982700.06.0.322930820627.issue40014@roundup.psfhosted.org>
2020-03-23 16:58:20vstinnerlinkissue40014 messages
2020-03-23 16:58:19vstinnercreate