diff options
author | Amitay Isaacs <amitay@gmail.com> | 2012-02-14 13:32:57 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@gmail.com> | 2012-02-21 18:24:30 +1100 |
commit | 28b12827b67a758652e9cc86b059a9af44e548f6 (patch) | |
tree | bde20ef12cb5d4c68700fd46e80bd5fbdd7c7d1c | |
parent | 4272a76075063a212c9a3b0454f69270799b3142 (diff) | |
download | samba-28b12827b67a758652e9cc86b059a9af44e548f6.tar.gz samba-28b12827b67a758652e9cc86b059a9af44e548f6.tar.bz2 samba-28b12827b67a758652e9cc86b059a9af44e548f6.zip |
samba-tool: dns: Convert dns data into a dns record for comparison
and compare two dns records directly. Refactor dns name comparision
as dns_name_equal().
-rw-r--r-- | source4/scripting/python/samba/netcmd/dns.py | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/source4/scripting/python/samba/netcmd/dns.py b/source4/scripting/python/samba/netcmd/dns.py index b566a34159..f1adc06faa 100644 --- a/source4/scripting/python/samba/netcmd/dns.py +++ b/source4/scripting/python/samba/netcmd/dns.py @@ -519,8 +519,15 @@ def data_to_dns_record(record_type, data): return rec +# Match dns name (of type DNS_RPC_NAME) +def dns_name_equal(n1, n2): + return n1.str.rstrip('.').lower() == n2.str.rstrip('.').lower() + + # Match a dns record with specified data def dns_record_match(dns_conn, server, zone, name, record_type, data): + urec = data_to_dns_record(record_type, data) + select_flags = dnsserver.DNS_RPC_VIEW_AUTHORITY_DATA try: @@ -547,19 +554,40 @@ def dns_record_match(dns_conn, server, zone, name, record_type, data): found = False if record_type == dnsp.DNS_TYPE_A: - if rec.data == data: + if rec.data == urec.data: found = True elif record_type == dnsp.DNS_TYPE_AAAA: - if rec.data == data: + if rec.data == urec.data: found = True elif record_type == dnsp.DNS_TYPE_PTR: - if rec.data.str.rstrip('.').lower() == data.rstrip('.').lower(): + if dns_name_equal(rec.data, urec.data): found = True elif record_type == dnsp.DNS_TYPE_CNAME: - if rec.data.str.rstrip('.').lower() == data.rstrip('.').lower(): + if dns_name_equal(rec.data, urec.data): found = True elif record_type == dnsp.DNS_TYPE_NS: - if rec.data.str.rstrip('.').lower() == data.rstrip('.').lower(): + if dns_name_equal(rec.data, urec.data): + found = True + elif record_type == dnsp.DNS_TYPE_MX: + if dns_name_equal(rec.data.nameExchange, urec.data.nameExchange) and \ + rec.data.wPreference == urec.data.wPreference: + found = True + elif record_type == dnsp.DNS_TYPE_SRV: + if rec.data.wPriority == urec.data.wPriority and \ + rec.data.wWeight == urec.data.wWeight and \ + rec.data.wPort == urec.data.wPort and \ + dns_name_equal(rec.data.nameTarget, urec.data.nameTarget): + found = True + elif record_type == dnsp.DNS_TYPE_SOA: + if rec.data.dwSerialNo == urec.data.dwSerialNo and \ + rec.data.dwRefresh == urec.data.dwRefresh and \ + rec.data.dwRetry == urec.data.dwRetry and \ + rec.data.dwExpire == urec.data.dwExpire and \ + rec.data.dwMinimumTtl == urec.data.dwMinimumTtl and \ + dns_name_equal(rec.data.NamePrimaryServer, + urec.data.NamePrimaryServer) and \ + dns_name_equal(rec.data.ZoneAdministratorEmail, + urec.data.ZoneAdministratorEmail): found = True if found: rec_match = rec |