diff --git a/src/middlewared/middlewared/plugins/smb_/groupmap.py b/src/middlewared/middlewared/plugins/smb_/groupmap.py index 175325f487b09..892bf5328037c 100644 --- a/src/middlewared/middlewared/plugins/smb_/groupmap.py +++ b/src/middlewared/middlewared/plugins/smb_/groupmap.py @@ -5,10 +5,11 @@ from middlewared.service import Service, job, private from middlewared.service_exception import CallError from middlewared.utils.sid import ( - BASE_RID_USER, db_id_to_rid, get_domain_rid, lsa_sidtype, + sid_is_valid, + BASE_RID_USER, DomainRid ) from middlewared.utils.tdb import ( @@ -288,6 +289,16 @@ def groupmap_list(self): return rv + @private + def groupmap_listmem(self, sid): + if not sid_is_valid(sid): + raise ValueError(f'{sid}: not a valid SID') + + data = list_foreign_group_memberships(GroupmapFile.DEFAULT, sid) + assert data.sid == sid + + return data.members + @private def sync_builtins(self, to_add): idmap_backend = self.middleware.call_sync("smb.getparm", "idmap config * : backend", "GLOBAL") @@ -334,9 +345,7 @@ def synchronize_group_mappings(self, job, bypass_sentinel_check=False): groupmap = self.groupmap_list() - groups = self.middleware.call_sync('group.query', [ - ('builtin', '=', False), ('local', '=', True), ('smb', '=', True) - ]) + groups = self.middleware.call_sync('group.query', [('local', '=', True), ('smb', '=', True)]) groups.append(self.middleware.call_sync('group.query', [('gid', '=', 545), ('local', '=', True)], {'get': True})) gid_set = {x["gid"] for x in groups} diff --git a/tests/api2/test_smb_groupmap.py b/tests/api2/test_smb_groupmap.py index bb04f799697e5..622c86fe0b37f 100644 --- a/tests/api2/test_smb_groupmap.py +++ b/tests/api2/test_smb_groupmap.py @@ -16,6 +16,11 @@ assert rid == expected_rid groupmap = call('smb.groupmap_list') + assert str(entry['gid']) in groupmap['local_builtins'] + assert groupmap['local_builtins'][str(entry['gid'])]['sid'] == entry['sid'] + + members = call('smb.groupmap_listmem', expected_memberof) + assert entry['sid'] in members test__builtin_users_account(): @@ -24,6 +29,9 @@ rid = int(entry['sid'].split('-')[-1]) assert rid == entry['id'] + BASE_RID_GROUP + members_dom_users = call('smb.groupmap_listmem', 'S-1-5-32-545') + assert entry['sid'] in members_dom_users + test__new_group(): with group({"name": "group1"}) as g: @@ -51,6 +59,5 @@ new = call('group.get_instance', g['id']) assert new['sid'] == g['sid'] - # groupmap = call('smb.groupmap_list') - assert new['gid'] in groupmap['local'] + assert str(new['gid']) in groupmap['local']