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