samba-tool dns: use bytes for inet_ntop
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 23 May 2019 21:58:12 +0000 (09:58 +1200)
committerNoel Power <npower@samba.org>
Wed, 29 May 2019 11:29:17 +0000 (11:29 +0000)
From Python's point of view, array.AddrArray is a list of byte-valued
integers. In Python 3 we can convert directly using the likes of

         bytes(array.AddrArray[i].MaxSa[8:24])

but in 4.10 we need to support both, so we use struct.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <npower@samba.org>
Autobuild-User(master): Noel Power <npower@samba.org>
Autobuild-Date(master): Wed May 29 11:29:17 UTC 2019 on sn-devel-184

python/samba/netcmd/dns.py
selftest/knownfail.d/sambatool-dns [deleted file]

index b7459a71acd9d5b340f167059b23c7420e1ad7f1..d9fda0b93cdc1cf58eb02f748a0f4170e52cb870 100644 (file)
@@ -26,6 +26,7 @@ from socket import inet_ntop
 from socket import AF_INET
 from socket import AF_INET6
 import shlex
+import struct
 
 from samba import remove_dc
 from samba.samdb import SamDB
@@ -153,10 +154,10 @@ def dns_addr_array_string(array):
         return ret
     for i in range(array.AddrCount):
         if array.AddrArray[i].MaxSa[0] == 0x02:
-            x = "".join([chr(b) for b in array.AddrArray[i].MaxSa])[4:8]
+            x = struct.pack('4B', *array.AddrArray[i].MaxSa[4:8])
             addr = inet_ntop(AF_INET, x)
         elif array.AddrArray[i].MaxSa[0] == 0x17:
-            x = "".join([chr(b) for b in array.AddrArray[i].MaxSa])[8:24]
+            x = struct.pack('16B', *array.AddrArray[i].MaxSa[8:24])
             addr = inet_ntop(AF_INET6, x)
         else:
             addr = 'UNKNOWN'
diff --git a/selftest/knownfail.d/sambatool-dns b/selftest/knownfail.d/sambatool-dns
deleted file mode 100644 (file)
index 382d740..0000000
+++ /dev/null
@@ -1 +0,0 @@
-samba.tests.samba_tool.dnscmd.samba.tests.samba_tool.dnscmd.DnsCmdTestCase.test_serverinfo