New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
please add posix.getgrouplist() #53590
Comments
A number of unix systems expose a getgroupslist function to fetch the groups that a user is a member of. It would be nice if that function were exposed to python. See bpo-7900 for more information on why that would be useful. |
Did a bit of digging and found that getgrouplist signature differs on (at least) Linux and Mac OS: |
I don't see how this difference is relevant for exposing the functionality in python: Linux: int getgrouplist(const char *user, gid_t group,
gid_t *groups, int *ngroups); MacOS: int
getgrouplist(const char *name, int basegid, int *groups, int *ngroups); The only difference is that Linux uses gid_t and MacOS uses int. The requested posix.getgrouplist() will take a python string and a python integer and return a list of integers. |
@alexander, it was just a note, that implementation in posixmodule.c won't be the same across all flavours of Unix :) |
Attached is a patch (against the latest revision, 87178) which adds the functionality to the posix module as well as adds a testcase for it. I haven't added it to the os module, I'm not sure if that should be done. I tested it on Linux & FreeBSD and it works as expected. Since I don't have an OS X system, I could not test it on there. |
A slightly updated patch. Targeting for 3.3. |
I can't say anything about the functionality, but the patch looks good to me (works under Linux and Solaris - the latter missing getgrouplist()). |
Patch looks good, but this likely runs into the same problem as bpo-7900: the user can be a member of more than NGROUPS_MAX on OSX. I'll test this tomorrow (by creating a temporary user that is a member of more than 16 groups). |
Looks good to me as well. Just a nit-pick: in python code base "sizeof" is not separated from the opening parenthesis. I understand the desire to distinguish "sizeof" from a function, but it is probably better to be consistent. |
Ronald, does it have the same problem as bpo-7900 on OS X or can I commit? |
I haven't tested yet, but feel free to commit and I'll fix any OSX issues later. |
New changeset 9ebee3211be9 by Ross Lagerwall in branch 'default': |
Thanks! |
Nit: when a patch gets committed and the issue closed, the preferred resolution is "fixed" ;) |
Sure, I will try remember that. |
Actually, when it is a feature request rather than a bug fix we usually use 'accepted'. It doesn't matter a whole lot, though. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: