Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1934 lines
49 KiB

  1. /*++
  2. Copyright (c) 1996-2002 Microsoft Corporation
  3. Module Name:
  4. windns.h
  5. Abstract:
  6. Domain Name System (DNS)
  7. DNS definitions and DNS API.
  8. Author:
  9. Jim Gilroy (jamesg) December 7, 1996
  10. Revision History:
  11. --*/
  12. #ifndef _WINDNS_INCLUDED_
  13. #define _WINDNS_INCLUDED_
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif // __cplusplus
  18. //
  19. // Define QWORD -- not yet defined globally
  20. //
  21. typedef unsigned __int64 QWORD, *PQWORD;
  22. //
  23. // DNS public types
  24. //
  25. typedef LONG DNS_STATUS, *PDNS_STATUS;
  26. //
  27. // IP Address
  28. //
  29. typedef DWORD IP4_ADDRESS, *PIP4_ADDRESS;
  30. #define SIZEOF_IP4_ADDRESS (4)
  31. #define IP4_ADDRESS_STRING_LENGTH (15)
  32. #define IP4_ADDRESS_STRING_BUFFER_LENGTH (16)
  33. //
  34. // IP Address Array type
  35. //
  36. typedef struct _IP4_ARRAY
  37. {
  38. DWORD AddrCount;
  39. #ifdef MIDL_PASS
  40. [size_is( AddrCount )] IP4_ADDRESS AddrArray[];
  41. #else
  42. IP4_ADDRESS AddrArray[1];
  43. #endif
  44. }
  45. IP4_ARRAY, *PIP4_ARRAY;
  46. //
  47. // IPv6 Address
  48. //
  49. #ifdef MIDL_PASS
  50. typedef struct
  51. {
  52. #ifdef _WIN64
  53. QWORD IP6Qword[2];
  54. #else
  55. DWORD IP6Dword[4];
  56. #endif
  57. }
  58. IP6_ADDRESS, *PIP6_ADDRESS;
  59. #else
  60. typedef union
  61. {
  62. #ifdef _WIN64
  63. QWORD IP6Qword[2];
  64. #endif
  65. DWORD IP6Dword[4];
  66. WORD IP6Word[8];
  67. BYTE IP6Byte[16];
  68. #ifdef IN6_ADDR
  69. IN6_ADDR In6;
  70. #endif
  71. }
  72. IP6_ADDRESS, *PIP6_ADDRESS;
  73. #endif
  74. // Backward compatibility
  75. //typedef IP6_ADDRESS DNS_IP6_ADDRESS, *PDNS_IP6_ADDRESS;
  76. //
  77. // IP6 string max is 45 bytes
  78. // - 6 WORDs in colon+hex (5 chars)
  79. // - last DWORD as IP4 (15 chars)
  80. //
  81. #undef IP6_ADDRESS_STRING_LENGTH
  82. #define IP6_ADDRESS_STRING_LENGTH (47)
  83. #define IP6_ADDRESS_STRING_BUFFER_LENGTH (48)
  84. // backcompat
  85. //#define IPV6_ADDRESS_STRING_LENGTH IP6_ADDRESS_STRING_LENGTH
  86. //
  87. // Inline byte flipping -- can be done in registers
  88. //
  89. #define INLINE_WORD_FLIP(out, in) \
  90. { \
  91. WORD _in = (in); \
  92. (out) = (_in << 8) | (_in >> 8); \
  93. }
  94. #define INLINE_HTONS(out, in) INLINE_WORD_FLIP(out, in)
  95. #define INLINE_NTOHS(out, in) INLINE_WORD_FLIP(out, in)
  96. #define INLINE_DWORD_FLIP(out, in) \
  97. { \
  98. DWORD _in = (in); \
  99. (out) = ((_in << 8) & 0x00ff0000) | \
  100. (_in << 24) | \
  101. ((_in >> 8) & 0x0000ff00) | \
  102. (_in >> 24); \
  103. }
  104. #define INLINE_NTOHL(out, in) INLINE_DWORD_FLIP(out, in)
  105. #define INLINE_HTONL(out, in) INLINE_DWORD_FLIP(out, in)
  106. //
  107. // Inline byte flip and write to packet (unaligned)
  108. //
  109. #define INLINE_WRITE_FLIPPED_WORD( pout, in ) \
  110. INLINE_WORD_FLIP( *((UNALIGNED WORD *)(pout)), in )
  111. #define INLINE_WRITE_FLIPPED_DWORD( pout, in ) \
  112. INLINE_DWORD_FLIP( *((UNALIGNED DWORD *)(pout)), in )
  113. //
  114. // Basic DNS definitions
  115. //
  116. //
  117. // DNS port for both UDP and TCP is 53.
  118. //
  119. #define DNS_PORT_HOST_ORDER (0x0035) // port 53
  120. #define DNS_PORT_NET_ORDER (0x3500)
  121. //
  122. // DNS UDP packets no more than 512 bytes
  123. //
  124. #define DNS_RFC_MAX_UDP_PACKET_LENGTH (512)
  125. //
  126. // DNS Names limited to 255, 63 in any one label
  127. //
  128. #define DNS_MAX_NAME_LENGTH (255)
  129. #define DNS_MAX_LABEL_LENGTH (63)
  130. #define DNS_MAX_NAME_BUFFER_LENGTH (256)
  131. #define DNS_MAX_LABEL_BUFFER_LENGTH (64)
  132. //
  133. // Reverse lookup domain names
  134. //
  135. #define DNS_IP4_REVERSE_DOMAIN_STRING_A ("in-addr.arpa.")
  136. #define DNS_IP4_REVERSE_DOMAIN_STRING_W (L"in-addr.arpa.")
  137. #define DNS_MAX_IP4_REVERSE_NAME_LENGTH \
  138. (IP4_ADDRESS_STRING_LENGTH+1+sizeof(DNS_IP4_REVERSE_DOMAIN_STRING_A))
  139. #define DNS_MAX_IP4_REVERSE_NAME_BUFFER_LENGTH \
  140. (DNS_MAX_IP4_REVERSE_NAME_LENGTH + 1)
  141. #define DNS_IP6_REVERSE_DOMAIN_STRING_A ("ip6.arpa.")
  142. #define DNS_IP6_REVERSE_DOMAIN_STRING_W (L"ip6.arpa.")
  143. #define DNS_MAX_IP6_REVERSE_NAME_LENGTH \
  144. (64+sizeof(DNS_IP6_REVERSE_DOMAIN_STRING_A))
  145. #define DNS_MAX_IP6_REVERSE_NAME_BUFFER_LENGTH \
  146. (DNS_MAX_IP6_REVERSE_NAME_LENGTH + 1)
  147. // Combined
  148. #define DNS_MAX_REVERSE_NAME_LENGTH DNS_MAX_IP6_REVERSE_NAME_LENGTH
  149. #define DNS_MAX_REVERSE_NAME_BUFFER_LENGTH DNS_MAX_IP6_REVERSE_NAME_BUFFER_LENGTH
  150. #ifdef UNICODE
  151. #define DNS_IP4_REVERSE_DOMAIN_STRING DNS_IP4_REVERSE_DOMAIN_STRING_W
  152. #define DNS_IP6_REVERSE_DOMAIN_STRING DNS_IP6_REVERSE_DOMAIN_STRING_W
  153. #else
  154. #define DNS_IP4_REVERSE_DOMAIN_STRING DNS_IP4_REVERSE_DOMAIN_STRING_A
  155. #define DNS_IP6_REVERSE_DOMAIN_STRING DNS_IP6_REVERSE_DOMAIN_STRING_A
  156. #endif
  157. //
  158. // DNS Text string limited by size representable
  159. // in a single byte length field
  160. #define DNS_MAX_TEXT_STRING_LENGTH (255)
  161. //
  162. // DNS On-The-Wire Structures
  163. //
  164. #pragma pack(1)
  165. //
  166. // DNS Message Header
  167. //
  168. typedef struct _DNS_HEADER
  169. {
  170. WORD Xid;
  171. BYTE RecursionDesired : 1;
  172. BYTE Truncation : 1;
  173. BYTE Authoritative : 1;
  174. BYTE Opcode : 4;
  175. BYTE IsResponse : 1;
  176. BYTE ResponseCode : 4;
  177. BYTE Reserved : 3;
  178. BYTE RecursionAvailable : 1;
  179. WORD QuestionCount;
  180. WORD AnswerCount;
  181. WORD NameServerCount;
  182. WORD AdditionalCount;
  183. }
  184. DNS_HEADER, *PDNS_HEADER;
  185. //
  186. // Flags as WORD
  187. //
  188. #define DNS_HEADER_FLAGS(pHead) ( *((PWORD)(pHead)+1) )
  189. //
  190. // Byte flip DNS header to\from host order.
  191. //
  192. // Note that this does NOT flip flags, as definition above defines
  193. // flags as individual bytes for direct access to net byte order.
  194. //
  195. #define DNS_BYTE_FLIP_HEADER_COUNTS(pHeader) \
  196. { \
  197. PDNS_HEADER _head = (pHeader); \
  198. INLINE_HTONS(_head->Xid, _head->Xid ); \
  199. INLINE_HTONS(_head->QuestionCount, _head->QuestionCount ); \
  200. INLINE_HTONS(_head->AnswerCount, _head->AnswerCount ); \
  201. INLINE_HTONS(_head->NameServerCount,_head->NameServerCount ); \
  202. INLINE_HTONS(_head->AdditionalCount,_head->AdditionalCount ); \
  203. }
  204. //
  205. // Question name follows header
  206. //
  207. #define DNS_OFFSET_TO_QUESTION_NAME sizeof(DNS_HEADER)
  208. //
  209. // Question immediately follows header so compressed question name
  210. // 0xC000 | sizeof(DNS_HEADER)
  211. #define DNS_COMPRESSED_QUESTION_NAME (0xC00C)
  212. //
  213. // Packet extraction macros
  214. //
  215. #define DNS_QUESTION_NAME_FROM_HEADER( _pHeader_ ) \
  216. ( (PCHAR)( (PDNS_HEADER)(_pHeader_) + 1 ) )
  217. #define DNS_ANSWER_FROM_QUESTION( _pQuestion_ ) \
  218. ( (PCHAR)( (PDNS_QUESTION)(_pQuestion_) + 1 ) )
  219. //
  220. // DNS Question
  221. //
  222. typedef struct _DNS_WIRE_QUESTION
  223. {
  224. // Preceded by question name
  225. WORD QuestionType;
  226. WORD QuestionClass;
  227. }
  228. DNS_WIRE_QUESTION, *PDNS_WIRE_QUESTION;
  229. //
  230. // DNS Resource Record
  231. //
  232. typedef struct _DNS_WIRE_RECORD
  233. {
  234. // Preceded by record owner name
  235. WORD RecordType;
  236. WORD RecordClass;
  237. DWORD TimeToLive;
  238. WORD DataLength;
  239. // Followed by record data
  240. }
  241. DNS_WIRE_RECORD, *PDNS_WIRE_RECORD;
  242. #pragma pack()
  243. //
  244. // DNS Query Types
  245. //
  246. #define DNS_OPCODE_QUERY 0 // Query
  247. #define DNS_OPCODE_IQUERY 1 // Obsolete: IP to name
  248. #define DNS_OPCODE_SERVER_STATUS 2 // Obsolete: DNS ping
  249. #define DNS_OPCODE_UNKNOWN 3 // Unknown
  250. #define DNS_OPCODE_NOTIFY 4 // Notify
  251. #define DNS_OPCODE_UPDATE 5 // Dynamic Update
  252. //
  253. // DNS response codes.
  254. //
  255. // Sent in the "ResponseCode" field of a DNS_HEADER.
  256. //
  257. #define DNS_RCODE_NOERROR 0
  258. #define DNS_RCODE_FORMERR 1 // Format error
  259. #define DNS_RCODE_SERVFAIL 2 // Server failure
  260. #define DNS_RCODE_NXDOMAIN 3 // Name error
  261. #define DNS_RCODE_NOTIMPL 4 // Not implemented
  262. #define DNS_RCODE_REFUSED 5 // Refused
  263. #define DNS_RCODE_YXDOMAIN 6 // Domain name should not exist
  264. #define DNS_RCODE_YXRRSET 7 // RR set should not exist
  265. #define DNS_RCODE_NXRRSET 8 // RR set does not exist
  266. #define DNS_RCODE_NOTAUTH 9 // Not authoritative for zone
  267. #define DNS_RCODE_NOTZONE 10 // Name is not zone
  268. #define DNS_RCODE_MAX 15
  269. //
  270. // Extended RCODEs
  271. //
  272. #define DNS_RCODE_BADVERS 16 // Bad EDNS version
  273. #define DNS_RCODE_BADSIG 16 // Bad signature
  274. #define DNS_RCODE_BADKEY 17 // Bad key
  275. #define DNS_RCODE_BADTIME 18 // Bad timestamp
  276. //
  277. // Mappings to friendly names
  278. //
  279. #define DNS_RCODE_NO_ERROR DNS_RCODE_NOERROR
  280. #define DNS_RCODE_FORMAT_ERROR DNS_RCODE_FORMERR
  281. #define DNS_RCODE_SERVER_FAILURE DNS_RCODE_SERVFAIL
  282. #define DNS_RCODE_NAME_ERROR DNS_RCODE_NXDOMAIN
  283. #define DNS_RCODE_NOT_IMPLEMENTED DNS_RCODE_NOTIMPL
  284. //
  285. // DNS Classes
  286. //
  287. // Classes are on the wire as WORDs.
  288. //
  289. // _CLASS_ defines in host order.
  290. // _RCLASS_ defines in net byte order.
  291. //
  292. // Generally we'll avoid byte flip and test class in net byte order.
  293. //
  294. #define DNS_CLASS_INTERNET 0x0001 // 1
  295. #define DNS_CLASS_CSNET 0x0002 // 2
  296. #define DNS_CLASS_CHAOS 0x0003 // 3
  297. #define DNS_CLASS_HESIOD 0x0004 // 4
  298. #define DNS_CLASS_NONE 0x00fe // 254
  299. #define DNS_CLASS_ALL 0x00ff // 255
  300. #define DNS_CLASS_ANY 0x00ff // 255
  301. #define DNS_RCLASS_INTERNET 0x0100 // 1
  302. #define DNS_RCLASS_CSNET 0x0200 // 2
  303. #define DNS_RCLASS_CHAOS 0x0300 // 3
  304. #define DNS_RCLASS_HESIOD 0x0400 // 4
  305. #define DNS_RCLASS_NONE 0xfe00 // 254
  306. #define DNS_RCLASS_ALL 0xff00 // 255
  307. #define DNS_RCLASS_ANY 0xff00 // 255
  308. //
  309. // DNS Record Types
  310. //
  311. // _TYPE_ defines are in host byte order.
  312. // _RTYPE_ defines are in net byte order.
  313. //
  314. // Generally always deal with types in host byte order as we index
  315. // resource record functions by type.
  316. //
  317. #define DNS_TYPE_ZERO 0x0000
  318. // RFC 1034/1035
  319. #define DNS_TYPE_A 0x0001 // 1
  320. #define DNS_TYPE_NS 0x0002 // 2
  321. #define DNS_TYPE_MD 0x0003 // 3
  322. #define DNS_TYPE_MF 0x0004 // 4
  323. #define DNS_TYPE_CNAME 0x0005 // 5
  324. #define DNS_TYPE_SOA 0x0006 // 6
  325. #define DNS_TYPE_MB 0x0007 // 7
  326. #define DNS_TYPE_MG 0x0008 // 8
  327. #define DNS_TYPE_MR 0x0009 // 9
  328. #define DNS_TYPE_NULL 0x000a // 10
  329. #define DNS_TYPE_WKS 0x000b // 11
  330. #define DNS_TYPE_PTR 0x000c // 12
  331. #define DNS_TYPE_HINFO 0x000d // 13
  332. #define DNS_TYPE_MINFO 0x000e // 14
  333. #define DNS_TYPE_MX 0x000f // 15
  334. #define DNS_TYPE_TEXT 0x0010 // 16
  335. // RFC 1183
  336. #define DNS_TYPE_RP 0x0011 // 17
  337. #define DNS_TYPE_AFSDB 0x0012 // 18
  338. #define DNS_TYPE_X25 0x0013 // 19
  339. #define DNS_TYPE_ISDN 0x0014 // 20
  340. #define DNS_TYPE_RT 0x0015 // 21
  341. // RFC 1348
  342. #define DNS_TYPE_NSAP 0x0016 // 22
  343. #define DNS_TYPE_NSAPPTR 0x0017 // 23
  344. // RFC 2065 (DNS security)
  345. #define DNS_TYPE_SIG 0x0018 // 24
  346. #define DNS_TYPE_KEY 0x0019 // 25
  347. // RFC 1664 (X.400 mail)
  348. #define DNS_TYPE_PX 0x001a // 26
  349. // RFC 1712 (Geographic position)
  350. #define DNS_TYPE_GPOS 0x001b // 27
  351. // RFC 1886 (IPv6 Address)
  352. #define DNS_TYPE_AAAA 0x001c // 28
  353. // RFC 1876 (Geographic location)
  354. #define DNS_TYPE_LOC 0x001d // 29
  355. // RFC 2065 (Secure negative response)
  356. #define DNS_TYPE_NXT 0x001e // 30
  357. // Patton (Endpoint Identifier)
  358. #define DNS_TYPE_EID 0x001f // 31
  359. // Patton (Nimrod Locator)
  360. #define DNS_TYPE_NIMLOC 0x0020 // 32
  361. // RFC 2052 (Service location)
  362. #define DNS_TYPE_SRV 0x0021 // 33
  363. // ATM Standard something-or-another (ATM Address)
  364. #define DNS_TYPE_ATMA 0x0022 // 34
  365. // RFC 2168 (Naming Authority Pointer)
  366. #define DNS_TYPE_NAPTR 0x0023 // 35
  367. // RFC 2230 (Key Exchanger)
  368. #define DNS_TYPE_KX 0x0024 // 36
  369. // RFC 2538 (CERT)
  370. #define DNS_TYPE_CERT 0x0025 // 37
  371. // A6 Draft (A6)
  372. #define DNS_TYPE_A6 0x0026 // 38
  373. // DNAME Draft (DNAME)
  374. #define DNS_TYPE_DNAME 0x0027 // 39
  375. // Eastlake (Kitchen Sink)
  376. #define DNS_TYPE_SINK 0x0028 // 40
  377. // RFC 2671 (EDNS OPT)
  378. #define DNS_TYPE_OPT 0x0029 // 41
  379. //
  380. // IANA Reserved
  381. //
  382. #define DNS_TYPE_UINFO 0x0064 // 100
  383. #define DNS_TYPE_UID 0x0065 // 101
  384. #define DNS_TYPE_GID 0x0066 // 102
  385. #define DNS_TYPE_UNSPEC 0x0067 // 103
  386. //
  387. // Query only types (1035, 1995)
  388. // - Crawford (ADDRS)
  389. // - TKEY draft (TKEY)
  390. // - TSIG draft (TSIG)
  391. // - RFC 1995 (IXFR)
  392. // - RFC 1035 (AXFR up)
  393. //
  394. #define DNS_TYPE_ADDRS 0x00f8 // 248
  395. #define DNS_TYPE_TKEY 0x00f9 // 249
  396. #define DNS_TYPE_TSIG 0x00fa // 250
  397. #define DNS_TYPE_IXFR 0x00fb // 251
  398. #define DNS_TYPE_AXFR 0x00fc // 252
  399. #define DNS_TYPE_MAILB 0x00fd // 253
  400. #define DNS_TYPE_MAILA 0x00fe // 254
  401. #define DNS_TYPE_ALL 0x00ff // 255
  402. #define DNS_TYPE_ANY 0x00ff // 255
  403. //
  404. // Temp Microsoft types -- use until get IANA approval for real type
  405. //
  406. #define DNS_TYPE_WINS 0xff01 // 64K - 255
  407. #define DNS_TYPE_WINSR 0xff02 // 64K - 254
  408. #define DNS_TYPE_NBSTAT (DNS_TYPE_WINSR)
  409. //
  410. // DNS Record Types -- Net Byte Order
  411. //
  412. #define DNS_RTYPE_A 0x0100 // 1
  413. #define DNS_RTYPE_NS 0x0200 // 2
  414. #define DNS_RTYPE_MD 0x0300 // 3
  415. #define DNS_RTYPE_MF 0x0400 // 4
  416. #define DNS_RTYPE_CNAME 0x0500 // 5
  417. #define DNS_RTYPE_SOA 0x0600 // 6
  418. #define DNS_RTYPE_MB 0x0700 // 7
  419. #define DNS_RTYPE_MG 0x0800 // 8
  420. #define DNS_RTYPE_MR 0x0900 // 9
  421. #define DNS_RTYPE_NULL 0x0a00 // 10
  422. #define DNS_RTYPE_WKS 0x0b00 // 11
  423. #define DNS_RTYPE_PTR 0x0c00 // 12
  424. #define DNS_RTYPE_HINFO 0x0d00 // 13
  425. #define DNS_RTYPE_MINFO 0x0e00 // 14
  426. #define DNS_RTYPE_MX 0x0f00 // 15
  427. #define DNS_RTYPE_TEXT 0x1000 // 16
  428. #define DNS_RTYPE_RP 0x1100 // 17
  429. #define DNS_RTYPE_AFSDB 0x1200 // 18
  430. #define DNS_RTYPE_X25 0x1300 // 19
  431. #define DNS_RTYPE_ISDN 0x1400 // 20
  432. #define DNS_RTYPE_RT 0x1500 // 21
  433. #define DNS_RTYPE_NSAP 0x1600 // 22
  434. #define DNS_RTYPE_NSAPPTR 0x1700 // 23
  435. #define DNS_RTYPE_SIG 0x1800 // 24
  436. #define DNS_RTYPE_KEY 0x1900 // 25
  437. #define DNS_RTYPE_PX 0x1a00 // 26
  438. #define DNS_RTYPE_GPOS 0x1b00 // 27
  439. #define DNS_RTYPE_AAAA 0x1c00 // 28
  440. #define DNS_RTYPE_LOC 0x1d00 // 29
  441. #define DNS_RTYPE_NXT 0x1e00 // 30
  442. #define DNS_RTYPE_EID 0x1f00 // 31
  443. #define DNS_RTYPE_NIMLOC 0x2000 // 32
  444. #define DNS_RTYPE_SRV 0x2100 // 33
  445. #define DNS_RTYPE_ATMA 0x2200 // 34
  446. #define DNS_RTYPE_NAPTR 0x2300 // 35
  447. #define DNS_RTYPE_KX 0x2400 // 36
  448. #define DNS_RTYPE_CERT 0x2500 // 37
  449. #define DNS_RTYPE_A6 0x2600 // 38
  450. #define DNS_RTYPE_DNAME 0x2700 // 39
  451. #define DNS_RTYPE_SINK 0x2800 // 40
  452. #define DNS_RTYPE_OPT 0x2900 // 41
  453. //
  454. // IANA Reserved
  455. //
  456. #define DNS_RTYPE_UINFO 0x6400 // 100
  457. #define DNS_RTYPE_UID 0x6500 // 101
  458. #define DNS_RTYPE_GID 0x6600 // 102
  459. #define DNS_RTYPE_UNSPEC 0x6700 // 103
  460. //
  461. // Query only types
  462. //
  463. #define DNS_RTYPE_TKEY 0xf900 // 249
  464. #define DNS_RTYPE_TSIG 0xfa00 // 250
  465. #define DNS_RTYPE_IXFR 0xfb00 // 251
  466. #define DNS_RTYPE_AXFR 0xfc00 // 252
  467. #define DNS_RTYPE_MAILB 0xfd00 // 253
  468. #define DNS_RTYPE_MAILA 0xfe00 // 254
  469. #define DNS_RTYPE_ALL 0xff00 // 255
  470. #define DNS_RTYPE_ANY 0xff00 // 255
  471. //
  472. // Temp Microsoft types -- use until get IANA approval for real type
  473. //
  474. #define DNS_RTYPE_WINS 0x01ff // 64K - 255
  475. #define DNS_RTYPE_WINSR 0x02ff // 64K - 254
  476. //
  477. // Record type specific definitions
  478. //
  479. //
  480. // ATMA (ATM address type) formats
  481. //
  482. // Define these directly for any environment (ex NT4)
  483. // without winsock2 ATM support (ws2atm.h)
  484. //
  485. #ifndef ATMA_E164
  486. #define DNS_ATMA_FORMAT_E164 1
  487. #define DNS_ATMA_FORMAT_AESA 2
  488. #define DNS_ATMA_MAX_ADDR_LENGTH (20)
  489. #else
  490. #define DNS_ATMA_FORMAT_E164 ATM_E164
  491. #define DNS_ATMA_FORMAT_AESA ATM_AESA
  492. #define DNS_ATMA_MAX_ADDR_LENGTH ATM_ADDR_SIZE
  493. #endif
  494. #define DNS_ATMA_AESA_ADDR_LENGTH (20)
  495. #define DNS_ATMA_MAX_RECORD_LENGTH (DNS_ATMA_MAX_ADDR_LENGTH+1)
  496. //
  497. // DNSSEC defs
  498. //
  499. // DNSSEC algorithms
  500. #define DNSSEC_ALGORITHM_RSAMD5 1
  501. #define DNSSEC_ALGORITHM_NULL 253
  502. #define DNSSEC_ALGORITHM_PRIVATE 254
  503. // DNSSEC KEY protocol table
  504. #define DNSSEC_PROTOCOL_NONE 0
  505. #define DNSSEC_PROTOCOL_TLS 1
  506. #define DNSSEC_PROTOCOL_EMAIL 2
  507. #define DNSSEC_PROTOCOL_DNSSEC 3
  508. #define DNSSEC_PROTOCOL_IPSEC 4
  509. // DNSSEC KEY flag field
  510. #define DNSSEC_KEY_FLAG_NOAUTH 0x0001
  511. #define DNSSEC_KEY_FLAG_NOCONF 0x0002
  512. #define DNSSEC_KEY_FLAG_FLAG2 0x0004
  513. #define DNSSEC_KEY_FLAG_EXTEND 0x0008
  514. #define DNSSEC_KEY_FLAG_
  515. #define DNSSEC_KEY_FLAG_FLAG4 0x0010
  516. #define DNSSEC_KEY_FLAG_FLAG5 0x0020
  517. // bits 6,7 are name type
  518. #define DNSSEC_KEY_FLAG_USER 0x0000
  519. #define DNSSEC_KEY_FLAG_ZONE 0x0040
  520. #define DNSSEC_KEY_FLAG_HOST 0x0080
  521. #define DNSSEC_KEY_FLAG_NTPE3 0x00c0
  522. // bits 8-11 are reserved for future use
  523. #define DNSSEC_KEY_FLAG_FLAG8 0x0100
  524. #define DNSSEC_KEY_FLAG_FLAG9 0x0200
  525. #define DNSSEC_KEY_FLAG_FLAG10 0x0400
  526. #define DNSSEC_KEY_FLAG_FLAG11 0x0800
  527. // bits 12-15 are sig field
  528. #define DNSSEC_KEY_FLAG_SIG0 0x0000
  529. #define DNSSEC_KEY_FLAG_SIG1 0x1000
  530. #define DNSSEC_KEY_FLAG_SIG2 0x2000
  531. #define DNSSEC_KEY_FLAG_SIG3 0x3000
  532. #define DNSSEC_KEY_FLAG_SIG4 0x4000
  533. #define DNSSEC_KEY_FLAG_SIG5 0x5000
  534. #define DNSSEC_KEY_FLAG_SIG6 0x6000
  535. #define DNSSEC_KEY_FLAG_SIG7 0x7000
  536. #define DNSSEC_KEY_FLAG_SIG8 0x8000
  537. #define DNSSEC_KEY_FLAG_SIG9 0x9000
  538. #define DNSSEC_KEY_FLAG_SIG10 0xa000
  539. #define DNSSEC_KEY_FLAG_SIG11 0xb000
  540. #define DNSSEC_KEY_FLAG_SIG12 0xc000
  541. #define DNSSEC_KEY_FLAG_SIG13 0xd000
  542. #define DNSSEC_KEY_FLAG_SIG14 0xe000
  543. #define DNSSEC_KEY_FLAG_SIG15 0xf000
  544. //
  545. // TKEY modes
  546. //
  547. #define DNS_TKEY_MODE_SERVER_ASSIGN 1
  548. #define DNS_TKEY_MODE_DIFFIE_HELLMAN 2
  549. #define DNS_TKEY_MODE_GSS 3
  550. #define DNS_TKEY_MODE_RESOLVER_ASSIGN 4
  551. //
  552. // WINS + NBSTAT flag field
  553. //
  554. #define DNS_WINS_FLAG_SCOPE (0x80000000)
  555. #define DNS_WINS_FLAG_LOCAL (0x00010000)
  556. //
  557. // Helpful checks
  558. //
  559. #define IS_WORD_ALIGNED(p) ( !((UINT_PTR)(p) & (UINT_PTR)1) )
  560. #define IS_DWORD_ALIGNED(p) ( !((UINT_PTR)(p) & (UINT_PTR)3) )
  561. #define IS_QWORD_ALIGNED(p) ( !((UINT_PTR)(p) & (UINT_PTR)7) )
  562. //
  563. // DNS config API
  564. //
  565. //
  566. // Types of DNS configuration info
  567. //
  568. typedef enum
  569. {
  570. // In Win2K
  571. DnsConfigPrimaryDomainName_W,
  572. DnsConfigPrimaryDomainName_A,
  573. DnsConfigPrimaryDomainName_UTF8,
  574. // Not available yet
  575. DnsConfigAdapterDomainName_W,
  576. DnsConfigAdapterDomainName_A,
  577. DnsConfigAdapterDomainName_UTF8,
  578. // In Win2K
  579. DnsConfigDnsServerList,
  580. // Not available yet
  581. DnsConfigSearchList,
  582. DnsConfigAdapterInfo,
  583. // In Win2K
  584. DnsConfigPrimaryHostNameRegistrationEnabled,
  585. DnsConfigAdapterHostNameRegistrationEnabled,
  586. DnsConfigAddressRegistrationMaxCount,
  587. // In WindowsXP
  588. DnsConfigHostName_W,
  589. DnsConfigHostName_A,
  590. DnsConfigHostName_UTF8,
  591. DnsConfigFullHostName_W,
  592. DnsConfigFullHostName_A,
  593. DnsConfigFullHostName_UTF8
  594. // In XP-SP1 (Server.net)
  595. }
  596. DNS_CONFIG_TYPE;
  597. //
  598. // Config API flags
  599. //
  600. //
  601. // Causes config info to be allocated.
  602. // Free with DnsFree().
  603. //
  604. #define DNS_CONFIG_FLAG_ALLOC (0x00000001)
  605. DNS_STATUS
  606. WINAPI
  607. DnsQueryConfig(
  608. IN DNS_CONFIG_TYPE Config,
  609. IN DWORD Flag,
  610. IN PWSTR pwsAdapterName,
  611. IN PVOID pReserved,
  612. OUT PVOID pBuffer,
  613. IN OUT PDWORD pBufferLength
  614. );
  615. //
  616. // DNS resource record structure
  617. //
  618. //
  619. // Record data for specific types
  620. //
  621. typedef struct
  622. {
  623. IP4_ADDRESS IpAddress;
  624. }
  625. DNS_A_DATA, *PDNS_A_DATA;
  626. typedef struct
  627. {
  628. PWSTR pNameHost;
  629. }
  630. DNS_PTR_DATAW, *PDNS_PTR_DATAW;
  631. typedef struct
  632. {
  633. PSTR pNameHost;
  634. }
  635. DNS_PTR_DATAA, *PDNS_PTR_DATAA;
  636. typedef struct
  637. {
  638. PWSTR pNamePrimaryServer;
  639. PWSTR pNameAdministrator;
  640. DWORD dwSerialNo;
  641. DWORD dwRefresh;
  642. DWORD dwRetry;
  643. DWORD dwExpire;
  644. DWORD dwDefaultTtl;
  645. }
  646. DNS_SOA_DATAW, *PDNS_SOA_DATAW;
  647. typedef struct
  648. {
  649. PSTR pNamePrimaryServer;
  650. PSTR pNameAdministrator;
  651. DWORD dwSerialNo;
  652. DWORD dwRefresh;
  653. DWORD dwRetry;
  654. DWORD dwExpire;
  655. DWORD dwDefaultTtl;
  656. }
  657. DNS_SOA_DATAA, *PDNS_SOA_DATAA;
  658. typedef struct
  659. {
  660. PWSTR pNameMailbox;
  661. PWSTR pNameErrorsMailbox;
  662. }
  663. DNS_MINFO_DATAW, *PDNS_MINFO_DATAW;
  664. typedef struct
  665. {
  666. PSTR pNameMailbox;
  667. PSTR pNameErrorsMailbox;
  668. }
  669. DNS_MINFO_DATAA, *PDNS_MINFO_DATAA;
  670. typedef struct
  671. {
  672. PWSTR pNameExchange;
  673. WORD wPreference;
  674. WORD Pad; // keep ptrs DWORD aligned
  675. }
  676. DNS_MX_DATAW, *PDNS_MX_DATAW;
  677. typedef struct
  678. {
  679. PSTR pNameExchange;
  680. WORD wPreference;
  681. WORD Pad; // keep ptrs DWORD aligned
  682. }
  683. DNS_MX_DATAA, *PDNS_MX_DATAA;
  684. typedef struct
  685. {
  686. DWORD dwStringCount;
  687. #ifdef MIDL_PASS
  688. [size_is(dwStringCount)] PWSTR pStringArray[];
  689. #else
  690. PWSTR pStringArray[1];
  691. #endif
  692. }
  693. DNS_TXT_DATAW, *PDNS_TXT_DATAW;
  694. typedef struct
  695. {
  696. DWORD dwStringCount;
  697. #ifdef MIDL_PASS
  698. [size_is(dwStringCount)] PSTR pStringArray[];
  699. #else
  700. PSTR pStringArray[1];
  701. #endif
  702. }
  703. DNS_TXT_DATAA, *PDNS_TXT_DATAA;
  704. typedef struct
  705. {
  706. DWORD dwByteCount;
  707. #ifdef MIDL_PASS
  708. [size_is(dwByteCount)] BYTE Data[];
  709. #else
  710. BYTE Data[1];
  711. #endif
  712. }
  713. DNS_NULL_DATA, *PDNS_NULL_DATA;
  714. typedef struct
  715. {
  716. IP4_ADDRESS IpAddress;
  717. UCHAR chProtocol;
  718. BYTE BitMask[1];
  719. }
  720. DNS_WKS_DATA, *PDNS_WKS_DATA;
  721. typedef struct
  722. {
  723. IP6_ADDRESS Ip6Address;
  724. }
  725. DNS_AAAA_DATA, *PDNS_AAAA_DATA;
  726. typedef struct
  727. {
  728. PWSTR pNameSigner;
  729. WORD wTypeCovered;
  730. BYTE chAlgorithm;
  731. BYTE chLabelCount;
  732. DWORD dwOriginalTtl;
  733. DWORD dwExpiration;
  734. DWORD dwTimeSigned;
  735. WORD wKeyTag;
  736. WORD Pad; // keep byte field aligned
  737. BYTE Signature[1];
  738. }
  739. DNS_SIG_DATAW, *PDNS_SIG_DATAW;
  740. typedef struct
  741. {
  742. PSTR pNameSigner;
  743. WORD wTypeCovered;
  744. BYTE chAlgorithm;
  745. BYTE chLabelCount;
  746. DWORD dwOriginalTtl;
  747. DWORD dwExpiration;
  748. DWORD dwTimeSigned;
  749. WORD wKeyTag;
  750. WORD Pad; // keep byte field aligned
  751. BYTE Signature[1];
  752. }
  753. DNS_SIG_DATAA, *PDNS_SIG_DATAA;
  754. typedef struct
  755. {
  756. WORD wFlags;
  757. BYTE chProtocol;
  758. BYTE chAlgorithm;
  759. BYTE Key[1];
  760. }
  761. DNS_KEY_DATA, *PDNS_KEY_DATA;
  762. typedef struct
  763. {
  764. WORD wVersion;
  765. WORD wSize;
  766. WORD wHorPrec;
  767. WORD wVerPrec;
  768. DWORD dwLatitude;
  769. DWORD dwLongitude;
  770. DWORD dwAltitude;
  771. }
  772. DNS_LOC_DATA, *PDNS_LOC_DATA;
  773. typedef struct
  774. {
  775. PWSTR pNameNext;
  776. WORD wNumTypes;
  777. WORD wTypes[1];
  778. }
  779. DNS_NXT_DATAW, *PDNS_NXT_DATAW;
  780. typedef struct
  781. {
  782. PSTR pNameNext;
  783. WORD wNumTypes;
  784. WORD wTypes[1];
  785. }
  786. DNS_NXT_DATAA, *PDNS_NXT_DATAA;
  787. typedef struct
  788. {
  789. PWSTR pNameTarget;
  790. WORD wPriority;
  791. WORD wWeight;
  792. WORD wPort;
  793. WORD Pad; // keep ptrs DWORD aligned
  794. }
  795. DNS_SRV_DATAW, *PDNS_SRV_DATAW;
  796. typedef struct
  797. {
  798. PSTR pNameTarget;
  799. WORD wPriority;
  800. WORD wWeight;
  801. WORD wPort;
  802. WORD Pad; // keep ptrs DWORD aligned
  803. }
  804. DNS_SRV_DATAA, *PDNS_SRV_DATAA;
  805. typedef struct
  806. {
  807. BYTE AddressType;
  808. BYTE Address[ DNS_ATMA_MAX_ADDR_LENGTH ];
  809. // E164 -- Null terminated string of less than
  810. // DNS_ATMA_MAX_ADDR_LENGTH
  811. //
  812. // For NSAP (AESA) BCD encoding of exactly
  813. // DNS_ATMA_AESA_ADDR_LENGTH
  814. }
  815. DNS_ATMA_DATA, *PDNS_ATMA_DATA;
  816. typedef struct
  817. {
  818. PWSTR pNameAlgorithm;
  819. PBYTE pAlgorithmPacket;
  820. PBYTE pKey;
  821. PBYTE pOtherData;
  822. DWORD dwCreateTime;
  823. DWORD dwExpireTime;
  824. WORD wMode;
  825. WORD wError;
  826. WORD wKeyLength;
  827. WORD wOtherLength;
  828. UCHAR cAlgNameLength;
  829. BOOL bPacketPointers;
  830. }
  831. DNS_TKEY_DATAW, *PDNS_TKEY_DATAW;
  832. typedef struct
  833. {
  834. PSTR pNameAlgorithm;
  835. PBYTE pAlgorithmPacket;
  836. PBYTE pKey;
  837. PBYTE pOtherData;
  838. DWORD dwCreateTime;
  839. DWORD dwExpireTime;
  840. WORD wMode;
  841. WORD wError;
  842. WORD wKeyLength;
  843. WORD wOtherLength;
  844. UCHAR cAlgNameLength;
  845. BOOL bPacketPointers;
  846. }
  847. DNS_TKEY_DATAA, *PDNS_TKEY_DATAA;
  848. typedef struct
  849. {
  850. PWSTR pNameAlgorithm;
  851. PBYTE pAlgorithmPacket;
  852. PBYTE pSignature;
  853. PBYTE pOtherData;
  854. LONGLONG i64CreateTime;
  855. WORD wFudgeTime;
  856. WORD wOriginalXid;
  857. WORD wError;
  858. WORD wSigLength;
  859. WORD wOtherLength;
  860. UCHAR cAlgNameLength;
  861. BOOL bPacketPointers;
  862. }
  863. DNS_TSIG_DATAW, *PDNS_TSIG_DATAW;
  864. typedef struct
  865. {
  866. PSTR pNameAlgorithm;
  867. PBYTE pAlgorithmPacket;
  868. PBYTE pSignature;
  869. PBYTE pOtherData;
  870. LONGLONG i64CreateTime;
  871. WORD wFudgeTime;
  872. WORD wOriginalXid;
  873. WORD wError;
  874. WORD wSigLength;
  875. WORD wOtherLength;
  876. UCHAR cAlgNameLength;
  877. BOOL bPacketPointers;
  878. }
  879. DNS_TSIG_DATAA, *PDNS_TSIG_DATAA;
  880. //
  881. // MS only types -- only hit the wire in MS-MS zone transfer
  882. //
  883. typedef struct
  884. {
  885. DWORD dwMappingFlag;
  886. DWORD dwLookupTimeout;
  887. DWORD dwCacheTimeout;
  888. DWORD cWinsServerCount;
  889. IP4_ADDRESS WinsServers[1];
  890. }
  891. DNS_WINS_DATA, *PDNS_WINS_DATA;
  892. typedef struct
  893. {
  894. DWORD dwMappingFlag;
  895. DWORD dwLookupTimeout;
  896. DWORD dwCacheTimeout;
  897. PWSTR pNameResultDomain;
  898. }
  899. DNS_WINSR_DATAW, *PDNS_WINSR_DATAW;
  900. typedef struct
  901. {
  902. DWORD dwMappingFlag;
  903. DWORD dwLookupTimeout;
  904. DWORD dwCacheTimeout;
  905. PSTR pNameResultDomain;
  906. }
  907. DNS_WINSR_DATAA, *PDNS_WINSR_DATAA;
  908. //
  909. // Unicode/ANSI record types
  910. //
  911. #ifdef UNICODE
  912. typedef DNS_PTR_DATAW DNS_PTR_DATA, *PDNS_PTR_DATA;
  913. typedef DNS_SOA_DATAW DNS_SOA_DATA, *PDNS_SOA_DATA;
  914. typedef DNS_MINFO_DATAW DNS_MINFO_DATA, *PDNS_MINFO_DATA;
  915. typedef DNS_MX_DATAW DNS_MX_DATA, *PDNS_MX_DATA;
  916. typedef DNS_TXT_DATAW DNS_TXT_DATA, *PDNS_TXT_DATA;
  917. typedef DNS_SIG_DATAW DNS_SIG_DATA, *PDNS_SIG_DATA;
  918. typedef DNS_NXT_DATAW DNS_NXT_DATA, *PDNS_NXT_DATA;
  919. typedef DNS_SRV_DATAW DNS_SRV_DATA, *PDNS_SRV_DATA;
  920. typedef DNS_TKEY_DATAW DNS_TKEY_DATA, *PDNS_TKEY_DATA;
  921. typedef DNS_TSIG_DATAW DNS_TSIG_DATA, *PDNS_TSIG_DATA;
  922. typedef DNS_WINSR_DATAW DNS_WINSR_DATA, *PDNS_WINSR_DATA;
  923. #else
  924. typedef DNS_PTR_DATAA DNS_PTR_DATA, *PDNS_PTR_DATA;
  925. typedef DNS_SOA_DATAA DNS_SOA_DATA, *PDNS_SOA_DATA;
  926. typedef DNS_MINFO_DATAA DNS_MINFO_DATA, *PDNS_MINFO_DATA;
  927. typedef DNS_MX_DATAA DNS_MX_DATA, *PDNS_MX_DATA;
  928. typedef DNS_TXT_DATAA DNS_TXT_DATA, *PDNS_TXT_DATA;
  929. typedef DNS_SIG_DATAA DNS_SIG_DATA, *PDNS_SIG_DATA;
  930. typedef DNS_NXT_DATAA DNS_NXT_DATA, *PDNS_NXT_DATA;
  931. typedef DNS_SRV_DATAA DNS_SRV_DATA, *PDNS_SRV_DATA;
  932. typedef DNS_TKEY_DATAA DNS_TKEY_DATA, *PDNS_TKEY_DATA;
  933. typedef DNS_TSIG_DATAA DNS_TSIG_DATA, *PDNS_TSIG_DATA;
  934. typedef DNS_WINSR_DATAA DNS_WINSR_DATA, *PDNS_WINSR_DATA;
  935. #endif
  936. //
  937. // Length of non-fixed-length data types
  938. //
  939. #define DNS_TEXT_RECORD_LENGTH(StringCount) \
  940. (FIELD_OFFSET(DNS_TXT_DATA, pStringArray) + ((StringCount) * sizeof(PCHAR)))
  941. #define DNS_NULL_RECORD_LENGTH(ByteCount) \
  942. (FIELD_OFFSET(DNS_NULL_DATA, Data) + (ByteCount))
  943. #define DNS_WKS_RECORD_LENGTH(ByteCount) \
  944. (FIELD_OFFSET(DNS_WKS_DATA, BitMask) + (ByteCount))
  945. #define DNS_WINS_RECORD_LENGTH(IpCount) \
  946. (FIELD_OFFSET(DNS_WINS_DATA, WinsServers) + ((IpCount) * sizeof(IP4_ADDRESS)))
  947. //
  948. // Record flags
  949. //
  950. typedef struct _DnsRecordFlags
  951. {
  952. DWORD Section : 2;
  953. DWORD Delete : 1;
  954. DWORD CharSet : 2;
  955. DWORD Unused : 3;
  956. DWORD Reserved : 24;
  957. }
  958. DNS_RECORD_FLAGS;
  959. //
  960. // Wire Record Sections
  961. //
  962. // Useable both in record flags "Section" and as index into
  963. // wire message header section counts.
  964. //
  965. typedef enum _DnsSection
  966. {
  967. DnsSectionQuestion,
  968. DnsSectionAnswer,
  969. DnsSectionAuthority,
  970. DnsSectionAddtional,
  971. }
  972. DNS_SECTION;
  973. // Update message section names
  974. #define DnsSectionZone DnsSectionQuestion
  975. #define DnsSectionPrereq DnsSectionAnswer
  976. #define DnsSectionUpdate DnsSectionAuthority
  977. //
  978. // Record flags as bit flags
  979. // These may be or'd together to set the fields
  980. //
  981. // RR Section in packet
  982. #define DNSREC_SECTION (0x00000003)
  983. #define DNSREC_QUESTION (0x00000000)
  984. #define DNSREC_ANSWER (0x00000001)
  985. #define DNSREC_AUTHORITY (0x00000002)
  986. #define DNSREC_ADDITIONAL (0x00000003)
  987. // RR Section in packet (update)
  988. #define DNSREC_ZONE (0x00000000)
  989. #define DNSREC_PREREQ (0x00000001)
  990. #define DNSREC_UPDATE (0x00000002)
  991. // Delete RR (update) or No-exist (prerequisite)
  992. #define DNSREC_DELETE (0x00000004)
  993. #define DNSREC_NOEXIST (0x00000004)
  994. //
  995. // Record \ RR set structure
  996. //
  997. // Note: The dwReserved flag serves to insure that the substructures
  998. // start on 64-bit boundaries. Do NOT pack this structure, as the
  999. // substructures may contain pointers or int64 values which are
  1000. // properly aligned unpacked.
  1001. //
  1002. #ifdef MIDL_PASS
  1003. #define PDNS_RECORD PVOID
  1004. #else
  1005. typedef struct _DnsRecordW
  1006. {
  1007. struct _DnsRecordW * pNext;
  1008. PWSTR pName;
  1009. WORD wType;
  1010. WORD wDataLength; // Not referenced for DNS record types
  1011. // defined above.
  1012. union
  1013. {
  1014. DWORD DW; // flags as DWORD
  1015. DNS_RECORD_FLAGS S; // flags as structure
  1016. } Flags;
  1017. DWORD dwTtl;
  1018. DWORD dwReserved;
  1019. // Record Data
  1020. union
  1021. {
  1022. DNS_A_DATA A;
  1023. DNS_SOA_DATAW SOA, Soa;
  1024. DNS_PTR_DATAW PTR, Ptr,
  1025. NS, Ns,
  1026. CNAME, Cname,
  1027. MB, Mb,
  1028. MD, Md,
  1029. MF, Mf,
  1030. MG, Mg,
  1031. MR, Mr;
  1032. DNS_MINFO_DATAW MINFO, Minfo,
  1033. RP, Rp;
  1034. DNS_MX_DATAW MX, Mx,
  1035. AFSDB, Afsdb,
  1036. RT, Rt;
  1037. DNS_TXT_DATAW HINFO, Hinfo,
  1038. ISDN, Isdn,
  1039. TXT, Txt,
  1040. X25;
  1041. DNS_NULL_DATA Null;
  1042. DNS_WKS_DATA WKS, Wks;
  1043. DNS_AAAA_DATA AAAA;
  1044. DNS_KEY_DATA KEY, Key;
  1045. DNS_SIG_DATAW SIG, Sig;
  1046. DNS_ATMA_DATA ATMA, Atma;
  1047. DNS_NXT_DATAW NXT, Nxt;
  1048. DNS_SRV_DATAW SRV, Srv;
  1049. DNS_TKEY_DATAW TKEY, Tkey;
  1050. DNS_TSIG_DATAW TSIG, Tsig;
  1051. DNS_WINS_DATA WINS, Wins;
  1052. DNS_WINSR_DATAW WINSR, WinsR, NBSTAT, Nbstat;
  1053. } Data;
  1054. }
  1055. DNS_RECORDW, *PDNS_RECORDW;
  1056. typedef struct _DnsRecordA
  1057. {
  1058. struct _DnsRecordA * pNext;
  1059. PSTR pName;
  1060. WORD wType;
  1061. WORD wDataLength; // Not referenced for DNS record types
  1062. // defined above.
  1063. union
  1064. {
  1065. DWORD DW; // flags as DWORD
  1066. DNS_RECORD_FLAGS S; // flags as structure
  1067. } Flags;
  1068. DWORD dwTtl;
  1069. DWORD dwReserved;
  1070. // Record Data
  1071. union
  1072. {
  1073. DNS_A_DATA A;
  1074. DNS_SOA_DATAA SOA, Soa;
  1075. DNS_PTR_DATAA PTR, Ptr,
  1076. NS, Ns,
  1077. CNAME, Cname,
  1078. MB, Mb,
  1079. MD, Md,
  1080. MF, Mf,
  1081. MG, Mg,
  1082. MR, Mr;
  1083. DNS_MINFO_DATAA MINFO, Minfo,
  1084. RP, Rp;
  1085. DNS_MX_DATAA MX, Mx,
  1086. AFSDB, Afsdb,
  1087. RT, Rt;
  1088. DNS_TXT_DATAA HINFO, Hinfo,
  1089. ISDN, Isdn,
  1090. TXT, Txt,
  1091. X25;
  1092. DNS_NULL_DATA Null;
  1093. DNS_WKS_DATA WKS, Wks;
  1094. DNS_AAAA_DATA AAAA;
  1095. DNS_KEY_DATA KEY, Key;
  1096. DNS_SIG_DATAA SIG, Sig;
  1097. DNS_ATMA_DATA ATMA, Atma;
  1098. DNS_NXT_DATAA NXT, Nxt;
  1099. DNS_SRV_DATAA SRV, Srv;
  1100. DNS_TKEY_DATAA TKEY, Tkey;
  1101. DNS_TSIG_DATAA TSIG, Tsig;
  1102. DNS_WINS_DATA WINS, Wins;
  1103. DNS_WINSR_DATAA WINSR, WinsR, NBSTAT, Nbstat;
  1104. } Data;
  1105. }
  1106. DNS_RECORDA, *PDNS_RECORDA;
  1107. #ifdef UNICODE
  1108. typedef DNS_RECORDW DNS_RECORD, *PDNS_RECORD;
  1109. #else
  1110. typedef DNS_RECORDA DNS_RECORD, *PDNS_RECORD;
  1111. #endif
  1112. //
  1113. // Header or fixed size of DNS_RECORD
  1114. //
  1115. #define DNS_RECORD_FIXED_SIZE FIELD_OFFSET( DNS_RECORD, Data )
  1116. #define SIZEOF_DNS_RECORD_HEADER DNS_RECORD_FIXED_SIZE
  1117. #endif // PRIVATE_DNS_RECORD
  1118. //
  1119. // Resource record set building
  1120. //
  1121. // pFirst points to first record in list.
  1122. // pLast points to last record in list.
  1123. //
  1124. typedef struct _DnsRRSet
  1125. {
  1126. PDNS_RECORD pFirstRR;
  1127. PDNS_RECORD pLastRR;
  1128. }
  1129. DNS_RRSET, *PDNS_RRSET;
  1130. //
  1131. // To init pFirst is NULL.
  1132. // But pLast points at the location of the pFirst pointer -- essentially
  1133. // treating the pFirst ptr as a DNS_RECORD. (It is a DNS_RECORD with
  1134. // only a pNext field, but that's the only part we use.)
  1135. //
  1136. // Then when the first record is added to the list, the pNext field of
  1137. // this dummy record (which corresponds to pFirst's value) is set to
  1138. // point at the first record. So pFirst then properly points at the
  1139. // first record.
  1140. //
  1141. // (This works only because pNext is the first field in a
  1142. // DNS_RECORD structure and hence casting a PDNS_RECORD ptr to
  1143. // PDNS_RECORD* and dereferencing yields its pNext field)
  1144. //
  1145. // Use TERMINATE when have built RR set by grabbing records out of
  1146. // existing set. This makes sure that at the end, the last RR is
  1147. // properly NULL terminated.
  1148. //
  1149. #define DNS_RRSET_INIT( rrset ) \
  1150. { \
  1151. PDNS_RRSET _prrset = &(rrset); \
  1152. _prrset->pFirstRR = NULL; \
  1153. _prrset->pLastRR = (PDNS_RECORD) &_prrset->pFirstRR; \
  1154. }
  1155. #define DNS_RRSET_ADD( rrset, pnewRR ) \
  1156. { \
  1157. PDNS_RRSET _prrset = &(rrset); \
  1158. PDNS_RECORD _prrnew = (pnewRR); \
  1159. _prrset->pLastRR->pNext = _prrnew; \
  1160. _prrset->pLastRR = _prrnew; \
  1161. }
  1162. #define DNS_RRSET_TERMINATE( rrset ) \
  1163. { \
  1164. PDNS_RRSET _prrset = &(rrset); \
  1165. _prrset->pLastRR->pNext = NULL; \
  1166. }
  1167. //
  1168. // Record set manipulation
  1169. //
  1170. //
  1171. // Record Copy
  1172. // Record copy functions also do conversion between character sets.
  1173. //
  1174. // Note, it might be advisable to directly expose non-Ex copy
  1175. // functions _W, _A for record and set, to avoid exposing the
  1176. // conversion enum.
  1177. //
  1178. typedef enum _DNS_CHARSET
  1179. {
  1180. DnsCharSetUnknown,
  1181. DnsCharSetUnicode,
  1182. DnsCharSetUtf8,
  1183. DnsCharSetAnsi,
  1184. }
  1185. DNS_CHARSET;
  1186. PDNS_RECORD
  1187. WINAPI
  1188. DnsRecordCopyEx(
  1189. IN PDNS_RECORD pRecord,
  1190. IN DNS_CHARSET CharSetIn,
  1191. IN DNS_CHARSET CharSetOut
  1192. );
  1193. PDNS_RECORD
  1194. WINAPI
  1195. DnsRecordSetCopyEx(
  1196. IN PDNS_RECORD pRecordSet,
  1197. IN DNS_CHARSET CharSetIn,
  1198. IN DNS_CHARSET CharSetOut
  1199. );
  1200. #ifdef UNICODE
  1201. #define DnsRecordCopy(pRR) \
  1202. DnsRecordCopyEx( (pRR), DnsCharSetUnicode, DnsCharSetUnicode )
  1203. #define DnsRecordSetCopy(pRR) \
  1204. DnsRecordSetCopyEx( (pRR), DnsCharSetUnicode, DnsCharSetUnicode )
  1205. #else
  1206. #define DnsRecordCopy(pRR) \
  1207. DnsRecordCopyEx( (pRR), DnsCharSetAnsi, DnsCharSetAnsi )
  1208. #define DnsRecordSetCopy(pRR) \
  1209. DnsRecordSetCopyEx( (pRR), DnsCharSetAnsi, DnsCharSetAnsi )
  1210. #endif
  1211. //
  1212. // Record Compare
  1213. //
  1214. // Note: these routines only compare records of the SAME character set.
  1215. // (ANSI, unicode or UTF8). Furthermore the routines assume the character
  1216. // set is indicated within the record. If compare of user created, rather
  1217. // than DNS API created record lists is desired, then caller should use
  1218. // DnsRecordCopy API and compare copies.
  1219. //
  1220. BOOL
  1221. WINAPI
  1222. DnsRecordCompare(
  1223. IN PDNS_RECORD pRecord1,
  1224. IN PDNS_RECORD pRecord2
  1225. );
  1226. BOOL
  1227. WINAPI
  1228. DnsRecordSetCompare(
  1229. IN OUT PDNS_RECORD pRR1,
  1230. IN OUT PDNS_RECORD pRR2,
  1231. OUT PDNS_RECORD * ppDiff1,
  1232. OUT PDNS_RECORD * ppDiff2
  1233. );
  1234. //
  1235. // Detach next record set from record list
  1236. //
  1237. PDNS_RECORD
  1238. DnsRecordSetDetach(
  1239. IN OUT PDNS_RECORD pRecordList
  1240. );
  1241. //
  1242. // Free structures returned from dnsapi.dll
  1243. //
  1244. // Currently supported free structures:
  1245. // Flat -- flat structure, including those allocated by DnsQueryConfig()
  1246. // RecordList -- deep record list free, including sub-fields of DNS_RECORD;
  1247. // includes those returned by DnsQuery() or DnsRecordSetCopy()
  1248. //
  1249. typedef enum
  1250. {
  1251. DnsFreeFlat = 0,
  1252. DnsFreeRecordList,
  1253. DnsFreeParsedMessageFields
  1254. }
  1255. DNS_FREE_TYPE;
  1256. VOID
  1257. WINAPI
  1258. DnsFree(
  1259. IN OUT PVOID pData,
  1260. IN DNS_FREE_TYPE FreeType
  1261. );
  1262. //
  1263. // Backward compatibility with Win2K, do not use for XP+ applications
  1264. //
  1265. // To free record lists, code
  1266. // DnsFree( pRecordList, DnsFreeRecordList );
  1267. //
  1268. #define DnsFreeRecordListDeep DnsFreeRecordList
  1269. VOID
  1270. WINAPI
  1271. DnsRecordListFree(
  1272. IN OUT PDNS_RECORD pRecordList,
  1273. IN DNS_FREE_TYPE FreeType
  1274. );
  1275. //
  1276. // DNS Query API
  1277. //
  1278. //
  1279. // Options for DnsQuery
  1280. //
  1281. #define DNS_QUERY_STANDARD 0x00000000
  1282. #define DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE 0x00000001
  1283. #define DNS_QUERY_USE_TCP_ONLY 0x00000002
  1284. #define DNS_QUERY_NO_RECURSION 0x00000004
  1285. #define DNS_QUERY_BYPASS_CACHE 0x00000008
  1286. #define DNS_QUERY_NO_WIRE_QUERY 0x00000010
  1287. #define DNS_QUERY_NO_LOCAL_NAME 0x00000020
  1288. #define DNS_QUERY_NO_HOSTS_FILE 0x00000040
  1289. #define DNS_QUERY_NO_NETBT 0x00000080
  1290. #define DNS_QUERY_WIRE_ONLY 0x00000100
  1291. #define DNS_QUERY_RETURN_MESSAGE 0x00000200
  1292. #define DNS_QUERY_TREAT_AS_FQDN 0x00001000
  1293. #define DNS_QUERY_DONT_RESET_TTL_VALUES 0x00100000
  1294. #define DNS_QUERY_RESERVED 0xff000000
  1295. // Backward compatibility with Win2K
  1296. // Do not use
  1297. #define DNS_QUERY_CACHE_ONLY DNS_QUERY_NO_WIRE_QUERY
  1298. DNS_STATUS
  1299. WINAPI
  1300. DnsQuery_A(
  1301. IN PCSTR pszName,
  1302. IN WORD wType,
  1303. IN DWORD Options,
  1304. IN PIP4_ARRAY aipServers OPTIONAL,
  1305. IN OUT PDNS_RECORD * ppQueryResults OPTIONAL,
  1306. IN OUT PVOID * pReserved OPTIONAL
  1307. );
  1308. DNS_STATUS
  1309. WINAPI
  1310. DnsQuery_UTF8(
  1311. IN PCSTR pszName,
  1312. IN WORD wType,
  1313. IN DWORD Options,
  1314. IN PIP4_ARRAY aipServers OPTIONAL,
  1315. IN OUT PDNS_RECORD * ppQueryResults OPTIONAL,
  1316. IN OUT PVOID * pReserved OPTIONAL
  1317. );
  1318. DNS_STATUS
  1319. WINAPI
  1320. DnsQuery_W(
  1321. IN PCWSTR pszName,
  1322. IN WORD wType,
  1323. IN DWORD Options,
  1324. IN PIP4_ARRAY aipServers OPTIONAL,
  1325. IN OUT PDNS_RECORD * ppQueryResults OPTIONAL,
  1326. IN OUT PVOID * pReserved OPTIONAL
  1327. );
  1328. #ifdef UNICODE
  1329. #define DnsQuery DnsQuery_W
  1330. #else
  1331. #define DnsQuery DnsQuery_A
  1332. #endif
  1333. //
  1334. // DNS Update API
  1335. //
  1336. // DnsAcquireContextHandle
  1337. // DnsReleaseContextHandle
  1338. // DnsModifyRecordsInSet
  1339. // DnsReplaceRecordSet
  1340. //
  1341. //
  1342. // Update flags
  1343. //
  1344. #define DNS_UPDATE_SECURITY_USE_DEFAULT 0x00000000
  1345. #define DNS_UPDATE_SECURITY_OFF 0x00000010
  1346. #define DNS_UPDATE_SECURITY_ON 0x00000020
  1347. #define DNS_UPDATE_SECURITY_ONLY 0x00000100
  1348. #define DNS_UPDATE_CACHE_SECURITY_CONTEXT 0x00000200
  1349. #define DNS_UPDATE_TEST_USE_LOCAL_SYS_ACCT 0x00000400
  1350. #define DNS_UPDATE_FORCE_SECURITY_NEGO 0x00000800
  1351. #define DNS_UPDATE_TRY_ALL_MASTER_SERVERS 0x00001000
  1352. #define DNS_UPDATE_SKIP_NO_UPDATE_ADAPTERS 0x00002000
  1353. #define DNS_UPDATE_REMOTE_SERVER 0x00004000
  1354. #define DNS_UPDATE_RESERVED 0xffff0000
  1355. //
  1356. // Note: pCredentials paramater is currently respectively
  1357. // PSEC_WINNT_AUTH_IDENTITY_W or PSEC_WINNT_AUTH_IDENTITY_A.
  1358. // Using PVOID to obviate the need for including rpcdce.h
  1359. // in order to include this file and to leave open the
  1360. // possibility of alternative credential specifications in
  1361. // the future.
  1362. //
  1363. DNS_STATUS
  1364. WINAPI
  1365. DnsAcquireContextHandle_W(
  1366. IN DWORD CredentialFlags,
  1367. IN PVOID pCredentials, OPTIONAL
  1368. //IN PSEC_WINNT_AUTH_IDENTITY_W pCredentials,
  1369. OUT PHANDLE pContextHandle
  1370. );
  1371. DNS_STATUS
  1372. WINAPI
  1373. DnsAcquireContextHandle_A(
  1374. IN DWORD CredentialFlags,
  1375. IN PVOID pCredentials, OPTIONAL
  1376. //IN PSEC_WINNT_AUTH_IDENTITY_A pCredentials,
  1377. OUT PHANDLE pContextHandle
  1378. );
  1379. #ifdef UNICODE
  1380. #define DnsAcquireContextHandle DnsAcquireContextHandle_W
  1381. #else
  1382. #define DnsAcquireContextHandle DnsAcquireContextHandle_A
  1383. #endif
  1384. VOID
  1385. WINAPI
  1386. DnsReleaseContextHandle(
  1387. IN HANDLE hContext
  1388. );
  1389. //
  1390. // Dynamic Update API
  1391. //
  1392. DNS_STATUS
  1393. WINAPI
  1394. DnsModifyRecordsInSet_W(
  1395. IN PDNS_RECORD pAddRecords,
  1396. IN PDNS_RECORD pDeleteRecords,
  1397. IN DWORD Options,
  1398. IN HANDLE hContext, OPTIONAL
  1399. IN PIP4_ARRAY pServerList, OPTIONAL
  1400. IN PVOID pReserved
  1401. );
  1402. DNS_STATUS
  1403. WINAPI
  1404. DnsModifyRecordsInSet_A(
  1405. IN PDNS_RECORD pAddRecords,
  1406. IN PDNS_RECORD pDeleteRecords,
  1407. IN DWORD Options,
  1408. IN HANDLE hContext, OPTIONAL
  1409. IN PIP4_ARRAY pServerList, OPTIONAL
  1410. IN PVOID pReserved
  1411. );
  1412. DNS_STATUS
  1413. WINAPI
  1414. DnsModifyRecordsInSet_UTF8(
  1415. IN PDNS_RECORD pAddRecords,
  1416. IN PDNS_RECORD pDeleteRecords,
  1417. IN DWORD Options,
  1418. IN HANDLE hContext, OPTIONAL
  1419. IN PIP4_ARRAY pServerList, OPTIONAL
  1420. IN PVOID pReserved
  1421. );
  1422. #ifdef UNICODE
  1423. #define DnsModifyRecordsInSet DnsModifyRecordsInSet_W
  1424. #else
  1425. #define DnsModifyRecordsInSet DnsModifyRecordsInSet_A
  1426. #endif
  1427. DNS_STATUS
  1428. WINAPI
  1429. DnsReplaceRecordSetW(
  1430. IN PDNS_RECORD pNewSet,
  1431. IN DWORD Options,
  1432. IN HANDLE hContext, OPTIONAL
  1433. IN PIP4_ARRAY pServerList, OPTIONAL
  1434. IN PVOID pReserved
  1435. );
  1436. DNS_STATUS
  1437. WINAPI
  1438. DnsReplaceRecordSetA(
  1439. IN PDNS_RECORD pNewSet,
  1440. IN DWORD Options,
  1441. IN HANDLE hContext, OPTIONAL
  1442. IN PIP4_ARRAY pServerList, OPTIONAL
  1443. IN PVOID pReserved
  1444. );
  1445. DNS_STATUS
  1446. WINAPI
  1447. DnsReplaceRecordSetUTF8(
  1448. IN PDNS_RECORD pNewSet,
  1449. IN DWORD Options,
  1450. IN HANDLE hContext, OPTIONAL
  1451. IN PIP4_ARRAY pServerList, OPTIONAL
  1452. IN PVOID pReserved
  1453. );
  1454. #ifdef UNICODE
  1455. #define DnsReplaceRecordSet DnsReplaceRecordSetW
  1456. #else
  1457. #define DnsReplaceRecordSet DnsReplaceRecordSetA
  1458. #endif
  1459. //
  1460. // DNS name validation
  1461. //
  1462. typedef enum _DNS_NAME_FORMAT
  1463. {
  1464. DnsNameDomain,
  1465. DnsNameDomainLabel,
  1466. DnsNameHostnameFull,
  1467. DnsNameHostnameLabel,
  1468. DnsNameWildcard,
  1469. DnsNameSrvRecord
  1470. }
  1471. DNS_NAME_FORMAT;
  1472. DNS_STATUS
  1473. DnsValidateName_UTF8(
  1474. IN LPCSTR pszName,
  1475. IN DNS_NAME_FORMAT Format
  1476. );
  1477. DNS_STATUS
  1478. DnsValidateName_W(
  1479. IN LPCWSTR pwszName,
  1480. IN DNS_NAME_FORMAT Format
  1481. );
  1482. DNS_STATUS
  1483. DnsValidateName_A(
  1484. IN LPCSTR pszName,
  1485. IN DNS_NAME_FORMAT Format
  1486. );
  1487. #ifdef UNICODE
  1488. #define DnsValidateName(p,f) DnsValidateName_W( (p), (f) )
  1489. #else
  1490. #define DnsValidateName(p,f) DnsValidateName_A( (p), (f) )
  1491. #endif
  1492. //
  1493. // DNS name comparison
  1494. //
  1495. BOOL
  1496. WINAPI
  1497. DnsNameCompare_A(
  1498. IN LPSTR pName1,
  1499. IN LPSTR pName2
  1500. );
  1501. BOOL
  1502. WINAPI
  1503. DnsNameCompare_W(
  1504. IN LPWSTR pName1,
  1505. IN LPWSTR pName2
  1506. );
  1507. #ifdef UNICODE
  1508. #define DnsNameCompare(n1,n2) DnsNameCompare_W( (n1),(n2) )
  1509. #else
  1510. #define DnsNameCompare(n1,n2) DnsNameCompare_A( (n1),(n2) )
  1511. #endif
  1512. //
  1513. // DNS message "roll-your-own" routines
  1514. //
  1515. typedef struct _DNS_MESSAGE_BUFFER
  1516. {
  1517. DNS_HEADER MessageHead;
  1518. CHAR MessageBody[1];
  1519. }
  1520. DNS_MESSAGE_BUFFER, *PDNS_MESSAGE_BUFFER;
  1521. BOOL
  1522. WINAPI
  1523. DnsWriteQuestionToBuffer_W(
  1524. IN OUT PDNS_MESSAGE_BUFFER pDnsBuffer,
  1525. IN OUT PDWORD pdwBufferSize,
  1526. IN LPWSTR pszName,
  1527. IN WORD wType,
  1528. IN WORD Xid,
  1529. IN BOOL fRecursionDesired
  1530. );
  1531. BOOL WINAPI
  1532. DnsWriteQuestionToBuffer_UTF8(
  1533. IN OUT PDNS_MESSAGE_BUFFER pDnsBuffer,
  1534. IN OUT LPDWORD pdwBufferSize,
  1535. IN LPSTR pszName,
  1536. IN WORD wType,
  1537. IN WORD Xid,
  1538. IN BOOL fRecursionDesired
  1539. );
  1540. DNS_STATUS
  1541. WINAPI
  1542. DnsExtractRecordsFromMessage_W(
  1543. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  1544. IN WORD wMessageLength,
  1545. OUT PDNS_RECORD * ppRecord
  1546. );
  1547. DNS_STATUS
  1548. WINAPI
  1549. DnsExtractRecordsFromMessage_UTF8(
  1550. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  1551. IN WORD wMessageLength,
  1552. OUT PDNS_RECORD * ppRecord
  1553. );
  1554. #ifdef __cplusplus
  1555. }
  1556. #endif // __cplusplus
  1557. #endif // _WINDNS_INCLUDED_