utils/net_dns.c

説明を見る。
00001 
00002 /* 
00003    Samba Unix/Linux Dynamic DNS Update
00004    net ads commands
00005 
00006    Copyright (C) Krishna Ganugapati (krishnag@centeris.com)         2006
00007    Copyright (C) Gerald Carter                                      2006
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 2 of the License, or
00012    (at your option) any later version.
00013    
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018    
00019    You should have received a copy of the GNU General Public License
00020    along with this program; if not, write to the Free Software
00021    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
00022 */
00023 
00024 #include "includes.h"
00025 #include "utils/net.h"
00026 #include "dns.h"
00027 
00028 #if defined(WITH_DNS_UPDATES)
00029 
00030 /*********************************************************************
00031 *********************************************************************/
00032 
00033 DNS_ERROR DoDNSUpdate(char *pszServerName,
00034                       const char *pszDomainName, const char *pszHostName,
00035                       const struct in_addr *iplist, size_t num_addrs )
00036 {
00037         DNS_ERROR err;
00038         struct dns_connection *conn;
00039         TALLOC_CTX *mem_ctx;
00040         OM_uint32 minor;
00041         struct dns_update_request *req, *resp;
00042 
00043         if ( (num_addrs <= 0) || !iplist ) {
00044                 return ERROR_DNS_INVALID_PARAMETER;
00045         }
00046 
00047         if (!(mem_ctx = talloc_init("DoDNSUpdate"))) {
00048                 return ERROR_DNS_NO_MEMORY;
00049         }
00050                 
00051         err = dns_open_connection( pszServerName, DNS_TCP, mem_ctx, &conn );
00052         if (!ERR_DNS_IS_OK(err)) {
00053                 goto error;
00054         }
00055 
00056         /*
00057          * Probe if everything's fine
00058          */
00059 
00060         err = dns_create_probe(mem_ctx, pszDomainName, pszHostName,
00061                                num_addrs, iplist, &req);
00062         if (!ERR_DNS_IS_OK(err)) goto error;
00063 
00064         err = dns_update_transaction(mem_ctx, conn, req, &resp);
00065         if (!ERR_DNS_IS_OK(err)) goto error;
00066 
00067         if (dns_response_code(resp->flags) == DNS_NO_ERROR) {
00068                 TALLOC_FREE(mem_ctx);
00069                 return ERROR_DNS_SUCCESS;
00070         }
00071 
00072         /*
00073          * First try without signing
00074          */
00075 
00076         err = dns_create_update_request(mem_ctx, pszDomainName, pszHostName,
00077                                         iplist, num_addrs, &req);
00078         if (!ERR_DNS_IS_OK(err)) goto error;
00079 
00080         err = dns_update_transaction(mem_ctx, conn, req, &resp);
00081         if (!ERR_DNS_IS_OK(err)) goto error;
00082 
00083         if (dns_response_code(resp->flags) == DNS_NO_ERROR) {
00084                 TALLOC_FREE(mem_ctx);
00085                 return ERROR_DNS_SUCCESS;
00086         }
00087 
00088         /*
00089          * Okay, we have to try with signing
00090          */
00091         {
00092                 gss_ctx_id_t gss_context;
00093                 char *keyname;
00094 
00095                 if (!(keyname = dns_generate_keyname( mem_ctx ))) {
00096                         err = ERROR_DNS_NO_MEMORY;
00097                         goto error;
00098                 }
00099 
00100                 err = dns_negotiate_sec_ctx( pszDomainName, pszServerName,
00101                                              keyname, &gss_context, DNS_SRV_ANY );
00102 
00103                 /* retry using the Windows 2000 DNS hack */
00104                 if (!ERR_DNS_IS_OK(err)) {
00105                         err = dns_negotiate_sec_ctx( pszDomainName, pszServerName,
00106                                                      keyname, &gss_context, 
00107                                                      DNS_SRV_WIN2000 );
00108                 }
00109                 
00110                 if (!ERR_DNS_IS_OK(err))
00111                         goto error;
00112                 
00113 
00114                 err = dns_sign_update(req, gss_context, keyname,
00115                                       "gss.microsoft.com", time(NULL), 3600);
00116 
00117                 gss_delete_sec_context(&minor, &gss_context, GSS_C_NO_BUFFER);
00118 
00119                 if (!ERR_DNS_IS_OK(err)) goto error;
00120 
00121                 err = dns_update_transaction(mem_ctx, conn, req, &resp);
00122                 if (!ERR_DNS_IS_OK(err)) goto error;
00123 
00124                 err = (dns_response_code(resp->flags) == DNS_NO_ERROR) ?
00125                         ERROR_DNS_SUCCESS : ERROR_DNS_UPDATE_FAILED;
00126         }
00127 
00128 
00129 error:
00130         TALLOC_FREE(mem_ctx);
00131         return err;
00132 }
00133 
00134 /*********************************************************************
00135 *********************************************************************/
00136 
00137 int get_my_ip_address( struct in_addr **ips )
00138 {
00139         struct iface_struct nics[MAX_INTERFACES];
00140         int i, n;
00141         struct in_addr loopback_ip = *interpret_addr2("127.0.0.1");
00142         struct in_addr *list;
00143         int count = 0;
00144 
00145         /* find the first non-loopback address from our list of interfaces */
00146 
00147         n = get_interfaces(nics, MAX_INTERFACES);
00148         
00149         if ( (list = SMB_MALLOC_ARRAY( struct in_addr, n )) == NULL ) {
00150                 return -1;
00151         }
00152 
00153         for ( i=0; i<n; i++ ) {
00154                 if ( nics[i].ip.s_addr != loopback_ip.s_addr ) {
00155                         memcpy( &list[count++], &nics[i].ip, sizeof( struct in_addr ) );
00156                 }
00157         }
00158         *ips = list;
00159 
00160         return count;
00161 }
00162 
00163 DNS_ERROR do_gethostbyname(const char *server, const char *host)
00164 {
00165         struct dns_connection *conn;
00166         struct dns_request *req, *resp;
00167         DNS_ERROR err;
00168 
00169         err = dns_open_connection(server, DNS_UDP, NULL, &conn);
00170         if (!ERR_DNS_IS_OK(err)) goto error;
00171 
00172         err = dns_create_query(conn, host, QTYPE_A, DNS_CLASS_IN, &req);
00173         if (!ERR_DNS_IS_OK(err)) goto error;
00174 
00175         err = dns_transaction(conn, conn, req, &resp);
00176 
00177  error:
00178         TALLOC_FREE(conn);
00179         return err;
00180 }
00181 
00182 #endif  /* defined(WITH_DNS_UPDATES) */

Sambaに対してSat Aug 29 21:23:28 2009に生成されました。  doxygen 1.4.7