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/>.
18 from samba
.gpclass
import gp_xml_ext
20 class vgp_motd_ext(gp_xml_ext
):
22 return 'Unix Settings/Message of the Day'
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 with
open(motd
, 'w') as w
:
36 self
.gp_db
.delete(str(self
), attribute
)
39 for gpo
in changed_gpo_list
:
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
)
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
:
54 self
.gp_db
.store(str(self
), 'motd', current
)
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
)
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