libaddns/dnsutils.c

説明を見る。
00001 /*
00002   Linux DNS client library implementation
00003 
00004   Copyright (C) 2006 Krishna Ganugapati <krishnag@centeris.com>
00005   Copyright (C) 2006 Gerald Carter <jerry@samba.org>
00006 
00007      ** NOTE! The following LGPL license applies to the libaddns
00008      ** library. This does NOT imply that all of Samba is released
00009      ** under the LGPL
00010 
00011   This library is free software; you can redistribute it and/or
00012   modify it under the terms of the GNU Lesser General Public
00013   License as published by the Free Software Foundation; either
00014   version 2.1 of the License, or (at your option) any later version.
00015 
00016   This library is distributed in the hope that it will be useful,
00017   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019   Lesser General Public License for more details.
00020 
00021   You should have received a copy of the GNU Lesser General Public
00022   License along with this library; if not, write to the Free Software
00023   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
00024   02110-1301  USA
00025 */
00026 
00027 #include "dns.h"
00028 #include <ctype.h>
00029 
00030 static DNS_ERROR LabelList( TALLOC_CTX *mem_ctx,
00031                             const char *name,
00032                             struct dns_domain_label **presult )
00033 {
00034         struct dns_domain_label *result;
00035         const char *dot;
00036 
00037         for (dot = name; *dot != '\0'; dot += 1) {
00038                 char c = *dot;
00039 
00040                 if (c == '.')
00041                         break;
00042 
00043                 if (c == '-') continue;
00044                 if ((c >= 'a') && (c <= 'z')) continue;
00045                 if ((c >= 'A') && (c <= 'Z')) continue;
00046                 if ((c >= '0') && (c <= '9')) continue;
00047 
00048                 return ERROR_DNS_INVALID_NAME;
00049         }
00050 
00051         if ((dot - name) > 63) {
00052                 /*
00053                  * DNS labels can only be 63 chars long
00054                  */
00055                 return ERROR_DNS_INVALID_NAME;
00056         }
00057 
00058         if (!(result = TALLOC_ZERO_P(mem_ctx, struct dns_domain_label))) {
00059                 return ERROR_DNS_NO_MEMORY;
00060         }
00061 
00062         if (*dot == '\0') {
00063                 /*
00064                  * No dot around, so this is the last component
00065                  */
00066 
00067                 if (!(result->label = talloc_strdup(result, name))) {
00068                         TALLOC_FREE(result);
00069                         return ERROR_DNS_NO_MEMORY;
00070                 }
00071                 result->len = strlen(result->label);
00072                 *presult = result;
00073                 return ERROR_DNS_SUCCESS;
00074         }
00075 
00076         if (dot[1] == '.') {
00077                 /*
00078                  * Two dots in a row, reject
00079                  */
00080 
00081                 TALLOC_FREE(result);
00082                 return ERROR_DNS_INVALID_NAME;
00083         }
00084 
00085         if (dot[1] != '\0') {
00086                 /*
00087                  * Something follows, get the rest
00088                  */
00089 
00090                 DNS_ERROR err = LabelList(result, dot+1, &result->next);
00091 
00092                 if (!ERR_DNS_IS_OK(err)) {
00093                         TALLOC_FREE(result);
00094                         return err;
00095                 }
00096         }
00097 
00098         result->len = (dot - name);
00099 
00100         if (!(result->label = talloc_strndup(result, name, result->len))) {
00101                 TALLOC_FREE(result);
00102                 return ERROR_DNS_NO_MEMORY;
00103         }
00104 
00105         *presult = result;
00106         return ERROR_DNS_SUCCESS;
00107 }
00108 
00109 DNS_ERROR dns_domain_name_from_string( TALLOC_CTX *mem_ctx,
00110                                        const char *pszDomainName,
00111                                        struct dns_domain_name **presult )
00112 {
00113         struct dns_domain_name *result;
00114         DNS_ERROR err;
00115 
00116         if (!(result = talloc(mem_ctx, struct dns_domain_name))) {
00117                 return ERROR_DNS_NO_MEMORY;
00118         }
00119 
00120         err = LabelList( result, pszDomainName, &result->pLabelList );
00121         if (!ERR_DNS_IS_OK(err)) {
00122                 TALLOC_FREE(result);
00123                 return err;
00124         }
00125 
00126         *presult = result;
00127         return ERROR_DNS_SUCCESS;
00128 }
00129 
00130 /*********************************************************************
00131 *********************************************************************/
00132 
00133 char *dns_generate_keyname( TALLOC_CTX *mem_ctx )
00134 {
00135         char *result = NULL;
00136 #if defined(WITH_DNS_UPDATES)
00137 
00138         uuid_t uuid;
00139 
00140         /*
00141          * uuid_unparse gives 36 bytes plus '\0'
00142          */
00143         if (!(result = TALLOC_ARRAY(mem_ctx, char, 37))) {
00144                 return NULL;
00145         }
00146 
00147         uuid_generate( uuid );
00148         uuid_unparse( uuid, result );
00149 
00150 #endif
00151 
00152         return result;
00153 }

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