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/>.
28 #include "../replace/replace.h"
29 #include "system/network.h"
30 #include "system/kerberos.h"
31 #include "system/gssapi.h"
33 /* make sure we have included the correct config.h */
34 #ifndef NO_CONFIG_H /* for some tests */
35 #ifndef CONFIG_H_IS_FROM_SAMBA
36 #error "make sure you have removed all config.h files from standalone builds!"
37 #error "the included config.h isn't from samba!"
39 #endif /* NO_CONFIG_H */
45 #ifdef HAVE_UUID_UUID_H
46 #include <uuid/uuid.h>
51 /*******************************************************************
52 Type definitions for int16, int32, uint16 and uint32. Needed
53 for Samba coding style
54 *******************************************************************/
57 # define uint8 unsigned char
60 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
61 # if (SIZEOF_SHORT == 4)
62 # define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
63 # else /* SIZEOF_SHORT != 4 */
65 # endif /* SIZEOF_SHORT != 4 */
66 /* needed to work around compile issue on HP-UX 11.x */
71 * Note we duplicate the size tests in the unsigned
72 * case as int16 may be a typedef from rpc/rpc.h
75 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
76 # if (SIZEOF_SHORT == 4)
77 # define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
78 # else /* SIZEOF_SHORT != 4 */
79 # define uint16 unsigned short
80 # endif /* SIZEOF_SHORT != 4 */
83 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
84 # if (SIZEOF_INT == 4)
86 # elif (SIZEOF_LONG == 4)
88 # elif (SIZEOF_SHORT == 4)
91 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
95 /* needed to work around compile issue on HP-UX 11.x */
101 * Note we duplicate the size tests in the unsigned
102 * case as int32 may be a typedef from rpc/rpc.h
105 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
106 # if (SIZEOF_INT == 4)
107 # define uint32 unsigned int
108 # elif (SIZEOF_LONG == 4)
109 # define uint32 unsigned long
110 # elif (SIZEOF_SHORT == 4)
111 # define uint32 unsigned short
113 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
114 # define uint32 unsigned
119 * check for 8 byte long long
123 # if (SIZEOF_LONG == 8)
124 # define uint64 unsigned long
125 # elif (SIZEOF_LONG_LONG == 8)
126 # define uint64 unsigned long long
127 # endif /* don't lie. If we don't have it, then don't use it */
130 /* needed on Sun boxes */
132 #define INADDR_NONE 0xFFFFFFFF
141 #define DNS_OPCODE_UPDATE 1
143 /* DNS Class Types */
145 #define DNS_CLASS_IN 1
146 #define DNS_CLASS_ANY 255
147 #define DNS_CLASS_NONE 254
153 #define DNS_TCP_PORT 53
154 #define DNS_UDP_PORT 53
159 #define QTYPE_CNAME 5
161 #define QTYPE_AAAA 28
162 #define QTYPE_ANY 255
163 #define QTYPE_TKEY 249
164 #define QTYPE_TSIG 250
167 MF 4 a mail forwarder (Obsolete - use MX)
168 CNAME 5 the canonical name for an alias
169 SOA 6 marks the start of a zone of authority
170 MB 7 a mailbox domain name (EXPERIMENTAL)
171 MG 8 a mail group member (EXPERIMENTAL)
172 MR 9 a mail rename domain name (EXPERIMENTAL)
173 NULL 10 a null RR (EXPERIMENTAL)
174 WKS 11 a well known service description
175 PTR 12 a domain name pointer
176 HINFO 13 host information
177 MINFO 14 mailbox or mail list information
182 #define QR_QUERY 0x0000
183 #define QR_RESPONSE 0x0001
185 #define OPCODE_QUERY 0x00
186 #define OPCODE_IQUERY 0x01
187 #define OPCODE_STATUS 0x02
191 #define RECURSION_DESIRED 0x01
193 #define RCODE_NOERROR 0
194 #define RCODE_FORMATERROR 1
195 #define RCODE_SERVER_FAILURE 2
196 #define RCODE_NAME_ERROR 3
197 #define RCODE_NOTIMPLEMENTED 4
198 #define RCODE_REFUSED 5
200 #define SENDBUFFER_SIZE 65536
201 #define RECVBUFFER_SIZE 65536
204 * TKEY Modes from rfc2930
207 #define DNS_TKEY_MODE_SERVER 1
208 #define DNS_TKEY_MODE_DH 2
209 #define DNS_TKEY_MODE_GSSAPI 3
210 #define DNS_TKEY_MODE_RESOLVER 4
211 #define DNS_TKEY_MODE_DELETE 5
214 #define DNS_ONE_DAY_IN_SECS 86400
215 #define DNS_TEN_HOURS_IN_SECS 36000
217 #define SOCKET_ERROR -1
218 #define INVALID_SOCKET -1
220 #define DNS_NO_ERROR 0
221 #define DNS_FORMAT_ERROR 1
222 #define DNS_SERVER_FAILURE 2
223 #define DNS_NAME_ERROR 3
224 #define DNS_NOT_IMPLEMENTED 4
225 #define DNS_REFUSED 5
229 enum dns_ServerType { DNS_SRV_ANY, DNS_SRV_WIN2000, DNS_SRV_WIN2003 };
231 struct dns_domain_label {
232 struct dns_domain_label *next;
237 struct dns_domain_name {
238 struct dns_domain_label *pLabelList;
241 struct dns_question {
242 struct dns_domain_name *name;
248 * Before changing the definition of dns_zone, look
249 * dns_marshall_update_request(), we rely on this being the same as
250 * dns_question right now.
254 struct dns_domain_name *name;
260 struct dns_domain_name *name;
268 struct dns_tkey_record {
269 struct dns_domain_name *algorithm;
281 uint16 num_questions;
284 uint16 num_additionals;
285 struct dns_question **questions;
286 struct dns_rrec **answers;
287 struct dns_rrec **auths;
288 struct dns_rrec **additionals;
292 * Before changing the definition of dns_update_request, look
293 * dns_marshall_update_request(), we rely on this being the same as
294 * dns_request right now.
297 struct dns_update_request {
303 uint16 num_additionals;
304 struct dns_zone **zones;
305 struct dns_rrec **preqs;
306 struct dns_rrec **updates;
307 struct dns_rrec **additionals;
310 struct dns_connection {
313 struct sockaddr RecvAddr;
323 /* from dnsutils.c */
325 DNS_ERROR dns_domain_name_from_string( TALLOC_CTX *mem_ctx,
326 const char *pszDomainName,
327 struct dns_domain_name **presult );
328 char *dns_generate_keyname( TALLOC_CTX *mem_ctx );
330 /* from dnsrecord.c */
332 DNS_ERROR dns_create_query( TALLOC_CTX *mem_ctx, const char *name,
333 uint16 q_type, uint16 q_class,
334 struct dns_request **preq );
335 DNS_ERROR dns_create_update( TALLOC_CTX *mem_ctx, const char *name,
336 struct dns_update_request **preq );
337 DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone,
338 const char *host, int num_ips,
339 const struct sockaddr_storage *sslist,
340 struct dns_update_request **preq);
341 DNS_ERROR dns_create_rrec(TALLOC_CTX *mem_ctx, const char *name,
342 uint16 type, uint16 r_class, uint32 ttl,
343 uint16 data_length, uint8 *data,
344 struct dns_rrec **prec);
345 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
346 uint16 *num_records, struct dns_rrec ***records);
347 DNS_ERROR dns_create_tkey_record(TALLOC_CTX *mem_ctx, const char *keyname,
348 const char *algorithm_name, time_t inception,
349 time_t expiration, uint16 mode, uint16 error,
350 uint16 key_length, const uint8 *key,
351 struct dns_rrec **prec);
352 DNS_ERROR dns_create_name_in_use_record(TALLOC_CTX *mem_ctx,
354 const struct sockaddr_storage *ip,
355 struct dns_rrec **prec);
356 DNS_ERROR dns_create_delete_record(TALLOC_CTX *mem_ctx, const char *name,
357 uint16 type, uint16 r_class,
358 struct dns_rrec **prec);
359 DNS_ERROR dns_create_name_not_in_use_record(TALLOC_CTX *mem_ctx,
360 const char *name, uint32 type,
361 struct dns_rrec **prec);
362 DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host,
363 uint32 ttl, const struct sockaddr_storage *pss,
364 struct dns_rrec **prec);
365 DNS_ERROR dns_create_aaaa_record(TALLOC_CTX *mem_ctx, const char *host,
366 uint32 ttl, const struct sockaddr_storage *pss,
367 struct dns_rrec **prec);
368 DNS_ERROR dns_unmarshall_tkey_record(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
369 struct dns_tkey_record **ptkey);
370 DNS_ERROR dns_create_tsig_record(TALLOC_CTX *mem_ctx, const char *keyname,
371 const char *algorithm_name,
372 time_t time_signed, uint16 fudge,
373 uint16 mac_length, const uint8 *mac,
374 uint16 original_id, uint16 error,
375 struct dns_rrec **prec);
376 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
377 uint16 *num_records, struct dns_rrec ***records);
378 DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx,
379 const char *domainname,
380 const char *hostname,
381 const struct sockaddr_storage *ip_addr,
383 struct dns_update_request **preq);
387 DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
389 struct dns_connection **conn );
390 DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf);
391 DNS_ERROR dns_receive(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
392 struct dns_buffer **presult);
393 DNS_ERROR dns_transaction(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
394 const struct dns_request *req,
395 struct dns_request **resp);
396 DNS_ERROR dns_update_transaction(TALLOC_CTX *mem_ctx,
397 struct dns_connection *conn,
398 struct dns_update_request *up_req,
399 struct dns_update_request **up_resp);
401 /* from dnsmarshall.c */
403 struct dns_buffer *dns_create_buffer(TALLOC_CTX *mem_ctx);
404 void dns_marshall_buffer(struct dns_buffer *buf, const uint8 *data,
406 void dns_marshall_uint16(struct dns_buffer *buf, uint16 val);
407 void dns_marshall_uint32(struct dns_buffer *buf, uint32 val);
408 void dns_unmarshall_buffer(struct dns_buffer *buf, uint8 *data,
410 void dns_unmarshall_uint16(struct dns_buffer *buf, uint16 *val);
411 void dns_unmarshall_uint32(struct dns_buffer *buf, uint32 *val);
412 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
413 struct dns_buffer *buf,
414 struct dns_domain_name **pname);
415 void dns_marshall_domain_name(struct dns_buffer *buf,
416 const struct dns_domain_name *name);
417 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
418 struct dns_buffer *buf,
419 struct dns_domain_name **pname);
420 DNS_ERROR dns_marshall_request(TALLOC_CTX *mem_ctx,
421 const struct dns_request *req,
422 struct dns_buffer **pbuf);
423 DNS_ERROR dns_unmarshall_request(TALLOC_CTX *mem_ctx,
424 struct dns_buffer *buf,
425 struct dns_request **preq);
426 DNS_ERROR dns_marshall_update_request(TALLOC_CTX *mem_ctx,
427 struct dns_update_request *update,
428 struct dns_buffer **pbuf);
429 DNS_ERROR dns_unmarshall_update_request(TALLOC_CTX *mem_ctx,
430 struct dns_buffer *buf,
431 struct dns_update_request **pupreq);
432 struct dns_request *dns_update2request(struct dns_update_request *update);
433 struct dns_update_request *dns_request2update(struct dns_request *request);
434 uint16 dns_response_code(uint16 flags);
435 const char *dns_errstr(DNS_ERROR err);
441 void display_status( const char *msg, OM_uint32 maj_stat, OM_uint32 min_stat );
442 DNS_ERROR dns_negotiate_sec_ctx( const char *target_realm,
443 const char *servername,
445 gss_ctx_id_t *gss_ctx,
446 enum dns_ServerType srv_type );
447 DNS_ERROR dns_sign_update(struct dns_update_request *req,
448 gss_ctx_id_t gss_ctx,
450 const char *algorithmname,
451 time_t time_signed, uint16 fudge);
453 #endif /* HAVE_KRB5 */