[PATCH] fix some parts of "samba-tool dns serverinfo ...."
Jelmer Vernooij
jelmer at samba.org
Sun Nov 9 15:14:54 MST 2014
On Sun, Nov 09, 2014 at 09:39:20PM +0100, Günter Kukkukk wrote:
> 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]
So, for starters, our Python bindings here are terrible. We should
actually be presenting them to the user in a way that they are familiar with.
So we should have a AddressFamily field, a portnumber field, an ipv4 address field
(that is a bytestring) and a ipv6 address field (that is also a bytestring).
That said, you can convert the byterray to a bytestring that inet_ntop
will understand by doing something like:
x = "".join([chr(b) for b in MaxSa])[8:]
print scoket.inet_ntop(socket.AF_INET6, x)
Hope this helps,
Jelmer
More information about the samba-technical
mailing list