s3: torture: adjust SMB1 cli_splice() test sizes
[Samba.git] / python / samba / gp_ext_loader.py
blob61cc29b788ce275a5b72e0d52b92935ee6051037
1 # Group Policy Client Side Extension Loader
2 # Copyright (C) David Mulder <dmulder@suse.com> 2018
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 import os
18 from samba.gpclass import list_gp_extensions
19 from samba.gpclass import gp_ext
21 try:
22 import importlib.util
23 def import_file(name, location):
24 spec = importlib.util.spec_from_file_location(name, location)
25 module = importlib.util.module_from_spec(spec)
26 spec.loader.exec_module(module)
27 return module
28 except ImportError:
29 import imp
30 def import_file(name, location):
31 return imp.load_source(name, location)
33 def get_gp_ext_from_module(name, mod):
34 if mod:
35 for k, v in vars(mod).items():
36 if k == name and issubclass(v, gp_ext):
37 return v
38 return None
40 def get_gp_client_side_extensions(logger, smb_conf):
41 user_exts = []
42 machine_exts = []
43 gp_exts = list_gp_extensions(smb_conf)
44 for gp_ext in gp_exts.values():
45 module = import_file(gp_ext['ProcessGroupPolicy'], gp_ext['DllName'])
46 ext = get_gp_ext_from_module(gp_ext['ProcessGroupPolicy'], module)
47 if ext and gp_ext['MachinePolicy']:
48 machine_exts.append(ext)
49 logger.info('Loaded machine extension from %s: %s'
50 % (gp_ext['DllName'], ext.__name__))
51 if ext and gp_ext['UserPolicy']:
52 user_exts.append(ext)
53 logger.info('Loaded user extension from %s: %s'
54 % (gp_ext['DllName'], ext.__name__))
55 return (machine_exts, user_exts)