]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool dns: update_record uses DnsConnWrapper
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 17 Aug 2022 21:21:39 +0000 (09:21 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 6 Sep 2022 21:12:36 +0000 (21:12 +0000)
The special thing about this one is the dns_conn is also used in the
dns_record_match() library function, which wants a real dns
connection.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/dns.py

index b7402f9979be34e20d5020180b29e9ab23e6091f..0da55c6898e49b3198aa678d4e57ad79cc89d068 100644 (file)
@@ -1214,11 +1214,11 @@ class cmd_update_record(Command):
 
         self.lp = sambaopts.get_loadparm()
         self.creds = credopts.get_credentials(self.lp)
-        dns_conn = dns_connect(server, self.lp, self.creds)
+        dns_conn = DnsConnWrapper(server, self.lp, self.creds)
 
         try:
-            rec_match = dns_record_match(dns_conn, server, zone, name, record_type,
-                                         olddata)
+            rec_match = dns_record_match(dns_conn.dns_conn, server, zone,
+                                         name, record_type, olddata)
         except DNSParseError as e:
             raise CommandError(*e.args) from None
 
@@ -1237,18 +1237,19 @@ class cmd_update_record(Command):
         del_rec_buf = dnsserver.DNS_RPC_RECORD_BUF()
         del_rec_buf.rec = rec_match
 
-        try:
-            dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
-                                         0,
-                                         server,
-                                         zone,
-                                         name,
-                                         add_rec_buf,
-                                         del_rec_buf)
-        except WERRORError as e:
-            if e.args[0] == werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST:
-                raise CommandError('Zone does not exist; record could not be updated.')
-            raise e
+        messages = {
+            werror.WERR_DNS_ERROR_NAME_DOES_NOT_EXIST: (
+                f'Zone {zone} does not exist; record could not be updated.'),
+        }
+
+        dns_conn.DnssrvUpdateRecord2(dnsserver.DNS_CLIENT_VERSION_LONGHORN,
+                                     0,
+                                     server,
+                                     zone,
+                                     name,
+                                     add_rec_buf,
+                                     del_rec_buf,
+                                     messages=messages)
 
         self.outf.write('Record updated successfully\n')