summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2012-02-14 13:19:36 +1100
committerAmitay Isaacs <amitay@gmail.com>2012-02-21 18:24:30 +1100
commit4272a76075063a212c9a3b0454f69270799b3142 (patch)
tree7a5c6344b668078f8bde2fbc376e465af4c8f145 /source4
parent1fc2fb5de1862de36235c896d1c7c4000e3c0349 (diff)
downloadsamba-4272a76075063a212c9a3b0454f69270799b3142.tar.gz
samba-4272a76075063a212c9a3b0454f69270799b3142.tar.bz2
samba-4272a76075063a212c9a3b0454f69270799b3142.zip
samba-tool: dns: Convert dns data in a string to DNS record
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/python/samba/netcmd/dns.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/source4/scripting/python/samba/netcmd/dns.py b/source4/scripting/python/samba/netcmd/dns.py
index 9607cd92fd..b566a34159 100644
--- a/source4/scripting/python/samba/netcmd/dns.py
+++ b/source4/scripting/python/samba/netcmd/dns.py
@@ -471,6 +471,54 @@ class SRVRecord(dnsserver.DNS_RPC_RECORD):
srv.nameTarget.len = len(target)
self.data = srv
+
+# 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)
+ else:
+ raise CommandError('Unsupported record type')
+ return rec
+
+
# Match a dns record with specified data
def dns_record_match(dns_conn, server, zone, name, record_type, data):
select_flags = dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA