summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2016-07-30 22:42:45 +0200
committerLukas Slebodnik <lslebodn@redhat.com>2016-08-18 13:59:37 +0200
commitde19c0af27f1576c13bef183600136851baf767d (patch)
treee359359d988652b78145c4443e6195105624b1c0
parent49a5412cbc98e630de17359c29cb8d6ce0e16168 (diff)
downloadsssd-de19c0af27f1576c13bef183600136851baf767d.tar.gz
sssd-de19c0af27f1576c13bef183600136851baf767d.tar.xz
sssd-de19c0af27f1576c13bef183600136851baf767d.zip
sssd_id.py: Primary group should be returned for initgroups
Side effect of this change was that some primary groups could not be resolved and therefore get_user_groups failed in override tests. We should do the same as "id user". return decimal representation GID if it cannot be mapped to name. Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
-rw-r--r--src/tests/intg/ldap_local_override_test.py4
-rw-r--r--src/tests/intg/sssd_id.py22
2 files changed, 23 insertions, 3 deletions
diff --git a/src/tests/intg/ldap_local_override_test.py b/src/tests/intg/ldap_local_override_test.py
index 046535c77..a27b819b6 100644
--- a/src/tests/intg/ldap_local_override_test.py
+++ b/src/tests/intg/ldap_local_override_test.py
@@ -947,12 +947,12 @@ def test_regr_2790_override(ldap_conn, env_regr_2790_override):
(res, errno, grp_list) = sssd_id.get_user_groups("alias1")
assert res == sssd_id.NssReturnCode.SUCCESS, \
"Could not find groups for user1 %d" % errno
- assert grp_list == ["group1"]
+ assert sorted(grp_list) == sorted(["20001", "group1"])
(res, errno, grp_list) = sssd_id.get_user_groups("alias2")
assert res == sssd_id.NssReturnCode.SUCCESS, \
"Could not find groups for user2 %d" % errno
- assert sorted(grp_list) == sorted(["group1", "group2"])
+ assert sorted(grp_list) == sorted(["20002", "group1", "group2"])
# Test fully qualified and case-insensitive names
diff --git a/src/tests/intg/sssd_id.py b/src/tests/intg/sssd_id.py
index 4ae41af98..95c9ab75a 100644
--- a/src/tests/intg/sssd_id.py
+++ b/src/tests/intg/sssd_id.py
@@ -73,6 +73,10 @@ def call_sssd_initgroups(user, gid):
for i in range(0, gids_count):
gids.append(int(p_groups.contents[i]))
+ # add primary group if missing
+ if gid not in gids:
+ gids.append(gid)
+
return (int(res), errno[0], gids)
@@ -97,6 +101,22 @@ def get_user_gids(user):
return call_sssd_initgroups(user, gid)
+def gid_to_str(gid):
+ """
+ Function will map numeric GID into names.
+ If there isn't a group for GID (getgrgid failed)
+ then the function will return decimal representation of ID.
+
+ @param int gid ID of groups which should be converted to string.
+ @return string name of group with requested ID or decimal
+ representation of ID
+ """
+ try:
+ return grp.getgrgid(gid).gr_name
+ except KeyError:
+ return str(gid)
+
+
def get_user_groups(user):
"""
Function will initialize the supplementary group access list
@@ -114,6 +134,6 @@ def get_user_groups(user):
groups = []
if res == NssReturnCode.SUCCESS:
- groups = [grp.getgrgid(gid).gr_name for gid in gids]
+ groups = [gid_to_str(gid) for gid in gids]
return (res, errno, groups)