This issue tracker will soon become read-only and move to GitHub.
For a smoother transition, remember to log in and link your GitHub username to your profile.
For more information, see this post about the migration.

classification
Title: grp library functions grp.getgrnam() & grp.getgrgid() returning incorrect gr_mem information
Type: behavior Stage:
Components: Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: abhi.sharma, ammar2
Priority: normal Keywords:

Created on 2020-03-02 04:54 by abhi.sharma, last changed 2020-03-02 05:31 by abhi.sharma.

Messages (3)
msg363113 - (view) Author: Abhishek (abhi.sharma) Date: 2020-03-02 04:54
If root user is part of a linux group, then in the response of getgrnam() & grp.getgrid(), in te gr_mem part, root user is not listed.

[root@biplab2 ~]# getent group | grep starwars
starwars:x:1011:root,abhi

[root@biplab2 ~]# python3
Python 3.6.8 (default, Dec  5 2019, 16:11:43)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
>>> import grp
>>> grp.getgrnam('starwars')
grp.struct_group(gr_name='starwars', gr_passwd='x', gr_gid=1011, gr_mem=['abhi'])
>>> grp.getgrgid(1011)
grp.struct_group(gr_name='starwars', gr_passwd='x', gr_gid=1011, gr_mem=['abhi'])

But, when grp.getgrall() is run, we the correct response (gr_mem includes root user as well)

>>> grp.getgrall()
grp.struct_group(gr_name='starwars', gr_passwd='x', gr_gid=1011, gr_mem=['root', 'abhi'])]
msg363115 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2020-03-02 05:08
I can't re-create this locally (tested on master and 3.5.2):

  ammar@cowlick:~/cpython$ getent group | grep testgroup
  testgroup:x:1008:ammar,root
  ammar@cowlick:~/cpython$ ./python
  Python 3.9.0a4+ (heads/master:02a4d57, Feb 27 2020, 01:54:32)
  [GCC 5.4.0 20160609] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import grp
  >>> grp.getgrnam('testgroup')
  grp.struct_group(gr_name='testgroup', gr_passwd='x', gr_gid=1008, gr_mem=['ammar', 'root'])

Both getgrnam and getgrall use the same underlying function to convert the `struct group` so this might be a problem with your libc. Could you post your distro info?
msg363118 - (view) Author: Abhishek (abhi.sharma) Date: 2020-03-02 05:31
I also observed now that it works on other distro. On red hat enterprise linux (rhel) 7.7, I a, getting the correct output.

The bug which I have raised was tested on rhel 8.2.

[root@biplab2 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.2 Beta (Ootpa)

[root@biplab2 ~]# cat /proc/version
Linux version 4.18.0-167.el8.ppc64le (mockbuild@ppc-061.build.eng.bos.redhat.com) (gcc version 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC)) #1 SMP Sun Dec 15 01:20:45 UTC 2019
History
Date User Action Args
2020-03-02 05:31:57abhi.sharmasetmessages: + msg363118
2020-03-02 05:08:32ammar2setnosy: + ammar2
messages: + msg363115
2020-03-02 04:54:37abhi.sharmacreate