def test_gpt_ext_register(self): this_path = os.path.dirname(os.path.realpath(__file__)) samba_path = os.path.realpath(os.path.join(this_path, '../../../')) ext_path = os.path.join(samba_path, 'python/samba/gp_sec_ext.py') ext_guid = '{827D319E-6EAC-11D2-A4EA-00C04F79F83A}' ret = register_gp_extension(ext_guid, 'gp_sec_ext', ext_path, smb_conf=self.lp.configfile, machine=True, user=False) self.assertTrue(ret, 'Failed to register a gp ext') gp_exts = list_gp_extensions(self.lp.configfile) self.assertTrue(ext_guid in gp_exts.keys(), 'Failed to list gp exts') self.assertEquals(gp_exts[ext_guid]['DllName'], ext_path, 'Failed to list gp exts') unregister_gp_extension(ext_guid) gp_exts = list_gp_extensions(self.lp.configfile) self.assertTrue(ext_guid not in gp_exts.keys(), 'Failed to unregister gp exts') self.assertTrue(check_guid(ext_guid), 'Failed to parse valid guid') self.assertFalse(check_guid('AAAAAABBBBBBBCCC'), 'Parsed invalid guid') lp, parser = parse_gpext_conf(self.lp.configfile) self.assertTrue(lp and parser, 'parse_gpext_conf() invalid return') parser.add_section('test_section') parser.set('test_section', 'test_var', ext_guid) atomic_write_conf(lp, parser) lp, parser = parse_gpext_conf(self.lp.configfile) self.assertTrue('test_section' in parser.sections(), 'test_section not found in gpext.conf') self.assertEquals(parser.get('test_section', 'test_var'), ext_guid, 'Failed to find test variable in gpext.conf') parser.remove_section('test_section') atomic_write_conf(lp, parser)
def get_gp_client_side_extensions(logger, smb_conf): user_exts = [] machine_exts = [] gp_exts = list_gp_extensions(smb_conf) for gp_ext in gp_exts.values(): module = import_file(gp_ext['ProcessGroupPolicy'], gp_ext['DllName']) ext = get_gp_ext_from_module(gp_ext['ProcessGroupPolicy'], module) if ext and gp_ext['MachinePolicy']: machine_exts.append(ext) logger.info('Loaded machine extension from %s: %s' % (gp_ext['DllName'], ext.__name__)) if ext and gp_ext['UserPolicy']: user_exts.append(ext) logger.info('Loaded user extension from %s: %s' % (gp_ext['DllName'], ext.__name__)) return (machine_exts, user_exts)