2 Linux DNS client library implementation
4 Copyright (C) 2006 Krishna Ganugapati <krishnag@centeris.com>
5 Copyright (C) 2006 Gerald Carter <jerry@samba.org>
7 ** NOTE! The following LGPL license applies to the libaddns
8 ** library. This does NOT imply that all of Samba is released
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include "librpc/ndr/libndr.h"
27 #include "librpc/gen_ndr/ndr_misc.h"
33 static DNS_ERROR
LabelList( TALLOC_CTX
*mem_ctx
,
35 struct dns_domain_label
**presult
)
37 struct dns_domain_label
*result
;
40 for (dot
= name
; *dot
!= '\0'; dot
+= 1) {
46 if (c
== '-') continue;
47 if ((c
>= 'a') && (c
<= 'z')) continue;
48 if ((c
>= 'A') && (c
<= 'Z')) continue;
49 if ((c
>= '0') && (c
<= '9')) continue;
51 return ERROR_DNS_INVALID_NAME
;
54 if ((dot
- name
) > 63) {
56 * DNS labels can only be 63 chars long
58 return ERROR_DNS_INVALID_NAME
;
61 if (!(result
= talloc_zero(mem_ctx
, struct dns_domain_label
))) {
62 return ERROR_DNS_NO_MEMORY
;
67 * No dot around, so this is the last component
70 if (!(result
->label
= talloc_strdup(result
, name
))) {
72 return ERROR_DNS_NO_MEMORY
;
74 result
->len
= strlen(result
->label
);
76 return ERROR_DNS_SUCCESS
;
81 * Two dots in a row, reject
85 return ERROR_DNS_INVALID_NAME
;
90 * Something follows, get the rest
93 DNS_ERROR err
= LabelList(result
, dot
+1, &result
->next
);
95 if (!ERR_DNS_IS_OK(err
)) {
101 result
->len
= (dot
- name
);
103 if (!(result
->label
= talloc_strndup(result
, name
, result
->len
))) {
105 return ERROR_DNS_NO_MEMORY
;
109 return ERROR_DNS_SUCCESS
;
112 DNS_ERROR
dns_domain_name_from_string( TALLOC_CTX
*mem_ctx
,
113 const char *pszDomainName
,
114 struct dns_domain_name
**presult
)
116 struct dns_domain_name
*result
;
119 if (!(result
= talloc(mem_ctx
, struct dns_domain_name
))) {
120 return ERROR_DNS_NO_MEMORY
;
123 err
= LabelList( result
, pszDomainName
, &result
->pLabelList
);
124 if (!ERR_DNS_IS_OK(err
)) {
130 return ERROR_DNS_SUCCESS
;
133 /*********************************************************************
134 *********************************************************************/
136 char *dns_generate_keyname( TALLOC_CTX
*mem_ctx
)
139 #if defined(WITH_DNS_UPDATES)
143 guid
= GUID_random();
144 result
= GUID_string(mem_ctx
, &guid
);