From f88b7a076be74a29a3bf876b4e2705f4a1ecf42b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Oct 2007 14:16:54 -0700 Subject: This is a large patch (sorry). Migrate from struct in_addr to struct sockaddr_storage in most places that matter (ie. not the nmbd and NetBIOS lookups). This passes make test on an IPv4 box, but I'll have to do more work/testing on IPv6 enabled boxes. This should now give us a framework for testing and finishing the IPv6 migration. It's at the state where someone with a working IPv6 setup should (theorecically) be able to type : smbclient //ipv6-address/share and have it work. Jeremy. (This used to be commit 98e154c3125d5732c37a72d74b0eb5cd7b6155fd) --- source3/libsmb/namequery_dc.c | 75 +++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'source3/libsmb/namequery_dc.c') diff --git a/source3/libsmb/namequery_dc.c b/source3/libsmb/namequery_dc.c index 16d8414b8f..0fa4b93990 100644 --- a/source3/libsmb/namequery_dc.c +++ b/source3/libsmb/namequery_dc.c @@ -48,12 +48,13 @@ static bool is_our_primary_domain(const char *domain) static bool ads_dc_name(const char *domain, const char *realm, - struct in_addr *dc_ip, + struct sockaddr_storage *dc_ss, fstring srv_name) { ADS_STRUCT *ads; char *sitename; int i; + char addr[INET6_ADDRSTRLEN]; if (!realm && strequal(domain, lp_workgroup())) { realm = lp_realm(); @@ -107,12 +108,12 @@ static bool ads_dc_name(const char *domain, create_local_private_krb5_conf_for_domain(realm, domain, sitename, - ads->ldap.ip); + &ads->ldap.ss); } else { create_local_private_krb5_conf_for_domain(realm, domain, NULL, - ads->ldap.ip); + &ads->ldap.ss); } } #endif @@ -131,34 +132,36 @@ static bool ads_dc_name(const char *domain, fstrcpy(srv_name, ads->config.ldap_server_name); strupper_m(srv_name); #ifdef HAVE_ADS - *dc_ip = ads->ldap.ip; + *dc_ss = ads->ldap.ss; #else - ZERO_STRUCT(*dc_ip); + zero_addr(dc_ss,AF_INET); #endif ads_destroy(&ads); - + + print_sockaddr(addr, sizeof(addr), dc_ss); DEBUG(4,("ads_dc_name: using server='%s' IP=%s\n", - srv_name, inet_ntoa(*dc_ip))); - + srv_name, addr)); + return True; } /**************************************************************************** - Utility function to return the name of a DC. The name is guaranteed to be - valid since we have already done a name_status_find on it + Utility function to return the name of a DC. The name is guaranteed to be + valid since we have already done a name_status_find on it ***************************************************************************/ -static bool rpc_dc_name(const char *domain, fstring srv_name, struct in_addr *ip_out) +static bool rpc_dc_name(const char *domain, + fstring srv_name, + struct sockaddr_storage *ss_out) { struct ip_service *ip_list = NULL; - struct in_addr dc_ip, exclude_ip; + struct sockaddr_storage dc_ss; int count, i; NTSTATUS result; - - zero_ip_v4(&exclude_ip); + char addr[INET6_ADDRSTRLEN]; /* get a list of all domain controllers */ - + if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, NULL, &ip_list, &count, False))) { DEBUG(3, ("Could not look up dc's for domain %s\n", domain)); @@ -168,35 +171,34 @@ static bool rpc_dc_name(const char *domain, fstring srv_name, struct in_addr *ip /* Remove the entry we've already failed with (should be the PDC). */ for (i = 0; i < count; i++) { - if (is_zero_ip_v4(ip_list[i].ip)) + if (is_zero_addr(&ip_list[i].ss)) continue; - if (name_status_find(domain, 0x1c, 0x20, ip_list[i].ip, srv_name)) { + if (name_status_find(domain, 0x1c, 0x20, &ip_list[i].ss, srv_name)) { result = check_negative_conn_cache( domain, srv_name ); if ( NT_STATUS_IS_OK(result) ) { - dc_ip = ip_list[i].ip; + dc_ss = ip_list[i].ss; goto done; } } } - SAFE_FREE(ip_list); /* No-one to talk to )-: */ return False; /* Boo-hoo */ - + done: /* We have the netbios name and IP address of a domain controller. Ideally we should sent a SAMLOGON request to determine whether the DC is alive and kicking. If we can catch a dead DC before performing a cli_connect() we can avoid a 30-second timeout. */ + print_sockaddr(addr, sizeof(addr), &dc_ss); DEBUG(3, ("rpc_dc_name: Returning DC %s (%s) for domain %s\n", srv_name, - inet_ntoa(dc_ip), domain)); - - *ip_out = dc_ip; + addr, domain)); + *ss_out = dc_ss; SAFE_FREE(ip_list); return True; @@ -206,37 +208,40 @@ static bool rpc_dc_name(const char *domain, fstring srv_name, struct in_addr *ip wrapper around ads and rpc methods of finds DC's **********************************************************************/ -bool get_dc_name(const char *domain, const char *realm, fstring srv_name, struct in_addr *ip_out) +bool get_dc_name(const char *domain, + const char *realm, + fstring srv_name, + struct sockaddr_storage *ss_out) { - struct in_addr dc_ip; + struct sockaddr_storage dc_ss; bool ret; bool our_domain = False; - zero_ip_v4(&dc_ip); + zero_addr(&dc_ss, AF_INET); ret = False; - + if ( strequal(lp_workgroup(), domain) || strequal(lp_realm(), realm) ) our_domain = True; - - /* always try to obey what the admin specified in smb.conf + + /* always try to obey what the admin specified in smb.conf (for the local domain) */ - + if ( (our_domain && lp_security()==SEC_ADS) || realm ) { - ret = ads_dc_name(domain, realm, &dc_ip, srv_name); + ret = ads_dc_name(domain, realm, &dc_ss, srv_name); } if (!domain) { /* if we have only the realm we can't do anything else */ return False; } - + if (!ret) { /* fall back on rpc methods if the ADS methods fail */ - ret = rpc_dc_name(domain, srv_name, &dc_ip); + ret = rpc_dc_name(domain, srv_name, &dc_ss); } - - *ip_out = dc_ip; + + *ss_out = dc_ss; return ret; } -- cgit