1 # gp_msgs_ext samba gpo policy
2 # Copyright (C) David Mulder <dmulder@suse.com> 2020
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 gp_pol_ext
20 class gp_msgs_ext(gp_pol_ext):
22 return 'Unix Settings/Messages'
24 def process_group_policy(self, deleted_gpo_list, changed_gpo_list,
26 for guid, settings in deleted_gpo_list:
27 self.gp_db.set_guid(guid)
28 if str(self) in settings:
29 for attribute, msg in settings[str(self)].items():
30 if attribute == 'motd':
31 mfile = os.path.join(cdir, 'motd')
32 elif attribute == 'issue':
33 mfile = os.path.join(cdir, 'issue')
36 with open(mfile, 'w') as w:
41 self.gp_db.delete(str(self), attribute)
44 for gpo in changed_gpo_list:
46 section_name = 'Software\\Policies\\Samba\\Unix Settings\\Messages'
47 self.gp_db.set_guid(gpo.name)
48 pol_file = 'MACHINE/Registry.pol'
49 path = os.path.join(gpo.file_sys_path, pol_file)
50 pol_conf = self.parse(path)
53 for e in pol_conf.entries:
54 if e.keyname == section_name and e.data.strip():
55 if e.valuename == 'motd':
56 mfile = os.path.join(cdir, 'motd')
57 elif e.valuename == 'issue':
58 mfile = os.path.join(cdir, 'issue')
61 if os.path.exists(mfile):
62 old_val = open(mfile, 'r').read()
65 with open(mfile, 'w') as w:
67 self.gp_db.store(str(self), e.valuename, old_val)