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, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
45 #ifdef HAVE_UUID_UUID_H
46 #include <uuid/uuid.h>
53 #ifdef HAVE_INTTYPES_H
61 #define uint16 uint16_t
69 #define uint32 uint32_t
79 #elif HAVE_GSSAPI_GSSAPI_H
80 #include <gssapi/gssapi.h>
81 #elif HAVE_GSSAPI_GSSAPI_GENERIC_H
82 #include <gssapi/gssapi_generic.h>
85 #if defined(HAVE_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_GENERIC_H)
86 #define HAVE_GSSAPI_SUPPORT 1
91 void *_talloc_zero_zeronull(const void *ctx
, size_t size
, const char *name
);
92 void *_talloc_memdup_zeronull(const void *t
, const void *p
, size_t size
, const char *name
);
93 void *_talloc_array_zeronull(const void *ctx
, size_t el_size
, unsigned count
, const char *name
);
94 void *_talloc_zero_array_zeronull(const void *ctx
, size_t el_size
, unsigned count
, const char *name
);
95 void *talloc_zeronull(const void *context
, size_t size
, const char *name
);
97 #define TALLOC(ctx, size) talloc_zeronull(ctx, size, __location__)
98 #define TALLOC_P(ctx, type) (type *)talloc_zeronull(ctx, sizeof(type), #type)
99 #define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_zeronull(ctx, sizeof(type), count, #type)
100 #define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_zeronull(ctx, ptr, size, __location__)
101 #define TALLOC_ZERO(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
102 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_zeronull(ctx, sizeof(type), #type)
103 #define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_zeronull(ctx, sizeof(type), count, #type)
104 #define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__)
105 #define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)_talloc_realloc_array(ctx, ptr, sizeof(type), count, #type)
106 #define talloc_destroy(ctx) talloc_free(ctx)
107 #define TALLOC_FREE(ctx) do { if ((ctx) != NULL) {talloc_free(ctx); ctx=NULL;} } while(0)
108 #define TALLOC_SIZE(ctx, size) talloc_zeronull(ctx, size, __location__)
109 #define TALLOC_ZERO_SIZE(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
111 /*******************************************************************
112 Type definitions for int16, int32, uint16 and uint32. Needed
113 for Samba coding style
114 *******************************************************************/
117 # define uint8 unsigned char
120 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
121 # if (SIZEOF_SHORT == 4)
122 # define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
123 # else /* SIZEOF_SHORT != 4 */
125 # endif /* SIZEOF_SHORT != 4 */
126 /* needed to work around compile issue on HP-UX 11.x */
131 * Note we duplicate the size tests in the unsigned
132 * case as int16 may be a typedef from rpc/rpc.h
135 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
136 # if (SIZEOF_SHORT == 4)
137 # define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
138 # else /* SIZEOF_SHORT != 4 */
139 # define uint16 unsigned short
140 # endif /* SIZEOF_SHORT != 4 */
143 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
144 # if (SIZEOF_INT == 4)
146 # elif (SIZEOF_LONG == 4)
148 # elif (SIZEOF_SHORT == 4)
151 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
154 /* needed to work around compile issue on HP-UX 11.x */
159 * Note we duplicate the size tests in the unsigned
160 * case as int32 may be a typedef from rpc/rpc.h
163 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
164 # if (SIZEOF_INT == 4)
165 # define uint32 unsigned int
166 # elif (SIZEOF_LONG == 4)
167 # define uint32 unsigned long
168 # elif (SIZEOF_SHORT == 4)
169 # define uint32 unsigned short
171 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
172 # define uint32 unsigned
177 * check for 8 byte long long
181 # if (SIZEOF_LONG == 8)
182 # define uint64 unsigned long
183 # elif (SIZEOF_LONG_LONG == 8)
184 # define uint64 unsigned long long
185 # endif /* don't lie. If we don't have it, then don't use it */
188 /* needed on Sun boxes */
190 #define INADDR_NONE 0xFFFFFFFF
199 #define DNS_OPCODE_UPDATE 1
201 /* DNS Class Types */
203 #define DNS_CLASS_IN 1
204 #define DNS_CLASS_ANY 255
205 #define DNS_CLASS_NONE 254
211 #define DNS_TCP_PORT 53
212 #define DNS_UDP_PORT 53
217 #define QTYPE_CNAME 5
219 #define QTYPE_ANY 255
220 #define QTYPE_TKEY 249
221 #define QTYPE_TSIG 250
224 MF 4 a mail forwarder (Obsolete - use MX)
225 CNAME 5 the canonical name for an alias
226 SOA 6 marks the start of a zone of authority
227 MB 7 a mailbox domain name (EXPERIMENTAL)
228 MG 8 a mail group member (EXPERIMENTAL)
229 MR 9 a mail rename domain name (EXPERIMENTAL)
230 NULL 10 a null RR (EXPERIMENTAL)
231 WKS 11 a well known service description
232 PTR 12 a domain name pointer
233 HINFO 13 host information
234 MINFO 14 mailbox or mail list information
239 #define QR_QUERY 0x0000
240 #define QR_RESPONSE 0x0001
242 #define OPCODE_QUERY 0x00
243 #define OPCODE_IQUERY 0x01
244 #define OPCODE_STATUS 0x02
248 #define RECURSION_DESIRED 0x01
250 #define RCODE_NOERROR 0
251 #define RCODE_FORMATERROR 1
252 #define RCODE_SERVER_FAILURE 2
253 #define RCODE_NAME_ERROR 3
254 #define RCODE_NOTIMPLEMENTED 4
255 #define RCODE_REFUSED 5
257 #define SENDBUFFER_SIZE 65536
258 #define RECVBUFFER_SIZE 65536
261 * TKEY Modes from rfc2930
264 #define DNS_TKEY_MODE_SERVER 1
265 #define DNS_TKEY_MODE_DH 2
266 #define DNS_TKEY_MODE_GSSAPI 3
267 #define DNS_TKEY_MODE_RESOLVER 4
268 #define DNS_TKEY_MODE_DELETE 5
271 #define DNS_ONE_DAY_IN_SECS 86400
272 #define DNS_TEN_HOURS_IN_SECS 36000
274 #define SOCKET_ERROR -1
275 #define INVALID_SOCKET -1
277 #define DNS_NO_ERROR 0
278 #define DNS_FORMAT_ERROR 1
279 #define DNS_SERVER_FAILURE 2
280 #define DNS_NAME_ERROR 3
281 #define DNS_NOT_IMPLEMENTED 4
282 #define DNS_REFUSED 5
292 enum dns_ServerType
{ DNS_SRV_ANY
, DNS_SRV_WIN2000
, DNS_SRV_WIN2003
};
294 struct dns_domain_label
{
295 struct dns_domain_label
*next
;
300 struct dns_domain_name
{
301 struct dns_domain_label
*pLabelList
;
304 struct dns_question
{
305 struct dns_domain_name
*name
;
311 * Before changing the definition of dns_zone, look
312 * dns_marshall_update_request(), we rely on this being the same as
313 * dns_question right now.
317 struct dns_domain_name
*name
;
323 struct dns_domain_name
*name
;
331 struct dns_tkey_record
{
332 struct dns_domain_name
*algorithm
;
344 uint16 num_questions
;
347 uint16 num_additionals
;
348 struct dns_question
**questions
;
349 struct dns_rrec
**answers
;
350 struct dns_rrec
**auths
;
351 struct dns_rrec
**additionals
;
355 * Before changing the definition of dns_update_request, look
356 * dns_marshall_update_request(), we rely on this being the same as
357 * dns_request right now.
360 struct dns_update_request
{
366 uint16 num_additionals
;
367 struct dns_zone
**zones
;
368 struct dns_rrec
**preqs
;
369 struct dns_rrec
**updates
;
370 struct dns_rrec
**additionals
;
373 struct dns_connection
{
376 struct sockaddr RecvAddr
;
386 /* from dnsutils.c */
388 DNS_ERROR
dns_domain_name_from_string( TALLOC_CTX
*mem_ctx
,
389 const char *pszDomainName
,
390 struct dns_domain_name
**presult
);
391 char *dns_generate_keyname( TALLOC_CTX
*mem_ctx
);
393 /* from dnsrecord.c */
395 DNS_ERROR
dns_create_query( TALLOC_CTX
*mem_ctx
, const char *name
,
396 uint16 q_type
, uint16 q_class
,
397 struct dns_request
**preq
);
398 DNS_ERROR
dns_create_update( TALLOC_CTX
*mem_ctx
, const char *name
,
399 struct dns_update_request
**preq
);
400 DNS_ERROR
dns_create_probe(TALLOC_CTX
*mem_ctx
, const char *zone
,
401 const char *host
, int num_ips
,
402 const struct in_addr
*iplist
,
403 struct dns_update_request
**preq
);
404 DNS_ERROR
dns_create_rrec(TALLOC_CTX
*mem_ctx
, const char *name
,
405 uint16 type
, uint16 r_class
, uint32 ttl
,
406 uint16 data_length
, uint8
*data
,
407 struct dns_rrec
**prec
);
408 DNS_ERROR
dns_add_rrec(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
409 uint16
*num_records
, struct dns_rrec
***records
);
410 DNS_ERROR
dns_create_tkey_record(TALLOC_CTX
*mem_ctx
, const char *keyname
,
411 const char *algorithm_name
, time_t inception
,
412 time_t expiration
, uint16 mode
, uint16 error
,
413 uint16 key_length
, const uint8
*key
,
414 struct dns_rrec
**prec
);
415 DNS_ERROR
dns_create_name_in_use_record(TALLOC_CTX
*mem_ctx
,
417 const struct in_addr
*ip
,
418 struct dns_rrec
**prec
);
419 DNS_ERROR
dns_create_delete_record(TALLOC_CTX
*mem_ctx
, const char *name
,
420 uint16 type
, uint16 r_class
,
421 struct dns_rrec
**prec
);
422 DNS_ERROR
dns_create_name_not_in_use_record(TALLOC_CTX
*mem_ctx
,
423 const char *name
, uint32 type
,
424 struct dns_rrec
**prec
);
425 DNS_ERROR
dns_create_a_record(TALLOC_CTX
*mem_ctx
, const char *host
,
426 uint32 ttl
, struct in_addr ip
,
427 struct dns_rrec
**prec
);
428 DNS_ERROR
dns_unmarshall_tkey_record(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
429 struct dns_tkey_record
**ptkey
);
430 DNS_ERROR
dns_create_tsig_record(TALLOC_CTX
*mem_ctx
, const char *keyname
,
431 const char *algorithm_name
,
432 time_t time_signed
, uint16 fudge
,
433 uint16 mac_length
, const uint8
*mac
,
434 uint16 original_id
, uint16 error
,
435 struct dns_rrec
**prec
);
436 DNS_ERROR
dns_add_rrec(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
437 uint16
*num_records
, struct dns_rrec
***records
);
441 DNS_ERROR
dns_open_connection( const char *nameserver
, int32 dwType
,
443 struct dns_connection
**conn
);
444 DNS_ERROR
dns_send(struct dns_connection
*conn
, const struct dns_buffer
*buf
);
445 DNS_ERROR
dns_receive(TALLOC_CTX
*mem_ctx
, struct dns_connection
*conn
,
446 struct dns_buffer
**presult
);
447 DNS_ERROR
dns_transaction(TALLOC_CTX
*mem_ctx
, struct dns_connection
*conn
,
448 const struct dns_request
*req
,
449 struct dns_request
**resp
);
450 DNS_ERROR
dns_update_transaction(TALLOC_CTX
*mem_ctx
,
451 struct dns_connection
*conn
,
452 struct dns_update_request
*up_req
,
453 struct dns_update_request
**up_resp
);
455 /* from dnsmarshall.c */
457 struct dns_buffer
*dns_create_buffer(TALLOC_CTX
*mem_ctx
);
458 void dns_marshall_buffer(struct dns_buffer
*buf
, const uint8
*data
,
460 void dns_marshall_uint16(struct dns_buffer
*buf
, uint16 val
);
461 void dns_marshall_uint32(struct dns_buffer
*buf
, uint32 val
);
462 void dns_unmarshall_buffer(struct dns_buffer
*buf
, uint8
*data
,
464 void dns_unmarshall_uint16(struct dns_buffer
*buf
, uint16
*val
);
465 void dns_unmarshall_uint32(struct dns_buffer
*buf
, uint32
*val
);
466 void dns_unmarshall_domain_name(TALLOC_CTX
*mem_ctx
,
467 struct dns_buffer
*buf
,
468 struct dns_domain_name
**pname
);
469 void dns_marshall_domain_name(struct dns_buffer
*buf
,
470 const struct dns_domain_name
*name
);
471 void dns_unmarshall_domain_name(TALLOC_CTX
*mem_ctx
,
472 struct dns_buffer
*buf
,
473 struct dns_domain_name
**pname
);
474 DNS_ERROR
dns_marshall_request(TALLOC_CTX
*mem_ctx
,
475 const struct dns_request
*req
,
476 struct dns_buffer
**pbuf
);
477 DNS_ERROR
dns_unmarshall_request(TALLOC_CTX
*mem_ctx
,
478 struct dns_buffer
*buf
,
479 struct dns_request
**preq
);
480 DNS_ERROR
dns_marshall_update_request(TALLOC_CTX
*mem_ctx
,
481 struct dns_update_request
*update
,
482 struct dns_buffer
**pbuf
);
483 DNS_ERROR
dns_unmarshall_update_request(TALLOC_CTX
*mem_ctx
,
484 struct dns_buffer
*buf
,
485 struct dns_update_request
**pupreq
);
486 struct dns_request
*dns_update2request(struct dns_update_request
*update
);
487 struct dns_update_request
*dns_request2update(struct dns_request
*request
);
488 uint16
dns_response_code(uint16 flags
);
492 #ifdef HAVE_GSSAPI_SUPPORT
494 void display_status( const char *msg
, OM_uint32 maj_stat
, OM_uint32 min_stat
);
495 DNS_ERROR
dns_negotiate_sec_ctx( const char *target_realm
,
496 const char *servername
,
498 gss_ctx_id_t
*gss_ctx
,
499 enum dns_ServerType srv_type
);
500 DNS_ERROR
dns_sign_update(struct dns_update_request
*req
,
501 gss_ctx_id_t gss_ctx
,
503 const char *algorithmname
,
504 time_t time_signed
, uint16 fudge
);
505 DNS_ERROR
dns_create_update_request(TALLOC_CTX
*mem_ctx
,
506 const char *domainname
,
507 const char *hostname
,
508 const struct in_addr
*ip_addr
,
510 struct dns_update_request
**preq
);
512 #endif /* HAVE_GSSAPI_SUPPORT */