s3-passdb: fix uninitialized variable in local_password_change().
[Samba.git] / source3 / libaddns / dns.h
bloba04a13bfd96a7027257970b2368555f8a1575ce4
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, see <http://www.gnu.org/licenses/>.
25 #ifndef _DNS_H
26 #define _DNS_H
28 #include "../replace/replace.h"
29 #include "system/network.h"
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 */
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>
52 #ifdef HAVE_UUID_UUID_H
53 #include <uuid/uuid.h>
54 #endif
56 #ifdef HAVE_KRB5_H
57 #include <krb5.h>
58 #endif
60 #ifdef HAVE_INTTYPES_H
61 #include <inttypes.h>
63 #ifndef int16
64 #define int16 int16_t
65 #endif
67 #ifndef uint16
68 #define uint16 uint16_t
69 #endif
71 #ifndef int32
72 #define int32 int32_t
73 #endif
75 #ifndef uint32
76 #define uint32 uint32_t
77 #endif
78 #endif
80 #ifdef HAVE_KRB5_H
81 #include <krb5.h>
82 #endif
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
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
96 #include <talloc.h>
98 #if 0
100 Disable these now we have checked all code paths and ensured
101 NULL returns on zero request. JRA.
103 void *_talloc_zero_zeronull(const void *ctx, size_t size, const char *name);
104 void *_talloc_memdup_zeronull(const void *t, const void *p, size_t size, const char *name);
105 void *_talloc_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
106 void *_talloc_zero_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
107 void *talloc_zeronull(const void *context, size_t size, const char *name);
109 #define TALLOC(ctx, size) talloc_zeronull(ctx, size, __location__)
110 #define TALLOC_P(ctx, type) (type *)talloc_zeronull(ctx, sizeof(type), #type)
111 #define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_zeronull(ctx, sizeof(type), count, #type)
112 #define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_zeronull(ctx, ptr, size, __location__)
113 #define TALLOC_ZERO(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
114 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_zeronull(ctx, sizeof(type), #type)
115 #define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_zeronull(ctx, sizeof(type), count, #type)
116 #define TALLOC_SIZE(ctx, size) talloc_zeronull(ctx, size, __location__)
117 #define TALLOC_ZERO_SIZE(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
119 #else
121 #define TALLOC(ctx, size) talloc_named_const(ctx, size, __location__)
122 #define TALLOC_P(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
123 #define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
124 #define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup(ctx, ptr, size, __location__)
125 #define TALLOC_ZERO(ctx, size) _talloc_zero(ctx, size, __location__)
126 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
127 #define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
128 #define TALLOC_SIZE(ctx, size) talloc_named_const(ctx, size, __location__)
129 #define TALLOC_ZERO_SIZE(ctx, size) _talloc_zero(ctx, size, __location__)
131 #endif
133 #define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__)
134 #define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)_talloc_realloc_array(ctx, ptr, sizeof(type), count, #type)
135 #define talloc_destroy(ctx) talloc_free(ctx)
136 #ifndef TALLOC_FREE
137 #define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0)
138 #endif
140 /*******************************************************************
141 Type definitions for int16, int32, uint16 and uint32. Needed
142 for Samba coding style
143 *******************************************************************/
145 #ifndef uint8
146 # define uint8 unsigned char
147 #endif
149 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
150 # if (SIZEOF_SHORT == 4)
151 # define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
152 # else /* SIZEOF_SHORT != 4 */
153 # define int16 short
154 # endif /* SIZEOF_SHORT != 4 */
155 /* needed to work around compile issue on HP-UX 11.x */
156 # define _INT16 1
157 #endif
160 * Note we duplicate the size tests in the unsigned
161 * case as int16 may be a typedef from rpc/rpc.h
164 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
165 # if (SIZEOF_SHORT == 4)
166 # define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
167 # else /* SIZEOF_SHORT != 4 */
168 # define uint16 unsigned short
169 # endif /* SIZEOF_SHORT != 4 */
170 #endif
172 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
173 # if (SIZEOF_INT == 4)
174 # define int32 int
175 # elif (SIZEOF_LONG == 4)
176 # define int32 long
177 # elif (SIZEOF_SHORT == 4)
178 # define int32 short
179 # else
180 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
181 # define int32 int
182 # endif
183 /* needed to work around compile issue on HP-UX 11.x */
184 # define _INT32 1
185 #endif
188 * Note we duplicate the size tests in the unsigned
189 * case as int32 may be a typedef from rpc/rpc.h
192 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
193 # if (SIZEOF_INT == 4)
194 # define uint32 unsigned int
195 # elif (SIZEOF_LONG == 4)
196 # define uint32 unsigned long
197 # elif (SIZEOF_SHORT == 4)
198 # define uint32 unsigned short
199 # else
200 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
201 # define uint32 unsigned
202 # endif
203 #endif
206 * check for 8 byte long long
209 #if !defined(uint64)
210 # if (SIZEOF_LONG == 8)
211 # define uint64 unsigned long
212 # elif (SIZEOF_LONG_LONG == 8)
213 # define uint64 unsigned long long
214 # endif /* don't lie. If we don't have it, then don't use it */
215 #endif
217 /* needed on Sun boxes */
218 #ifndef INADDR_NONE
219 #define INADDR_NONE 0xFFFFFFFF
220 #endif
222 #include "dnserr.h"
225 #define DNS_TCP 1
226 #define DNS_UDP 2
228 #define DNS_OPCODE_UPDATE 1
230 /* DNS Class Types */
232 #define DNS_CLASS_IN 1
233 #define DNS_CLASS_ANY 255
234 #define DNS_CLASS_NONE 254
236 /* DNS RR Types */
238 #define DNS_RR_A 1
240 #define DNS_TCP_PORT 53
241 #define DNS_UDP_PORT 53
243 #define QTYPE_A 1
244 #define QTYPE_NS 2
245 #define QTYPE_MD 3
246 #define QTYPE_CNAME 5
247 #define QTYPE_SOA 6
248 #define QTYPE_ANY 255
249 #define QTYPE_TKEY 249
250 #define QTYPE_TSIG 250
253 MF 4 a mail forwarder (Obsolete - use MX)
254 CNAME 5 the canonical name for an alias
255 SOA 6 marks the start of a zone of authority
256 MB 7 a mailbox domain name (EXPERIMENTAL)
257 MG 8 a mail group member (EXPERIMENTAL)
258 MR 9 a mail rename domain name (EXPERIMENTAL)
259 NULL 10 a null RR (EXPERIMENTAL)
260 WKS 11 a well known service description
261 PTR 12 a domain name pointer
262 HINFO 13 host information
263 MINFO 14 mailbox or mail list information
264 MX 15 mail exchange
265 TXT 16 text strings
268 #define QR_QUERY 0x0000
269 #define QR_RESPONSE 0x0001
271 #define OPCODE_QUERY 0x00
272 #define OPCODE_IQUERY 0x01
273 #define OPCODE_STATUS 0x02
275 #define AA 1
277 #define RECURSION_DESIRED 0x01
279 #define RCODE_NOERROR 0
280 #define RCODE_FORMATERROR 1
281 #define RCODE_SERVER_FAILURE 2
282 #define RCODE_NAME_ERROR 3
283 #define RCODE_NOTIMPLEMENTED 4
284 #define RCODE_REFUSED 5
286 #define SENDBUFFER_SIZE 65536
287 #define RECVBUFFER_SIZE 65536
290 * TKEY Modes from rfc2930
293 #define DNS_TKEY_MODE_SERVER 1
294 #define DNS_TKEY_MODE_DH 2
295 #define DNS_TKEY_MODE_GSSAPI 3
296 #define DNS_TKEY_MODE_RESOLVER 4
297 #define DNS_TKEY_MODE_DELETE 5
300 #define DNS_ONE_DAY_IN_SECS 86400
301 #define DNS_TEN_HOURS_IN_SECS 36000
303 #define SOCKET_ERROR -1
304 #define INVALID_SOCKET -1
306 #define DNS_NO_ERROR 0
307 #define DNS_FORMAT_ERROR 1
308 #define DNS_SERVER_FAILURE 2
309 #define DNS_NAME_ERROR 3
310 #define DNS_NOT_IMPLEMENTED 4
311 #define DNS_REFUSED 5
313 typedef long HANDLE;
315 enum dns_ServerType { DNS_SRV_ANY, DNS_SRV_WIN2000, DNS_SRV_WIN2003 };
317 struct dns_domain_label {
318 struct dns_domain_label *next;
319 char *label;
320 size_t len;
323 struct dns_domain_name {
324 struct dns_domain_label *pLabelList;
327 struct dns_question {
328 struct dns_domain_name *name;
329 uint16 q_type;
330 uint16 q_class;
334 * Before changing the definition of dns_zone, look
335 * dns_marshall_update_request(), we rely on this being the same as
336 * dns_question right now.
339 struct dns_zone {
340 struct dns_domain_name *name;
341 uint16 z_type;
342 uint16 z_class;
345 struct dns_rrec {
346 struct dns_domain_name *name;
347 uint16 type;
348 uint16 r_class;
349 uint32 ttl;
350 uint16 data_length;
351 uint8 *data;
354 struct dns_tkey_record {
355 struct dns_domain_name *algorithm;
356 time_t inception;
357 time_t expiration;
358 uint16 mode;
359 uint16 error;
360 uint16 key_length;
361 uint8 *key;
364 struct dns_request {
365 uint16 id;
366 uint16 flags;
367 uint16 num_questions;
368 uint16 num_answers;
369 uint16 num_auths;
370 uint16 num_additionals;
371 struct dns_question **questions;
372 struct dns_rrec **answers;
373 struct dns_rrec **auths;
374 struct dns_rrec **additionals;
378 * Before changing the definition of dns_update_request, look
379 * dns_marshall_update_request(), we rely on this being the same as
380 * dns_request right now.
383 struct dns_update_request {
384 uint16 id;
385 uint16 flags;
386 uint16 num_zones;
387 uint16 num_preqs;
388 uint16 num_updates;
389 uint16 num_additionals;
390 struct dns_zone **zones;
391 struct dns_rrec **preqs;
392 struct dns_rrec **updates;
393 struct dns_rrec **additionals;
396 struct dns_connection {
397 int32 hType;
398 int s;
399 struct sockaddr RecvAddr;
402 struct dns_buffer {
403 uint8 *data;
404 size_t size;
405 size_t offset;
406 DNS_ERROR error;
409 /* from dnsutils.c */
411 DNS_ERROR dns_domain_name_from_string( TALLOC_CTX *mem_ctx,
412 const char *pszDomainName,
413 struct dns_domain_name **presult );
414 char *dns_generate_keyname( TALLOC_CTX *mem_ctx );
416 /* from dnsrecord.c */
418 DNS_ERROR dns_create_query( TALLOC_CTX *mem_ctx, const char *name,
419 uint16 q_type, uint16 q_class,
420 struct dns_request **preq );
421 DNS_ERROR dns_create_update( TALLOC_CTX *mem_ctx, const char *name,
422 struct dns_update_request **preq );
423 DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone,
424 const char *host, int num_ips,
425 const struct sockaddr_storage *sslist,
426 struct dns_update_request **preq);
427 DNS_ERROR dns_create_rrec(TALLOC_CTX *mem_ctx, const char *name,
428 uint16 type, uint16 r_class, uint32 ttl,
429 uint16 data_length, uint8 *data,
430 struct dns_rrec **prec);
431 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
432 uint16 *num_records, struct dns_rrec ***records);
433 DNS_ERROR dns_create_tkey_record(TALLOC_CTX *mem_ctx, const char *keyname,
434 const char *algorithm_name, time_t inception,
435 time_t expiration, uint16 mode, uint16 error,
436 uint16 key_length, const uint8 *key,
437 struct dns_rrec **prec);
438 DNS_ERROR dns_create_name_in_use_record(TALLOC_CTX *mem_ctx,
439 const char *name,
440 const struct sockaddr_storage *ip,
441 struct dns_rrec **prec);
442 DNS_ERROR dns_create_delete_record(TALLOC_CTX *mem_ctx, const char *name,
443 uint16 type, uint16 r_class,
444 struct dns_rrec **prec);
445 DNS_ERROR dns_create_name_not_in_use_record(TALLOC_CTX *mem_ctx,
446 const char *name, uint32 type,
447 struct dns_rrec **prec);
448 DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host,
449 uint32 ttl, const struct sockaddr_storage *pss,
450 struct dns_rrec **prec);
451 DNS_ERROR dns_unmarshall_tkey_record(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
452 struct dns_tkey_record **ptkey);
453 DNS_ERROR dns_create_tsig_record(TALLOC_CTX *mem_ctx, const char *keyname,
454 const char *algorithm_name,
455 time_t time_signed, uint16 fudge,
456 uint16 mac_length, const uint8 *mac,
457 uint16 original_id, uint16 error,
458 struct dns_rrec **prec);
459 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
460 uint16 *num_records, struct dns_rrec ***records);
461 DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx,
462 const char *domainname,
463 const char *hostname,
464 const struct sockaddr_storage *ip_addr,
465 size_t num_adds,
466 struct dns_update_request **preq);
468 /* from dnssock.c */
470 DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
471 TALLOC_CTX *mem_ctx,
472 struct dns_connection **conn );
473 DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf);
474 DNS_ERROR dns_receive(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
475 struct dns_buffer **presult);
476 DNS_ERROR dns_transaction(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
477 const struct dns_request *req,
478 struct dns_request **resp);
479 DNS_ERROR dns_update_transaction(TALLOC_CTX *mem_ctx,
480 struct dns_connection *conn,
481 struct dns_update_request *up_req,
482 struct dns_update_request **up_resp);
484 /* from dnsmarshall.c */
486 struct dns_buffer *dns_create_buffer(TALLOC_CTX *mem_ctx);
487 void dns_marshall_buffer(struct dns_buffer *buf, const uint8 *data,
488 size_t len);
489 void dns_marshall_uint16(struct dns_buffer *buf, uint16 val);
490 void dns_marshall_uint32(struct dns_buffer *buf, uint32 val);
491 void dns_unmarshall_buffer(struct dns_buffer *buf, uint8 *data,
492 size_t len);
493 void dns_unmarshall_uint16(struct dns_buffer *buf, uint16 *val);
494 void dns_unmarshall_uint32(struct dns_buffer *buf, uint32 *val);
495 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
496 struct dns_buffer *buf,
497 struct dns_domain_name **pname);
498 void dns_marshall_domain_name(struct dns_buffer *buf,
499 const struct dns_domain_name *name);
500 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
501 struct dns_buffer *buf,
502 struct dns_domain_name **pname);
503 DNS_ERROR dns_marshall_request(TALLOC_CTX *mem_ctx,
504 const struct dns_request *req,
505 struct dns_buffer **pbuf);
506 DNS_ERROR dns_unmarshall_request(TALLOC_CTX *mem_ctx,
507 struct dns_buffer *buf,
508 struct dns_request **preq);
509 DNS_ERROR dns_marshall_update_request(TALLOC_CTX *mem_ctx,
510 struct dns_update_request *update,
511 struct dns_buffer **pbuf);
512 DNS_ERROR dns_unmarshall_update_request(TALLOC_CTX *mem_ctx,
513 struct dns_buffer *buf,
514 struct dns_update_request **pupreq);
515 struct dns_request *dns_update2request(struct dns_update_request *update);
516 struct dns_update_request *dns_request2update(struct dns_request *request);
517 uint16 dns_response_code(uint16 flags);
519 /* from dnsgss.c */
521 #ifdef HAVE_GSSAPI_SUPPORT
523 void display_status( const char *msg, OM_uint32 maj_stat, OM_uint32 min_stat );
524 DNS_ERROR dns_negotiate_sec_ctx( const char *target_realm,
525 const char *servername,
526 const char *keyname,
527 gss_ctx_id_t *gss_ctx,
528 enum dns_ServerType srv_type );
529 DNS_ERROR dns_sign_update(struct dns_update_request *req,
530 gss_ctx_id_t gss_ctx,
531 const char *keyname,
532 const char *algorithmname,
533 time_t time_signed, uint16 fudge);
535 #endif /* HAVE_GSSAPI_SUPPORT */
537 #endif /* _DNS_H */