tests/auth_log: adjust expected authDescription for test_smb_bad_user
[Samba.git] / python / samba / vgp_motd_ext.py
blob1ac152c29e936e2dbc163ebe836588f506f8e264
1 # vgp_motd_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/>.
17 import os
18 from samba.gpclass import gp_xml_ext
20 class vgp_motd_ext(gp_xml_ext):
21 def __str__(self):
22 return 'Unix Settings/Message of the Day'
24 def process_group_policy(self, deleted_gpo_list, changed_gpo_list,
25 motd='/etc/motd'):
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 with open(motd, 'w') as w:
32 if msg:
33 w.write(msg)
34 else:
35 w.truncate()
36 self.gp_db.delete(str(self), attribute)
37 self.gp_db.commit()
39 for gpo in changed_gpo_list:
40 if gpo.file_sys_path:
41 self.gp_db.set_guid(gpo.name)
42 xml = 'MACHINE/VGP/VTLA/Unix/MOTD/manifest.xml'
43 path = os.path.join(gpo.file_sys_path, xml)
44 xml_conf = self.parse(path)
45 if not xml_conf:
46 continue
47 policy = xml_conf.find('policysetting')
48 data = policy.find('data')
49 text = data.find('text')
50 current = open(motd, 'r').read() if os.path.exists(motd) else ''
51 if current != text.text:
52 with open(motd, 'w') as w:
53 w.write(text.text)
54 self.gp_db.store(str(self), 'motd', current)
55 self.gp_db.commit()
57 def rsop(self, gpo):
58 output = {}
59 if gpo.file_sys_path:
60 xml = 'MACHINE/VGP/VTLA/Unix/MOTD/manifest.xml'
61 path = os.path.join(gpo.file_sys_path, xml)
62 xml_conf = self.parse(path)
63 if not xml_conf:
64 return output
65 policy = xml_conf.find('policysetting')
66 data = policy.find('data')
67 filename = data.find('filename')
68 text = data.find('text')
69 mfile = os.path.join('/etc', filename.text)
70 output[mfile] = text.text
71 return output