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
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/>.
28 #include "../replace/replace.h"
29 #include "system/network.h"
30 #include "system/kerberos.h"
32 /* make sure we have included the correct config.h */
33 #ifndef NO_CONFIG_H /* for some tests */
34 #ifndef CONFIG_H_IS_FROM_SAMBA
35 #error "make sure you have removed all config.h files from standalone builds!"
36 #error "the included config.h isn't from samba!"
38 #endif /* NO_CONFIG_H */
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
53 #ifdef HAVE_UUID_UUID_H
54 #include <uuid/uuid.h>
61 #ifdef HAVE_INTTYPES_H
69 #define uint16 uint16_t
77 #define uint32 uint32_t
83 /*******************************************************************
84 Type definitions for int16, int32, uint16 and uint32. Needed
85 for Samba coding style
86 *******************************************************************/
89 # define uint8 unsigned char
92 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
93 # if (SIZEOF_SHORT == 4)
94 # define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
95 # else /* SIZEOF_SHORT != 4 */
97 # endif /* SIZEOF_SHORT != 4 */
98 /* needed to work around compile issue on HP-UX 11.x */
103 * Note we duplicate the size tests in the unsigned
104 * case as int16 may be a typedef from rpc/rpc.h
107 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
108 # if (SIZEOF_SHORT == 4)
109 # define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
110 # else /* SIZEOF_SHORT != 4 */
111 # define uint16 unsigned short
112 # endif /* SIZEOF_SHORT != 4 */
115 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
116 # if (SIZEOF_INT == 4)
118 # elif (SIZEOF_LONG == 4)
120 # elif (SIZEOF_SHORT == 4)
123 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
127 /* needed to work around compile issue on HP-UX 11.x */
133 * Note we duplicate the size tests in the unsigned
134 * case as int32 may be a typedef from rpc/rpc.h
137 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
138 # if (SIZEOF_INT == 4)
139 # define uint32 unsigned int
140 # elif (SIZEOF_LONG == 4)
141 # define uint32 unsigned long
142 # elif (SIZEOF_SHORT == 4)
143 # define uint32 unsigned short
145 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
146 # define uint32 unsigned
151 * check for 8 byte long long
155 # if (SIZEOF_LONG == 8)
156 # define uint64 unsigned long
157 # elif (SIZEOF_LONG_LONG == 8)
158 # define uint64 unsigned long long
159 # endif /* don't lie. If we don't have it, then don't use it */
162 /* needed on Sun boxes */
164 #define INADDR_NONE 0xFFFFFFFF
173 #define DNS_OPCODE_UPDATE 1
175 /* DNS Class Types */
177 #define DNS_CLASS_IN 1
178 #define DNS_CLASS_ANY 255
179 #define DNS_CLASS_NONE 254
185 #define DNS_TCP_PORT 53
186 #define DNS_UDP_PORT 53
191 #define QTYPE_CNAME 5
193 #define QTYPE_AAAA 28
194 #define QTYPE_ANY 255
195 #define QTYPE_TKEY 249
196 #define QTYPE_TSIG 250
199 MF 4 a mail forwarder (Obsolete - use MX)
200 CNAME 5 the canonical name for an alias
201 SOA 6 marks the start of a zone of authority
202 MB 7 a mailbox domain name (EXPERIMENTAL)
203 MG 8 a mail group member (EXPERIMENTAL)
204 MR 9 a mail rename domain name (EXPERIMENTAL)
205 NULL 10 a null RR (EXPERIMENTAL)
206 WKS 11 a well known service description
207 PTR 12 a domain name pointer
208 HINFO 13 host information
209 MINFO 14 mailbox or mail list information
214 #define QR_QUERY 0x0000
215 #define QR_RESPONSE 0x0001
217 #define OPCODE_QUERY 0x00
218 #define OPCODE_IQUERY 0x01
219 #define OPCODE_STATUS 0x02
223 #define RECURSION_DESIRED 0x01
225 #define RCODE_NOERROR 0
226 #define RCODE_FORMATERROR 1
227 #define RCODE_SERVER_FAILURE 2
228 #define RCODE_NAME_ERROR 3
229 #define RCODE_NOTIMPLEMENTED 4
230 #define RCODE_REFUSED 5
232 #define SENDBUFFER_SIZE 65536
233 #define RECVBUFFER_SIZE 65536
236 * TKEY Modes from rfc2930
239 #define DNS_TKEY_MODE_SERVER 1
240 #define DNS_TKEY_MODE_DH 2
241 #define DNS_TKEY_MODE_GSSAPI 3
242 #define DNS_TKEY_MODE_RESOLVER 4
243 #define DNS_TKEY_MODE_DELETE 5
246 #define DNS_ONE_DAY_IN_SECS 86400
247 #define DNS_TEN_HOURS_IN_SECS 36000
249 #define SOCKET_ERROR -1
250 #define INVALID_SOCKET -1
252 #define DNS_NO_ERROR 0
253 #define DNS_FORMAT_ERROR 1
254 #define DNS_SERVER_FAILURE 2
255 #define DNS_NAME_ERROR 3
256 #define DNS_NOT_IMPLEMENTED 4
257 #define DNS_REFUSED 5
261 enum dns_ServerType
{ DNS_SRV_ANY
, DNS_SRV_WIN2000
, DNS_SRV_WIN2003
};
263 struct dns_domain_label
{
264 struct dns_domain_label
*next
;
269 struct dns_domain_name
{
270 struct dns_domain_label
*pLabelList
;
273 struct dns_question
{
274 struct dns_domain_name
*name
;
280 * Before changing the definition of dns_zone, look
281 * dns_marshall_update_request(), we rely on this being the same as
282 * dns_question right now.
286 struct dns_domain_name
*name
;
292 struct dns_domain_name
*name
;
300 struct dns_tkey_record
{
301 struct dns_domain_name
*algorithm
;
313 uint16 num_questions
;
316 uint16 num_additionals
;
317 struct dns_question
**questions
;
318 struct dns_rrec
**answers
;
319 struct dns_rrec
**auths
;
320 struct dns_rrec
**additionals
;
324 * Before changing the definition of dns_update_request, look
325 * dns_marshall_update_request(), we rely on this being the same as
326 * dns_request right now.
329 struct dns_update_request
{
335 uint16 num_additionals
;
336 struct dns_zone
**zones
;
337 struct dns_rrec
**preqs
;
338 struct dns_rrec
**updates
;
339 struct dns_rrec
**additionals
;
342 struct dns_connection
{
345 struct sockaddr RecvAddr
;
355 /* from dnsutils.c */
357 DNS_ERROR
dns_domain_name_from_string( TALLOC_CTX
*mem_ctx
,
358 const char *pszDomainName
,
359 struct dns_domain_name
**presult
);
360 char *dns_generate_keyname( TALLOC_CTX
*mem_ctx
);
362 /* from dnsrecord.c */
364 DNS_ERROR
dns_create_query( TALLOC_CTX
*mem_ctx
, const char *name
,
365 uint16 q_type
, uint16 q_class
,
366 struct dns_request
**preq
);
367 DNS_ERROR
dns_create_update( TALLOC_CTX
*mem_ctx
, const char *name
,
368 struct dns_update_request
**preq
);
369 DNS_ERROR
dns_create_probe(TALLOC_CTX
*mem_ctx
, const char *zone
,
370 const char *host
, int num_ips
,
371 const struct sockaddr_storage
*sslist
,
372 struct dns_update_request
**preq
);
373 DNS_ERROR
dns_create_rrec(TALLOC_CTX
*mem_ctx
, const char *name
,
374 uint16 type
, uint16 r_class
, uint32 ttl
,
375 uint16 data_length
, uint8
*data
,
376 struct dns_rrec
**prec
);
377 DNS_ERROR
dns_add_rrec(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
378 uint16
*num_records
, struct dns_rrec
***records
);
379 DNS_ERROR
dns_create_tkey_record(TALLOC_CTX
*mem_ctx
, const char *keyname
,
380 const char *algorithm_name
, time_t inception
,
381 time_t expiration
, uint16 mode
, uint16 error
,
382 uint16 key_length
, const uint8
*key
,
383 struct dns_rrec
**prec
);
384 DNS_ERROR
dns_create_name_in_use_record(TALLOC_CTX
*mem_ctx
,
386 const struct sockaddr_storage
*ip
,
387 struct dns_rrec
**prec
);
388 DNS_ERROR
dns_create_delete_record(TALLOC_CTX
*mem_ctx
, const char *name
,
389 uint16 type
, uint16 r_class
,
390 struct dns_rrec
**prec
);
391 DNS_ERROR
dns_create_name_not_in_use_record(TALLOC_CTX
*mem_ctx
,
392 const char *name
, uint32 type
,
393 struct dns_rrec
**prec
);
394 DNS_ERROR
dns_create_a_record(TALLOC_CTX
*mem_ctx
, const char *host
,
395 uint32 ttl
, const struct sockaddr_storage
*pss
,
396 struct dns_rrec
**prec
);
397 DNS_ERROR
dns_create_aaaa_record(TALLOC_CTX
*mem_ctx
, const char *host
,
398 uint32 ttl
, const struct sockaddr_storage
*pss
,
399 struct dns_rrec
**prec
);
400 DNS_ERROR
dns_unmarshall_tkey_record(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
401 struct dns_tkey_record
**ptkey
);
402 DNS_ERROR
dns_create_tsig_record(TALLOC_CTX
*mem_ctx
, const char *keyname
,
403 const char *algorithm_name
,
404 time_t time_signed
, uint16 fudge
,
405 uint16 mac_length
, const uint8
*mac
,
406 uint16 original_id
, uint16 error
,
407 struct dns_rrec
**prec
);
408 DNS_ERROR
dns_add_rrec(TALLOC_CTX
*mem_ctx
, struct dns_rrec
*rec
,
409 uint16
*num_records
, struct dns_rrec
***records
);
410 DNS_ERROR
dns_create_update_request(TALLOC_CTX
*mem_ctx
,
411 const char *domainname
,
412 const char *hostname
,
413 const struct sockaddr_storage
*ip_addr
,
415 struct dns_update_request
**preq
);
419 DNS_ERROR
dns_open_connection( const char *nameserver
, int32 dwType
,
421 struct dns_connection
**conn
);
422 DNS_ERROR
dns_send(struct dns_connection
*conn
, const struct dns_buffer
*buf
);
423 DNS_ERROR
dns_receive(TALLOC_CTX
*mem_ctx
, struct dns_connection
*conn
,
424 struct dns_buffer
**presult
);
425 DNS_ERROR
dns_transaction(TALLOC_CTX
*mem_ctx
, struct dns_connection
*conn
,
426 const struct dns_request
*req
,
427 struct dns_request
**resp
);
428 DNS_ERROR
dns_update_transaction(TALLOC_CTX
*mem_ctx
,
429 struct dns_connection
*conn
,
430 struct dns_update_request
*up_req
,
431 struct dns_update_request
**up_resp
);
433 /* from dnsmarshall.c */
435 struct dns_buffer
*dns_create_buffer(TALLOC_CTX
*mem_ctx
);
436 void dns_marshall_buffer(struct dns_buffer
*buf
, const uint8
*data
,
438 void dns_marshall_uint16(struct dns_buffer
*buf
, uint16 val
);
439 void dns_marshall_uint32(struct dns_buffer
*buf
, uint32 val
);
440 void dns_unmarshall_buffer(struct dns_buffer
*buf
, uint8
*data
,
442 void dns_unmarshall_uint16(struct dns_buffer
*buf
, uint16
*val
);
443 void dns_unmarshall_uint32(struct dns_buffer
*buf
, uint32
*val
);
444 void dns_unmarshall_domain_name(TALLOC_CTX
*mem_ctx
,
445 struct dns_buffer
*buf
,
446 struct dns_domain_name
**pname
);
447 void dns_marshall_domain_name(struct dns_buffer
*buf
,
448 const struct dns_domain_name
*name
);
449 void dns_unmarshall_domain_name(TALLOC_CTX
*mem_ctx
,
450 struct dns_buffer
*buf
,
451 struct dns_domain_name
**pname
);
452 DNS_ERROR
dns_marshall_request(TALLOC_CTX
*mem_ctx
,
453 const struct dns_request
*req
,
454 struct dns_buffer
**pbuf
);
455 DNS_ERROR
dns_unmarshall_request(TALLOC_CTX
*mem_ctx
,
456 struct dns_buffer
*buf
,
457 struct dns_request
**preq
);
458 DNS_ERROR
dns_marshall_update_request(TALLOC_CTX
*mem_ctx
,
459 struct dns_update_request
*update
,
460 struct dns_buffer
**pbuf
);
461 DNS_ERROR
dns_unmarshall_update_request(TALLOC_CTX
*mem_ctx
,
462 struct dns_buffer
*buf
,
463 struct dns_update_request
**pupreq
);
464 struct dns_request
*dns_update2request(struct dns_update_request
*update
);
465 struct dns_update_request
*dns_request2update(struct dns_request
*request
);
466 uint16
dns_response_code(uint16 flags
);
467 const char *dns_errstr(DNS_ERROR err
);
473 void display_status( const char *msg
, OM_uint32 maj_stat
, OM_uint32 min_stat
);
474 DNS_ERROR
dns_negotiate_sec_ctx( const char *target_realm
,
475 const char *servername
,
477 gss_ctx_id_t
*gss_ctx
,
478 enum dns_ServerType srv_type
);
479 DNS_ERROR
dns_sign_update(struct dns_update_request
*req
,
480 gss_ctx_id_t gss_ctx
,
482 const char *algorithmname
,
483 time_t time_signed
, uint16 fudge
);
485 #endif /* HAVE_KRB5 */