source: trunk-3.0/source/libaddns/dns.h@ 101

Last change on this file since 101 was 39, checked in by Paul Smedley, 18 years ago

Upgrade source to 3.0.25a

File size: 15.2 KB
Line 
1/*
2 Linux DNS client library implementation
3
4 Copyright (C) 2006 Krishna Ganugapati <krishnag@centeris.com>
5 Copyright (C) 2006 Gerald Carter <jerry@samba.org>
6
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
10
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.
15
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.
20
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
25*/
26
27#ifndef _DNS_H
28#define _DNS_H
29
30#include "config.h"
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <fcntl.h>
35#include <time.h>
36#ifndef __OS2__
37#include <string.h>
38#endif
39#include <errno.h>
40#include <netdb.h>
41#include <sys/types.h>
42#include <sys/socket.h>
43#include <netinet/in.h>
44#include <arpa/inet.h>
45#include <stdarg.h>
46
47#ifdef HAVE_UUID_UUID_H
48#include <uuid/uuid.h>
49#endif
50
51#ifdef HAVE_KRB5_H
52#include <krb5.h>
53#endif
54
55#ifdef HAVE_INTTYPES_H
56#include <inttypes.h>
57
58#ifndef int16
59#define int16 int16_t
60#endif
61
62#ifndef uint16
63#define uint16 uint16_t
64#endif
65
66#ifndef int32
67#define int32 int32_t
68#endif
69
70#ifndef uint32
71#define uint32 uint32_t
72#endif
73#endif
74
75#ifdef HAVE_KRB5_H
76#include <krb5.h>
77#endif
78
79#if HAVE_GSSAPI_H
80#include <gssapi.h>
81#elif HAVE_GSSAPI_GSSAPI_H
82#include <gssapi/gssapi.h>
83#elif HAVE_GSSAPI_GSSAPI_GENERIC_H
84#include <gssapi/gssapi_generic.h>
85#endif
86
87#if defined(HAVE_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_GENERIC_H)
88#define HAVE_GSSAPI_SUPPORT 1
89#endif
90
91#include <talloc.h>
92
93void *_talloc_zero_zeronull(const void *ctx, size_t size, const char *name);
94void *_talloc_memdup_zeronull(const void *t, const void *p, size_t size, const char *name);
95void *_talloc_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
96void *_talloc_zero_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
97void *talloc_zeronull(const void *context, size_t size, const char *name);
98
99#define TALLOC(ctx, size) talloc_zeronull(ctx, size, __location__)
100#define TALLOC_P(ctx, type) (type *)talloc_zeronull(ctx, sizeof(type), #type)
101#define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_zeronull(ctx, sizeof(type), count, #type)
102#define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_zeronull(ctx, ptr, size, __location__)
103#define TALLOC_ZERO(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
104#define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_zeronull(ctx, sizeof(type), #type)
105#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_zeronull(ctx, sizeof(type), count, #type)
106#define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__)
107#define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)_talloc_realloc_array(ctx, ptr, sizeof(type), count, #type)
108#define talloc_destroy(ctx) talloc_free(ctx)
109#define TALLOC_FREE(ctx) do { if ((ctx) != NULL) {talloc_free(ctx); ctx=NULL;} } while(0)
110#define TALLOC_SIZE(ctx, size) talloc_zeronull(ctx, size, __location__)
111#define TALLOC_ZERO_SIZE(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
112
113/*******************************************************************
114 Type definitions for int16, int32, uint16 and uint32. Needed
115 for Samba coding style
116*******************************************************************/
117
118#ifndef uint8
119# define uint8 unsigned char
120#endif
121
122#if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
123# if (SIZEOF_SHORT == 4)
124# define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
125# else /* SIZEOF_SHORT != 4 */
126# define int16 short
127# endif /* SIZEOF_SHORT != 4 */
128 /* needed to work around compile issue on HP-UX 11.x */
129# define _INT16 1
130#endif
131
132/*
133 * Note we duplicate the size tests in the unsigned
134 * case as int16 may be a typedef from rpc/rpc.h
135 */
136
137#if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
138# if (SIZEOF_SHORT == 4)
139# define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
140# else /* SIZEOF_SHORT != 4 */
141# define uint16 unsigned short
142# endif /* SIZEOF_SHORT != 4 */
143#endif
144
145#if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
146# if (SIZEOF_INT == 4)
147# define int32 int
148# elif (SIZEOF_LONG == 4)
149# define int32 long
150# elif (SIZEOF_SHORT == 4)
151# define int32 short
152# else
153 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
154# define int32 int
155# endif
156 /* needed to work around compile issue on HP-UX 11.x */
157# define _INT32 1
158#endif
159
160/*
161 * Note we duplicate the size tests in the unsigned
162 * case as int32 may be a typedef from rpc/rpc.h
163 */
164
165#if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
166# if (SIZEOF_INT == 4)
167# define uint32 unsigned int
168# elif (SIZEOF_LONG == 4)
169# define uint32 unsigned long
170# elif (SIZEOF_SHORT == 4)
171# define uint32 unsigned short
172# else
173 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
174# define uint32 unsigned
175# endif
176#endif
177
178/*
179 * check for 8 byte long long
180 */
181
182#if !defined(uint64)
183# if (SIZEOF_LONG == 8)
184# define uint64 unsigned long
185# elif (SIZEOF_LONG_LONG == 8)
186# define uint64 unsigned long long
187# endif /* don't lie. If we don't have it, then don't use it */
188#endif
189
190/* needed on Sun boxes */
191#ifndef INADDR_NONE
192#define INADDR_NONE 0xFFFFFFFF
193#endif
194
195#include "dnserr.h"
196
197
198#define DNS_TCP 1
199#define DNS_UDP 2
200
201#define DNS_OPCODE_UPDATE 1
202
203/* DNS Class Types */
204
205#define DNS_CLASS_IN 1
206#define DNS_CLASS_ANY 255
207#define DNS_CLASS_NONE 254
208
209/* DNS RR Types */
210
211#define DNS_RR_A 1
212
213#define DNS_TCP_PORT 53
214#define DNS_UDP_PORT 53
215
216#define QTYPE_A 1
217#define QTYPE_NS 2
218#define QTYPE_MD 3
219#define QTYPE_CNAME 5
220#define QTYPE_SOA 6
221#define QTYPE_ANY 255
222#define QTYPE_TKEY 249
223#define QTYPE_TSIG 250
224
225/*
226MF 4 a mail forwarder (Obsolete - use MX)
227CNAME 5 the canonical name for an alias
228SOA 6 marks the start of a zone of authority
229MB 7 a mailbox domain name (EXPERIMENTAL)
230MG 8 a mail group member (EXPERIMENTAL)
231MR 9 a mail rename domain name (EXPERIMENTAL)
232NULL 10 a null RR (EXPERIMENTAL)
233WKS 11 a well known service description
234PTR 12 a domain name pointer
235HINFO 13 host information
236MINFO 14 mailbox or mail list information
237MX 15 mail exchange
238TXT 16 text strings
239*/
240
241#define QR_QUERY 0x0000
242#define QR_RESPONSE 0x0001
243
244#define OPCODE_QUERY 0x00
245#define OPCODE_IQUERY 0x01
246#define OPCODE_STATUS 0x02
247
248#define AA 1
249
250#define RECURSION_DESIRED 0x01
251
252#define RCODE_NOERROR 0
253#define RCODE_FORMATERROR 1
254#define RCODE_SERVER_FAILURE 2
255#define RCODE_NAME_ERROR 3
256#define RCODE_NOTIMPLEMENTED 4
257#define RCODE_REFUSED 5
258
259#define SENDBUFFER_SIZE 65536
260#define RECVBUFFER_SIZE 65536
261
262/*
263 * TKEY Modes from rfc2930
264 */
265
266#define DNS_TKEY_MODE_SERVER 1
267#define DNS_TKEY_MODE_DH 2
268#define DNS_TKEY_MODE_GSSAPI 3
269#define DNS_TKEY_MODE_RESOLVER 4
270#define DNS_TKEY_MODE_DELETE 5
271
272
273#define DNS_ONE_DAY_IN_SECS 86400
274#define DNS_TEN_HOURS_IN_SECS 36000
275
276#define SOCKET_ERROR -1
277#define INVALID_SOCKET -1
278
279#define DNS_NO_ERROR 0
280#define DNS_FORMAT_ERROR 1
281#define DNS_SERVER_FAILURE 2
282#define DNS_NAME_ERROR 3
283#define DNS_NOT_IMPLEMENTED 4
284#define DNS_REFUSED 5
285
286typedef long HANDLE;
287
288#ifndef _UPPER_BOOL
289typedef int BOOL;
290#define _UPPER_BOOL
291#endif
292
293
294enum dns_ServerType { DNS_SRV_ANY, DNS_SRV_WIN2000, DNS_SRV_WIN2003 };
295
296struct dns_domain_label {
297 struct dns_domain_label *next;
298 char *label;
299 size_t len;
300};
301
302struct dns_domain_name {
303 struct dns_domain_label *pLabelList;
304};
305
306struct dns_question {
307 struct dns_domain_name *name;
308 uint16 q_type;
309 uint16 q_class;
310};
311
312/*
313 * Before changing the definition of dns_zone, look
314 * dns_marshall_update_request(), we rely on this being the same as
315 * dns_question right now.
316 */
317
318struct dns_zone {
319 struct dns_domain_name *name;
320 uint16 z_type;
321 uint16 z_class;
322};
323
324struct dns_rrec {
325 struct dns_domain_name *name;
326 uint16 type;
327 uint16 r_class;
328 uint32 ttl;
329 uint16 data_length;
330 uint8 *data;
331};
332
333struct dns_tkey_record {
334 struct dns_domain_name *algorithm;
335 time_t inception;
336 time_t expiration;
337 uint16 mode;
338 uint16 error;
339 uint16 key_length;
340 uint8 *key;
341};
342
343struct dns_request {
344 uint16 id;
345 uint16 flags;
346 uint16 num_questions;
347 uint16 num_answers;
348 uint16 num_auths;
349 uint16 num_additionals;
350 struct dns_question **questions;
351 struct dns_rrec **answers;
352 struct dns_rrec **auths;
353 struct dns_rrec **additionals;
354};
355
356/*
357 * Before changing the definition of dns_update_request, look
358 * dns_marshall_update_request(), we rely on this being the same as
359 * dns_request right now.
360 */
361
362struct dns_update_request {
363 uint16 id;
364 uint16 flags;
365 uint16 num_zones;
366 uint16 num_preqs;
367 uint16 num_updates;
368 uint16 num_additionals;
369 struct dns_zone **zones;
370 struct dns_rrec **preqs;
371 struct dns_rrec **updates;
372 struct dns_rrec **additionals;
373};
374
375struct dns_connection {
376 int32 hType;
377 int s;
378 struct sockaddr RecvAddr;
379};
380
381struct dns_buffer {
382 uint8 *data;
383 size_t size;
384 size_t offset;
385 DNS_ERROR error;
386};
387
388/* from dnsutils.c */
389
390DNS_ERROR dns_domain_name_from_string( TALLOC_CTX *mem_ctx,
391 const char *pszDomainName,
392 struct dns_domain_name **presult );
393char *dns_generate_keyname( TALLOC_CTX *mem_ctx );
394
395/* from dnsrecord.c */
396
397DNS_ERROR dns_create_query( TALLOC_CTX *mem_ctx, const char *name,
398 uint16 q_type, uint16 q_class,
399 struct dns_request **preq );
400DNS_ERROR dns_create_update( TALLOC_CTX *mem_ctx, const char *name,
401 struct dns_update_request **preq );
402DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone,
403 const char *host, int num_ips,
404 const struct in_addr *iplist,
405 struct dns_update_request **preq);
406DNS_ERROR dns_create_rrec(TALLOC_CTX *mem_ctx, const char *name,
407 uint16 type, uint16 r_class, uint32 ttl,
408 uint16 data_length, uint8 *data,
409 struct dns_rrec **prec);
410DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
411 uint16 *num_records, struct dns_rrec ***records);
412DNS_ERROR dns_create_tkey_record(TALLOC_CTX *mem_ctx, const char *keyname,
413 const char *algorithm_name, time_t inception,
414 time_t expiration, uint16 mode, uint16 error,
415 uint16 key_length, const uint8 *key,
416 struct dns_rrec **prec);
417DNS_ERROR dns_create_name_in_use_record(TALLOC_CTX *mem_ctx,
418 const char *name,
419 const struct in_addr *ip,
420 struct dns_rrec **prec);
421DNS_ERROR dns_create_delete_record(TALLOC_CTX *mem_ctx, const char *name,
422 uint16 type, uint16 r_class,
423 struct dns_rrec **prec);
424DNS_ERROR dns_create_name_not_in_use_record(TALLOC_CTX *mem_ctx,
425 const char *name, uint32 type,
426 struct dns_rrec **prec);
427DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host,
428 uint32 ttl, struct in_addr ip,
429 struct dns_rrec **prec);
430DNS_ERROR dns_unmarshall_tkey_record(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
431 struct dns_tkey_record **ptkey);
432DNS_ERROR dns_create_tsig_record(TALLOC_CTX *mem_ctx, const char *keyname,
433 const char *algorithm_name,
434 time_t time_signed, uint16 fudge,
435 uint16 mac_length, const uint8 *mac,
436 uint16 original_id, uint16 error,
437 struct dns_rrec **prec);
438DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
439 uint16 *num_records, struct dns_rrec ***records);
440
441/* from dnssock.c */
442
443DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
444 TALLOC_CTX *mem_ctx,
445 struct dns_connection **conn );
446DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf);
447DNS_ERROR dns_receive(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
448 struct dns_buffer **presult);
449DNS_ERROR dns_transaction(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
450 const struct dns_request *req,
451 struct dns_request **resp);
452DNS_ERROR dns_update_transaction(TALLOC_CTX *mem_ctx,
453 struct dns_connection *conn,
454 struct dns_update_request *up_req,
455 struct dns_update_request **up_resp);
456
457/* from dnsmarshall.c */
458
459struct dns_buffer *dns_create_buffer(TALLOC_CTX *mem_ctx);
460void dns_marshall_buffer(struct dns_buffer *buf, const uint8 *data,
461 size_t len);
462void dns_marshall_uint16(struct dns_buffer *buf, uint16 val);
463void dns_marshall_uint32(struct dns_buffer *buf, uint32 val);
464void dns_unmarshall_buffer(struct dns_buffer *buf, uint8 *data,
465 size_t len);
466void dns_unmarshall_uint16(struct dns_buffer *buf, uint16 *val);
467void dns_unmarshall_uint32(struct dns_buffer *buf, uint32 *val);
468void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
469 struct dns_buffer *buf,
470 struct dns_domain_name **pname);
471void dns_marshall_domain_name(struct dns_buffer *buf,
472 const struct dns_domain_name *name);
473void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
474 struct dns_buffer *buf,
475 struct dns_domain_name **pname);
476DNS_ERROR dns_marshall_request(TALLOC_CTX *mem_ctx,
477 const struct dns_request *req,
478 struct dns_buffer **pbuf);
479DNS_ERROR dns_unmarshall_request(TALLOC_CTX *mem_ctx,
480 struct dns_buffer *buf,
481 struct dns_request **preq);
482DNS_ERROR dns_marshall_update_request(TALLOC_CTX *mem_ctx,
483 struct dns_update_request *update,
484 struct dns_buffer **pbuf);
485DNS_ERROR dns_unmarshall_update_request(TALLOC_CTX *mem_ctx,
486 struct dns_buffer *buf,
487 struct dns_update_request **pupreq);
488struct dns_request *dns_update2request(struct dns_update_request *update);
489struct dns_update_request *dns_request2update(struct dns_request *request);
490uint16 dns_response_code(uint16 flags);
491
492/* from dnsgss.c */
493
494#ifdef HAVE_GSSAPI_SUPPORT
495
496void display_status( const char *msg, OM_uint32 maj_stat, OM_uint32 min_stat );
497DNS_ERROR dns_negotiate_sec_ctx( const char *target_realm,
498 const char *servername,
499 const char *keyname,
500 gss_ctx_id_t *gss_ctx,
501 enum dns_ServerType srv_type );
502DNS_ERROR dns_sign_update(struct dns_update_request *req,
503 gss_ctx_id_t gss_ctx,
504 const char *keyname,
505 const char *algorithmname,
506 time_t time_signed, uint16 fudge);
507DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx,
508 const char *domainname,
509 const char *hostname,
510 const struct in_addr *ip_addr,
511 size_t num_adds,
512 struct dns_update_request **preq);
513
514#endif /* HAVE_GSSAPI_SUPPORT */
515
516#endif /* _DNS_H */
Note: See TracBrowser for help on using the repository browser.