samba-tool: Add a gpo command for listing VGP MOTD Group Policy
authorDavid Mulder <dmulder@suse.com>
Thu, 18 Feb 2021 14:50:08 +0000 (07:50 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 8 Mar 2021 19:45:30 +0000 (19:45 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
docs-xml/manpages/samba-tool.8.xml
python/samba/netcmd/gpo.py
selftest/knownfail.d/gpo [deleted file]

index b808c9b2616d71ba67afd9306f3e89abe7f8fb60..0b9245c0985c60e7053c339dd690f07c0781c681 100644 (file)
        <para>Removes VGP Startup Script Group Policy from the sysvol</para>
 </refsect3>
 
+<refsect3>
+       <title>gpo manage motd list</title>
+       <para>List VGP MOTD Group Policy from the sysvol.</para>
+</refsect3>
+
 <refsect2>
        <title>group</title>
        <para>Manage groups.</para>
index d2bede247d3047509e476c3a4bc229b175f94e95..9f1a0f9e6ecdc793ae75a9cbb16d2385610ec09a 100644 (file)
@@ -3349,7 +3349,43 @@ samba-tool gpo manage motd list {31B2F340-016D-11D2-945F-00C04FB984F9}
     takes_args = ["gpo"]
 
     def run(self, gpo, H=None, sambaopts=None, credopts=None, versionopts=None):
-        pass
+        self.lp = sambaopts.get_loadparm()
+        self.creds = credopts.get_credentials(self.lp, fallback_machine=True)
+
+        # We need to know writable DC to setup SMB connection
+        if H and H.startswith('ldap://'):
+            dc_hostname = H[7:]
+            self.url = H
+        else:
+            dc_hostname = netcmd_finddc(self.lp, self.creds)
+            self.url = dc_url(self.lp, self.creds, dc=dc_hostname)
+
+        # SMB connect to DC
+        conn = smb_connection(dc_hostname,
+                              'sysvol',
+                              lp=self.lp,
+                              creds=self.creds)
+
+        realm = self.lp.get('realm')
+        vgp_xml = '\\'.join([realm.lower(), 'Policies', gpo,
+                                'MACHINE\\VGP\\VTLA\\Unix',
+                                'MOTD\\manifest.xml'])
+        try:
+            xml_data = ET.fromstring(conn.loadfile(vgp_xml))
+        except NTSTATUSError as e:
+            # STATUS_OBJECT_NAME_INVALID, STATUS_OBJECT_NAME_NOT_FOUND,
+            # STATUS_OBJECT_PATH_NOT_FOUND
+            if e.args[0] in [0xC0000033, 0xC0000034, 0xC000003A]:
+                return # The file doesn't exist, so there is nothing to list
+            if e.args[0] == 0xC0000022: # STATUS_ACCESS_DENIED
+                raise CommandError("The authenticated user does "
+                                   "not have sufficient privileges")
+            raise
+
+        policy = xml_data.find('policysetting')
+        data = policy.find('data')
+        text = data.find('text')
+        self.outf.write(text.text)
 
 class cmd_motd(SuperCommand):
     """Manage Message of the Day Group Policy Objects"""
diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo
deleted file mode 100644 (file)
index 41587fc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba.tests.samba_tool.gpo.samba.tests.samba_tool.gpo.GpoCmdTestCase.test_vgp_motd