00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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
00079
00080
00081 TALLOC_FREE(result);
00082 return ERROR_DNS_INVALID_NAME;
00083 }
00084
00085 if (dot[1] != '\0') {
00086
00087
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
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 }