From: Douglas Bagnall Date: Fri, 26 Mar 2021 07:41:29 +0000 (+1300) Subject: samba-tool dns: use dnsserver.record_from_string X-Git-Tag: tevent-0.11.0~1240 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87e71cd61168bbd6ed61484c98b84a72fb93482d;p=thirdparty%2Fsamba.git samba-tool dns: use dnsserver.record_from_string Signed-off-by: Douglas Bagnall Reviewed-by: Andreas Schneider --- diff --git a/python/samba/netcmd/dns.py b/python/samba/netcmd/dns.py index dd1cf474c0f..183cc3dae66 100644 --- a/python/samba/netcmd/dns.py +++ b/python/samba/netcmd/dns.py @@ -40,7 +40,7 @@ from samba.netcmd import ( ) from samba.dcerpc import dnsp, dnsserver -from samba.dnsserver import ARecord, AAAARecord, PTRRecord, CNAMERecord, NSRecord, MXRecord, SOARecord, SRVRecord, TXTRecord +from samba.dnsserver import record_from_string, DNSParseError def dns_connect(server, lp, creds): @@ -406,51 +406,11 @@ def print_dnsrecords(outf, records): # Convert data into a dns record def data_to_dns_record(record_type, data): - if record_type == dnsp.DNS_TYPE_A: - rec = ARecord(data) - elif record_type == dnsp.DNS_TYPE_AAAA: - rec = AAAARecord(data) - elif record_type == dnsp.DNS_TYPE_PTR: - rec = PTRRecord(data) - elif record_type == dnsp.DNS_TYPE_CNAME: - rec = CNAMERecord(data) - elif record_type == dnsp.DNS_TYPE_NS: - rec = NSRecord(data) - elif record_type == dnsp.DNS_TYPE_MX: - tmp = data.split() - if len(tmp) != 2: - raise CommandError('Data requires 2 elements - mail_server, preference') - mail_server = tmp[0] - preference = int(tmp[1]) - rec = MXRecord(mail_server, preference) - elif record_type == dnsp.DNS_TYPE_SRV: - tmp = data.split() - if len(tmp) != 4: - raise CommandError('Data requires 4 elements - server, port, priority, weight') - server = tmp[0] - port = int(tmp[1]) - priority = int(tmp[2]) - weight = int(tmp[3]) - rec = SRVRecord(server, port, priority=priority, weight=weight) - elif record_type == dnsp.DNS_TYPE_SOA: - tmp = data.split() - if len(tmp) != 7: - raise CommandError('Data requires 7 elements - nameserver, email, serial, ' - 'refresh, retry, expire, minimumttl') - nameserver = tmp[0] - email = tmp[1] - serial = int(tmp[2]) - refresh = int(tmp[3]) - retry = int(tmp[4]) - expire = int(tmp[5]) - minimum = int(tmp[6]) - rec = SOARecord(nameserver, email, serial=serial, refresh=refresh, - retry=retry, expire=expire, minimum=minimum) - elif record_type == dnsp.DNS_TYPE_TXT: - slist = shlex.split(data) - rec = TXTRecord(slist) - else: - raise CommandError('Unsupported record type') + try: + rec = record_from_string(record_type, data) + except DNSParseError as e: + raise CommandError(*e.args) from None + return rec