]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool: Add a gpo command for removing VGP Host Access Group Policy
authorDavid Mulder <dmulder@suse.com>
Wed, 3 Mar 2021 21:19:01 +0000 (14:19 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 18 Mar 2021 20:02:50 +0000 (20:02 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Mar 18 20:02:50 UTC 2021 on sn-devel-184

docs-xml/manpages/samba-tool.8.xml
python/samba/netcmd/gpo.py
selftest/knownfail.d/gpo [deleted file]

index fb79eb7f9e0a1767fac34a1117f1da97c33a0aa2..beef6cfb265fdbccaa82863ea08e4ee9f5da5d6b 100644 (file)
        <para>List VGP Host Access Group Policy from the sysvol</para>
 </refsect3>
 
+<refsect3>
+       <title>gpo manage access remove</title>
+       <para>Remove a VGP Host Access Group Policy from the sysvol</para>
+</refsect3>
+
 <refsect2>
        <title>group</title>
        <para>Manage groups.</para>
index ce838551442ee70f79edbe20e0eb60bfc3140b8d..bd2db9b1ab2094b722cdda0eba7788831bffd892 100644 (file)
@@ -3911,7 +3911,75 @@ samba-tool gpo manage access remove {31B2F340-016D-11D2-945F-00C04FB984F9} allow
 
     def run(self, gpo, etype, name, domain, 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')
+        if etype == 'allow':
+            vgp_dir = '\\'.join([realm.lower(), 'Policies', gpo,
+                                 'MACHINE\\VGP\\VTLA\\VAS'
+                                 'HostAccessControl\\Allow'])
+        elif etype == 'deny':
+            vgp_dir = '\\'.join([realm.lower(), 'Policies', gpo,
+                                 'MACHINE\\VGP\\VTLA\\VAS'
+                                 'HostAccessControl\\Deny'])
+        else:
+            raise CommandError("The entry type must be either 'allow' or "
+                               "'deny'. Unknown type '%s'" % etype)
+        vgp_xml = '\\'.join([vgp_dir, 'manifest.xml'])
+        try:
+            xml_data = ET.ElementTree(ET.fromstring(conn.loadfile(vgp_xml)))
+            policy = xml_data.getroot().find('policysetting')
+            data = policy.find('data')
+        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]:
+                raise CommandError("Cannot remove %s entry because it does "
+                                   "not exist" % etype)
+            elif e.args[0] == 0xC0000022: # STATUS_ACCESS_DENIED
+                raise CommandError("The authenticated user does "
+                                   "not have sufficient privileges")
+            else:
+                raise
+
+        for listelement in data.findall('listelement'):
+            adobject = listelement.find('adobject')
+            name_elm = adobject.find('name')
+            domain_elm = adobject.find('domain')
+            if name_elm is not None and name_elm.text == name and \
+               domain_elm is not None and domain_elm.text == domain:
+                data.remove(listelement)
+                break
+        else:
+            raise CommandError("Cannot remove %s entry because it does "
+                                   "not exist" % etype)
+
+        out = BytesIO()
+        xml_data.write(out, encoding='UTF-8', xml_declaration=True)
+        out.seek(0)
+        try:
+            create_directory_hier(conn, vgp_dir)
+            conn.savefile(vgp_xml, out.read())
+        except NTSTATUSError as e:
+            if e.args[0] == 0xC0000022: # STATUS_ACCESS_DENIED
+                raise CommandError("The authenticated user does "
+                                   "not have sufficient privileges")
+            raise
 
 class cmd_access(SuperCommand):
     """Manage Host Access Group Policy Objects"""
diff --git a/selftest/knownfail.d/gpo b/selftest/knownfail.d/gpo
deleted file mode 100644 (file)
index 837f9c7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba.tests.samba_tool.gpo_exts.samba.tests.samba_tool.gpo_exts.GpoCmdTestCase.test_vgp_access_list