summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavid Mulder <dmulder@suse.com>2021-02-17 13:24:55 -0700
committerJeremy Allison <jra@samba.org>2021-03-08 19:45:30 +0000
commitf200c6933b39988a815a064efd165aee106d117d (patch)
treebd0910737dc2cfa3e6438d6921ff31f839e3ccf9 /python
parente5e0a9a7318db25a6213a2516db824caddca8f1e (diff)
downloadsamba-f200c6933b39988a815a064efd165aee106d117d.tar.gz
gpo: Test Group Policy VGP MOTD Policy
Signed-off-by: David Mulder <dmulder@suse.com> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'python')
-rw-r--r--python/samba/tests/gpo.py50
-rw-r--r--python/samba/vgp_motd_ext.py26
2 files changed, 76 insertions, 0 deletions
diff --git a/python/samba/tests/gpo.py b/python/samba/tests/gpo.py
index f849ff2c031..c44cd822447 100644
--- a/python/samba/tests/gpo.py
+++ b/python/samba/tests/gpo.py
@@ -34,6 +34,7 @@ from samba.gp_smb_conf_ext import gp_smb_conf_ext
from samba.vgp_files_ext import vgp_files_ext
from samba.vgp_openssh_ext import vgp_openssh_ext
from samba.vgp_startup_scripts_ext import vgp_startup_scripts_ext
+from samba.vgp_motd_ext import vgp_motd_ext
import logging
from samba.credentials import Credentials
from samba.gp_msgs_ext import gp_msgs_ext
@@ -1256,3 +1257,52 @@ class GPOTests(tests.TestCase):
# Unstage the manifest.xml and script files
unstage_file(manifest)
unstage_file(test_script)
+
+ def test_vgp_motd(self):
+ local_path = self.lp.cache_path('gpo_cache')
+ guid = '{31B2F340-016D-11D2-945F-00C04FB984F9}'
+ manifest = os.path.join(local_path, policies, guid, 'MACHINE',
+ 'VGP/VTLA/UNIX/MOTD/MANIFEST.XML')
+ logger = logging.getLogger('gpo_tests')
+ cache_dir = self.lp.get('cache directory')
+ store = GPOStorage(os.path.join(cache_dir, 'gpo.tdb'))
+
+ machine_creds = Credentials()
+ machine_creds.guess(self.lp)
+ machine_creds.set_machine_account()
+
+ # Initialize the group policy extension
+ ext = vgp_motd_ext(logger, self.lp, machine_creds, store)
+
+ ads = gpo.ADS_STRUCT(self.server, self.lp, machine_creds)
+ if ads.connect():
+ gpos = ads.get_gpo_list(machine_creds.get_username())
+
+ # Stage the manifest.xml file with test data
+ stage = etree.Element('vgppolicy')
+ policysetting = etree.SubElement(stage, 'policysetting')
+ version = etree.SubElement(policysetting, 'version')
+ version.text = '1'
+ data = etree.SubElement(policysetting, 'data')
+ filename = etree.SubElement(data, 'filename')
+ filename.text = 'motd'
+ text = etree.SubElement(data, 'text')
+ text.text = 'This is the message of the day'
+ ret = stage_file(manifest, etree.tostring(stage))
+ self.assertTrue(ret, 'Could not create the target %s' % manifest)
+
+ # Process all gpos, with temp output directory
+ with NamedTemporaryFile() as f:
+ ext.process_group_policy([], gpos, f.name)
+ self.assertEquals(open(f.name, 'r').read(), text.text,
+ 'The motd was not applied')
+
+ # Remove policy
+ gp_db = store.get_gplog(machine_creds.get_username())
+ del_gpos = get_deleted_gpos_list(gp_db, [])
+ ext.process_group_policy(del_gpos, [], f.name)
+ self.assertNotEquals(open(f.name, 'r').read(), text.text,
+ 'The motd was not unapplied')
+
+ # Unstage the Registry.pol file
+ unstage_file(manifest)
diff --git a/python/samba/vgp_motd_ext.py b/python/samba/vgp_motd_ext.py
new file mode 100644
index 00000000000..1e45e8c73c5
--- /dev/null
+++ b/python/samba/vgp_motd_ext.py
@@ -0,0 +1,26 @@
+# vgp_motd_ext samba gpo policy
+# Copyright (C) David Mulder <dmulder@suse.com> 2020
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from samba.gpclass import gp_xml_ext
+
+class vgp_motd_ext(gp_xml_ext):
+ def process_group_policy(self, deleted_gpo_list, changed_gpo_list,
+ motd='/etc/motd'):
+ pass
+
+ def rsop(self, gpo):
+ output = {}
+ return output