r21585: Start syncing the monster that will become 3.0.25pre1
[Samba.git] / source / libaddns / dns.h
blob6f480a546957ecc432a5ca54462cf7d0654a51f1
1 /*
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
9 ** under the LGPL
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
24 02110-1301 USA
27 #ifndef _DNS_H
28 #define _DNS_H
30 #include "config.h"
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <fcntl.h>
35 #include <time.h>
36 #include <string.h>
37 #include <errno.h>
38 #include <netdb.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
43 #include <stdarg.h>
45 #ifdef HAVE_UUID_UUID_H
46 #include <uuid/uuid.h>
47 #endif
49 #ifdef HAVE_KRB5_H
50 #include <krb5.h>
51 #endif
53 #ifdef HAVE_INTTYPES_H
54 #include <inttypes.h>
56 #ifndef int16
57 #define int16 int16_t
58 #endif
60 #ifndef uint16
61 #define uint16 uint16_t
62 #endif
64 #ifndef int32
65 #define int32 int32_t
66 #endif
68 #ifndef uint32
69 #define uint32 uint32_t
70 #endif
71 #endif
73 #ifdef HAVE_KRB5_H
74 #include <krb5.h>
75 #endif
77 #if HAVE_GSSAPI_H
78 #include <gssapi.h>
79 #elif HAVE_GSSAPI_GSSAPI_H
80 #include <gssapi/gssapi.h>
81 #elif HAVE_GSSAPI_GSSAPI_GENERIC_H
82 #include <gssapi/gssapi_generic.h>
83 #endif
85 #if defined(HAVE_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_GENERIC_H)
86 #define HAVE_GSSAPI_SUPPORT 1
87 #endif
89 #include <talloc.h>
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 *******************************************************************/
107 #ifndef uint8
108 # define uint8 unsigned char
109 #endif
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 */
115 # define int16 short
116 # endif /* SIZEOF_SHORT != 4 */
117 /* needed to work around compile issue on HP-UX 11.x */
118 # define _INT16 1
119 #endif
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 */
132 #endif
134 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
135 # if (SIZEOF_INT == 4)
136 # define int32 int
137 # elif (SIZEOF_LONG == 4)
138 # define int32 long
139 # elif (SIZEOF_SHORT == 4)
140 # define int32 short
141 # else
142 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
143 # define int32 int
144 # endif
145 /* needed to work around compile issue on HP-UX 11.x */
146 # define _INT32 1
147 #endif
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
161 # else
162 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
163 # define uint32 unsigned
164 # endif
165 #endif
168 * check for 8 byte long long
171 #if !defined(uint64)
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 */
177 #endif
179 /* needed on Sun boxes */
180 #ifndef INADDR_NONE
181 #define INADDR_NONE 0xFFFFFFFF
182 #endif
184 #include "dnserr.h"
187 #define DNS_TCP 1
188 #define DNS_UDP 2
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
198 /* DNS RR Types */
200 #define DNS_RR_A 1
202 #define DNS_TCP_PORT 53
203 #define DNS_UDP_PORT 53
205 #define QTYPE_A 1
206 #define QTYPE_NS 2
207 #define QTYPE_MD 3
208 #define QTYPE_CNAME 5
209 #define QTYPE_SOA 6
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
226 MX 15 mail exchange
227 TXT 16 text strings
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
237 #define AA 1
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
275 typedef long HANDLE;
277 #ifndef _UPPER_BOOL
278 typedef int BOOL;
279 #define _UPPER_BOOL
280 #endif
283 enum dns_ServerType { DNS_SRV_ANY, DNS_SRV_WIN2000, DNS_SRV_WIN2003 };
285 struct dns_domain_label {
286 struct dns_domain_label *next;
287 char *label;
288 size_t len;
291 struct dns_domain_name {
292 struct dns_domain_label *pLabelList;
295 struct dns_question {
296 struct dns_domain_name *name;
297 uint16 q_type;
298 uint16 q_class;
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.
307 struct dns_zone {
308 struct dns_domain_name *name;
309 uint16 z_type;
310 uint16 z_class;
313 struct dns_rrec {
314 struct dns_domain_name *name;
315 uint16 type;
316 uint16 r_class;
317 uint32 ttl;
318 uint16 data_length;
319 uint8 *data;
322 struct dns_tkey_record {
323 struct dns_domain_name *algorithm;
324 time_t inception;
325 time_t expiration;
326 uint16 mode;
327 uint16 error;
328 uint16 key_length;
329 uint8 *key;
332 struct dns_request {
333 uint16 id;
334 uint16 flags;
335 uint16 num_questions;
336 uint16 num_answers;
337 uint16 num_auths;
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 {
352 uint16 id;
353 uint16 flags;
354 uint16 num_zones;
355 uint16 num_preqs;
356 uint16 num_updates;
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 {
365 int32 hType;
366 int s;
367 struct sockaddr RecvAddr;
370 struct dns_buffer {
371 uint8 *data;
372 size_t size;
373 size_t offset;
374 DNS_ERROR error;
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,
407 const char *name,
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);
430 /* from dnssock.c */
432 DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
433 TALLOC_CTX *mem_ctx,
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,
450 size_t len);
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,
454 size_t len);
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);
481 /* from dnsgss.c */
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,
488 const char *keyname,
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,
493 const char *keyname,
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,
500 size_t num_adds,
501 struct dns_update_request **preq);
503 #endif /* HAVE_GSSAPI_SUPPORT */
505 #endif /* _DNS_H */