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