The Samba-Bugzilla – Attachment 10451 Details for
Bug 10952
samba-tool dns serverinfo <server> is broken for IPv6 - also in mixed IPv4/IPv6 environments
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
fix all the missing C-related pieces
0003-Add-IPv6-support-to-samba-tool-dns-serverinfo-server.patch (text/plain), 11.58 KB, created by
Guenter Kukkukk
on 2014-11-23 03:54:13 UTC
(
hide
)
Description:
fix all the missing C-related pieces
Filename:
MIME Type:
Creator:
Guenter Kukkukk
Created:
2014-11-23 03:54:13 UTC
Size:
11.58 KB
patch
obsolete
>From d8a822b32962990f219f42d09006184a87d1175e Mon Sep 17 00:00:00 2001 >From: Guenter Kukkukk <linux@kukkukk.com> >Date: Fri, 21 Nov 2014 16:57:45 +0100 >Subject: [PATCH 3/3] Add IPv6 support to "samba-tool dns serverinfo <server>" > >In the initial implementation only IPv4 addresses were supported. >Add IPv6 (and mixed IPv4/IPv6) support and all further needed conversion >routines to support w2k, dotnet, longhorn clients. > >Signed-off-by: Guenter Kukkukk <linux@kukkukk.com> >--- > source4/rpc_server/dnsserver/dcerpc_dnsserver.c | 20 +++-- > source4/rpc_server/dnsserver/dnsdata.c | 56 +++++++++++++ > source4/rpc_server/dnsserver/dnsserver.h | 7 +- > source4/rpc_server/dnsserver/dnsutils.c | 104 ++++++++++++++++++------ > 4 files changed, 149 insertions(+), 38 deletions(-) > >diff --git a/source4/rpc_server/dnsserver/dcerpc_dnsserver.c b/source4/rpc_server/dnsserver/dcerpc_dnsserver.c >index 5162ab0..be31500 100644 >--- a/source4/rpc_server/dnsserver/dcerpc_dnsserver.c >+++ b/source4/rpc_server/dnsserver/dcerpc_dnsserver.c >@@ -202,8 +202,10 @@ static WERROR dnsserver_query_server(struct dnsserver_state *dsstate, > r->ServerInfoW2K->fDsAvailable = serverinfo->fDsAvailable; > r->ServerInfoW2K->pszServerName = talloc_strdup(mem_ctx, serverinfo->pszServerName); > r->ServerInfoW2K->pszDsContainer = talloc_strdup(mem_ctx, serverinfo->pszDsContainer); >- r->ServerInfoW2K->aipServerAddrs = ip4_array_copy(mem_ctx, serverinfo->aipServerAddrs); >- r->ServerInfoW2K->aipListenAddrs = ip4_array_copy(mem_ctx, serverinfo->aipListenAddrs); >+ r->ServerInfoW2K->aipServerAddrs = dns_addr_array_to_ip4_array(mem_ctx, >+ serverinfo->aipServerAddrs); >+ r->ServerInfoW2K->aipListenAddrs = dns_addr_array_to_ip4_array(mem_ctx, >+ serverinfo->aipListenAddrs); > r->ServerInfoW2K->aipForwarders = ip4_array_copy(mem_ctx, serverinfo->aipForwarders); > r->ServerInfoW2K->dwLogLevel = serverinfo->dwLogLevel; > r->ServerInfoW2K->dwDebugLevel = serverinfo->dwDebugLevel; >@@ -244,8 +246,10 @@ static WERROR dnsserver_query_server(struct dnsserver_state *dsstate, > r->ServerInfoDotNet->fDsAvailable = serverinfo->fDsAvailable; > r->ServerInfoDotNet->pszServerName = talloc_strdup(mem_ctx, serverinfo->pszServerName); > r->ServerInfoDotNet->pszDsContainer = talloc_strdup(mem_ctx, serverinfo->pszDsContainer); >- r->ServerInfoDotNet->aipServerAddrs = ip4_array_copy(mem_ctx, serverinfo->aipServerAddrs); >- r->ServerInfoDotNet->aipListenAddrs = ip4_array_copy(mem_ctx, serverinfo->aipListenAddrs); >+ r->ServerInfoDotNet->aipServerAddrs = dns_addr_array_to_ip4_array(mem_ctx, >+ serverinfo->aipServerAddrs); >+ r->ServerInfoDotNet->aipListenAddrs = dns_addr_array_to_ip4_array(mem_ctx, >+ serverinfo->aipListenAddrs); > r->ServerInfoDotNet->aipForwarders = ip4_array_copy(mem_ctx, serverinfo->aipForwarders); > r->ServerInfoDotNet->aipLogFilter = ip4_array_copy(mem_ctx, serverinfo->aipLogFilter); > r->ServerInfoDotNet->pwszLogFilePath = talloc_strdup(mem_ctx, serverinfo->pwszLogFilePath); >@@ -299,8 +303,8 @@ static WERROR dnsserver_query_server(struct dnsserver_state *dsstate, > r->ServerInfo->fDsAvailable = serverinfo->fDsAvailable; > r->ServerInfo->pszServerName = talloc_strdup(mem_ctx, serverinfo->pszServerName); > r->ServerInfo->pszDsContainer = talloc_strdup(mem_ctx, serverinfo->pszDsContainer); >- r->ServerInfo->aipServerAddrs = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipServerAddrs); >- r->ServerInfo->aipListenAddrs = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipListenAddrs); >+ r->ServerInfo->aipServerAddrs = serverinfo->aipServerAddrs; >+ r->ServerInfo->aipListenAddrs = serverinfo->aipListenAddrs; > r->ServerInfo->aipForwarders = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipForwarders); > r->ServerInfo->aipLogFilter = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipLogFilter); > r->ServerInfo->pwszLogFilePath = talloc_strdup(mem_ctx, serverinfo->pwszLogFilePath); >@@ -700,9 +704,9 @@ static WERROR dnsserver_query_server(struct dnsserver_state *dsstate, > is_addresses = 1; > } else if (strcasecmp(operation, "ListenAddresses") == 0) { > if (client_version == DNS_CLIENT_VERSION_LONGHORN) { >- answer_addrarray = ip4_array_to_dns_addr_array(mem_ctx, serverinfo->aipListenAddrs); >+ answer_addrarray = serverinfo->aipListenAddrs; > } else { >- answer_iparray = ip4_array_copy(mem_ctx, serverinfo->aipListenAddrs); >+ answer_iparray = dns_addr_array_to_ip4_array(mem_ctx, serverinfo->aipListenAddrs); > } > is_addresses = 1; > } else if (strcasecmp(operation, "BreakOnReceiveFrom") == 0) { >diff --git a/source4/rpc_server/dnsserver/dnsdata.c b/source4/rpc_server/dnsserver/dnsdata.c >index 2461a4b..067654a 100644 >--- a/source4/rpc_server/dnsserver/dnsdata.c >+++ b/source4/rpc_server/dnsserver/dnsdata.c >@@ -91,6 +91,62 @@ struct DNS_ADDR_ARRAY *ip4_array_to_dns_addr_array(TALLOC_CTX *mem_ctx, > return ret; > } > >+struct IP4_ARRAY *dns_addr_array_to_ip4_array(TALLOC_CTX *mem_ctx, >+ struct DNS_ADDR_ARRAY *ip) >+{ >+ struct IP4_ARRAY *ret; >+ int i, count, curr; >+ >+ if (ip == NULL) { >+ return NULL; >+ } >+ /* We must only return IPv4 addresses. >+ The passed DNS_ADDR_ARRAY may contain: >+ - only ipv4 addresses >+ - only ipv6 addresses >+ - a mixture of both >+ - an empty array >+ */ >+ ret = talloc_zero(mem_ctx, struct IP4_ARRAY); >+ if (!ret) { >+ return ret; >+ } >+ if (ip->AddrCount == 0 || ip->Family == AF_INET6) { >+ ret->AddrCount = 0; >+ return ret; >+ } >+ /* Now only ipv4 addresses or a mixture are left */ >+ count = 0; >+ for (i = 0; i < ip->AddrCount; i++) { >+ if (ip->AddrArray[i].MaxSa[0] == 0x02) { >+ /* Is ipv4 */ >+ count++; >+ } >+ } >+ if (count == 0) { >+ /* should not happen */ >+ ret->AddrCount = 0; >+ return ret; >+ } >+ ret->AddrArray = talloc_zero_array(mem_ctx, uint32_t, count); >+ if (ret->AddrArray) { >+ curr = 0; >+ for (i = 0; i < ip->AddrCount; i++) { >+ if (ip->AddrArray[i].MaxSa[0] == 0x02) { >+ /* Is ipv4 */ >+ memcpy(&ret->AddrArray[curr], >+ &ip->AddrArray[i].MaxSa[4], >+ sizeof(uint32_t)); >+ curr++; >+ } >+ } >+ } else { >+ talloc_free(ret); >+ return NULL; >+ } >+ ret->AddrCount = curr; >+ return ret; >+} > > struct DNS_ADDR_ARRAY *dns_addr_array_copy(TALLOC_CTX *mem_ctx, > struct DNS_ADDR_ARRAY *addr) >diff --git a/source4/rpc_server/dnsserver/dnsserver.h b/source4/rpc_server/dnsserver/dnsserver.h >index e3db0b2..cfe6d4e 100644 >--- a/source4/rpc_server/dnsserver/dnsserver.h >+++ b/source4/rpc_server/dnsserver/dnsserver.h >@@ -46,8 +46,8 @@ struct dnsserver_serverinfo { > char * pszDomainDirectoryPartition; > char * pszForestDirectoryPartition; > >- struct IP4_ARRAY * aipServerAddrs; >- struct IP4_ARRAY * aipListenAddrs; >+ struct DNS_ADDR_ARRAY * aipServerAddrs; >+ struct DNS_ADDR_ARRAY * aipListenAddrs; > struct IP4_ARRAY * aipForwarders; > > struct IP4_ARRAY * aipLogFilter; >@@ -179,6 +179,8 @@ struct dns_tree { > > struct IP4_ARRAY *ip4_array_copy(TALLOC_CTX *mem_ctx, struct IP4_ARRAY *ip4); > struct DNS_ADDR_ARRAY *ip4_array_to_dns_addr_array(TALLOC_CTX *mem_ctx, struct IP4_ARRAY *ip4); >+struct IP4_ARRAY *dns_addr_array_to_ip4_array(TALLOC_CTX *mem_ctx, >+ struct DNS_ADDR_ARRAY *ip); > struct DNS_ADDR_ARRAY *dns_addr_array_copy(TALLOC_CTX *mem_ctx, struct DNS_ADDR_ARRAY *addr); > > int dns_split_name_components(TALLOC_CTX *mem_ctx, const char *name, char ***components); >@@ -217,7 +219,6 @@ struct ldb_dn *dnsserver_name_to_dn(TALLOC_CTX *mem_ctx, struct dnsserver_zone * > const char *name); > uint32_t dnsserver_zone_to_request_filter(const char *zone); > >- > /* Database functions from dnsdb.c */ > > struct dnsserver_partition *dnsserver_db_enumerate_partitions(TALLOC_CTX *mem_ctx, >diff --git a/source4/rpc_server/dnsserver/dnsutils.c b/source4/rpc_server/dnsserver/dnsutils.c >index 9f95646..d71eda3 100644 >--- a/source4/rpc_server/dnsserver/dnsutils.c >+++ b/source4/rpc_server/dnsserver/dnsutils.c >@@ -24,7 +24,76 @@ > #include "rpc_server/common/common.h" > #include "dsdb/samdb/samdb.h" > #include "lib/socket/netif.h" >+#include "lib/util/util_net.h" > >+static struct DNS_ADDR_ARRAY *fill_dns_addr_array(TALLOC_CTX *mem_ctx, >+ struct loadparm_context *lp_ctx, >+ bool listen_only) >+{ >+ struct interface *ifaces; >+ int num_interfaces, i; >+ struct DNS_ADDR_ARRAY *dns_addr_array; >+ const char *ipstr; >+ bool have_ipv4, have_ipv6; >+ uint16_t family; >+ >+ have_ipv4 = have_ipv6 = false; >+ >+ if (!listen_only) { >+ /* >+ Return all interfaces from kernel >+ Not implemented! >+ */ >+ return NULL; >+ } >+ >+ /* Only the used interfaces */ >+ load_interface_list(mem_ctx, lp_ctx, &ifaces); >+ num_interfaces = iface_list_count(ifaces); >+ >+ dns_addr_array = talloc_zero(mem_ctx, struct DNS_ADDR_ARRAY); >+ if (dns_addr_array == NULL) { >+ goto nomem; >+ } >+ dns_addr_array->MaxCount = num_interfaces; >+ dns_addr_array->AddrCount = num_interfaces; >+ if (num_interfaces > 0) { >+ dns_addr_array->AddrArray = >+ talloc_zero_array(mem_ctx, struct DNS_ADDR, >+ num_interfaces); >+ if (dns_addr_array->AddrArray) { >+ for (i = 0; i < num_interfaces; i++) { >+ ipstr = iface_list_n_ip(ifaces, i); >+ if (is_ipaddress_v4(ipstr)) { >+ have_ipv4 = true; >+ dns_addr_array->AddrArray[i].MaxSa[0] = 0x02; >+ inet_pton(AF_INET, ipstr, >+ &dns_addr_array->AddrArray[i].MaxSa[4]); >+ } else { >+ have_ipv6 = true; >+ dns_addr_array->AddrArray[i].MaxSa[0] = 0x17; >+ inet_pton(AF_INET6, ipstr, >+ &dns_addr_array->AddrArray[i].MaxSa[8]); >+ } >+ } >+ if (have_ipv4 && have_ipv6) { >+ family = 0; /* mixed: MS-DNSP */ >+ } else if (have_ipv4 && !have_ipv6) { >+ family = AF_INET; >+ } else { >+ family = AF_INET6; >+ } >+ dns_addr_array->Family = family; >+ } else { >+ talloc_free(ifaces); >+ talloc_free(dns_addr_array); >+ return NULL; >+ } >+ } >+nomem: >+ talloc_free(ifaces); >+ return dns_addr_array; >+} > > struct dnsserver_serverinfo *dnsserver_init_serverinfo(TALLOC_CTX *mem_ctx, > struct loadparm_context *lp_ctx, >@@ -33,8 +102,6 @@ struct dnsserver_serverinfo *dnsserver_init_serverinfo(TALLOC_CTX *mem_ctx, > struct dnsserver_serverinfo *serverinfo; > struct dcerpc_server_info *dinfo; > struct ldb_dn *domain_dn, *forest_dn; >- struct interface *ifaces; >- int num_interfaces, i; > > serverinfo = talloc_zero(mem_ctx, struct dnsserver_serverinfo); > if (serverinfo == NULL) { >@@ -80,31 +147,14 @@ struct dnsserver_serverinfo *dnsserver_init_serverinfo(TALLOC_CTX *mem_ctx, > serverinfo->pszForestDirectoryPartition = talloc_asprintf(mem_ctx, > "DC=ForestDnsZones,%s", > ldb_dn_get_linearized(forest_dn)); >- >- load_interface_list(mem_ctx, lp_ctx, &ifaces); >- num_interfaces = iface_list_count(ifaces); >- >- serverinfo->aipServerAddrs = talloc_zero(mem_ctx, struct IP4_ARRAY); >- >- if (serverinfo->aipServerAddrs) { >- serverinfo->aipServerAddrs->AddrCount = num_interfaces; >- if (num_interfaces > 0) { >- serverinfo->aipServerAddrs->AddrArray = talloc_zero_array(mem_ctx, >- unsigned int, >- num_interfaces); >- if (serverinfo->aipServerAddrs->AddrArray) { >- for (i=0; i<num_interfaces; i++) { >- serverinfo->aipServerAddrs->AddrArray[i] = inet_addr(iface_list_n_ip(ifaces, i)); >- } >- } else { >- serverinfo->aipServerAddrs->AddrCount = 0; >- } >- } >- } >- talloc_free(ifaces); >- >- /* Assume listen addresses are same as server addresses */ >- serverinfo->aipListenAddrs = serverinfo->aipServerAddrs; >+ /* IP addresses on which the DNS server listens for DNS requests */ >+ serverinfo->aipListenAddrs = fill_dns_addr_array(mem_ctx, lp_ctx, true); >+ >+ /* All IP addresses available on the server >+ * Not implemented! >+ * Use same as listen addresses >+ */ >+ serverinfo->aipServerAddrs = serverinfo->aipListenAddrs; > > serverinfo->aipForwarders = NULL; > >-- >1.8.4.5 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 10952
:
10449
|
10450
|
10451
|
10461
|
10462