Web lists-archives.com

Re: [Samba] samba-tool dns serverinfo command throws error




On 29/05/19 4:45 AM, James Atwell wrote:

>>> "/usr/local/samba/lib/python3.5/site-packages/samba/netcmd/dns.py", line
>>> 157, in dns_addr_array_string
>>>      addr = inet_ntop(AF_INET, x)
>>>
>>> I'm not experiencing any DNS issues so I believe this may be a bug with
>>> the move to python3 Am I correct?
>> Yes, you are very likely correct.
>>
>> Does the attached patch help?
>>
>> If you can confirm this at
>> https://bugzilla.samba.org/show_bug.cgi?id=13965
>> it can get into the next 4.10 release.
>>
>> Douglas
> 
> Douglas,
> 
>     Now I get the following error with the patch applied.
>  [...]

OK. THIS time I wrote a test, and it is running in CI.

Does this one help?

Douglas
>From 4e9fa1fca92a6542702e68bec3ca5c49ca4ec23c Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall@xxxxxxxxxxxxxxx>
Date: Fri, 24 May 2019 09:58:12 +1200
Subject: [PATCH] samba-tool dns: use bytes for inet_ntop

>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@xxxxxxxxxxxxxxx>
---
 python/samba/netcmd/dns.py         | 5 +++--
 selftest/knownfail.d/sambatool-dns | 1 -
 2 files changed, 3 insertions(+), 3 deletions(-)
 delete mode 100644 selftest/knownfail.d/sambatool-dns

diff --git a/python/samba/netcmd/dns.py b/python/samba/netcmd/dns.py
index b7459a71acd..d9fda0b93cd 100644
--- a/python/samba/netcmd/dns.py
+++ b/python/samba/netcmd/dns.py
@@ -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
index 382d740aa7c..00000000000
--- a/selftest/knownfail.d/sambatool-dns
+++ /dev/null
@@ -1 +0,0 @@
-samba.tests.samba_tool.dnscmd.samba.tests.samba_tool.dnscmd.DnsCmdTestCase.test_serverinfo
-- 
2.11.0

-- 
To unsubscribe from this list go to the following URL and read the
instructions:  https://lists.samba.org/mailman/options/samba