s3:libsmb: remove unused 'inbuf' variable
[Samba/gebeck_regimport.git] / lib / addns / dns.h
blobc0820fe0bd82979ef207b60f118fe6e8a73115ae
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 <fcntl.h>
42 #include <time.h>
43 #include <netdb.h>
45 #include <talloc.h>
47 /*******************************************************************
48 Type definitions for int16, int32, uint16 and uint32. Needed
49 for Samba coding style
50 *******************************************************************/
52 #ifndef uint8
53 # define uint8 unsigned char
54 #endif
56 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
57 # if (SIZEOF_SHORT == 4)
58 # define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
59 # else /* SIZEOF_SHORT != 4 */
60 # define int16 short
61 # endif /* SIZEOF_SHORT != 4 */
62 /* needed to work around compile issue on HP-UX 11.x */
63 # define _INT16 1
64 #endif
67 * Note we duplicate the size tests in the unsigned
68 * case as int16 may be a typedef from rpc/rpc.h
71 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
72 # if (SIZEOF_SHORT == 4)
73 # define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
74 # else /* SIZEOF_SHORT != 4 */
75 # define uint16 unsigned short
76 # endif /* SIZEOF_SHORT != 4 */
77 #endif
79 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
80 # if (SIZEOF_INT == 4)
81 # define int32 int
82 # elif (SIZEOF_LONG == 4)
83 # define int32 long
84 # elif (SIZEOF_SHORT == 4)
85 # define int32 short
86 # else
87 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
88 # define int32 int
89 # endif
90 # ifndef _INT32
91 /* needed to work around compile issue on HP-UX 11.x */
92 # define _INT32 1
93 # endif
94 #endif
97 * Note we duplicate the size tests in the unsigned
98 * case as int32 may be a typedef from rpc/rpc.h
101 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
102 # if (SIZEOF_INT == 4)
103 # define uint32 unsigned int
104 # elif (SIZEOF_LONG == 4)
105 # define uint32 unsigned long
106 # elif (SIZEOF_SHORT == 4)
107 # define uint32 unsigned short
108 # else
109 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
110 # define uint32 unsigned
111 # endif
112 #endif
115 * check for 8 byte long long
118 #if !defined(uint64)
119 # if (SIZEOF_LONG == 8)
120 # define uint64 unsigned long
121 # elif (SIZEOF_LONG_LONG == 8)
122 # define uint64 unsigned long long
123 # endif /* don't lie. If we don't have it, then don't use it */
124 #endif
126 /* needed on Sun boxes */
127 #ifndef INADDR_NONE
128 #define INADDR_NONE 0xFFFFFFFF
129 #endif
131 #include "dnserr.h"
134 #define DNS_TCP 1
135 #define DNS_UDP 2
137 #define DNS_OPCODE_UPDATE 1
139 /* DNS Class Types */
141 #define DNS_CLASS_IN 1
142 #define DNS_CLASS_ANY 255
143 #define DNS_CLASS_NONE 254
145 /* DNS RR Types */
147 #define DNS_RR_A 1
149 #define DNS_TCP_PORT 53
150 #define DNS_UDP_PORT 53
152 #define QTYPE_A 1
153 #define QTYPE_NS 2
154 #define QTYPE_MD 3
155 #define QTYPE_CNAME 5
156 #define QTYPE_SOA 6
157 #define QTYPE_AAAA 28
158 #define QTYPE_ANY 255
159 #define QTYPE_TKEY 249
160 #define QTYPE_TSIG 250
163 MF 4 a mail forwarder (Obsolete - use MX)
164 CNAME 5 the canonical name for an alias
165 SOA 6 marks the start of a zone of authority
166 MB 7 a mailbox domain name (EXPERIMENTAL)
167 MG 8 a mail group member (EXPERIMENTAL)
168 MR 9 a mail rename domain name (EXPERIMENTAL)
169 NULL 10 a null RR (EXPERIMENTAL)
170 WKS 11 a well known service description
171 PTR 12 a domain name pointer
172 HINFO 13 host information
173 MINFO 14 mailbox or mail list information
174 MX 15 mail exchange
175 TXT 16 text strings
178 #define QR_QUERY 0x0000
179 #define QR_RESPONSE 0x0001
181 #define OPCODE_QUERY 0x00
182 #define OPCODE_IQUERY 0x01
183 #define OPCODE_STATUS 0x02
185 #define AA 1
187 #define RECURSION_DESIRED 0x01
189 #define RCODE_NOERROR 0
190 #define RCODE_FORMATERROR 1
191 #define RCODE_SERVER_FAILURE 2
192 #define RCODE_NAME_ERROR 3
193 #define RCODE_NOTIMPLEMENTED 4
194 #define RCODE_REFUSED 5
196 #define SENDBUFFER_SIZE 65536
197 #define RECVBUFFER_SIZE 65536
200 * TKEY Modes from rfc2930
203 #define DNS_TKEY_MODE_SERVER 1
204 #define DNS_TKEY_MODE_DH 2
205 #define DNS_TKEY_MODE_GSSAPI 3
206 #define DNS_TKEY_MODE_RESOLVER 4
207 #define DNS_TKEY_MODE_DELETE 5
210 #define DNS_ONE_DAY_IN_SECS 86400
211 #define DNS_TEN_HOURS_IN_SECS 36000
213 #define SOCKET_ERROR -1
214 #define INVALID_SOCKET -1
216 #define DNS_NO_ERROR 0
217 #define DNS_FORMAT_ERROR 1
218 #define DNS_SERVER_FAILURE 2
219 #define DNS_NAME_ERROR 3
220 #define DNS_NOT_IMPLEMENTED 4
221 #define DNS_REFUSED 5
223 typedef long HANDLE;
225 enum dns_ServerType { DNS_SRV_ANY, DNS_SRV_WIN2000, DNS_SRV_WIN2003 };
227 struct dns_domain_label {
228 struct dns_domain_label *next;
229 char *label;
230 size_t len;
233 struct dns_domain_name {
234 struct dns_domain_label *pLabelList;
237 struct dns_question {
238 struct dns_domain_name *name;
239 uint16 q_type;
240 uint16 q_class;
244 * Before changing the definition of dns_zone, look
245 * dns_marshall_update_request(), we rely on this being the same as
246 * dns_question right now.
249 struct dns_zone {
250 struct dns_domain_name *name;
251 uint16 z_type;
252 uint16 z_class;
255 struct dns_rrec {
256 struct dns_domain_name *name;
257 uint16 type;
258 uint16 r_class;
259 uint32 ttl;
260 uint16 data_length;
261 uint8 *data;
264 struct dns_tkey_record {
265 struct dns_domain_name *algorithm;
266 time_t inception;
267 time_t expiration;
268 uint16 mode;
269 uint16 error;
270 uint16 key_length;
271 uint8 *key;
274 struct dns_request {
275 uint16 id;
276 uint16 flags;
277 uint16 num_questions;
278 uint16 num_answers;
279 uint16 num_auths;
280 uint16 num_additionals;
281 struct dns_question **questions;
282 struct dns_rrec **answers;
283 struct dns_rrec **auths;
284 struct dns_rrec **additionals;
288 * Before changing the definition of dns_update_request, look
289 * dns_marshall_update_request(), we rely on this being the same as
290 * dns_request right now.
293 struct dns_update_request {
294 uint16 id;
295 uint16 flags;
296 uint16 num_zones;
297 uint16 num_preqs;
298 uint16 num_updates;
299 uint16 num_additionals;
300 struct dns_zone **zones;
301 struct dns_rrec **preqs;
302 struct dns_rrec **updates;
303 struct dns_rrec **additionals;
306 struct dns_connection {
307 int32 hType;
308 int s;
309 struct sockaddr RecvAddr;
312 struct dns_buffer {
313 uint8 *data;
314 size_t size;
315 size_t offset;
316 DNS_ERROR error;
319 /* from dnsutils.c */
321 DNS_ERROR dns_domain_name_from_string( TALLOC_CTX *mem_ctx,
322 const char *pszDomainName,
323 struct dns_domain_name **presult );
324 char *dns_generate_keyname( TALLOC_CTX *mem_ctx );
326 /* from dnsrecord.c */
328 DNS_ERROR dns_create_query( TALLOC_CTX *mem_ctx, const char *name,
329 uint16 q_type, uint16 q_class,
330 struct dns_request **preq );
331 DNS_ERROR dns_create_update( TALLOC_CTX *mem_ctx, const char *name,
332 struct dns_update_request **preq );
333 DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone,
334 const char *host, int num_ips,
335 const struct sockaddr_storage *sslist,
336 struct dns_update_request **preq);
337 DNS_ERROR dns_create_rrec(TALLOC_CTX *mem_ctx, const char *name,
338 uint16 type, uint16 r_class, uint32 ttl,
339 uint16 data_length, uint8 *data,
340 struct dns_rrec **prec);
341 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
342 uint16 *num_records, struct dns_rrec ***records);
343 DNS_ERROR dns_create_tkey_record(TALLOC_CTX *mem_ctx, const char *keyname,
344 const char *algorithm_name, time_t inception,
345 time_t expiration, uint16 mode, uint16 error,
346 uint16 key_length, const uint8 *key,
347 struct dns_rrec **prec);
348 DNS_ERROR dns_create_name_in_use_record(TALLOC_CTX *mem_ctx,
349 const char *name,
350 const struct sockaddr_storage *ip,
351 struct dns_rrec **prec);
352 DNS_ERROR dns_create_delete_record(TALLOC_CTX *mem_ctx, const char *name,
353 uint16 type, uint16 r_class,
354 struct dns_rrec **prec);
355 DNS_ERROR dns_create_name_not_in_use_record(TALLOC_CTX *mem_ctx,
356 const char *name, uint32 type,
357 struct dns_rrec **prec);
358 DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host,
359 uint32 ttl, const struct sockaddr_storage *pss,
360 struct dns_rrec **prec);
361 DNS_ERROR dns_create_aaaa_record(TALLOC_CTX *mem_ctx, const char *host,
362 uint32 ttl, const struct sockaddr_storage *pss,
363 struct dns_rrec **prec);
364 DNS_ERROR dns_unmarshall_tkey_record(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
365 struct dns_tkey_record **ptkey);
366 DNS_ERROR dns_create_tsig_record(TALLOC_CTX *mem_ctx, const char *keyname,
367 const char *algorithm_name,
368 time_t time_signed, uint16 fudge,
369 uint16 mac_length, const uint8 *mac,
370 uint16 original_id, uint16 error,
371 struct dns_rrec **prec);
372 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
373 uint16 *num_records, struct dns_rrec ***records);
374 DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx,
375 const char *domainname,
376 const char *hostname,
377 const struct sockaddr_storage *ip_addr,
378 size_t num_adds,
379 struct dns_update_request **preq);
381 /* from dnssock.c */
383 DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
384 TALLOC_CTX *mem_ctx,
385 struct dns_connection **conn );
386 DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf);
387 DNS_ERROR dns_receive(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
388 struct dns_buffer **presult);
389 DNS_ERROR dns_transaction(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
390 const struct dns_request *req,
391 struct dns_request **resp);
392 DNS_ERROR dns_update_transaction(TALLOC_CTX *mem_ctx,
393 struct dns_connection *conn,
394 struct dns_update_request *up_req,
395 struct dns_update_request **up_resp);
397 /* from dnsmarshall.c */
399 struct dns_buffer *dns_create_buffer(TALLOC_CTX *mem_ctx);
400 void dns_marshall_buffer(struct dns_buffer *buf, const uint8 *data,
401 size_t len);
402 void dns_marshall_uint16(struct dns_buffer *buf, uint16 val);
403 void dns_marshall_uint32(struct dns_buffer *buf, uint32 val);
404 void dns_unmarshall_buffer(struct dns_buffer *buf, uint8 *data,
405 size_t len);
406 void dns_unmarshall_uint16(struct dns_buffer *buf, uint16 *val);
407 void dns_unmarshall_uint32(struct dns_buffer *buf, uint32 *val);
408 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
409 struct dns_buffer *buf,
410 struct dns_domain_name **pname);
411 void dns_marshall_domain_name(struct dns_buffer *buf,
412 const struct dns_domain_name *name);
413 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
414 struct dns_buffer *buf,
415 struct dns_domain_name **pname);
416 DNS_ERROR dns_marshall_request(TALLOC_CTX *mem_ctx,
417 const struct dns_request *req,
418 struct dns_buffer **pbuf);
419 DNS_ERROR dns_unmarshall_request(TALLOC_CTX *mem_ctx,
420 struct dns_buffer *buf,
421 struct dns_request **preq);
422 DNS_ERROR dns_marshall_update_request(TALLOC_CTX *mem_ctx,
423 struct dns_update_request *update,
424 struct dns_buffer **pbuf);
425 DNS_ERROR dns_unmarshall_update_request(TALLOC_CTX *mem_ctx,
426 struct dns_buffer *buf,
427 struct dns_update_request **pupreq);
428 struct dns_request *dns_update2request(struct dns_update_request *update);
429 struct dns_update_request *dns_request2update(struct dns_request *request);
430 uint16 dns_response_code(uint16 flags);
431 const char *dns_errstr(DNS_ERROR err);
433 /* from dnsgss.c */
435 #ifdef HAVE_GSSAPI
437 void display_status( const char *msg, OM_uint32 maj_stat, OM_uint32 min_stat );
438 DNS_ERROR dns_negotiate_sec_ctx( const char *target_realm,
439 const char *servername,
440 const char *keyname,
441 gss_ctx_id_t *gss_ctx,
442 enum dns_ServerType srv_type );
443 DNS_ERROR dns_sign_update(struct dns_update_request *req,
444 gss_ctx_id_t gss_ctx,
445 const char *keyname,
446 const char *algorithmname,
447 time_t time_signed, uint16 fudge);
449 #endif /* HAVE_GSSAPI */
451 #endif /* _DNS_H */