summaryrefslogtreecommitdiff
path: root/source3/utils/net_dns.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2006-08-24 15:43:32 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:38:48 -0500
commit5693e6c599a586b1bb19eea375c6b1e22526031c (patch)
tree9190fcd83791a892aaca33debd400fd0b4124fc2 /source3/utils/net_dns.c
parent6717e0d467bea50cb7712e6b5278ddb403fdf828 (diff)
downloadsamba-5693e6c599a586b1bb19eea375c6b1e22526031c.tar.gz
samba-5693e6c599a586b1bb19eea375c6b1e22526031c.tar.bz2
samba-5693e6c599a586b1bb19eea375c6b1e22526031c.zip
r17798: Beginnings of a standalone libaddns library released under
the LGPL. Original code by Krishna Ganugapati <krishnag@centeris.com>. 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)
Diffstat (limited to 'source3/utils/net_dns.c')
-rw-r--r--source3/utils/net_dns.c99
1 files changed, 99 insertions, 0 deletions
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<n; i++ ) {
+ if ( nics[i].ip.s_addr != loopback_ip.s_addr ) {
+ memcpy( &list[count++], &nics[i].ip, sizeof( struct in_addr ) );
+ }
+ }
+ *ips = list;
+
+ return count;
+}
+
+#endif /* defined(WITH_DNS_UPDATES) */