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/>.
18 from samba
.gpclass
import list_gp_extensions
19 from samba
.gpclass
import gp_ext
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
)
30 def import_file(name
, location
):
31 return imp
.load_source(name
, location
)
33 def get_gp_ext_from_module(name
, mod
):
35 for k
, v
in vars(mod
).items():
36 if k
== name
and issubclass(v
, gp_ext
):
40 def get_gp_client_side_extensions(logger
, smb_conf
):
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']:
53 logger
.info('Loaded user extension from %s: %s'
54 % (gp_ext
['DllName'], ext
.__name
__))
55 return (machine_exts
, user_exts
)