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 #define TALLOC(ctx, size) talloc_named_const(ctx, size, __location__)
92 #define TALLOC_P(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
93 #define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
94 #define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup(ctx, ptr, size, __location__)
95 #define TALLOC_ZERO(ctx, size) _talloc_zero(ctx, size, __location__)
96 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
97 #define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
98 #define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__)
99 #define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)_talloc_realloc_array(ctx, ptr, sizeof(type), count, #type)
100 #define TALLOC_FREE(ctx) do { if ((ctx) != NULL) {talloc_free(ctx); ctx=NULL;} } while(0)
102 /*******************************************************************
103 Type definitions for int16, int32, uint16 and uint32. Needed
104 for Samba coding style
105 *******************************************************************/
108 # define uint8 unsigned char
111 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
112 # if (SIZEOF_SHORT == 4)
113 # define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
114 # else /* SIZEOF_SHORT != 4 */
116 # endif /* SIZEOF_SHORT != 4 */
117 /* needed to work around compile issue on HP-UX 11.x */
122 * Note we duplicate the size tests in the unsigned
123 * case as int16 may be a typedef from rpc/rpc.h
126 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
127 # if (SIZEOF_SHORT == 4)
128 # define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
129 # else /* SIZEOF_SHORT != 4 */
130 # define uint16 unsigned short
131 # endif /* SIZEOF_SHORT != 4 */
134 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
135 # if (SIZEOF_INT == 4)
137 # elif (SIZEOF_LONG == 4)
139 # elif (SIZEOF_SHORT == 4)
142 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
145 /* needed to work around compile issue on HP-UX 11.x */
150 * Note we duplicate the size tests in the unsigned
151 * case as int32 may be a typedef from rpc/rpc.h
154 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
155 # if (SIZEOF_INT == 4)
156 # define uint32 unsigned int
157 # elif (SIZEOF_LONG == 4)
158 # define uint32 unsigned long
159 # elif (SIZEOF_SHORT == 4)
160 # define uint32 unsigned short
162 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
163 # define uint32 unsigned
168 * check for 8 byte long long
172 # if (SIZEOF_LONG == 8)
173 # define uint64 unsigned long
174 # elif (SIZEOF_LONG_LONG == 8)
175 # define uint64 unsigned long long
176 # endif /* don't lie. If we don't have it, then don't use it */
179 /* needed on Sun boxes */
181 #define INADDR_NONE 0xFFFFFFFF
190 #define DNS_OPCODE_UPDATE 1
192 /* DNS Class Types */
194 #define DNS_CLASS_IN 1
195 #define DNS_CLASS_ANY 255
196 #define DNS_CLASS_NONE 254
202 #define DNS_TCP_PORT 53
203 #define DNS_UDP_PORT 53
208 #define QTYPE_CNAME 5
210 #define QTYPE_ANY 255
211 #define QTYPE_TKEY 249
212 #define QTYPE_TSIG 250
215 MF 4 a mail forwarder (Obsolete - use MX)
216 CNAME 5 the canonical name for an alias
217 SOA 6 marks the start of a zone of authority
218 MB 7 a mailbox domain name (EXPERIMENTAL)
219 MG 8 a mail group member (EXPERIMENTAL)
220 MR 9 a mail rename domain name (EXPERIMENTAL)
221 NULL 10 a null RR (EXPERIMENTAL)
222 WKS 11 a well known service description
223 PTR 12 a domain name pointer
224 HINFO 13 host information
225 MINFO 14 mailbox or mail list information
230 #define QR_QUERY 0x0000
231 #define QR_RESPONSE 0x0001
233 #define OPCODE_QUERY 0x00
234 #define OPCODE_IQUERY 0x01
235 #define OPCODE_STATUS 0x02
239 #define RECURSION_DESIRED 0x01
241 #define RCODE_NOERROR 0
242 #define RCODE_FORMATERROR 1
243 #define RCODE_SERVER_FAILURE 2
244 #define RCODE_NAME_ERROR 3
245 #define RCODE_NOTIMPLEMENTED 4
246 #define RCODE_REFUSED 5
248 #define SENDBUFFER_SIZE 65536
249 #define RECVBUFFER_SIZE 65536
252 * TKEY Modes from rfc2930
255 #define DNS_TKEY_MODE_SERVER 1
256 #define DNS_TKEY_MODE_DH 2
257 #define DNS_TKEY_MODE_GSSAPI 3
258 #define DNS_TKEY_MODE_RESOLVER 4
259 #define DNS_TKEY_MODE_DELETE 5
262 #define DNS_ONE_DAY_IN_SECS 86400
263 #define DNS_TEN_HOURS_IN_SECS 36000
265 #define SOCKET_ERROR -1
266 #define INVALID_SOCKET -1
268 #define DNS_NO_ERROR 0
269 #define DNS_FORMAT_ERROR 1
270 #define DNS_SERVER_FAILURE 2
271 #define DNS_NAME_ERROR 3
272 #define DNS_NOT_IMPLEMENTED 4
273 #define DNS_REFUSED 5
283 enum dns_ServerType
{ DNS_SRV_ANY
, DNS_SRV_WIN2000
, DNS_SRV_WIN2003
};
285 struct dns_domain_label
{
286 struct dns_domain_label
*next
;
291 struct dns_domain_name
{
292 struct dns_domain_label
*pLabelList
;
295 struct dns_question
{
296 struct dns_domain_name
*name
;
302 * Before changing the definition of dns_zone, look
303 * dns_marshall_update_request(), we rely on this being the same as
304 * dns_question right now.
308 struct dns_domain_name
*name
;
314 struct dns_domain_name
*name
;
322 struct dns_tkey_record
{
323 struct dns_domain_name
*algorithm
;
335 uint16 num_questions
;
338 uint16 num_additionals
;
339 struct dns_question
**questions
;
340 struct dns_rrec
**answers
;
341 struct dns_rrec
**auths
;
342 struct dns_rrec
**additionals
;
346 * Before changing the definition of dns_update_request, look
347 * dns_marshall_update_request(), we rely on this being the same as
348 * dns_request right now.
351 struct dns_update_request
{
357 uint16 num_additionals
;
358 struct dns_zone
**zones
;
359 struct dns_rrec
**preqs
;
360 struct dns_rrec
**updates
;
361 struct dns_rrec
**additionals
;
364 struct dns_connection
{
367 struct sockaddr RecvAddr
;
377 /* from dnsutils.c */
379 DNS_ERROR
dns_domain_name_from_string( TALLOC_CTX
*mem_ctx
,
380 const char *pszDomainName
,
381 struct dns_domain_name
**presult
);
382 char *dns_generate_keyname( TALLOC_CTX
*mem_ctx
);
384 /* from dnsrecord.c */
386 DNS_ERROR
dns_create_query( TALLOC_CTX
*mem_ctx
, const char *name
,
387 uint16 q_type
, uint16 q_class
,
388 struct dns_request
**preq
);
389 DNS_ERROR
dns_create_update( TALLOC_CTX
*mem_ctx
, const char *name
,
390 struct dns_update_request
**preq
);
391 DNS_ERROR
dns_create_probe(TALLOC_CTX
*mem_ctx
, const char *zone
,
392 const char *host
, int num_ips
,
393 const struct in_addr
*iplist
,
394 struct dns_update_request
**preq
);
395 DNS_ERROR
dns_create_rrec(TALLOC_CTX
*mem_ctx
, const char *name
,
396 uint16 type
, uint16 r_class
, uint32 ttl
,
397 uint16 data_length
, uint8
*data
,
398 struct dns_rrec
**prec
);
399 DNS_ERROR
dns_add_rrec(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
400 uint16
*num_records
, struct dns_rrec
***records
);
401 DNS_ERROR
dns_create_tkey_record(TALLOC_CTX
*mem_ctx
, const char *keyname
,
402 const char *algorithm_name
, time_t inception
,
403 time_t expiration
, uint16 mode
, uint16 error
,
404 uint16 key_length
, const uint8
*key
,
405 struct dns_rrec
**prec
);
406 DNS_ERROR
dns_create_name_in_use_record(TALLOC_CTX
*mem_ctx
,
408 const struct in_addr
*ip
,
409 struct dns_rrec
**prec
);
410 DNS_ERROR
dns_create_delete_record(TALLOC_CTX
*mem_ctx
, const char *name
,
411 uint16 type
, uint16 r_class
,
412 struct dns_rrec
**prec
);
413 DNS_ERROR
dns_create_name_not_in_use_record(TALLOC_CTX
*mem_ctx
,
414 const char *name
, uint32 type
,
415 struct dns_rrec
**prec
);
416 DNS_ERROR
dns_create_a_record(TALLOC_CTX
*mem_ctx
, const char *host
,
417 uint32 ttl
, struct in_addr ip
,
418 struct dns_rrec
**prec
);
419 DNS_ERROR
dns_unmarshall_tkey_record(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
420 struct dns_tkey_record
**ptkey
);
421 DNS_ERROR
dns_create_tsig_record(TALLOC_CTX
*mem_ctx
, const char *keyname
,
422 const char *algorithm_name
,
423 time_t time_signed
, uint16 fudge
,
424 uint16 mac_length
, const uint8
*mac
,
425 uint16 original_id
, uint16 error
,
426 struct dns_rrec
**prec
);
427 DNS_ERROR
dns_add_rrec(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
428 uint16
*num_records
, struct dns_rrec
***records
);
432 DNS_ERROR
dns_open_connection( const char *nameserver
, int32 dwType
,
434 struct dns_connection
**conn
);
435 DNS_ERROR
dns_send(struct dns_connection
*conn
, const struct dns_buffer
*buf
);
436 DNS_ERROR
dns_receive(TALLOC_CTX
*mem_ctx
, struct dns_connection
*conn
,
437 struct dns_buffer
**presult
);
438 DNS_ERROR
dns_transaction(TALLOC_CTX
*mem_ctx
, struct dns_connection
*conn
,
439 const struct dns_request
*req
,
440 struct dns_request
**resp
);
441 DNS_ERROR
dns_update_transaction(TALLOC_CTX
*mem_ctx
,
442 struct dns_connection
*conn
,
443 struct dns_update_request
*up_req
,
444 struct dns_update_request
**up_resp
);
446 /* from dnsmarshall.c */
448 struct dns_buffer
*dns_create_buffer(TALLOC_CTX
*mem_ctx
);
449 void dns_marshall_buffer(struct dns_buffer
*buf
, const uint8
*data
,
451 void dns_marshall_uint16(struct dns_buffer
*buf
, uint16 val
);
452 void dns_marshall_uint32(struct dns_buffer
*buf
, uint32 val
);
453 void dns_unmarshall_buffer(struct dns_buffer
*buf
, uint8
*data
,
455 void dns_unmarshall_uint16(struct dns_buffer
*buf
, uint16
*val
);
456 void dns_unmarshall_uint32(struct dns_buffer
*buf
, uint32
*val
);
457 void dns_unmarshall_domain_name(TALLOC_CTX
*mem_ctx
,
458 struct dns_buffer
*buf
,
459 struct dns_domain_name
**pname
);
460 void dns_marshall_domain_name(struct dns_buffer
*buf
,
461 const struct dns_domain_name
*name
);
462 void dns_unmarshall_domain_name(TALLOC_CTX
*mem_ctx
,
463 struct dns_buffer
*buf
,
464 struct dns_domain_name
**pname
);
465 DNS_ERROR
dns_marshall_request(TALLOC_CTX
*mem_ctx
,
466 const struct dns_request
*req
,
467 struct dns_buffer
**pbuf
);
468 DNS_ERROR
dns_unmarshall_request(TALLOC_CTX
*mem_ctx
,
469 struct dns_buffer
*buf
,
470 struct dns_request
**preq
);
471 DNS_ERROR
dns_marshall_update_request(TALLOC_CTX
*mem_ctx
,
472 struct dns_update_request
*update
,
473 struct dns_buffer
**pbuf
);
474 DNS_ERROR
dns_unmarshall_update_request(TALLOC_CTX
*mem_ctx
,
475 struct dns_buffer
*buf
,
476 struct dns_update_request
**pupreq
);
477 struct dns_request
*dns_update2request(struct dns_update_request
*update
);
478 struct dns_update_request
*dns_request2update(struct dns_request
*request
);
479 uint16
dns_response_code(uint16 flags
);
483 #ifdef HAVE_GSSAPI_SUPPORT
485 void display_status( const char *msg
, OM_uint32 maj_stat
, OM_uint32 min_stat
);
486 DNS_ERROR
dns_negotiate_sec_ctx( const char *target_realm
,
487 const char *servername
,
489 gss_ctx_id_t
*gss_ctx
,
490 enum dns_ServerType srv_type
);
491 DNS_ERROR
dns_sign_update(struct dns_update_request
*req
,
492 gss_ctx_id_t gss_ctx
,
494 const char *algorithmname
,
495 time_t time_signed
, uint16 fudge
);
496 DNS_ERROR
dns_create_update_request(TALLOC_CTX
*mem_ctx
,
497 const char *domainname
,
498 const char *hostname
,
499 const struct in_addr
*ip_addr
,
501 struct dns_update_request
**preq
);
503 #endif /* HAVE_GSSAPI_SUPPORT */