From: Björn Baumbach Date: Thu, 15 Jun 2023 16:24:50 +0000 (+0200) Subject: samba-tool: add new --dns-directory-partition option to dns zonecreate command X-Git-Tag: talloc-2.4.1~313 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6640cf5e32fd8c0561aa8bb4a48fe0fc73740403;p=thirdparty%2Fsamba.git samba-tool: add new --dns-directory-partition option to dns zonecreate command The new --dns-directory-partition chooses the directory partition for the new zone - "domain" or "forest". Defaults to the current default "domain". Signed-off-by: Björn Baumbach Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Fri Jun 16 21:23:28 UTC 2023 on atb-devel-224 --- diff --git a/python/samba/netcmd/dns.py b/python/samba/netcmd/dns.py index d61f121b5b9..f10e67e0d4e 100644 --- a/python/samba/netcmd/dns.py +++ b/python/samba/netcmd/dns.py @@ -913,18 +913,35 @@ class cmd_zonecreate(Command): takes_options = [ Option('--client-version', help='Client Version', default='longhorn', metavar='w2k|dotnet|longhorn', - choices=['w2k', 'dotnet', 'longhorn'], dest='cli_ver') + choices=['w2k', 'dotnet', 'longhorn'], dest='cli_ver'), + Option('--dns-directory-partition', + help='Specify the naming context for the new zone, which ' + 'affects the replication scope (domain or forest wide ' + 'replication).', + default='domain', + metavar='domain|forest', + choices=['domain', 'forest'], + dest='dns_dp'), ] - def run(self, server, zone, cli_ver, sambaopts=None, credopts=None, + def run(self, + server, + zone, + cli_ver, + dns_dp, + sambaopts=None, + credopts=None, versionopts=None): - self.lp = sambaopts.get_loadparm() self.creds = credopts.get_credentials(self.lp) dns_conn = DnsConnWrapper(server, self.lp, self.creds) zone = zone.lower() + dns_directorypartition = dnsserver.DNS_DP_DOMAIN_DEFAULT + if dns_dp == 'forest': + dns_directorypartition = dnsserver.DNS_DP_FOREST_DEFAULT + client_version = dns_client_version(cli_ver) if client_version == dnsserver.DNS_CLIENT_VERSION_W2K: typeid = dnsserver.DNSSRV_TYPEID_ZONE_CREATE_W2K @@ -942,7 +959,7 @@ class cmd_zonecreate(Command): zone_create_info.fAging = 0 zone_create_info.fDsIntegrated = 1 zone_create_info.fLoadExisting = 1 - zone_create_info.dwDpFlags = dnsserver.DNS_DP_DOMAIN_DEFAULT + zone_create_info.dwDpFlags = dns_directorypartition else: typeid = dnsserver.DNSSRV_TYPEID_ZONE_CREATE zone_create_info = dnsserver.DNS_RPC_ZONE_CREATE_INFO_LONGHORN() @@ -951,7 +968,7 @@ class cmd_zonecreate(Command): zone_create_info.fAging = 0 zone_create_info.fDsIntegrated = 1 zone_create_info.fLoadExisting = 1 - zone_create_info.dwDpFlags = dnsserver.DNS_DP_DOMAIN_DEFAULT + zone_create_info.dwDpFlags = dns_directorypartition dns_conn.DnssrvOperation2(client_version, 0, server, None, 0, 'ZoneCreate', typeid, diff --git a/python/samba/tests/samba_tool/dnscmd.py b/python/samba/tests/samba_tool/dnscmd.py index 33492458be3..c36c4b535d0 100644 --- a/python/samba/tests/samba_tool/dnscmd.py +++ b/python/samba/tests/samba_tool/dnscmd.py @@ -1415,3 +1415,94 @@ class DnsCmdTestCase(SambaToolCmdTest): for s in output_substrings: self.assertIn(s, out) tsmap = new_tsmap + + def test_zonecreate_dns_domain_directory_partition(self): + zone = "test-dns-domain-dp-zone" + dns_dp_opt = "--dns-directory-partition=domain" + + result, out, err = self.runsubcmd("dns", + "zonecreate", + os.environ["SERVER"], + zone, + self.creds_string, + dns_dp_opt) + self.assertCmdSuccess(result, + out, + err, + "Failed to create zone with " + "--dns-directory-partition option") + self.assertTrue('Zone %s created successfully' % zone in out, + "Unexpected output: %s") + + result, out, err = self.runsubcmd("dns", + "zoneinfo", + os.environ["SERVER"], + zone, + self.creds_string) + self.assertCmdSuccess(result, out, err) + self.assertTrue("DNS_DP_DOMAIN_DEFAULT" in out, + "Missing DNS_DP_DOMAIN_DEFAULT flag") + + result, out, err = self.runsubcmd("dns", + "zonedelete", + os.environ["SERVER"], + zone, + self.creds_string) + self.assertCmdSuccess(result, out, err, + "Failed to delete zone in domain DNS directory " + "partition") + result, out, err = self.runsubcmd("dns", + "zonelist", + os.environ["SERVER"], + self.creds_string) + self.assertCmdSuccess(result, out, err, + "Failed to delete zone in domain DNS directory " + "partition") + self.assertTrue(zone not in out, + "Deleted zone still exists") + + def test_zonecreate_dns_forest_directory_partition(self): + zone = "test-dns-forest-dp-zone" + dns_dp_opt = "--dns-directory-partition=forest" + + result, out, err = self.runsubcmd("dns", + "zonecreate", + os.environ["SERVER"], + zone, + self.creds_string, + dns_dp_opt) + self.assertCmdSuccess(result, + out, + err, + "Failed to create zone with " + "--dns-directory-partition option") + self.assertTrue('Zone %s created successfully' % zone in out, + "Unexpected output: %s") + + result, out, err = self.runsubcmd("dns", + "zoneinfo", + os.environ["SERVER"], + zone, + self.creds_string) + self.assertCmdSuccess(result, out, err) + self.assertTrue("DNS_DP_FOREST_DEFAULT" in out, + "Missing DNS_DP_FOREST_DEFAULT flag") + + result, out, err = self.runsubcmd("dns", + "zonedelete", + os.environ["SERVER"], + zone, + self.creds_string) + self.assertCmdSuccess(result, out, err, + "Failed to delete zone in forest DNS directory " + "partition") + + result, out, err = self.runsubcmd("dns", + "zonelist", + os.environ["SERVER"], + self.creds_string) + self.assertCmdSuccess(result, out, err, + "Failed to delete zone in forest DNS directory " + "partition") + self.assertTrue(zone not in out, + "Deleted zone still exists")