source: trunk/samba/source/libaddns/dns.h @ 30

Last change on this file since 30 was 30, checked in by Paul Smedley, 14 years ago

Code updated to Samba 3.0.25rc2 level

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