[PATCH] fix some parts of "samba-tool dns serverinfo ...."

Günter Kukkukk linux at kukkukk.com
Sun Nov 9 13:39:20 MST 2014


Am 09.11.2014 um 14:01 schrieb Jelmer Vernooij:
> On Sun, Nov 09, 2014 at 08:12:55AM +0100, Günter Kukkukk wrote:
>> The attached patch fixes the IPv6 related infos in
>>    samba-tool dns serverinfo <some-server>
>>
>> Due to many missing pieces in the samba code, the IPv6 info can
>> atm only be queried from MS servers:
>>
>> The obviously *wrong* IPv6 display:
>>   pszServerName               : w08r2.addlz.kukkukk.com
>>   pszDsContainer              : cn=MicrosoftDNS,cn=System,DC=addlz,DC=kukkukk,DC=com
>>   aipServerAddrs              : ['00:00:2a2:819:8f40:11e0:a1a2:fff8 (53)', '00:00:fd4d:e013:bb96:a6c:00:00 (53)', '00:00:fd4d:e013:bb96:a6c:a1a2:fff8
>> (53)', '00:00:fe80:00:00:00:a1a2:fff8 (53)', '192.168.200.81 (53)']
>>   aipListenAddrs              : ['00:00:fd4d:e013:bb96:a6c:00:00 (53)', '00:00:fe80:00:00:00:a1a2:fff8 (53)', '192.168.200.81 (53)']
>>   aipForwarders               : ['192.168.200.70 (53)']
>>
>> Fixed one:
>>
>>   pszServerName               : w08r2.addlz.kukkukk.com
>>   pszDsContainer              : cn=MicrosoftDNS,cn=System,DC=addlz,DC=kukkukk,DC=com
>>   aipServerAddrs              : ['2a02:8109:8f40:11e0:a1a2:fff8:4aa6:3613 (53)', 'fd4d:e013:bb96:a60c:0000:0000:0000:0051 (53)',
>> 'fd4d:e013:bb96:a60c:a1a2:fff8:4aa6:3613 (53)', 'fe80:0000:0000:0000:a1a2:fff8:4aa6:3613 (53)', '192.168.200.81 (53)']
>>   aipListenAddrs              : ['fd4d:e013:bb96:a60c:0000:0000:0000:0051 (53)', 'fe80:0000:0000:0000:a1a2:fff8:4aa6:3613 (53)', '192.168.200.81 (53)']
>>   aipForwarders               : ['192.168.200.70 (53)']
>>
>> There are atm many missing pieces in the samba code regarding
>>   - IPv4/IPv6 addresses available on the samba host
>>   - IPv4/IPv6 addresses which samba bound to
>>   - dynamically enable/disable bound interfaces
>>   - ...
>>
>> The code is all there, but the API looks really strange to me.
> We should really be using a standard formatting function for IPv6 addresses here.
> For example, fd4d:e013:bb96:a60c:0000:0000:0000:0051 really should be formatted as 
> fd4d:e013:bb96:a60c::51.
> 
> Cheers,
> 
> Jelmer
> 

Hi Jelmer,

i've a question regarding the somewhat special case
printing an IPv6 address when the available data
is passed in an array of bytes. (MS-DNSP)

Afaik the usual python procedure would be like:

File "tstipv6.py:
=================
#!/usr/bin/python

import os
import sys
import socket

for addr in sys.stdin:
  addr = addr.rstrip(os.linesep)

  try:
    internal = socket.inet_pton(socket.AF_INET6, addr)
    print socket.inet_ntop(socket.AF_INET6, internal)

  except socket.error:
    print "Invalid address " + addr

----------------------------------------------

echo '2001:db8:0:0:0:0:cafe:1111
2001:db8::a:1:2:3:4
2001:0DB8:AAAA:0000:0000:0000:0000:000C
2001:db8::1:0:0:0:4' | tstipv6.py

results to:
2001:db8::cafe:1111
2001:db8:0:a:1:2:3:4
2001:db8:aaaa::c
2001:db8:0:1::4

------------------------------------------------
But this approach cannot easily be used when the IPv6 data is passed
in as an array of bytes:
   print socket.inet_ntop(socket.AF_INET6, array_of_bytes)
or can that data be easily casted or converted?

The passed in data has the following format
struct DNS_ADDR {
        uint8_t MaxSa[32];
        uint32_t DnsAddrUserDword[8];
};

where MaxSa[32] is the array of bytes.
Offset | data
0:     | uint16_t  AddressFamily
2:     | uint16_t  PortNumber
4:     | uint32_t  IPv4Address
8:     | uint8_t   IPv6Address[16]
....

So the IPv6 address starts at MaxSa[8]

My python foo is too weak, so how would you program this?
Just a cast?

Cheers,  Günter

-----------------
PS - the info i found about that python API:

socket.inet_ntop(address_family, packed_ip)
    Convert a packed IP address (a string of some number of characters)
    to its standard, family-specific string representation
    (for example, '7.10.0.5' or '5aef:2b::8')
    inet_ntop() is useful when a library or network protocol returns an
    object of type struct in_addr (similar to inet_ntoa()) or struct in6_addr.

    Supported values for address_family are currently AF_INET and AF_INET6.
    If the string packed_ip is not the correct length for the specified address family,
    ValueError will be raised. A socket.error is raised for errors from the call to inet_ntop().

    Availability: Unix (maybe not all platforms).

    New in version 2.3.

-- 



More information about the samba-technical mailing list