From c7b8588c739bae8abcec5f8b91ad8489ab39a13f Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Sat, 30 Jul 2016 22:42:45 +0200 Subject: [PATCH 06/16] 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. --- src/tests/intg/ldap_local_override_test.py | 4 ++-- src/tests/intg/sssd_id.py | 22 +++++++++++++++++++++- 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 046535c7727d0f2271f4b974f68ba0722222982b..a27b819b6bca7f5f1411826a496fc6aee924bfc0 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 4ae41af98bad804026083b193eddfa6c2d3c924c..95c9ab75a381ca58dde230796c1c4c9fa7aa61d5 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) -- 2.9.2