PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/addns/dns.h

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