Skip to content
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

ESRF's addition for group IDs from sssd #1631

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions grouplist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python
import pwd, os
from ctypes import *
from ctypes.util import find_library

libc = cdll.LoadLibrary(find_library('libc'))
getgrouplist = libc.getgrouplist

def grouplist(username, startmax=50):
# 50 groups should be enought?
ngroups = startmax
getgrouplist.argtypes = [c_char_p, c_uint, POINTER(c_uint * ngroups), POINTER(c_int)]
getgrouplist.restype = c_int32

gidlist = (c_uint * ngroups)()
ngrouplist = c_int(ngroups)

user = pwd.getpwnam(username)

ct = getgrouplist(user.pw_name, user.pw_gid, byref(gidlist), byref(ngrouplist))

# If 50 groups was not enought this will be -1, try again
# luckily the last call put the correct number of groups in ngrouplist
if ct < 0:
getgrouplist.argtypes = [c_char_p, c_uint, POINTER(c_uint *int(ngrouplist.value)), POINTER(c_int)]
gidlist = (c_uint * int(ngrouplist.value))()
ct = getgrouplist(user.pw_name, user.pw_gid, byref(gidlist), byref(ngrouplist))

for i in xrange(0, ct):
gid = gidlist[i]
yield int(gid)
9 changes: 7 additions & 2 deletions supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
from supervisor import xmlrpc
from supervisor import poller

# ESRF's addition for group IDs from sssd
from supervisor.grouplist import grouplist

def _read_version_txt():
mydir = os.path.abspath(os.path.dirname(__file__))
version_txt = os.path.join(mydir, 'version.txt')
Expand Down Expand Up @@ -1387,8 +1390,10 @@ def drop_privileges(self, user):
gid = pwrec[3]
if hasattr(os, 'setgroups'):
user = pwrec[0]
groups = [grprec[2] for grprec in grp.getgrall() if user in
grprec[3]]
# groups = [grprec[2] for grprec in grp.getgrall() if user in
# grprec[3]]
# ESRF's addition for group IDs from sssd
groups = list(grouplist(user))

# always put our primary gid first in this list, otherwise we can
# lose group info since sometimes the first group in the setgroups
Expand Down
Loading