From 5693e6c599a586b1bb19eea375c6b1e22526031c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 24 Aug 2006 15:43:32 +0000 Subject: r17798: Beginnings of a standalone libaddns library released under the LGPL. Original code by Krishna Ganugapati . Additional work by me. It's still got some warts, but non-secure updates do currently work. There are at least four things left to really clean up. 1. Change the memory management to use talloc() rather than malloc() and cleanup the leaks. 2. Fix the error code reporting (see initial changes to dnserr.h) 3. Fix the secure updates 4. Define a public interface in addns.h 5. Move the code in libads/dns.c into the libaddns/ directory (and under the LGPL). A few notes: * Enable the new code by compiling with --with-dnsupdate * Also adds the command 'net ads dns register' * Requires -luuid (included in the e2fsprogs-devel package). * Has only been tested on Linux platforms so there may be portability issues. (This used to be commit 36f04674aeefd93c5a0408b8967dcd48b86fdbc1) --- source3/utils/net_dns.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 source3/utils/net_dns.c (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c new file mode 100644 index 0000000000..873eda377e --- /dev/null +++ b/source3/utils/net_dns.c @@ -0,0 +1,99 @@ + +/* + Samba Unix/Linux Dynamic DNS Update + net ads commands + + Copyright (C) Krishna Ganugapati (krishnag@centeris.com) 2006 + Copyright (C) Gerald Carter 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "utils/net.h" +#include "dns.h" + +#if defined(WITH_DNS_UPDATES) + +/********************************************************************* +*********************************************************************/ + +int DoDNSUpdate( char *pszServerName, char *pszDomainName, + char *pszHostName, struct in_addr *iplist, int num_addrs ) +{ + int32 dwError = 0; + DNS_ERROR dns_status; + HANDLE hDNSServer = ( HANDLE ) NULL; + int32 dwResponseCode = 0; + DNS_UPDATE_RESPONSE *pDNSUpdateResponse = NULL; +#if 0 + DNS_UPDATE_RESPONSE *pDNSSecureUpdateResponse = NULL; +#endif + + if ( (num_addrs <= 0) || !iplist ) { + return -1; + } + + dns_status = DNSOpen( pszServerName, DNS_TCP, &hDNSServer ); + BAIL_ON_DNS_ERROR( dns_status ); + + dwError = DNSSendUpdate( hDNSServer, pszDomainName, pszHostName, + iplist, num_addrs, &pDNSUpdateResponse ); + BAIL_ON_ERROR( dwError ); + + dwError = DNSUpdateGetResponseCode( pDNSUpdateResponse, + &dwResponseCode ); + if ( dwResponseCode == DNS_REFUSED ) { + dwError = -1; + } + BAIL_ON_ERROR( dwError ); + +cleanup: + return dwError; + +error: + goto cleanup; +} + +/********************************************************************* +*********************************************************************/ + +int get_my_ip_address( struct in_addr **ips ) +{ + struct iface_struct nics[MAX_INTERFACES]; + int i, n; + struct in_addr loopback_ip = *interpret_addr2("127.0.0.1"); + struct in_addr *list; + int count = 0; + + /* find the first non-loopback address from our list of interfaces */ + + n = get_interfaces(nics, MAX_INTERFACES); + + if ( (list = SMB_MALLOC_ARRAY( struct in_addr, n )) == NULL ) { + return -1; + } + + for ( i=0; i Date: Sun, 3 Sep 2006 21:07:16 +0000 Subject: r18019: Fix a C++ warnings: Don't use void * in libads/ for LDAPMessage anymore. Compiled it on systems with and without LDAP, I hope it does not break the build farm too badly. If it does, I'll fix it tomorrow. Volker (This used to be commit b2ff9680ebe0979fbeef7f2dabc2e3f27c959d11) --- source3/utils/net_dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 873eda377e..cb83b000ca 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -30,7 +30,7 @@ /********************************************************************* *********************************************************************/ -int DoDNSUpdate( char *pszServerName, char *pszDomainName, +int DoDNSUpdate( char *pszServerName, const char *pszDomainName, char *pszHostName, struct in_addr *iplist, int num_addrs ) { int32 dwError = 0; -- cgit From c2aae726ea3f697c50f8d2304e2a9e69c56ab90f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 17 Nov 2006 21:46:26 +0000 Subject: r19762: libaddns/*[ch] code fixes donated by Centeris Corporation (http://www.centeris.com/) under my copyright. * Rework error reporting to use DNS_ERROR instead of int32 * Convert memory allocation to use talloc() * Generalize the DNS request/response packet marshalling * Fix the secure update requests (This used to be commit c78798333616c3f823514df0f58da2eb3a30a988) --- source3/utils/net_dns.c | 141 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 24 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index cb83b000ca..d372211a5f 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -30,41 +30,115 @@ /********************************************************************* *********************************************************************/ -int DoDNSUpdate( char *pszServerName, const char *pszDomainName, - char *pszHostName, struct in_addr *iplist, int num_addrs ) +DNS_ERROR DoDNSUpdate(ADS_STRUCT *ads, char *pszServerName, + const char *pszDomainName, const char *pszHostName, + const struct in_addr *iplist, int num_addrs ) { - int32 dwError = 0; - DNS_ERROR dns_status; - HANDLE hDNSServer = ( HANDLE ) NULL; - int32 dwResponseCode = 0; - DNS_UPDATE_RESPONSE *pDNSUpdateResponse = NULL; -#if 0 - DNS_UPDATE_RESPONSE *pDNSSecureUpdateResponse = NULL; -#endif + DNS_ERROR err; + struct dns_connection *conn; + TALLOC_CTX *mem_ctx; + OM_uint32 minor; + struct dns_update_request *req, *resp; if ( (num_addrs <= 0) || !iplist ) { - return -1; + return ERROR_DNS_INVALID_PARAMETER; + } + + if (!(mem_ctx = talloc_init("DoDNSUpdate"))) { + return ERROR_DNS_NO_MEMORY; } - dns_status = DNSOpen( pszServerName, DNS_TCP, &hDNSServer ); - BAIL_ON_DNS_ERROR( dns_status ); + err = dns_open( pszServerName, DNS_TCP, mem_ctx, &conn ); + if (!ERR_DNS_IS_OK(err)) { + goto error; + } + + /* + * Probe if everything's fine + */ + + err = dns_create_probe(mem_ctx, pszDomainName, pszHostName, + num_addrs, iplist, &req); + if (!ERR_DNS_IS_OK(err)) goto error; + + err = dns_update_transaction(mem_ctx, conn, req, &resp); + if (!ERR_DNS_IS_OK(err)) goto error; + + if (dns_response_code(resp->flags) == DNS_NO_ERROR) { + TALLOC_FREE(mem_ctx); + return ERROR_DNS_SUCCESS; + } + + /* + * First try without signing + */ - dwError = DNSSendUpdate( hDNSServer, pszDomainName, pszHostName, - iplist, num_addrs, &pDNSUpdateResponse ); - BAIL_ON_ERROR( dwError ); + err = dns_create_update_request(mem_ctx, pszDomainName, pszHostName, + iplist[0].s_addr, &req); + if (!ERR_DNS_IS_OK(err)) goto error; - dwError = DNSUpdateGetResponseCode( pDNSUpdateResponse, - &dwResponseCode ); - if ( dwResponseCode == DNS_REFUSED ) { - dwError = -1; + err = dns_update_transaction(mem_ctx, conn, req, &resp); + if (!ERR_DNS_IS_OK(err)) goto error; + + if (dns_response_code(resp->flags) == DNS_NO_ERROR) { + TALLOC_FREE(mem_ctx); + return ERROR_DNS_SUCCESS; + } + + /* + * Okay, we have to try with signing + */ + { + ADS_STRUCT *ads_s; + gss_ctx_id_t gss_context; + int res; + char *keyname; + + if (!(keyname = dns_generate_keyname( mem_ctx ))) { + err = ERROR_DNS_NO_MEMORY; + goto error; + } + + if (!(ads_s = ads_init(ads->server.realm, ads->server.workgroup, + ads->server.ldap_server))) { + return ERROR_DNS_NO_MEMORY; + } + + /* kinit with the machine password */ + setenv(KRB5_ENV_CCNAME, "MEMORY:net_ads", 1); + asprintf( &ads_s->auth.user_name, "%s$", global_myname() ); + ads_s->auth.password = secrets_fetch_machine_password( + lp_workgroup(), NULL, NULL ); + ads_s->auth.realm = SMB_STRDUP( lp_realm() ); + res = ads_kinit_password( ads_s ); + ads_destroy(&ads_s); + if (res) { + err = ERROR_DNS_GSS_ERROR; + goto error; + } + + err = dns_negotiate_sec_ctx( pszDomainName, pszServerName, + keyname, &gss_context ); + if (!ERR_DNS_IS_OK(err)) goto error; + + err = dns_sign_update(req, gss_context, keyname, + "gss.microsoft.com", time(NULL), 3600); + + gss_delete_sec_context(&minor, &gss_context, GSS_C_NO_BUFFER); + + if (!ERR_DNS_IS_OK(err)) goto error; + + err = dns_update_transaction(mem_ctx, conn, req, &resp); + if (!ERR_DNS_IS_OK(err)) goto error; + + err = (dns_response_code(resp->flags) == DNS_NO_ERROR) ? + ERROR_DNS_SUCCESS : ERROR_DNS_UPDATE_FAILED; } - BAIL_ON_ERROR( dwError ); -cleanup: - return dwError; error: - goto cleanup; + TALLOC_FREE(mem_ctx); + return err; } /********************************************************************* @@ -96,4 +170,23 @@ int get_my_ip_address( struct in_addr **ips ) return count; } +DNS_ERROR do_gethostbyname(const char *server, const char *host) +{ + struct dns_connection *conn; + struct dns_request *req, *resp; + DNS_ERROR err; + + err = dns_open(server, DNS_UDP, NULL, &conn); + if (!ERR_DNS_IS_OK(err)) goto error; + + err = dns_create_query(conn, host, QTYPE_A, DNS_CLASS_IN, &req); + if (!ERR_DNS_IS_OK(err)) goto error; + + err = dns_transaction(conn, conn, req, &resp); + + error: + TALLOC_FREE(conn); + return err; +} + #endif /* defined(WITH_DNS_UPDATES) */ -- cgit From d879aa8f3617b256a16889d04a39a25b27f5bb39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 14 Dec 2006 16:27:45 +0000 Subject: r20170: Fix secure DNS updates to work against Wnidows 2000 DNS which expects the TKEY payload to be in the answer section and not in the additional set of records (like Windows 2003 and the RFC). (This used to be commit a3b6734fdad5fd92dbec075ebcd8d7044aac45c2) --- source3/utils/net_dns.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index d372211a5f..81d7dd596a 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -118,8 +118,18 @@ DNS_ERROR DoDNSUpdate(ADS_STRUCT *ads, char *pszServerName, } err = dns_negotiate_sec_ctx( pszDomainName, pszServerName, - keyname, &gss_context ); - if (!ERR_DNS_IS_OK(err)) goto error; + keyname, &gss_context, DNS_SRV_ANY ); + + /* retry using the Windows 2000 DNS hack */ + if (!ERR_DNS_IS_OK(err)) { + err = dns_negotiate_sec_ctx( pszDomainName, pszServerName, + keyname, &gss_context, + DNS_SRV_WIN2000 ); + } + + if (!ERR_DNS_IS_OK(err)) + goto error; + err = dns_sign_update(req, gss_context, keyname, "gss.microsoft.com", time(NULL), 3600); -- cgit From db7bf9a6b6754b604ee44d28c564bab10c7b98a7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 14 Dec 2006 17:00:10 +0000 Subject: r20173: DNS update fixes: * Fix DNS updates for multi-homed hosts * Child domains often don't have an NS record in DNS so we have to fall back to looking up the the NS records for the forest root. * Fix compile warning caused by mismatched 'struct in_addr' and 'in_addr_t' parameters called to DoDNSUpdate() (This used to be commit 3486acd3c3ebefae8f98dcc72d1c3d6b06fffcc7) --- source3/utils/net_dns.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 81d7dd596a..16f50ae4cd 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -30,9 +30,9 @@ /********************************************************************* *********************************************************************/ -DNS_ERROR DoDNSUpdate(ADS_STRUCT *ads, char *pszServerName, +DNS_ERROR DoDNSUpdate(char *pszServerName, const char *pszDomainName, const char *pszHostName, - const struct in_addr *iplist, int num_addrs ) + const struct in_addr *iplist, size_t num_addrs ) { DNS_ERROR err; struct dns_connection *conn; @@ -74,7 +74,7 @@ DNS_ERROR DoDNSUpdate(ADS_STRUCT *ads, char *pszServerName, */ err = dns_create_update_request(mem_ctx, pszDomainName, pszHostName, - iplist[0].s_addr, &req); + iplist, num_addrs, &req); if (!ERR_DNS_IS_OK(err)) goto error; err = dns_update_transaction(mem_ctx, conn, req, &resp); @@ -89,9 +89,7 @@ DNS_ERROR DoDNSUpdate(ADS_STRUCT *ads, char *pszServerName, * Okay, we have to try with signing */ { - ADS_STRUCT *ads_s; gss_ctx_id_t gss_context; - int res; char *keyname; if (!(keyname = dns_generate_keyname( mem_ctx ))) { @@ -99,24 +97,6 @@ DNS_ERROR DoDNSUpdate(ADS_STRUCT *ads, char *pszServerName, goto error; } - if (!(ads_s = ads_init(ads->server.realm, ads->server.workgroup, - ads->server.ldap_server))) { - return ERROR_DNS_NO_MEMORY; - } - - /* kinit with the machine password */ - setenv(KRB5_ENV_CCNAME, "MEMORY:net_ads", 1); - asprintf( &ads_s->auth.user_name, "%s$", global_myname() ); - ads_s->auth.password = secrets_fetch_machine_password( - lp_workgroup(), NULL, NULL ); - ads_s->auth.realm = SMB_STRDUP( lp_realm() ); - res = ads_kinit_password( ads_s ); - ads_destroy(&ads_s); - if (res) { - err = ERROR_DNS_GSS_ERROR; - goto error; - } - err = dns_negotiate_sec_ctx( pszDomainName, pszServerName, keyname, &gss_context, DNS_SRV_ANY ); -- cgit From 62382d19e9d31177679fc0e89c16b95b1c35cbef Mon Sep 17 00:00:00 2001 From: James Peach Date: Sun, 31 Dec 2006 06:50:44 +0000 Subject: r20428: Rename dns_open. This conflicts with the dns_open symbol in libSystem on Mac OS X. (This used to be commit 2117904f18869fca0d4770883cf2de5fb00c4f85) --- source3/utils/net_dns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 16f50ae4cd..cd779bf2c3 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -48,7 +48,7 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, return ERROR_DNS_NO_MEMORY; } - err = dns_open( pszServerName, DNS_TCP, mem_ctx, &conn ); + err = dns_open_connection( pszServerName, DNS_TCP, mem_ctx, &conn ); if (!ERR_DNS_IS_OK(err)) { goto error; } @@ -166,7 +166,7 @@ DNS_ERROR do_gethostbyname(const char *server, const char *host) struct dns_request *req, *resp; DNS_ERROR err; - err = dns_open(server, DNS_UDP, NULL, &conn); + err = dns_open_connection(server, DNS_UDP, NULL, &conn); if (!ERR_DNS_IS_OK(err)) goto error; err = dns_create_query(conn, host, QTYPE_A, DNS_CLASS_IN, &req); -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/net_dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index cd779bf2c3..cacd93fa27 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/utils/net_dns.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index cacd93fa27..fed5fa556e 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 5e066d5ee1b2e8d15a7af80313eb2b622a511b00 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 25 Jul 2007 18:45:57 +0000 Subject: r24047: With -Wmissing-prototypes these two always generate warnings. They should be properly prototyped. For now, gloss over the warning. (This used to be commit 2137158260cc9677bf9652a3d85334b0d7512b7b) --- source3/utils/net_dns.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index fed5fa556e..6163f53c6e 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -26,6 +26,14 @@ #if defined(WITH_DNS_UPDATES) +/* + * Silly prototype to get rid of a warning + */ + +DNS_ERROR DoDNSUpdate(char *pszServerName, + const char *pszDomainName, const char *pszHostName, + const struct in_addr *iplist, size_t num_addrs ); + /********************************************************************* *********************************************************************/ @@ -159,6 +167,12 @@ int get_my_ip_address( struct in_addr **ips ) return count; } +/* + * Silly prototype to get rid of a warning + */ + +DNS_ERROR do_gethostbyname(const char *server, const char *host); + DNS_ERROR do_gethostbyname(const char *server, const char *host) { struct dns_connection *conn; -- cgit From 3fbd1ae54ced2eb889a8fe0a6ea32dfd8175f941 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 Oct 2007 19:27:25 +0000 Subject: r25472: Fix the interfaces code to detect IPv6 interfaces, using the new standard getifaddrs() and freeifaddrs() interfaces. Currently we only return IPv4 af_families. Needs fixing for binds to IPv6 but this has to be careful work. Jeremy. (This used to be commit 327875182c9219aeba687e10aaea93546d9a70ea) --- source3/utils/net_dns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 6163f53c6e..e1993488f5 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -158,8 +158,8 @@ int get_my_ip_address( struct in_addr **ips ) } for ( i=0; i Date: Wed, 10 Oct 2007 18:25:16 -0700 Subject: Add start of IPv6 implementation. Currently most of this is avoiding IPv6 in winbindd, but moves most of the socket functions that were wrongly in lib/util.c into lib/util_sock.c and provides generic IPv4/6 independent versions of most things. Still lots of work to do, but now I can see how I'll fix the access check code. Nasty part that remains is the name resolution code which is used to returning arrays of in_addr structs. Jeremy. (This used to be commit 3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08) --- source3/utils/net_dns.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index e1993488f5..716192b057 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -145,7 +145,6 @@ int get_my_ip_address( struct in_addr **ips ) { struct iface_struct nics[MAX_INTERFACES]; int i, n; - struct in_addr loopback_ip = *interpret_addr2("127.0.0.1"); struct in_addr *list; int count = 0; @@ -158,7 +157,7 @@ int get_my_ip_address( struct in_addr **ips ) } for ( i=0; i Date: Fri, 12 Oct 2007 11:37:03 +0200 Subject: Fix the build WITH_DNS_UPDATES. Jeremy, please have a look. Guenther (This used to be commit 4dfda879a3ad44be7008702b9fbefe3858436118) --- source3/utils/net_dns.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 716192b057..8b82a96892 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -157,8 +157,14 @@ int get_my_ip_address( struct in_addr **ips ) } for ( i=0; isin_addr; + + if (!is_loopback_ip_v4(ifip)) { + memcpy(&list[count++], &ifip, sizeof(struct in_addr)); + } } } *ips = list; -- cgit From 7ca33d1112f415a41ed48be02a7f732a2c640ff7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Jan 2008 13:11:12 -0800 Subject: Move the DNS tsig update to using struct sockaddr_storage from struct in_addr. Still only does IPv4 updates but now it'll be easy to add IPv6 when we have time. Jeremy. (This used to be commit ac3a433befca2c6b674fc7e7f2f2c700d78b0a0c) --- source3/utils/net_dns.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 8b82a96892..c661c77ce6 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -32,14 +32,14 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, const char *pszDomainName, const char *pszHostName, - const struct in_addr *iplist, size_t num_addrs ); + const struct sockaddr_storage *sslist, size_t num_addrs ); /********************************************************************* *********************************************************************/ DNS_ERROR DoDNSUpdate(char *pszServerName, const char *pszDomainName, const char *pszHostName, - const struct in_addr *iplist, size_t num_addrs ) + const struct sockaddr_storage *sslist, size_t num_addrs ) { DNS_ERROR err; struct dns_connection *conn; @@ -65,7 +65,7 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, */ err = dns_create_probe(mem_ctx, pszDomainName, pszHostName, - num_addrs, iplist, &req); + num_addrs, sslist, &req); if (!ERR_DNS_IS_OK(err)) goto error; err = dns_update_transaction(mem_ctx, conn, req, &resp); @@ -81,7 +81,7 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, */ err = dns_create_update_request(mem_ctx, pszDomainName, pszHostName, - iplist, num_addrs, &req); + sslist, num_addrs, &req); if (!ERR_DNS_IS_OK(err)) goto error; err = dns_update_transaction(mem_ctx, conn, req, &resp); @@ -141,30 +141,37 @@ error: /********************************************************************* *********************************************************************/ -int get_my_ip_address( struct in_addr **ips ) +int get_my_ip_address( struct sockaddr_storage **pp_ss ) + { struct iface_struct nics[MAX_INTERFACES]; int i, n; - struct in_addr *list; + struct sockaddr_storage *list = NULL; int count = 0; /* find the first non-loopback address from our list of interfaces */ n = get_interfaces(nics, MAX_INTERFACES); - - if ( (list = SMB_MALLOC_ARRAY( struct in_addr, n )) == NULL ) { + + if (n <= 0) { + return -1; + } + + if ( (list = SMB_MALLOC_ARRAY( struct sockaddr_storage, n )) == NULL ) { return -1; } for ( i=0; isin_addr; - - if (!is_loopback_ip_v4(ifip)) { - memcpy(&list[count++], &ifip, sizeof(struct in_addr)); - } + memcpy(&list[count++], &nics[i].ip); + } else +#endif + if ((nics[i].ip.ss_family == AF_INET)) { + memcpy(&list[count++], &nics[i].ip); } } *ips = list; -- cgit From b43719d0fb240d7eacc7d0e08ac220c982516867 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 9 Jan 2008 11:44:40 +0100 Subject: Attempt to fix the compile of source/utils/net_dns.c Jeremy, please check! (This used to be commit 66d3012bf422b2ffc47fa6a405269bad2a80bd6f) --- source3/utils/net_dns.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index c661c77ce6..44a0b46e4e 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -47,7 +47,7 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, OM_uint32 minor; struct dns_update_request *req, *resp; - if ( (num_addrs <= 0) || !iplist ) { + if ( (num_addrs <= 0) || !sslist ) { return ERROR_DNS_INVALID_PARAMETER; } @@ -167,14 +167,16 @@ int get_my_ip_address( struct sockaddr_storage **pp_ss ) } #if defined(HAVE_IPV6) if ((nics[i].ip.ss_family == AF_INET)) { - memcpy(&list[count++], &nics[i].ip); + memcpy(&list[count++], &nics[i].ip, + sizeof(struct sockaddr_storage)); } else #endif - if ((nics[i].ip.ss_family == AF_INET)) { - memcpy(&list[count++], &nics[i].ip); + if (nics[i].ip.ss_family == AF_INET) { + memcpy(&list[count++], &nics[i].ip, + sizeof(struct sockaddr_storage)); } } - *ips = list; + *pp_ss = list; return count; } -- cgit From 2b144283300cee03e76f405d2739bc2a4cb021b8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 14 Jan 2008 22:38:16 +0100 Subject: Fix some warnings -- Jeremy, please check (This used to be commit b66ac8567c16f2c35fceceba2f858d5503620309) --- source3/utils/net_dns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index 44a0b46e4e..fb6644d6b2 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -32,7 +32,8 @@ DNS_ERROR DoDNSUpdate(char *pszServerName, const char *pszDomainName, const char *pszHostName, - const struct sockaddr_storage *sslist, size_t num_addrs ); + const struct sockaddr_storage *sslist, + size_t num_addrs ); /********************************************************************* *********************************************************************/ -- cgit From 82d7429a27b5ff5a269d1f8ffab22e2172fc3be0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Apr 2008 09:28:47 -0700 Subject: Fix typo noticed by David Disseldorp . AF_INET should be AF_INET6 in this case. Jeremy. (This used to be commit 767740a914c7ebeb88886f520380b7fa365e315d) --- source3/utils/net_dns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_dns.c') diff --git a/source3/utils/net_dns.c b/source3/utils/net_dns.c index fb6644d6b2..14d45e2b0f 100644 --- a/source3/utils/net_dns.c +++ b/source3/utils/net_dns.c @@ -167,7 +167,7 @@ int get_my_ip_address( struct sockaddr_storage **pp_ss ) continue; } #if defined(HAVE_IPV6) - if ((nics[i].ip.ss_family == AF_INET)) { + if ((nics[i].ip.ss_family == AF_INET6)) { memcpy(&list[count++], &nics[i].ip, sizeof(struct sockaddr_storage)); } else -- cgit