Skip to content

Commit

Permalink
samba-tool: dns: Convert dns data in a string to DNS record
Browse files Browse the repository at this point in the history
  • Loading branch information
amitay committed Feb 21, 2012
1 parent 1fc2fb5 commit 4272a76
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions source4/scripting/python/samba/netcmd/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,54 @@ def __init__(self, target, port, priority=0, weight=100, serial=1, ttl=900,
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
Expand Down

0 comments on commit 4272a76

Please sign in to comment.