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.

4127 lines
94 KiB

  1. /*++
  2. Copyright (c) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. dnslib.h
  5. Abstract:
  6. Domain Name System (DNS) Library
  7. DNS Library Routines -- Main Header File
  8. Author:
  9. Jim Gilroy (jamesg) December 7, 1996
  10. Revision History:
  11. --*/
  12. #ifndef _DNSLIB_INCLUDED_
  13. #define _DNSLIB_INCLUDED_
  14. #include <windns.h>
  15. #include <dnsapi.h>
  16. #ifndef MIDL_PASS
  17. #include <rpc.h>
  18. #endif
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif // __cplusplus
  23. //
  24. // Handy alignment and rounding macros
  25. //
  26. #define WORD_ALIGN(ptr) ((PVOID) ((UINT_PTR)((PBYTE)ptr + 1) & ~(UINT_PTR)1))
  27. #define DWORD_ALIGN(ptr) ((PVOID) ((UINT_PTR)((PBYTE)ptr + 3) & ~(UINT_PTR)3))
  28. #define QWORD_ALIGN(ptr) ((PVOID) ((UINT_PTR)((PBYTE)ptr + 7) & ~(UINT_PTR)7))
  29. #ifdef WIN64
  30. #define POINTER_ALIGN(ptr) QWORD_ALIGN(ptr)
  31. #else
  32. #define POINTER_ALIGN(ptr) DWORD_ALIGN(ptr)
  33. #endif
  34. #define WORD_ALIGN_DWORD(dw) (((DWORD)dw + 1) & ~(DWORD)1)
  35. #define DWORD_ALIGN_DWORD(dw) (((DWORD)dw + 3) & ~(DWORD)3)
  36. #define QWORD_ALIGN_DWORD(dw) (((DWORD)dw + 7) & ~(DWORD)7)
  37. #ifdef WIN64
  38. #define POINTER_ALIGN_DWORD(dw) QWORD_ALIGN_DWORD(dw)
  39. #else
  40. #define POINTER_ALIGN_DWORD(dw) DWORD_ALIGN_DWORD(dw)
  41. #endif
  42. //
  43. // Useful type defs
  44. //
  45. #define PGUID LPGUID
  46. #define PADDRINFO LPADDRINFO
  47. //
  48. // Until converted must define PDNS_NAME
  49. //
  50. // Note: PDNS_NAME is NOT really a LPTSTR.
  51. // Rather it's the definition of a field that can be
  52. // either an PWSTR or PSTR depending on some other field.
  53. //
  54. #ifdef UNICODE
  55. typedef PWSTR PDNS_NAME;
  56. #else
  57. typedef PSTR PDNS_NAME;
  58. #endif
  59. //
  60. // Inline byte flipping
  61. //
  62. #ifndef MIDL_PASS
  63. __inline
  64. WORD
  65. inline_word_flip(
  66. IN WORD Word
  67. )
  68. {
  69. return ( (Word << 8) | (Word >> 8) );
  70. }
  71. #define inline_htons(w) inline_word_flip(w)
  72. #define inline_ntohs(w) inline_word_flip(w)
  73. __inline
  74. DWORD
  75. inline_dword_flip(
  76. IN DWORD Dword
  77. )
  78. {
  79. return ( ((Dword << 8) & 0x00ff0000) |
  80. (Dword << 24) |
  81. ((Dword >> 8) & 0x0000ff00) |
  82. (Dword >> 24) );
  83. }
  84. #define inline_htonl(d) inline_dword_flip(d)
  85. #define inline_ntohl(d) inline_dword_flip(d)
  86. #endif MIDL_PASS
  87. //
  88. // Flat buffer definition
  89. //
  90. // Note: using INT for sizes so that we can push BytesLeft negative
  91. // and use routines to determine REQUIRED space, even when no
  92. // buffer or buf too small.
  93. //
  94. typedef struct _FLATBUF
  95. {
  96. PBYTE pBuffer;
  97. PBYTE pEnd;
  98. PBYTE pCurrent;
  99. INT Size;
  100. INT BytesLeft;
  101. }
  102. FLATBUF, *PFLATBUF;
  103. //
  104. // Flat buffer routines -- argument versions
  105. //
  106. // These versions have the actual code so that we can
  107. // easily use this stuff with existing code that has
  108. // independent pCurrent and BytesLeft variables.
  109. //
  110. // FLATBUF structure versions just call these inline.
  111. //
  112. #ifndef MIDL_PASS
  113. PBYTE
  114. FlatBuf_Arg_Reserve(
  115. IN OUT PBYTE * ppCurrent,
  116. IN OUT PINT pBytesLeft,
  117. IN DWORD Size,
  118. IN DWORD Alignment
  119. );
  120. PBYTE
  121. FlatBuf_Arg_WriteString(
  122. IN OUT PBYTE * ppCurrent,
  123. IN OUT PINT pBytesLeft,
  124. IN PSTR pString,
  125. IN BOOL fUnicode
  126. );
  127. PBYTE
  128. FlatBuf_Arg_CopyMemory(
  129. IN OUT PBYTE * ppCurrent,
  130. IN OUT PINT pBytesLeft,
  131. IN PVOID pMemory,
  132. IN DWORD Length,
  133. IN DWORD Alignment
  134. );
  135. __inline
  136. PBYTE
  137. FlatBuf_Arg_ReserveAlignPointer(
  138. IN OUT PBYTE * ppCurrent,
  139. IN OUT PINT pBytesLeft,
  140. IN DWORD Size
  141. )
  142. {
  143. return FlatBuf_Arg_Reserve(
  144. ppCurrent,
  145. pBytesLeft,
  146. Size,
  147. sizeof(PVOID) );
  148. }
  149. __inline
  150. PBYTE
  151. FlatBuf_Arg_ReserveAlignQword(
  152. IN OUT PBYTE * ppCurrent,
  153. IN OUT PINT pBytesLeft,
  154. IN DWORD Size
  155. )
  156. {
  157. return FlatBuf_Arg_Reserve(
  158. ppCurrent,
  159. pBytesLeft,
  160. Size,
  161. sizeof(QWORD) );
  162. }
  163. __inline
  164. PBYTE
  165. FlatBuf_Arg_ReserveAlignDword(
  166. IN OUT PBYTE * ppCurrent,
  167. IN OUT PINT pBytesLeft,
  168. IN DWORD Size
  169. )
  170. {
  171. return FlatBuf_Arg_Reserve(
  172. ppCurrent,
  173. pBytesLeft,
  174. Size,
  175. sizeof(DWORD) );
  176. }
  177. __inline
  178. PBYTE
  179. FlatBuf_Arg_ReserveAlignWord(
  180. IN OUT PBYTE * ppCurrent,
  181. IN OUT PINT pBytesLeft,
  182. IN DWORD Size
  183. )
  184. {
  185. return FlatBuf_Arg_Reserve(
  186. ppCurrent,
  187. pBytesLeft,
  188. Size,
  189. sizeof(WORD) );
  190. }
  191. __inline
  192. PBYTE
  193. FlatBuf_Arg_ReserveAlignByte(
  194. IN OUT PBYTE * ppCurrent,
  195. IN OUT PINT pBytesLeft,
  196. IN DWORD Size
  197. )
  198. {
  199. return FlatBuf_Arg_Reserve(
  200. ppCurrent,
  201. pBytesLeft,
  202. Size,
  203. 0 );
  204. }
  205. PBYTE
  206. __inline
  207. FlatBuf_Arg_WriteString_A(
  208. IN OUT PBYTE * ppCurrent,
  209. IN OUT PINT pBytesLeft,
  210. IN PSTR pString
  211. )
  212. {
  213. return FlatBuf_Arg_WriteString(
  214. ppCurrent,
  215. pBytesLeft,
  216. pString,
  217. FALSE // not unicode
  218. );
  219. }
  220. PBYTE
  221. __inline
  222. FlatBuf_Arg_WriteString_W(
  223. IN OUT PBYTE * ppCurrent,
  224. IN OUT PINT pBytesLeft,
  225. IN PWSTR pString
  226. )
  227. {
  228. return FlatBuf_Arg_WriteString(
  229. ppCurrent,
  230. pBytesLeft,
  231. (PSTR) pString,
  232. TRUE // unicode
  233. );
  234. }
  235. //
  236. // Flat buffer routines -- structure versions
  237. //
  238. VOID
  239. FlatBuf_Init(
  240. IN OUT PFLATBUF pFlatBuf,
  241. IN PBYTE pBuffer,
  242. IN INT Size
  243. );
  244. __inline
  245. PBYTE
  246. FlatBuf_Reserve(
  247. IN OUT PFLATBUF pBuf,
  248. IN DWORD Size,
  249. IN DWORD Alignment
  250. )
  251. {
  252. return FlatBuf_Arg_Reserve(
  253. & pBuf->pCurrent,
  254. & pBuf->BytesLeft,
  255. Size,
  256. Alignment );
  257. }
  258. __inline
  259. PBYTE
  260. FlatBuf_ReserveAlignPointer(
  261. IN OUT PFLATBUF pBuf,
  262. IN DWORD Size
  263. )
  264. {
  265. return FlatBuf_Arg_Reserve(
  266. & pBuf->pCurrent,
  267. & pBuf->BytesLeft,
  268. Size,
  269. sizeof(PVOID) );
  270. }
  271. __inline
  272. PBYTE
  273. FlatBuf_ReserveAlignQword(
  274. IN OUT PFLATBUF pBuf,
  275. IN DWORD Size
  276. )
  277. {
  278. return FlatBuf_Arg_Reserve(
  279. & pBuf->pCurrent,
  280. & pBuf->BytesLeft,
  281. Size,
  282. sizeof(QWORD) );
  283. }
  284. __inline
  285. PBYTE
  286. FlatBuf_ReserveAlignDword(
  287. IN OUT PFLATBUF pBuf,
  288. IN DWORD Size
  289. )
  290. {
  291. return FlatBuf_Arg_Reserve(
  292. & pBuf->pCurrent,
  293. & pBuf->BytesLeft,
  294. Size,
  295. sizeof(DWORD) );
  296. }
  297. __inline
  298. PBYTE
  299. FlatBuf_ReserveAlignWord(
  300. IN OUT PFLATBUF pBuf,
  301. IN DWORD Size
  302. )
  303. {
  304. return FlatBuf_Arg_Reserve(
  305. & pBuf->pCurrent,
  306. & pBuf->BytesLeft,
  307. Size,
  308. sizeof(WORD) );
  309. }
  310. __inline
  311. PBYTE
  312. FlatBuf_ReserveAlignByte(
  313. IN OUT PFLATBUF pBuf,
  314. IN DWORD Size
  315. )
  316. {
  317. return FlatBuf_Arg_Reserve(
  318. & pBuf->pCurrent,
  319. & pBuf->BytesLeft,
  320. Size,
  321. 0 );
  322. }
  323. PBYTE
  324. __inline
  325. FlatBuf_WriteString(
  326. IN OUT PFLATBUF pBuf,
  327. IN PSTR pString,
  328. IN BOOL fUnicode
  329. )
  330. {
  331. return FlatBuf_Arg_WriteString(
  332. & pBuf->pCurrent,
  333. & pBuf->BytesLeft,
  334. pString,
  335. fUnicode
  336. );
  337. }
  338. PBYTE
  339. __inline
  340. FlatBuf_WriteString_A(
  341. IN OUT PFLATBUF pBuf,
  342. IN PSTR pString
  343. )
  344. {
  345. return FlatBuf_Arg_WriteString(
  346. & pBuf->pCurrent,
  347. & pBuf->BytesLeft,
  348. pString,
  349. FALSE // not unicode
  350. );
  351. }
  352. PBYTE
  353. __inline
  354. FlatBuf_WriteString_W(
  355. IN OUT PFLATBUF pBuf,
  356. IN PWSTR pString
  357. )
  358. {
  359. return FlatBuf_Arg_WriteString(
  360. & pBuf->pCurrent,
  361. & pBuf->BytesLeft,
  362. (PSTR) pString,
  363. TRUE // unicode
  364. );
  365. }
  366. PBYTE
  367. __inline
  368. FlatBuf_CopyMemory(
  369. IN OUT PFLATBUF pBuf,
  370. IN PVOID pMemory,
  371. IN DWORD Length,
  372. IN DWORD Alignment
  373. )
  374. {
  375. return FlatBuf_Arg_CopyMemory(
  376. & pBuf->pCurrent,
  377. & pBuf->BytesLeft,
  378. pMemory,
  379. Length,
  380. Alignment );
  381. }
  382. #endif // not MIDL_PASS
  383. //
  384. // Read unaligned value from given position in packet
  385. //
  386. #define READ_PACKET_HOST_DWORD(pch) \
  387. FlipUnalignedDword( pch )
  388. #define READ_PACKET_NET_DWORD(pch) \
  389. ( *(UNALIGNED DWORD *)(pch) )
  390. #define READ_PACKET_HOST_WORD(pch) \
  391. FlipUnalignedWord( pch )
  392. #define READ_PACKET_NET_WORD(pch) \
  393. ( *(UNALIGNED WORD *)(pch) )
  394. //
  395. // Private DNS_RECORD Flag field structure definition and macros
  396. //
  397. // Note: don't add to this list -- private stuff in dnslibp.h
  398. //
  399. typedef struct _DnsRecordLibFlags
  400. {
  401. DWORD Section : 2;
  402. DWORD Delete : 1;
  403. DWORD CharSet : 2;
  404. DWORD Unused : 6;
  405. DWORD Matched : 1;
  406. DWORD FreeData : 1;
  407. DWORD FreeOwner : 1;
  408. DWORD Reserved : 18;
  409. }
  410. DNSRECLIB_FLAGS, *PDNSRECLIB_FLAGS;
  411. #define PFLAGS( pRecord ) ((PDNSRECLIB_FLAGS)&pRecord->Flags.DW)
  412. #define FLAG_Section( pRecord ) (PFLAGS( pRecord )->Section)
  413. #define FLAG_Delete( pRecord ) (PFLAGS( pRecord )->Delete)
  414. #define FLAG_CharSet( pRecord ) (PFLAGS( pRecord )->CharSet)
  415. #define FLAG_FreeData( pRecord ) (PFLAGS( pRecord )->FreeData)
  416. #define FLAG_FreeOwner( pRecord ) (PFLAGS( pRecord )->FreeOwner)
  417. #define FLAG_Matched( pRecord ) (PFLAGS( pRecord )->Matched)
  418. #define SET_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR) = TRUE)
  419. #define SET_FREE_DATA(pRR) (FLAG_FreeData(pRR) = TRUE)
  420. #define SET_RR_MATCHED(pRR) (FLAG_Matched(pRR) = TRUE)
  421. #define CLEAR_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR) = FALSE)
  422. #define CLEAR_FREE_DATA(pRR) (FLAG_FreeData(pRR) = FALSE)
  423. #define CLEAR_RR_MATCHED(pRR) (FLAG_Matched(pRR) = FALSE)
  424. #define IS_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR))
  425. #define IS_FREE_DATA(pRR) (FLAG_FreeData(pRR))
  426. #define IS_RR_MATCHED(pRR) (FLAG_Matched(pRR))
  427. #define IS_ANSWER_RR(pRR) (FLAG_Section(pRR) == DNSREC_ANSWER)
  428. #define IS_AUTHORITY_RR(pRR) (FLAG_Section(pRR) == DNSREC_AUTHORITY)
  429. #define IS_ADDITIONAL_RR(pRR) (FLAG_Section(pRR) == DNSREC_ADDITIONAL)
  430. //
  431. // Converting RCODEs to\from DNS errors.
  432. //
  433. #define DNS_ERROR_FROM_RCODE(rcode) ((rcode)+DNS_ERROR_RESPONSE_CODES_BASE)
  434. #define DNS_RCODE_FROM_ERROR(err) ((err)-DNS_ERROR_RESPONSE_CODES_BASE)
  435. //
  436. // Record character sets
  437. //
  438. // Currently supports records in three character sets
  439. // - unicode
  440. // - ANSI
  441. // - UTF8
  442. //
  443. // Unicode and ANSI are supported through external DNSAPI interfaces.
  444. // UTF8 is not (at least offcially).
  445. //
  446. // However, internally unicode and UTF8 are used for caching, reading
  447. // to and writing from packet.
  448. //
  449. // All DNS_RECORD structs created by our code, are tagged with a
  450. // character set type in the flags CharSet field.
  451. //
  452. //
  453. // A couple of handy macros:
  454. //
  455. #define RECORD_CHARSET(pRR) \
  456. ( (DNS_CHARSET) (pRR)->Flags.S.CharSet )
  457. #define IS_UNICODE_RECORD(pRR) \
  458. ( (DNS_CHARSET) (pRR)->Flags.S.CharSet == DnsCharSetUnicode )
  459. //
  460. // Quick buffer size determination
  461. //
  462. // Strings are read from the wire into dotted UTF8 format.
  463. // Strings are in UTF8 in RPC buffers.
  464. //
  465. // Goal here is to quickly determine adequate buffer size,
  466. // slight overallocation is not critical.
  467. //
  468. // Currently supporting only UTF8 or Unicode, however, if later
  469. // support direct ANSI conversion that's ok too, as ANSI will
  470. // no (to my knowledge) use more space than UTF8.
  471. //
  472. #define STR_BUF_SIZE_GIVEN_UTF8_LEN( Utf8Length, CharSet ) \
  473. ( ((CharSet)==DnsCharSetUnicode) ? ((Utf8Length)+1)*2 : (Utf8Length)+1 )
  474. //
  475. // Default locale for string comparison and case mappings
  476. //
  477. // Sublang: US English (0x04) Lang: English (0x09)
  478. //
  479. #define DNS_DEFAULT_LOCALE (0x0409)
  480. //
  481. // IP4 array utilities (iparray.c)
  482. //
  483. // Note some of these require memory allocation, see note
  484. // on memory allocation below.
  485. //
  486. #define DNS_NET_ORDER_LOOPBACK (0x0100007f)
  487. // NT5-autonet is 169.254.x.y
  488. #define AUTONET_MASK (0x0000ffff)
  489. #define AUTONET_NET (0x0000fea9)
  490. #define DNS_IS_AUTONET_IP(ip) ( ((ip) & AUTONET_MASK) == AUTONET_NET )
  491. #define DNS_IPARRAY_CLEAN_ZERO (0x00000001)
  492. #define DNS_IPARRAY_CLEAN_LOOPBACK (0x00000002)
  493. #define DNS_IPARRAY_CLEAN_AUTONET (0x00000010)
  494. //
  495. // Simple IP address array routines
  496. //
  497. PIP4_ADDRESS
  498. Dns_CreateIpAddressArrayCopy(
  499. IN PIP4_ADDRESS aipAddress,
  500. IN DWORD cipAddress
  501. );
  502. BOOL
  503. Dns_ValidateIpAddressArray(
  504. IN PIP4_ADDRESS aipAddress,
  505. IN DWORD cipAddress,
  506. IN DWORD dwFlag
  507. );
  508. //
  509. // IP4_ARRAY datatype routines
  510. //
  511. PIP4_ARRAY
  512. Dns_CreateIpArray(
  513. IN DWORD cAddrCount
  514. );
  515. DWORD
  516. Dns_SizeofIpArray(
  517. IN PIP4_ARRAY pIpArray
  518. );
  519. PIP4_ARRAY
  520. Dns_BuildIpArray(
  521. IN DWORD cAddrCount,
  522. IN PIP4_ADDRESS pipAddrs
  523. );
  524. PIP4_ARRAY
  525. Dns_CopyAndExpandIpArray(
  526. IN PIP4_ARRAY pIpArray,
  527. IN DWORD ExpandCount,
  528. IN BOOL fDeleteExisting
  529. );
  530. PIP4_ARRAY
  531. Dns_CreateIpArrayCopy(
  532. IN PIP4_ARRAY pIpArray
  533. );
  534. BOOL
  535. Dns_IsAddressInIpArray(
  536. IN PIP4_ARRAY pIpArray,
  537. IN IP4_ADDRESS IpAddress
  538. );
  539. BOOL
  540. Dns_AddIpToIpArray(
  541. IN OUT PIP4_ARRAY pIpArray,
  542. IN IP4_ADDRESS IpNew
  543. );
  544. VOID
  545. Dns_ClearIpArray(
  546. IN OUT PIP4_ARRAY pIpArray
  547. );
  548. VOID
  549. Dns_ReverseOrderOfIpArray(
  550. IN OUT PIP4_ARRAY pIpArray
  551. );
  552. BOOL
  553. Dns_CheckAndMakeIpArraySubset(
  554. IN OUT PIP4_ARRAY pIpArraySub,
  555. IN PIP4_ARRAY pIpArraySuper
  556. );
  557. INT
  558. WINAPI
  559. Dns_ClearIpFromIpArray(
  560. IN OUT PIP4_ARRAY pIpArray,
  561. IN IP4_ADDRESS IpDelete
  562. );
  563. INT
  564. WINAPI
  565. Dns_DeleteIpFromIpArray(
  566. IN OUT PIP4_ARRAY pIpArray,
  567. IN IP4_ADDRESS IpDelete
  568. );
  569. #define Dns_RemoveZerosFromIpArray(pArray) \
  570. Dns_DeleteIpFromIpArray( (pArray), 0 )
  571. INT
  572. WINAPI
  573. Dns_CleanIpArray(
  574. IN OUT PIP4_ARRAY pIpArray,
  575. IN DWORD Flag
  576. );
  577. BOOL
  578. Dns_AreIpArraysEqual(
  579. IN PIP4_ARRAY pIpArray1,
  580. IN PIP4_ARRAY pIpArray2
  581. );
  582. BOOL
  583. Dns_AreIpArraysSimilar(
  584. IN PIP4_ARRAY pIpArray1,
  585. IN PIP4_ARRAY pIpArray2
  586. );
  587. DNS_STATUS
  588. WINAPI
  589. Dns_DiffOfIpArrays(
  590. IN PIP4_ARRAY pIpArray1,
  591. IN PIP4_ARRAY pIpArray2,
  592. OUT PIP4_ARRAY* ppOnlyIn1,
  593. OUT PIP4_ARRAY* ppOnlyIn2,
  594. OUT PIP4_ARRAY* ppIntersect
  595. );
  596. BOOL
  597. WINAPI
  598. Dns_IsIntersectionOfIpArrays(
  599. IN PIP4_ARRAY pIpArray1,
  600. IN PIP4_ARRAY pIpArray2
  601. );
  602. DNS_STATUS
  603. WINAPI
  604. Dns_UnionOfIpArrays(
  605. IN PIP4_ARRAY pIpArray1,
  606. IN PIP4_ARRAY pIpArray2,
  607. OUT PIP4_ARRAY* ppUnion
  608. );
  609. #define Dns_IntersectionOfIpArrays(p1, p2, ppInt) \
  610. Dns_DiffOfIpArrays( (p1), (p2), NULL, NULL, (ppInt) )
  611. DNS_STATUS
  612. Dns_CreateIpArrayFromMultiIpString(
  613. IN PSTR pchMultiIpString,
  614. OUT PIP4_ARRAY* ppIpArray
  615. );
  616. PSTR
  617. Dns_CreateMultiIpStringFromIpArray(
  618. IN PIP4_ARRAY pIpArray,
  619. IN CHAR chSeparator OPTIONAL
  620. );
  621. //
  622. // Type list array routines
  623. //
  624. DNS_STATUS
  625. Dns_CreateTypeArrayFromMultiTypeString(
  626. IN PSTR pchMultiTypeString,
  627. OUT INT * piTypeCount,
  628. OUT PWORD * ppwTypeArray
  629. );
  630. PSTR
  631. Dns_CreateMultiTypeStringFromTypeArray(
  632. IN INT iTypeCount,
  633. IN PWORD ppwTypeArray,
  634. IN CHAR chSeparator OPTIONAL
  635. );
  636. //
  637. // IP6 stuff
  638. //
  639. #ifndef DEFINED_IP6_ARRAY
  640. typedef struct _Ip6Array
  641. {
  642. DWORD MaxCount;
  643. DWORD AddrCount;
  644. #ifdef MIDL_PASS
  645. [size_is(MaxCount)] IP6_ADDRESS AddrArray[];
  646. #else
  647. IP6_ADDRESS AddrArray[1];
  648. #endif
  649. }
  650. IP6_ARRAY, *PIP6_ARRAY;
  651. #define DEFINED_IP6_ARRAY 1
  652. #endif
  653. //
  654. // General utilities
  655. //
  656. //
  657. // Wrap free, multi-thread safe seconds timer (timer.c)
  658. //
  659. VOID
  660. Dns_InitializeSecondsTimer(
  661. VOID
  662. );
  663. DWORD
  664. Dns_GetCurrentTimeInSeconds(
  665. VOID
  666. );
  667. //
  668. // Tokenizer
  669. //
  670. DWORD
  671. Dns_TokenizeStringA(
  672. IN OUT PSTR pBuffer,
  673. OUT PCHAR * Argv,
  674. IN DWORD MaxArgs
  675. );
  676. DWORD
  677. Dns_TokenizeStringW(
  678. IN OUT PWSTR pBuffer,
  679. OUT PWCHAR * Argv,
  680. IN DWORD MaxArgs
  681. );
  682. //
  683. // IP interfaces on local machine (iplist.c)
  684. //
  685. #define DNS_MAX_NAME_SERVERS (50)
  686. #define DNS_MAX_IP_INTERFACE_COUNT (10000)
  687. PIP4_ARRAY
  688. Dns_GetLocalIpAddressArray(
  689. VOID
  690. );
  691. //
  692. // NetInfo structures
  693. //
  694. // WARNING: Do NOT use these!
  695. //
  696. // These are internal dnsapi.dll structures. They are only
  697. // included here for backward compatibility with previous
  698. // code (netdiag) which incorrectly used these.
  699. //
  700. // If you code with them you will inevitably wake up broken
  701. // down the road.
  702. //
  703. #if 0
  704. #ifndef MIDL_PASS
  705. typedef struct
  706. {
  707. DNS_STATUS Status;
  708. DWORD Priority;
  709. // Address is now DNS_ADDR
  710. // Preserve IP4 field by putting it in correct place
  711. union
  712. {
  713. struct
  714. {
  715. DWORD Pad0;
  716. IP4_ADDRESS IpAddress;
  717. };
  718. DNS_ADDR Address;
  719. };
  720. }
  721. DNSLIB_SERVER_INFO, *PDNSLIB_SERVER_INFO;
  722. typedef struct
  723. {
  724. PWSTR pszAdapterGuidName;
  725. PWSTR pwsAdapterDomain;
  726. PWSTR pszAdapterDomain;
  727. PVOID pLocalAddrs;
  728. PVOID pServerArray;
  729. DWORD InterfaceIndex;
  730. DWORD InterfaceIndex6;
  731. DWORD InfoFlags;
  732. DWORD Status;
  733. DWORD ReturnFlags;
  734. DWORD ServerIndex;
  735. DWORD cServerCount;
  736. DWORD cTotalListSize;
  737. //DNSLIB_SERVER_INFO ServerArray[1];
  738. }
  739. DNSLIB_ADAPTER, *PDNSLIB_ADAPTER;
  740. #define DNS_MAX_SEARCH_LIST_ENTRIES (50)
  741. typedef struct
  742. {
  743. PWSTR pszName;
  744. DWORD Flags;
  745. }
  746. DNSLIB_SEARCH_NAME, *PDNSLIB_SEARCH_NAME;
  747. typedef struct
  748. {
  749. PWSTR pszDomainOrZoneName;
  750. DWORD cNameCount; // Zero for FAZ result
  751. DWORD cTotalListSize; // Zero for FAZ result
  752. DWORD CurrentName; // 0 for pszDomainOrZoneName
  753. // 1 for first name in array below
  754. // 2 for second name in array below
  755. // ...
  756. DNSLIB_SEARCH_NAME SearchNameArray[1];
  757. }
  758. DNSLIB_SEARCH_LIST, *PDNSLIB_SEARCH_LIST;
  759. typedef struct
  760. {
  761. PWSTR pwsDomainName;
  762. PWSTR pszDomainName;
  763. PWSTR pszHostName;
  764. PDNSLIB_SEARCH_LIST pSearchList;
  765. DWORD TimeStamp;
  766. DWORD InfoFlags;
  767. DWORD Tag;
  768. DWORD ReturnFlags;
  769. DWORD cAdapterCount;
  770. DWORD cTotalListSize;
  771. DNSLIB_ADAPTER AdapterArray[1];
  772. }
  773. DNSLIB_NETINFO, *PDNSLIB_NETINFO;
  774. //
  775. // Do NOT use these defs internally
  776. //
  777. #ifdef USE_DNSLIB_NETINFO
  778. typedef DNSLIB_SERVER_INFO DNS_SERVER_INFO, *PDNS_SERVER_INFO;
  779. typedef DNSLIB_ADAPTER DNS_ADAPTER, *PDNS_ADAPTER;
  780. typedef DNSLIB_SEARCH_NAME SEARCH_NAME, *PSEARCH_NAME;
  781. typedef DNSLIB_SEARCH_LIST SEARCH_LIST, *PSEARCH_LIST;
  782. typedef DNSLIB_NETINFO DNS_NETINFO, *PDNS_NETINFO;
  783. #endif // not USE_DNSLIB_NETINFO
  784. #endif // not MIDL_PASS
  785. #endif // ifdef'd out
  786. //
  787. // General DNS utilities (dnsutil.c)
  788. //
  789. IP4_ADDRESS
  790. Dns_GetNetworkMask(
  791. IN IP4_ADDRESS IpAddress
  792. );
  793. PSTR
  794. _fastcall
  795. Dns_StatusString(
  796. IN DNS_STATUS Status
  797. );
  798. #define Dns_StatusToErrorString_A(status) Dns_StatusString(status)
  799. DNS_STATUS
  800. _fastcall
  801. Dns_MapRcodeToStatus(
  802. IN BYTE ResponseCode
  803. );
  804. BYTE
  805. _fastcall
  806. Dns_IsStatusRcode(
  807. IN DNS_STATUS Status
  808. );
  809. //
  810. // Name utilities (name.c)
  811. //
  812. PSTR
  813. _fastcall
  814. Dns_GetDomainName(
  815. IN PCSTR pszName
  816. );
  817. PWSTR
  818. _fastcall
  819. Dns_GetDomainName_W(
  820. IN PCWSTR pwsName
  821. );
  822. PCHAR
  823. _fastcall
  824. Dns_GetTldForName(
  825. IN PCSTR pszName
  826. );
  827. BOOL
  828. _fastcall
  829. Dns_IsNameShort(
  830. IN PCSTR pszName
  831. );
  832. BOOL
  833. _fastcall
  834. Dns_IsNameFQDN(
  835. IN PCSTR pszName
  836. );
  837. DNS_STATUS
  838. Dns_ValidateAndCategorizeDnsNameEx(
  839. IN PCHAR pchName,
  840. IN DWORD cchNameLength,
  841. OUT PDWORD pLabelCount
  842. );
  843. #define Dns_ValidateAndCategorizeDnsName(p,c) \
  844. Dns_ValidateAndCategorizeDnsNameEx((p),(c),NULL)
  845. DWORD
  846. Dns_NameLabelCount(
  847. IN PCSTR pszName
  848. );
  849. #define DNS_NAME_UNKNOWN 0x00000000
  850. #define DNS_NAME_IS_FQDN 0x00000001
  851. #define DNS_NAME_SINGLE_LABEL 0x00000010
  852. #define DNS_NAME_MULTI_LABEL 0x00000100
  853. DWORD
  854. _fastcall
  855. Dns_GetNameAttributes(
  856. IN PCSTR pszName
  857. );
  858. //
  859. // Packet create\read\write (packet.c)
  860. //
  861. //
  862. // UDP packet buffer
  863. //
  864. // 1472 is the maximum ethernet IP\UDP payload size
  865. // without causing fragmentation, use as default buffer
  866. //
  867. #define DNS_MAX_UDP_PACKET_BUFFER_LENGTH (1472)
  868. // parsing RR
  869. // convenient to get WIRE records into aligned\host order format
  870. typedef struct _DNS_PARSED_RR
  871. {
  872. PCHAR pchName;
  873. PCHAR pchRR;
  874. PCHAR pchData;
  875. PCHAR pchNextRR;
  876. // note from here on down mimics wire record
  877. WORD Type;
  878. WORD Class;
  879. DWORD Ttl;
  880. WORD DataLength;
  881. }
  882. DNS_PARSED_RR, *PDNS_PARSED_RR;
  883. //
  884. // DNS Server Message Info structure
  885. //
  886. // This is structure in which requests are held while being
  887. // processed by the DNS server.
  888. //
  889. typedef struct _DnsMessageBuf
  890. {
  891. LIST_ENTRY ListEntry; // for queuing
  892. //
  893. // Addressing
  894. //
  895. SOCKET Socket4;
  896. SOCKET Socket6;
  897. //16/32
  898. DNS_ADDR RemoteAddress;
  899. //32/48
  900. SOCKET Socket;
  901. //
  902. // Basic packet info
  903. //
  904. DWORD BufferLength; // total length of buffer
  905. PCHAR pBufferEnd; // ptr to byte after buffer
  906. PBYTE pCurrent; // current location in buffer
  907. PWORD pCurrentCountField; // current count field being written
  908. //
  909. // Current lookup info
  910. //
  911. DWORD Timeout; // recv timeout
  912. DWORD QueryTime; // time of original query
  913. WORD wTypeCurrent; // type of query being done
  914. WORD wOffsetCurrent;
  915. //
  916. // Queuing
  917. //
  918. WORD wQueuingXid; // match XID to response
  919. DWORD QueuingTime; // time queued
  920. DWORD ExpireTime; // queue timeout
  921. //
  922. // Basic packet flags
  923. //
  924. BOOLEAN fTcp;
  925. BOOLEAN fSwapped; // header in net order
  926. BOOLEAN fMessageComplete; // complete message received
  927. BOOLEAN fConvertUnicode; // convert to unicode
  928. BOOLEAN fSocketKeepalive; // keep socket alive
  929. BOOLEAN fLastSendOpt; // last send contained OPT
  930. //
  931. // TCP message reception
  932. //
  933. PCHAR pchRecv; // ptr to next pos in message
  934. //
  935. // End of message before OPT addition
  936. //
  937. PCHAR pPreOptEnd;
  938. //
  939. // WARNING !
  940. //
  941. // Message length MUST
  942. // - be a WORD type
  943. // - immediately preceed message itself
  944. // for proper send/recv of TCP messages.
  945. //
  946. // Use pointers above to DWORD (or QWORD) align, then recv bytes to push
  947. // message length against MessageHead. Note, that DNS_HEADER contains
  948. // only WORDs as it's largest element and so should chummy up even on
  949. // WORD boundary. DWORD boundary should be very safe.
  950. //
  951. WORD BytesToReceive;
  952. WORD MessageLength;
  953. //
  954. // DNS Message itself
  955. //
  956. DNS_HEADER MessageHead;
  957. //
  958. // Question and RR section
  959. //
  960. // This simply provides some coding simplicity in accessing
  961. // this section given MESSAGE_INFO structure.
  962. //
  963. CHAR MessageBody[1];
  964. }
  965. DNS_MSG_BUF, *PDNS_MSG_BUF;
  966. #define SIZEOF_MSG_BUF_OVERHEAD (sizeof(DNS_MSG_BUF) - sizeof(DNS_HEADER) - 1)
  967. #define DNS_MESSAGE_END(pMsg) \
  968. ((PCHAR)&(pMsg)->MessageHead + (pMsg)->MessageLength)
  969. #define DNS_MESSAGE_OFFSET( pMsg, p ) \
  970. ((PCHAR)(p) - (PCHAR)(&(pMsg)->MessageHead))
  971. #define DNS_MESSAGE_CURRENT_OFFSET( pMsg ) \
  972. DNS_MESSAGE_OFFSET( (pMsg), (pMsg)->pCurrent )
  973. // Sockaddr combined length
  974. #define DNS_MESSAGE_REMOTE_ADDRESS_AND_LENGTH_
  975. //
  976. // Handy for packet setup
  977. //
  978. #define CLEAR_DNS_HEADER_FLAGS_AND_XID( pHead ) ( *(PDWORD)(pHead) = 0 )
  979. PDNS_MSG_BUF
  980. Dns_AllocateMsgBuf(
  981. IN WORD wBufferLength OPTIONAL
  982. );
  983. VOID
  984. Dns_InitializeMsgBuf(
  985. IN OUT PDNS_MSG_BUF pMsg
  986. );
  987. PDNS_MSG_BUF
  988. Dns_BuildPacket(
  989. IN PDNS_HEADER pHeader,
  990. IN BOOL fNoHeaderCounts,
  991. IN PDNS_NAME pszQuestionName,
  992. IN WORD wQuestionType,
  993. IN PDNS_RECORD pRecord,
  994. IN DWORD dwFlags,
  995. IN BOOL fUpdatePacket
  996. );
  997. PCHAR
  998. _fastcall
  999. Dns_WriteDottedNameToPacket(
  1000. IN OUT PCHAR pch,
  1001. IN PCHAR pchStop,
  1002. IN PSTR pszName,
  1003. IN PSTR pszDomain, OPTIONAL
  1004. IN WORD wDomainOffset, OPTIONAL
  1005. IN BOOL fUnicodeName
  1006. );
  1007. PCHAR
  1008. _fastcall
  1009. Dns_WriteStringToPacket(
  1010. IN OUT PCHAR pch,
  1011. IN PCHAR pchStop,
  1012. IN PSTR pszString,
  1013. IN BOOL fUnicodeString
  1014. );
  1015. PCHAR
  1016. Dns_WriteQuestionToMessage(
  1017. IN OUT PDNS_MSG_BUF pMsg,
  1018. IN PDNS_NAME pszName,
  1019. IN WORD wType,
  1020. IN BOOL fUnicodeName
  1021. );
  1022. DNS_STATUS
  1023. Dns_WriteRecordStructureToMessage(
  1024. IN OUT PDNS_MSG_BUF pMsg,
  1025. IN WORD wType,
  1026. IN WORD wClass,
  1027. IN DWORD dwTtl,
  1028. IN WORD wDataLength
  1029. );
  1030. PCHAR
  1031. Dns_WriteRecordStructureToPacketEx(
  1032. IN OUT PCHAR pchBuf,
  1033. IN WORD wType,
  1034. IN WORD wClass,
  1035. IN DWORD dwTtl,
  1036. IN WORD wDataLength
  1037. );
  1038. DNS_STATUS
  1039. Dns_WriteRecordStructureToPacket(
  1040. IN OUT PCHAR pchBuf,
  1041. IN PDNS_RECORD pRecord,
  1042. IN BOOL fUpdatePacket
  1043. );
  1044. VOID
  1045. Dns_SetRecordDatalength(
  1046. IN OUT PDNS_WIRE_RECORD pRecord,
  1047. IN WORD wDataLength
  1048. );
  1049. DNS_STATUS
  1050. Dns_AddRecordsToMessage(
  1051. IN OUT PDNS_MSG_BUF pMsg,
  1052. IN PDNS_RECORD pRecord,
  1053. IN BOOL fUpdateMessage
  1054. );
  1055. PCHAR
  1056. _fastcall
  1057. Dns_SkipPacketName(
  1058. IN PCHAR pch,
  1059. IN PCHAR pchEnd
  1060. );
  1061. BOOL
  1062. Dns_IsSamePacketQuestion(
  1063. IN PDNS_MSG_BUF pMsg1,
  1064. IN PDNS_MSG_BUF pMsg2
  1065. );
  1066. PCHAR
  1067. _fastcall
  1068. Dns_SkipPacketRecord(
  1069. IN PCHAR pchRecord,
  1070. IN PCHAR pchMsgEnd
  1071. );
  1072. PCHAR
  1073. Dns_SkipToRecord(
  1074. IN PDNS_HEADER pMsgHead,
  1075. IN PCHAR pMsgEnd,
  1076. IN INT iCount
  1077. );
  1078. PCHAR
  1079. Dns_ReadRecordStructureFromPacket(
  1080. IN PCHAR pchPacket,
  1081. IN PCHAR pchMsgEnd,
  1082. IN OUT PDNS_PARSED_RR pParsedRR
  1083. );
  1084. DNS_STATUS
  1085. Dns_ExtractRecordsFromMessage(
  1086. IN PDNS_MSG_BUF pMsg,
  1087. IN BOOL fUnicode,
  1088. OUT PDNS_RECORD * ppRecord
  1089. );
  1090. DNS_STATUS
  1091. Dns_ExtractRecordsFromBuffer(
  1092. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  1093. IN WORD wMessageLength,
  1094. IN BOOL fUnicode,
  1095. OUT PDNS_RECORD * ppRecord
  1096. );
  1097. void
  1098. Dns_NormalizeAllRecordTtls(
  1099. IN PDNS_RECORD pRecord
  1100. );
  1101. PCHAR
  1102. _fastcall
  1103. Dns_ReadPacketName(
  1104. IN OUT PCHAR pchNameBuffer,
  1105. OUT PWORD pwNameLength,
  1106. IN OUT PWORD pwNameOffset, OPTIONAL
  1107. OUT PBOOL pfNameSameAsPrevious, OPTIONAL
  1108. IN PCHAR pchName,
  1109. IN PCHAR pchStart,
  1110. IN PCHAR pchEnd
  1111. );
  1112. PCHAR
  1113. _fastcall
  1114. Dns_ReadPacketNameAllocate(
  1115. IN OUT PCHAR * ppchName,
  1116. OUT PWORD pwNameLength,
  1117. IN OUT PWORD pwPrevNameOffset, OPTIONAL
  1118. OUT PBOOL pfNameSameAsPrevious, OPTIONAL
  1119. IN PCHAR pchPacketName,
  1120. IN PCHAR pchStart,
  1121. IN PCHAR pchEnd
  1122. );
  1123. WORD
  1124. Dns_GetRandomXid(
  1125. IN PVOID pSeed
  1126. );
  1127. //
  1128. // Socket setup (socket.c)
  1129. //
  1130. //
  1131. // these two routines really don't belong here -- system stuff should be elsewhere
  1132. //
  1133. DNS_STATUS
  1134. Dns_InitializeWinsock(
  1135. VOID
  1136. );
  1137. VOID
  1138. Dns_CleanupWinsock(
  1139. VOID
  1140. );
  1141. SOCKET
  1142. Dns_CreateSocket(
  1143. IN INT SockType,
  1144. IN IP4_ADDRESS ipAddress,
  1145. IN USHORT Port
  1146. );
  1147. VOID
  1148. Dns_CloseSocket(
  1149. IN SOCKET Socket
  1150. );
  1151. VOID
  1152. Dns_CloseConnection(
  1153. IN SOCKET Socket
  1154. );
  1155. DNS_STATUS
  1156. Dns_SetupGlobalAsyncSocket(
  1157. VOID
  1158. );
  1159. //
  1160. // Query (query.c)
  1161. //
  1162. //
  1163. // Flags to DnsQuery
  1164. //
  1165. // These are in addition to public flags in dnsapi.h
  1166. // They must all be in the reserved section defined by
  1167. // DNS_QUERY_RESERVED
  1168. //
  1169. // Unicode i\o
  1170. #define DNSQUERY_UNICODE_NAME (0x01000000)
  1171. #define DNSQUERY_UNICODE_OUT (0x02000000)
  1172. #define DNSQUERY_NO_SERVER_RECORDS (0x04000000)
  1173. #define DNSQUERY_NULL_LOCAL (0x04000000)
  1174. // DNS server query
  1175. #define DNS_SERVER_QUERY_NAME (L"..DnsServers")
  1176. //
  1177. // Screen DNSAPI_INTERNAL use for everything with NETINFO
  1178. // these must be defined (where used) internally using good def.
  1179. //
  1180. #ifdef DNSLIB_NETINFO
  1181. //
  1182. // Raw packet send and recv (send.c)
  1183. //
  1184. DNS_STATUS
  1185. Dns_SendAndRecvUdp(
  1186. IN OUT PDNS_MSG_BUF pMsgSend,
  1187. OUT PDNS_MSG_BUF pMsgRecv,
  1188. IN DWORD dwFlags,
  1189. IN PIP4_ARRAY aipServers,
  1190. IN OUT PDNS_NETINFO pAdapterInfo
  1191. );
  1192. DNS_STATUS
  1193. Dns_SendAndRecvTcp(
  1194. IN OUT PDNS_MSG_BUF pMsgSend,
  1195. OUT PDNS_MSG_BUF pMsgRecv,
  1196. IN PIP4_ARRAY aipServers,
  1197. IN OUT PDNS_NETINFO pAdapterInfo
  1198. );
  1199. DNS_STATUS
  1200. Dns_SendAndRecv(
  1201. IN OUT PDNS_MSG_BUF pMsgSend,
  1202. OUT PDNS_MSG_BUF * ppMsgRecv,
  1203. OUT PDNS_RECORD * ppResponseRecords,
  1204. IN DWORD dwFlags,
  1205. IN PIP4_ARRAY aipServers,
  1206. IN OUT PDNS_NETINFO pAdapterInfo
  1207. );
  1208. //
  1209. // End non-internal only DNS_NETINFO with external def
  1210. //
  1211. #endif // not DNSLIB_NETINFO
  1212. DNS_STATUS
  1213. Dns_SendEx(
  1214. IN OUT PDNS_MSG_BUF pMsg,
  1215. IN IP4_ADDRESS SendIp, OPTIONAL
  1216. IN BOOL fNoOpt
  1217. );
  1218. #define Dns_Send( pMsg ) Dns_SendEx( (pMsg), 0, 0 )
  1219. DNS_STATUS
  1220. Dns_Recv(
  1221. IN OUT PDNS_MSG_BUF pMsg
  1222. );
  1223. DNS_STATUS
  1224. Dns_RecvUdp(
  1225. IN OUT PDNS_MSG_BUF pMsg
  1226. );
  1227. DNS_STATUS
  1228. Dns_OpenTcpConnectionAndSend(
  1229. IN OUT PDNS_MSG_BUF pMsg,
  1230. IN IP4_ADDRESS ipServer,
  1231. IN BOOL fBlocking
  1232. );
  1233. DNS_STATUS
  1234. Dns_RecvTcp(
  1235. IN OUT PDNS_MSG_BUF pMsg
  1236. );
  1237. VOID
  1238. Dns_InitializeMsgRemoteSockaddr(
  1239. IN OUT PDNS_MSG_BUF pMsg,
  1240. IN IP4_ADDRESS IpAddress
  1241. );
  1242. VOID
  1243. Dns_InitQueryTimeouts(
  1244. VOID
  1245. );
  1246. //
  1247. // Dynamic update (update.c)
  1248. //
  1249. PCHAR
  1250. Dns_WriteNoDataUpdateRecordToMessage(
  1251. IN PCHAR pch,
  1252. IN PCHAR pchStop,
  1253. IN WORD wClass,
  1254. IN WORD wType
  1255. );
  1256. PCHAR
  1257. Dns_WriteDataUpdateRecordToMessage(
  1258. IN PCHAR pch,
  1259. IN PCHAR pchStop,
  1260. IN WORD wClass,
  1261. IN WORD wType,
  1262. IN DWORD dwTtl,
  1263. IN WORD wDataLength
  1264. );
  1265. PDNS_MSG_BUF
  1266. Dns_BuildHostUpdateMessage(
  1267. IN OUT PDNS_MSG_BUF pMsg,
  1268. IN PSTR pszZone,
  1269. IN PSTR pszName,
  1270. IN PIP4_ARRAY aipAddresses,
  1271. IN DWORD dwTtl
  1272. );
  1273. PDNS_RECORD
  1274. Dns_HostUpdateRRSet(
  1275. IN PSTR pszHostName,
  1276. IN PIP4_ARRAY aipAddrs,
  1277. IN DWORD dwTtl
  1278. );
  1279. DNS_STATUS
  1280. Dns_UpdateHostAddrs(
  1281. IN PSTR pszName,
  1282. IN PIP4_ARRAY aipAddresses,
  1283. IN PIP4_ARRAY aipServers,
  1284. IN DWORD dwTtl
  1285. );
  1286. DNS_STATUS
  1287. Dns_UpdateHostAddrsOld(
  1288. IN PSTR pszName,
  1289. IN PIP4_ARRAY aipAddresses,
  1290. IN PIP4_ARRAY aipServers,
  1291. IN DWORD dwTtl
  1292. );
  1293. DNS_STATUS
  1294. Dns_UpdateLibEx(
  1295. IN PDNS_RECORD pRecord,
  1296. IN DWORD dwFlags,
  1297. IN PDNS_NAME pszZone,
  1298. IN PDNS_NAME pszServerName,
  1299. IN PIP4_ARRAY aipServers,
  1300. IN HANDLE hCreds, OPTIONAL
  1301. OUT PDNS_MSG_BUF * ppMsgRecv OPTIONAL
  1302. );
  1303. //
  1304. // RenDom stuff
  1305. //
  1306. // Record verification table
  1307. //
  1308. typedef struct _DnsVerifyTable
  1309. {
  1310. DWORD RecordCount;
  1311. PDNS_RECORD pRecordList;
  1312. PIP6_ARRAY pServerArray;
  1313. PBOOL pVerifyArray;
  1314. }
  1315. DNS_VERIFY_TABLE, *PDNS_VERIFY_TABLE;
  1316. DNS_STATUS
  1317. Dns_VerifyRecords(
  1318. IN OUT PDNS_VERIFY_TABLE pTable
  1319. );
  1320. //
  1321. // Record verification table for rendom
  1322. //
  1323. // Implementation note:
  1324. // Using pointers here for server\bool arrays here instead
  1325. // of open array of server count. The reason is to allow dynamic
  1326. // allocation of the lists by the API if it FAZes to find to
  1327. // zone\servers to target.
  1328. // The server IPs and bools could be combined in another
  1329. // structure, but that doesn't seem to add much and makes
  1330. // use of the existing IP array stuff more difficult.
  1331. //
  1332. typedef struct _DnsRendomEntry
  1333. {
  1334. PSTR pDcName;
  1335. // could have this in unicode
  1336. //PWSTR pDcName;
  1337. PDNS_RECORD pRecord;
  1338. PIP6_ARRAY pServerArray;
  1339. PBOOL pVerifyArray;
  1340. }
  1341. DNS_RENDOM_ENTRY, *PDNS_RENDOM_ENTRY;
  1342. #define DNS_RENDOM_VERIFY_WITH_FAZ (0x00000001)
  1343. #define DNS_RENDOM_VERIFY_WITH_LIST (0x00000002)
  1344. typedef struct _DnsZoneServerList
  1345. {
  1346. PSTR pZoneName;
  1347. // could have this in unicode
  1348. //PWSTR pZoneName;
  1349. PIP6_ARRAY pServerArray;
  1350. }
  1351. DNS_ZONE_SERVER_LIST, *PDNS_ZONE_SERVER_LIST;
  1352. DNS_STATUS
  1353. Dns_VerifyRendomDcRecords(
  1354. IN OUT PDNS_RENDOM_ENTRY pTable,
  1355. IN PDNS_ZONE_SERVER_LIST pZoneServList, OPTIONAL
  1356. IN DWORD Flag
  1357. );
  1358. //
  1359. // List build
  1360. //
  1361. // pFirst points to first element in list.
  1362. // pLast points to last element in list.
  1363. //
  1364. // This builds a list for element types which have a pNext field
  1365. // as their first structure member.
  1366. //
  1367. typedef struct _Dns_List
  1368. {
  1369. PVOID pFirst;
  1370. PVOID pLast;
  1371. }
  1372. DNS_LIST, *PDNS_LIST;
  1373. //
  1374. // To init pFirst is NULL.
  1375. // But pLast points at the location of the pFirst pointer -- essentially
  1376. // treating the DNS_LIST as an element and pFirst as its next ptr.
  1377. //
  1378. // During an add, the address given in pLast, is set with the new element,
  1379. // equivalent to setting pLast's pNext field. Then pLast is reset to point
  1380. // at a new element.
  1381. //
  1382. // When the first element is added to the list, pLast is pointing at the
  1383. // DNS_LIST structure itself, so pFirst (as a dummy pNext) is set with
  1384. // the ptr to the first element.
  1385. //
  1386. // This works ONLY for elements which have a pNext field as the first
  1387. // structure member.
  1388. //
  1389. #define DNS_LIST_INIT( pList ) \
  1390. { \
  1391. PDNS_LIST _plist = (pList); \
  1392. _plist->pFirst = NULL; \
  1393. _plist->pLast = (_plist); \
  1394. }
  1395. #define DNS_LIST_ADD( pList, pnew ) \
  1396. { \
  1397. PDNS_LIST _plist = (pList); \
  1398. PVOID _pnew = (pnew); \
  1399. *(PVOID*)(_plist->pLast) = _pnew; \
  1400. _plist->pLast = _pnew; \
  1401. }
  1402. #define IS_DNS_LIST_EMPTY( pList ) \
  1403. ( (pList)->pFirst == NULL )
  1404. //
  1405. // DNS_LIST as structure macros
  1406. //
  1407. // Faster when function contains DNS_LIST structure itself and
  1408. // NO SIDE EFFECTS will be present in call.
  1409. //
  1410. #define DNS_LIST_STRUCT_INIT( List ) \
  1411. { \
  1412. List.pFirst = NULL; \
  1413. List.pLast = &List; \
  1414. }
  1415. #define DNS_LIST_STRUCT_ADD( List, pnew ) \
  1416. { \
  1417. *(PVOID*)(List.pLast) = (PVOID)pnew; \
  1418. List.pLast = (PVOID)pnew; \
  1419. }
  1420. #define IS_DNS_LIST_STRUCT_EMPTY( List ) \
  1421. ( List.pFirst == NULL )
  1422. //
  1423. // Record building (rralloc.c)
  1424. //
  1425. PDNS_RECORD
  1426. WINAPI
  1427. Dns_AllocateRecord(
  1428. IN WORD wBufferLength
  1429. );
  1430. VOID
  1431. WINAPI
  1432. Dns_RecordFree(
  1433. IN OUT PDNS_RECORD pRecord
  1434. );
  1435. #if 1
  1436. // Old BS with flag -- kill when all fixed up
  1437. VOID
  1438. WINAPI
  1439. Dns_RecordListFreeEx(
  1440. IN OUT PDNS_RECORD pRRList,
  1441. IN BOOL fFreeOwner
  1442. );
  1443. #define Dns_RecordListFree(p, f) Dns_RecordListFreeEx(p, f)
  1444. #else // new version
  1445. VOID
  1446. WINAPI
  1447. Dns_RecordListFree(
  1448. IN OUT PDNS_RECORD pRRList
  1449. );
  1450. #endif
  1451. PDNS_RECORD
  1452. Dns_RecordSetDetach(
  1453. IN OUT PDNS_RECORD pRRList
  1454. );
  1455. PDNS_RECORD
  1456. WINAPI
  1457. Dns_RecordListAppend(
  1458. IN OUT PDNS_RECORD pHeadList,
  1459. IN PDNS_RECORD pTailList
  1460. );
  1461. DWORD
  1462. Dns_RecordListCount(
  1463. IN PDNS_RECORD pRRList,
  1464. IN WORD wType
  1465. );
  1466. //
  1467. // Record build from data strings (rrbuild.c)
  1468. //
  1469. PDNS_RECORD
  1470. Dns_RecordBuild_A(
  1471. IN OUT PDNS_RRSET pRRSet,
  1472. IN PSTR pszOwner,
  1473. IN WORD wType,
  1474. IN BOOL fAdd,
  1475. IN UCHAR Section,
  1476. IN INT Argc,
  1477. IN PCHAR * Argv
  1478. );
  1479. PDNS_RECORD
  1480. Dns_RecordBuild_W(
  1481. IN OUT PDNS_RRSET pRRSet,
  1482. IN PWSTR pszOwner,
  1483. IN WORD wType,
  1484. IN BOOL fAdd,
  1485. IN UCHAR Section,
  1486. IN INT Argc,
  1487. IN PWCHAR * Argv
  1488. );
  1489. //
  1490. // Record to\from string functions.
  1491. //
  1492. DNS_STATUS
  1493. Dns_WriteRecordToString(
  1494. OUT PCHAR pBuffer,
  1495. IN DWORD BufferLength,
  1496. IN PDNS_RECORD pRecord,
  1497. IN DNS_CHARSET CharSet,
  1498. IN DWORD Flags
  1499. );
  1500. PDNS_RECORD
  1501. Dns_CreateRecordFromString(
  1502. IN PSTR pString,
  1503. IN DNS_CHARSET CharSet,
  1504. IN DWORD Flags
  1505. );
  1506. //
  1507. // Record set manipulation
  1508. //
  1509. //
  1510. // Record Compare
  1511. //
  1512. // Note: these routines will NOT do proper unicode compare, unless
  1513. // records have the fUnicode flag set.
  1514. //
  1515. BOOL
  1516. WINAPI
  1517. Dns_RecordCompare(
  1518. IN PDNS_RECORD pRecord1,
  1519. IN PDNS_RECORD pRecord2
  1520. );
  1521. BOOL
  1522. WINAPI
  1523. Dns_RecordSetCompare(
  1524. IN OUT PDNS_RECORD pRR1,
  1525. IN OUT PDNS_RECORD pRR2,
  1526. OUT PDNS_RECORD * ppDiff1, OPTIONAL
  1527. OUT PDNS_RECORD * ppDiff2 OPTIONAL
  1528. );
  1529. typedef enum _DnsSetCompareResult
  1530. {
  1531. DnsSetCompareError = (-1),
  1532. DnsSetCompareIdentical,
  1533. DnsSetCompareNoOverlap,
  1534. DnsSetCompareOneSubsetOfTwo,
  1535. DnsSetCompareTwoSubsetOfOne,
  1536. DnsSetCompareIntersection
  1537. }
  1538. DNS_SET_COMPARE_RESULT;
  1539. DNS_SET_COMPARE_RESULT
  1540. WINAPI
  1541. Dns_RecordSetCompareEx(
  1542. IN OUT PDNS_RECORD pRR1,
  1543. IN OUT PDNS_RECORD pRR2,
  1544. OUT PDNS_RECORD * ppDiff1, OPTIONAL
  1545. OUT PDNS_RECORD * ppDiff2 OPTIONAL
  1546. );
  1547. BOOL
  1548. WINAPI
  1549. Dns_RecordSetCompareForIntersection(
  1550. IN OUT PDNS_RECORD pRR1,
  1551. IN OUT PDNS_RECORD pRR2
  1552. );
  1553. //
  1554. // Record set prioritization (rrsort.c)
  1555. //
  1556. BOOL
  1557. Dns_CompareIpAddresses(
  1558. IN IP4_ADDRESS addr1,
  1559. IN IP4_ADDRESS addr2,
  1560. IN IP4_ADDRESS subnetMask
  1561. );
  1562. //
  1563. // DNS Name compare
  1564. //
  1565. BOOL
  1566. Dns_NameCompare_A(
  1567. IN PCSTR pName1,
  1568. IN PCSTR pName2
  1569. );
  1570. BOOL
  1571. Dns_NameCompare_W(
  1572. IN PCWSTR pName1,
  1573. IN PCWSTR pName2
  1574. );
  1575. BOOL
  1576. Dns_NameCompare_UTF8(
  1577. IN PCSTR pName1,
  1578. IN PCSTR pName2
  1579. );
  1580. BOOL
  1581. Dns_NameComparePrivate(
  1582. IN PCSTR pName1,
  1583. IN PCSTR pName2,
  1584. IN DNS_CHARSET CharSet
  1585. );
  1586. //
  1587. // Advanced name comparison
  1588. // Includes hierarchial name relationship.
  1589. //
  1590. DNS_NAME_COMPARE_STATUS
  1591. Dns_NameCompareEx(
  1592. IN LPCSTR pszNameLeft,
  1593. IN LPCSTR pszNameRight,
  1594. IN DWORD dwReserved,
  1595. IN DNS_CHARSET CharSet
  1596. );
  1597. //
  1598. // Record Copy
  1599. //
  1600. PDNS_RECORD
  1601. WINAPI
  1602. Dns_RecordCopyEx(
  1603. IN PDNS_RECORD pRecord,
  1604. IN DNS_CHARSET CharSetIn,
  1605. IN DNS_CHARSET CharSetOut
  1606. );
  1607. //
  1608. // RR Set copy
  1609. //
  1610. PDNS_RECORD
  1611. WINAPI
  1612. Dns_RecordSetCopyEx(
  1613. IN PDNS_RECORD pRR,
  1614. IN DNS_CHARSET CharSetIn,
  1615. IN DNS_CHARSET CharSetOut
  1616. );
  1617. //
  1618. // Record \ type routines
  1619. //
  1620. //
  1621. // Resource record type\name mapping table
  1622. //
  1623. typedef struct
  1624. {
  1625. PCHAR pszTypeName; // type string (used in database files)
  1626. WORD wType; // type in host byte order
  1627. }
  1628. TYPE_NAME_TABLE;
  1629. extern TYPE_NAME_TABLE TypeTable[];
  1630. //
  1631. // Max record name length, allows upcasing of incoming labels
  1632. // to optimize comparisons
  1633. //
  1634. #define MAX_RECORD_NAME_LENGTH (8)
  1635. //
  1636. // Record type specific sizes
  1637. //
  1638. #define WKS_MAX_PORT (1024) // max well known service port
  1639. #define WKS_MAX_BITMASK_LENGTH (128) // 1024bits / 8bits/byte
  1640. #define SIZEOF_A6_ADDRESS_SUFFIX_LENGTH 16
  1641. #define SIZEOF_SOA_FIXED_DATA (5 * sizeof(DWORD))
  1642. #define SIZEOF_MX_FIXED_DATA (sizeof(WORD))
  1643. #define SIZEOF_WKS_FIXED_DATA (SIZEOF_IP4_ADDRESS+ sizeof(BYTE))
  1644. #define SIZEOF_KEY_FIXED_DATA (sizeof(DWORD))
  1645. #define SIZEOF_SIG_FIXED_DATA (4 * sizeof(DWORD) + sizeof(WORD))
  1646. #define SIZEOF_NXT_FIXED_DATA (0)
  1647. #define SIZEOF_LOC_FIXED_DATA (4 * sizeof(DWORD))
  1648. #define SIZEOF_SRV_FIXED_DATA (3 * sizeof(WORD))
  1649. #define SIZEOF_A6_FIXED_DATA (1 + SIZEOF_A6_ADDRESS_SUFFIX_LENGTH)
  1650. #define SIZEOF_TKEY_FIXED_DATA (2 * sizeof(DWORD) + 4 * sizeof(WORD))
  1651. #define SIZEOF_TSIG_PRE_SIG_FIXED_DATA (2 * sizeof(DWORD) + sizeof(WORD))
  1652. #define SIZEOF_TSIG_POST_SIG_FIXED_DATA (3 * sizeof(WORD))
  1653. #define SIZEOF_TSIG_FIXED_DATA (2 * sizeof(DWORD) + 4 * sizeof(WORD))
  1654. #define SIZEOF_WINS_FIXED_DATA (4 * sizeof(DWORD))
  1655. #define SIZEOF_NBSTAT_FIXED_DATA (3 * sizeof(DWORD))
  1656. //
  1657. // Record type routines
  1658. // These ones are of possible public interest and exposed in dnsapi.dll
  1659. //
  1660. BOOL
  1661. _fastcall
  1662. Dns_IsAMailboxType(
  1663. IN WORD wType
  1664. );
  1665. WORD
  1666. Dns_RecordTypeForNameA(
  1667. IN PCHAR pszName,
  1668. IN INT cchNameLength
  1669. );
  1670. WORD
  1671. Dns_RecordTypeForNameW(
  1672. IN PWCHAR pchName,
  1673. IN INT cchNameLength
  1674. );
  1675. #define Dns_RecordTypeForName(p,c) Dns_RecordTypeForNameA((p),(c))
  1676. BOOL
  1677. Dns_WriteStringForType_A(
  1678. OUT PCHAR pBuffer,
  1679. IN WORD wType
  1680. );
  1681. BOOL
  1682. Dns_WriteStringForType_W(
  1683. OUT PWCHAR pBuffer,
  1684. IN WORD wType
  1685. );
  1686. PCHAR
  1687. Dns_RecordStringForType(
  1688. IN WORD wType
  1689. );
  1690. PCHAR
  1691. Dns_RecordStringForWritableType(
  1692. IN WORD wType
  1693. );
  1694. //
  1695. // Record type specific stuff
  1696. //
  1697. BOOL
  1698. Dns_IsStringCountValidForTextType(
  1699. IN WORD wType,
  1700. IN WORD StringCount
  1701. );
  1702. //
  1703. // ATMA conversions
  1704. //
  1705. DWORD
  1706. Dns_AtmaAddressLengthForAddressString(
  1707. IN PCHAR pchString,
  1708. IN DWORD dwStringLength
  1709. );
  1710. DNS_STATUS
  1711. Dns_AtmaStringToAddress(
  1712. OUT PBYTE pAddress,
  1713. IN OUT PDWORD pdwAddrLength,
  1714. IN PCHAR pchString,
  1715. IN DWORD dwStringLength
  1716. );
  1717. PCHAR
  1718. Dns_AtmaAddressToString(
  1719. OUT PCHAR pchString,
  1720. IN UCHAR AddrType,
  1721. IN PBYTE pAddress,
  1722. IN DWORD dwAddrLength
  1723. );
  1724. //
  1725. // DNSSEC SIG and KEY routines
  1726. //
  1727. // Max key is 4096 bit giving 512 byte length.
  1728. //
  1729. // Max string representation is actually 33% larger as each three byte (24bit)
  1730. // block contains four base64 characters.
  1731. #define DNS_MAX_KEY_LENGTH (512)
  1732. #define DNS_MAX_KEY_STRING_LENGTH (685)
  1733. WORD
  1734. Dns_KeyRecordFlagForString(
  1735. IN PCHAR pchName,
  1736. IN INT cchNameLength
  1737. );
  1738. PCHAR
  1739. Dns_KeyRecordFlagString(
  1740. IN DWORD dwFlag,
  1741. IN OUT PCHAR pchFlag
  1742. );
  1743. UCHAR
  1744. Dns_KeyRecordProtocolForString(
  1745. IN PCHAR pchName,
  1746. IN INT cchNameLength
  1747. );
  1748. PCHAR
  1749. Dns_GetKeyProtocolString(
  1750. IN UCHAR uchProtocol
  1751. );
  1752. UCHAR
  1753. Dns_SecurityAlgorithmForString(
  1754. IN PCHAR pchName,
  1755. IN INT cchNameLength
  1756. );
  1757. PCHAR
  1758. Dns_GetDnssecAlgorithmString(
  1759. IN UCHAR uchAlgorithm
  1760. );
  1761. UCHAR
  1762. Dns_SecurityBase64CharToBits(
  1763. IN CHAR ch64
  1764. );
  1765. DNS_STATUS
  1766. Dns_SecurityBase64StringToKey(
  1767. OUT PBYTE pKey,
  1768. OUT PDWORD pKeyLength,
  1769. IN PCHAR pchString,
  1770. IN DWORD cchLength
  1771. );
  1772. PCHAR
  1773. Dns_SecurityKeyToBase64String(
  1774. IN PBYTE pKey,
  1775. IN DWORD KeyLength,
  1776. OUT PCHAR pchBuffer
  1777. );
  1778. LONG
  1779. Dns_ParseSigTime(
  1780. IN PCHAR pchString,
  1781. IN INT cchLength
  1782. );
  1783. PCHAR
  1784. Dns_SigTimeString(
  1785. IN LONG SigTime,
  1786. OUT PCHAR pchBuffer
  1787. );
  1788. //
  1789. // WINS \ WINS-R types detection
  1790. //
  1791. #define IS_WINS_TYPE(type) (((type) & 0xfffc) == 0xff00)
  1792. //
  1793. // MS WINS mapping flags
  1794. //
  1795. // return on invalid WINS flag
  1796. #define DNS_WINS_FLAG_ERROR (-1)
  1797. // max length of WINS flags
  1798. // pass buffer at least this big
  1799. #define WINS_FLAG_MAX_LENGTH (80)
  1800. DWORD
  1801. Dns_WinsRecordFlagForString(
  1802. IN PCHAR pchName,
  1803. IN INT cchNameLength
  1804. );
  1805. PCHAR
  1806. Dns_WinsRecordFlagString(
  1807. IN DWORD dwFlag,
  1808. IN OUT PCHAR pchFlag
  1809. );
  1810. //
  1811. // must sit here until PDNS_RECORD defined in public dns.h header
  1812. //
  1813. DNS_STATUS
  1814. Dns_RecordWriteFileString(
  1815. IN PDNS_RECORD pRecord,
  1816. IN PSTR pszZoneName,
  1817. IN DWORD dwDefaultTtl OPTIONAL
  1818. );
  1819. //
  1820. // IP Address to\from string utilities (straddr.c)
  1821. //
  1822. //
  1823. // String to Address
  1824. //
  1825. BOOL
  1826. Dns_Ip4StringToAddress_W(
  1827. OUT PIP4_ADDRESS pIp4Addr,
  1828. IN PCWSTR pwString
  1829. );
  1830. BOOL
  1831. Dns_Ip4StringToAddress_A(
  1832. OUT PIP4_ADDRESS pIp4Addr,
  1833. IN PCSTR pString
  1834. );
  1835. BOOL
  1836. Dns_Ip6StringToAddress_A(
  1837. OUT PIP6_ADDRESS pIp6Addr,
  1838. IN PCSTR pString
  1839. );
  1840. BOOL
  1841. Dns_Ip6StringToAddress_W(
  1842. OUT PIP6_ADDRESS pIp6Addr,
  1843. IN PCWSTR pwString
  1844. );
  1845. //
  1846. // Combined IP4\IP6 string to address
  1847. //
  1848. BOOL
  1849. Dns_StringToAddress_W(
  1850. OUT PCHAR pAddrBuf,
  1851. IN OUT PDWORD pBufLength,
  1852. IN PCWSTR pString,
  1853. IN OUT PDWORD pAddrFamily
  1854. );
  1855. BOOL
  1856. Dns_StringToAddress_A(
  1857. OUT PCHAR pAddrBuf,
  1858. IN OUT PDWORD pBufLength,
  1859. IN PCSTR pString,
  1860. IN OUT PDWORD pAddrFamily
  1861. );
  1862. //
  1863. // Address to string
  1864. //
  1865. PWCHAR
  1866. Dns_Ip6AddressToString_W(
  1867. OUT PWCHAR pwString,
  1868. IN PIP6_ADDRESS pIp6Addr
  1869. );
  1870. PCHAR
  1871. Dns_Ip6AddressToString_A(
  1872. OUT PCHAR pchString,
  1873. IN PIP6_ADDRESS pIp6Addr
  1874. );
  1875. PWCHAR
  1876. Dns_Ip4AddressToString_W(
  1877. OUT PWCHAR pwString,
  1878. IN PIP4_ADDRESS pIp4Addr
  1879. );
  1880. PCHAR
  1881. Dns_Ip4AddressToString_A(
  1882. OUT PCHAR pString,
  1883. IN PIP4_ADDRESS pIp4Addr
  1884. );
  1885. //
  1886. // Address to string -- combined
  1887. //
  1888. PCHAR
  1889. Dns_AddressToString_A(
  1890. OUT PCHAR pchString,
  1891. IN OUT PDWORD pStringLength,
  1892. IN PBYTE pAddr,
  1893. IN DWORD AddrLength,
  1894. IN DWORD AddrFamily
  1895. );
  1896. //
  1897. // Reverse lookup address-to-name IP4
  1898. //
  1899. PCHAR
  1900. Dns_Ip4AddressToReverseName_A(
  1901. OUT PCHAR pBuffer,
  1902. IN IP4_ADDRESS IpAddr
  1903. );
  1904. PWCHAR
  1905. Dns_Ip4AddressToReverseName_W(
  1906. OUT PWCHAR pBuffer,
  1907. IN IP4_ADDRESS IpAddr
  1908. );
  1909. PCHAR
  1910. Dns_Ip4AddressToReverseNameAlloc_A(
  1911. IN IP4_ADDRESS IpAddr
  1912. );
  1913. PWCHAR
  1914. Dns_Ip4AddressToReverseNameAlloc_W(
  1915. IN IP4_ADDRESS IpAddr
  1916. );
  1917. //
  1918. // Reverse lookup address-to-name IP6
  1919. //
  1920. PCHAR
  1921. Dns_Ip6AddressToReverseName_A(
  1922. OUT PCHAR pBuffer,
  1923. IN IP6_ADDRESS Ip6Addr
  1924. );
  1925. PWCHAR
  1926. Dns_Ip6AddressToReverseName_W(
  1927. OUT PWCHAR pBuffer,
  1928. IN IP6_ADDRESS Ip6Addr
  1929. );
  1930. PCHAR
  1931. Dns_Ip6AddressToReverseNameAlloc_A(
  1932. IN IP6_ADDRESS Ip6Addr
  1933. );
  1934. PWCHAR
  1935. Dns_Ip6AddressToReverseNameAlloc_W(
  1936. IN IP6_ADDRESS Ip6Addr
  1937. );
  1938. //
  1939. // Reverse lookup name-to-address
  1940. //
  1941. BOOL
  1942. Dns_Ip4ReverseNameToAddress_A(
  1943. OUT PIP4_ADDRESS pIp4Addr,
  1944. IN PCSTR pszName
  1945. );
  1946. BOOL
  1947. Dns_Ip4ReverseNameToAddress_W(
  1948. OUT PIP4_ADDRESS pIp4Addr,
  1949. IN PCWSTR pwsName
  1950. );
  1951. BOOL
  1952. Dns_Ip6ReverseNameToAddress_A(
  1953. OUT PIP6_ADDRESS pIp6Addr,
  1954. IN PCSTR pszName
  1955. );
  1956. BOOL
  1957. Dns_Ip6ReverseNameToAddress_W(
  1958. OUT PIP6_ADDRESS pIp6Addr,
  1959. IN PCWSTR pwsName
  1960. );
  1961. //
  1962. // Combined IP4\IP6 reverse lookup name-to-address
  1963. //
  1964. BOOL
  1965. Dns_ReverseNameToAddress_W(
  1966. OUT PCHAR pAddrBuf,
  1967. IN OUT PDWORD pBufLength,
  1968. IN PCWSTR pString,
  1969. IN OUT PDWORD pAddrFamily
  1970. );
  1971. BOOL
  1972. Dns_ReverseNameToAddress_A(
  1973. OUT PCHAR pAddrBuf,
  1974. IN OUT PDWORD pBufLength,
  1975. IN PCSTR pString,
  1976. IN OUT PDWORD pAddrFamily
  1977. );
  1978. //
  1979. // String utilities (string.c)
  1980. //
  1981. // Note some of these require memory allocation, see note
  1982. // on memory allocation below.
  1983. //
  1984. // Flags are defined in dnsapi.h
  1985. //
  1986. //#define DNS_ALLOW_RFC_NAMES_ONLY (0)
  1987. //#define DNS_ALLOW_NONRFC_NAMES (0x00000001)
  1988. //#define DNS_ALLOW_MULTIBYTE_NAMES (0x00000002)
  1989. //#define DNS_ALLOW_ALL_NAMES (0x00000003)
  1990. //
  1991. // Unicode name buffer length.
  1992. // Non-type specific routines below take buffer counts in bytes.
  1993. // Unicode buffers of max name length have twice the bytes.
  1994. //
  1995. #define DNS_MAX_NAME_BUFFER_LENGTH_UNICODE (2 * DNS_MAX_NAME_BUFFER_LENGTH)
  1996. //
  1997. // Macros to simplify UTF8 conversions
  1998. //
  1999. // UTF8 is simply a representation of unicode that maps one-to-one
  2000. // for the ASCII space.
  2001. // Unicode UTF8
  2002. // ------- ----
  2003. // < 0x80 (128) -> use low byte (one-to-one mapping)
  2004. // < 0x07ff -> two chars
  2005. // > 0x07ff -> three chars
  2006. //
  2007. #define UTF8_1ST_OF_2 0xc0 // 110x xxxx
  2008. #define UTF8_1ST_OF_3 0xe0 // 1110 xxxx
  2009. #define UTF8_TRAIL 0x80 // 10xx xxxx
  2010. #define UTF8_2_MAX 0x07ff // max unicode character representable in
  2011. // in two byte UTF8
  2012. //
  2013. // Explicitly UTF8 string
  2014. //
  2015. typedef PSTR PU8STR;
  2016. PSTR
  2017. Dns_CreateStringCopy(
  2018. IN PCHAR pchString,
  2019. IN DWORD cchString
  2020. );
  2021. DWORD
  2022. Dns_GetBufferLengthForStringCopy(
  2023. IN PCHAR pchString,
  2024. IN DWORD cchString,
  2025. IN DNS_CHARSET CharSetIn,
  2026. IN DNS_CHARSET CharSetOut
  2027. );
  2028. DWORD
  2029. Dns_StringCopy(
  2030. OUT PBYTE pBuffer,
  2031. IN OUT PDWORD pdwBufLength,
  2032. IN PCHAR pchString,
  2033. IN DWORD cchString,
  2034. IN DNS_CHARSET CharSetIn,
  2035. IN DNS_CHARSET CharSetOut
  2036. );
  2037. PVOID
  2038. Dns_StringCopyAllocate(
  2039. IN PCHAR pchString,
  2040. IN DWORD cchString,
  2041. IN DNS_CHARSET CharSetIn,
  2042. IN DNS_CHARSET CharSetOut
  2043. );
  2044. #define Dns_StringCopyAllocate_W( p, c ) \
  2045. ( (PWCHAR) Dns_StringCopyAllocate( \
  2046. (PCHAR) (p), \
  2047. (c), \
  2048. DnsCharSetUnicode, \
  2049. DnsCharSetUnicode ) )
  2050. #define Dns_StringCopyAllocate_A( p, c ) \
  2051. ( (PCHAR) Dns_StringCopyAllocate( \
  2052. (p), \
  2053. (c), \
  2054. DnsCharSetUtf8, \
  2055. DnsCharSetUtf8 ) )
  2056. PSTR
  2057. Dns_CreateStringCopy_A(
  2058. IN PCSTR pwsString
  2059. );
  2060. PWSTR
  2061. Dns_CreateStringCopy_W(
  2062. IN PCWSTR pwsString
  2063. );
  2064. PWSTR
  2065. Dns_CreateConcatenatedString_W(
  2066. IN PCWSTR * pStringArray
  2067. );
  2068. PWSTR
  2069. Dns_GetResourceString(
  2070. IN DWORD dwStringId,
  2071. IN PWSTR pwszBuffer,
  2072. IN DWORD cbBuffer
  2073. );
  2074. INT
  2075. wcsicmp_ThatWorks(
  2076. IN PWSTR pString1,
  2077. IN PWSTR pString2
  2078. );
  2079. //
  2080. // Special DNS name string functions
  2081. //
  2082. #define Dns_GetBufferLengthForNameCopy(a,b,c,d)\
  2083. Dns_GetBufferLengthForStringCopy((a),(b),(c),(d))
  2084. #define Dns_NameCopy(a,b,c,d,e,f) \
  2085. Dns_StringCopy(a,b,c,d,e,f)
  2086. #define Dns_NameCopyAllocate(a,b,c,d) \
  2087. Dns_StringCopyAllocate(a,b,c,d)
  2088. //
  2089. // Name validation (string.c)
  2090. //
  2091. DNS_STATUS
  2092. Dns_ValidateName_UTF8(
  2093. IN LPCSTR pszName,
  2094. IN DNS_NAME_FORMAT Format
  2095. );
  2096. DNS_STATUS
  2097. Dns_ValidateName_W(
  2098. IN LPCWSTR pwszName,
  2099. IN DNS_NAME_FORMAT Format
  2100. );
  2101. DNS_STATUS
  2102. Dns_ValidateName_A(
  2103. IN LPCSTR pszName,
  2104. IN DNS_NAME_FORMAT Format
  2105. );
  2106. DNS_STATUS
  2107. Dns_ValidateDnsString_UTF8(
  2108. IN LPCSTR pszName
  2109. );
  2110. DNS_STATUS
  2111. Dns_ValidateDnsString_W(
  2112. IN LPCWSTR pszName
  2113. );
  2114. PSTR
  2115. Dns_CreateStandardDnsNameCopy(
  2116. IN PCHAR pchName,
  2117. IN DWORD cchName,
  2118. IN DWORD dwFlag
  2119. );
  2120. //
  2121. // UTF8 conversions (utf8.c)
  2122. //
  2123. DNS_STATUS
  2124. _fastcall
  2125. Dns_ValidateUtf8Byte(
  2126. IN BYTE chUtf8,
  2127. IN OUT PDWORD pdwTrailCount
  2128. );
  2129. DWORD
  2130. _fastcall
  2131. Dns_UnicodeToUtf8(
  2132. IN PWCHAR pwUnicode,
  2133. IN DWORD cchUnicode,
  2134. OUT PCHAR pchResult,
  2135. IN DWORD cchResult
  2136. );
  2137. DWORD
  2138. _fastcall
  2139. Dns_Utf8ToUnicode(
  2140. IN PCHAR pchUtf8,
  2141. IN DWORD cchUtf8,
  2142. OUT PWCHAR pwResult,
  2143. IN DWORD cwResult
  2144. );
  2145. DWORD
  2146. Dns_Utf8ToOrFromAnsi(
  2147. OUT PCHAR pchResult,
  2148. IN DWORD cchResult,
  2149. IN PCHAR pchIn,
  2150. IN DWORD cchIn,
  2151. IN DNS_CHARSET InCharSet,
  2152. IN DNS_CHARSET OutCharSet
  2153. );
  2154. DWORD
  2155. Dns_AnsiToUtf8(
  2156. IN PCHAR pchAnsi,
  2157. IN DWORD cchAnsi,
  2158. OUT PCHAR pchResult,
  2159. IN DWORD cchResult
  2160. );
  2161. DWORD
  2162. Dns_Utf8ToAnsi(
  2163. IN PCHAR pchUtf8,
  2164. IN DWORD cchUtf8,
  2165. OUT PCHAR pchResult,
  2166. IN DWORD cchResult
  2167. );
  2168. BOOL
  2169. _fastcall
  2170. Dns_IsStringAscii(
  2171. IN PSTR pszString
  2172. );
  2173. BOOL
  2174. _fastcall
  2175. Dns_IsStringAsciiEx(
  2176. IN PCHAR pchString,
  2177. IN DWORD cchString
  2178. );
  2179. BOOL
  2180. _fastcall
  2181. Dns_IsWideStringAscii(
  2182. IN PWSTR pwsString
  2183. );
  2184. //
  2185. // Resource record dispatch tables
  2186. //
  2187. // Resource record tables are indexed by type for standard types
  2188. // These define limits on tables.
  2189. //
  2190. // Currently indexing out to RR 40, so that we'll handle any new RR types
  2191. // out this far without interfering with WINS stuff.
  2192. //
  2193. #define MAX_SELF_INDEXED_TYPE (48)
  2194. //
  2195. // Mappings for non-self indexed types
  2196. //
  2197. // Note: these are presented here for information purposes only!
  2198. //
  2199. // Always call Dns_RecordTableIndexForType(wType) to get correct index.
  2200. //
  2201. #define TKEY_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 1)
  2202. #define TSIG_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 2)
  2203. #define WINS_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 3)
  2204. #define WINSR_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 4)
  2205. // End of actual record types.
  2206. // Query type indexes may extend beyond this index.
  2207. #define MAX_RECORD_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 4)
  2208. //
  2209. // Generic indexer for both regular and extended (non-self-indexing) types
  2210. //
  2211. #define INDEX_FOR_TYPE(type) Dns_RecordTableIndexForType(type)
  2212. //
  2213. // Type to index mapping
  2214. //
  2215. WORD
  2216. Dns_RecordTableIndexForType(
  2217. IN WORD wType
  2218. );
  2219. //
  2220. // Generic print routine
  2221. //
  2222. // All our print routines will take the real print routine
  2223. // as a parameter. This routine must have "sprintf-like"
  2224. // or "fprintf-like" semantics. In other words a context,
  2225. // format and variable number of arguments.
  2226. //
  2227. // Note the context argument is effectively a PVOID --
  2228. // different routines will have different contexts. The
  2229. // explicit definition is to enforce strong type checking
  2230. // so a call without a context is caught on compile.
  2231. //
  2232. typedef struct _DnsPrintContext
  2233. {
  2234. PVOID pvDummy;
  2235. DWORD Dummy;
  2236. }
  2237. PRINT_CONTEXT, *PPRINT_CONTEXT;
  2238. typedef VOID (* PRINT_ROUTINE)(
  2239. PPRINT_CONTEXT,
  2240. CHAR*,
  2241. ... );
  2242. //
  2243. // RnR utilities
  2244. //
  2245. DWORD
  2246. Dns_RnrLupFlagForString(
  2247. IN PCHAR pchName,
  2248. IN INT cchNameLength
  2249. );
  2250. PCHAR
  2251. Dns_GetRnrLupFlagString(
  2252. IN DWORD dwFlag
  2253. );
  2254. DWORD
  2255. Dns_RnrNameSpaceIdForString(
  2256. IN PCHAR pchName,
  2257. IN INT cchNameLength
  2258. );
  2259. DWORD
  2260. Dns_RnrNameSpaceIdForStringW(
  2261. IN PWSTR pwsName
  2262. );
  2263. PCHAR
  2264. Dns_GetRnrNameSpaceIdString(
  2265. IN DWORD dwFlag
  2266. );
  2267. //
  2268. // Hostent utilities
  2269. //
  2270. BOOL
  2271. Hostent_IsSupportedAddrType(
  2272. IN WORD wType
  2273. );
  2274. DWORD
  2275. Hostent_Size(
  2276. IN PHOSTENT pHostent,
  2277. IN DNS_CHARSET CharSetExisting,
  2278. IN DNS_CHARSET CharSetTarget,
  2279. IN PDWORD pAliasCount,
  2280. IN PDWORD pAddrCount
  2281. );
  2282. PHOSTENT
  2283. Hostent_Copy(
  2284. IN OUT PBYTE * ppBuffer,
  2285. IN OUT PINT pBufferSize,
  2286. OUT PINT pHostentSize,
  2287. IN PHOSTENT pHostent,
  2288. IN DNS_CHARSET CharSetIn,
  2289. IN DNS_CHARSET CharSetTarget,
  2290. IN BOOL fOffsets,
  2291. IN BOOL fAlloc
  2292. );
  2293. DWORD
  2294. Hostent_WriteIp4Addrs(
  2295. IN OUT PHOSTENT pHostent,
  2296. OUT PCHAR pAddrBuf,
  2297. IN DWORD MaxBufCount,
  2298. IN PIP4_ADDRESS Ip4Array,
  2299. IN DWORD ArrayCount,
  2300. IN BOOL fScreenZero
  2301. );
  2302. DWORD
  2303. Hostent_WriteLocalIp4Array(
  2304. IN OUT PHOSTENT pHostent,
  2305. OUT PCHAR pAddrBuf,
  2306. IN DWORD MaxBufCount,
  2307. IN PIP4_ARRAY pIpArray
  2308. );
  2309. BOOL
  2310. Hostent_IsAddressInHostent(
  2311. IN OUT PHOSTENT pHostent,
  2312. IN PCHAR pAddr,
  2313. IN DWORD AddrLength,
  2314. IN INT Family OPTIONAL
  2315. );
  2316. BOOL
  2317. Hostent_IsIp4AddressInHostent(
  2318. IN OUT PHOSTENT pHostent,
  2319. IN IP4_ADDRESS Ip4Addr
  2320. );
  2321. //
  2322. // Hostent Object
  2323. //
  2324. typedef struct _HostentBlob
  2325. {
  2326. PHOSTENT pHostent;
  2327. // flags
  2328. BOOL fAllocatedBlob;
  2329. BOOL fAllocatedBuf;
  2330. // buffer allocated
  2331. PCHAR pBuffer;
  2332. DWORD BufferLength;
  2333. DWORD AvailLength;
  2334. PCHAR pAvailBuffer;
  2335. // buffer in build
  2336. PCHAR pCurrent;
  2337. DWORD BytesLeft;
  2338. // sizing info
  2339. DWORD MaxAliasCount;
  2340. DWORD MaxAddrCount;
  2341. // hostent building
  2342. DWORD AliasCount;
  2343. DWORD AddrCount;
  2344. BOOL fWroteName;
  2345. DNS_CHARSET CharSet;
  2346. BOOL fUnicode;
  2347. }
  2348. HOSTENT_BLOB, *PHOSTENT_BLOB;
  2349. typedef struct _HostentInitRequest
  2350. {
  2351. INT AddrFamily;
  2352. WORD wType;
  2353. DWORD AddrCount;
  2354. BOOL fUnicode;
  2355. DNS_CHARSET CharSet;
  2356. DWORD NameLength;
  2357. PBYTE pName;
  2358. DWORD AliasCount;
  2359. DWORD AliasNameLength;
  2360. }
  2361. HOSTENT_INIT, *PHOSTENT_INIT;
  2362. DNS_STATUS
  2363. HostentBlob_Create(
  2364. IN OUT PHOSTENT_BLOB * ppBlob,
  2365. IN PHOSTENT_INIT pReq
  2366. );
  2367. PHOSTENT_BLOB
  2368. HostentBlob_CreateAttachExisting(
  2369. IN PHOSTENT pHostent,
  2370. IN BOOL fUnicode
  2371. );
  2372. VOID
  2373. HostentBlob_Free(
  2374. IN OUT PHOSTENT_BLOB pBlob
  2375. );
  2376. DNS_STATUS
  2377. HostentBlob_WriteAddress(
  2378. IN OUT PHOSTENT_BLOB pBlob,
  2379. IN PVOID pAddress,
  2380. IN DWORD AddrSize,
  2381. IN DWORD AddrType
  2382. );
  2383. DNS_STATUS
  2384. HostentBlob_WriteAddressArray(
  2385. IN OUT PHOSTENT_BLOB pBlob,
  2386. IN PVOID pAddrArray,
  2387. IN DWORD AddrCount,
  2388. IN DWORD AddrSize,
  2389. IN DWORD AddrType
  2390. );
  2391. DNS_STATUS
  2392. HostentBlob_WriteNameOrAlias(
  2393. IN OUT PHOSTENT_BLOB pBlob,
  2394. IN PSTR pszName,
  2395. IN BOOL fAlias,
  2396. IN BOOL fUnicode
  2397. );
  2398. DNS_STATUS
  2399. HostentBlob_WriteRecords(
  2400. IN OUT PHOSTENT_BLOB pBlob,
  2401. IN PDNS_RECORD pRecords,
  2402. IN BOOL fWriteName
  2403. );
  2404. // Special hostents
  2405. PHOSTENT_BLOB
  2406. Hostent_Localhost(
  2407. IN INT AddrFamily
  2408. );
  2409. DNS_STATUS
  2410. HostentBlob_CreateFromIpArray(
  2411. IN OUT PHOSTENT_BLOB * ppBlob,
  2412. IN INT AddrFamily,
  2413. IN INT AddrSize,
  2414. IN INT AddrCount,
  2415. IN PCHAR pArray,
  2416. IN PSTR pName,
  2417. IN BOOL fUnicode
  2418. );
  2419. DNS_STATUS
  2420. HostentBlob_CreateLocal(
  2421. IN OUT PHOSTENT_BLOB * ppBlob,
  2422. IN INT AddrFamily,
  2423. IN BOOL fLoopback,
  2424. IN BOOL fZero,
  2425. IN BOOL fHostnameOnly
  2426. );
  2427. // Query for hostent
  2428. PHOSTENT_BLOB
  2429. HostentBlob_Query(
  2430. IN PWSTR pwsName,
  2431. IN WORD wType,
  2432. IN DWORD Flags,
  2433. IN OUT PVOID * ppMsg, OPTIONAL
  2434. IN INT AddrFamily OPTIONAL
  2435. );
  2436. //
  2437. // Sockaddr blob stuff (for RnR)
  2438. //
  2439. typedef DNS_SOCKADDR_RESULTS SABLOB, *PSABLOB;
  2440. PSABLOB
  2441. SaBlob_Create(
  2442. IN DWORD AddrCount
  2443. );
  2444. VOID
  2445. SaBlob_Free(
  2446. IN OUT PSABLOB pBlob
  2447. );
  2448. DNS_STATUS
  2449. SaBlob_WriteNameOrAlias(
  2450. IN OUT PSABLOB pBlob,
  2451. IN PWSTR pszName,
  2452. IN BOOL fAlias
  2453. );
  2454. PSABLOB
  2455. SaBlob_CreateFromIp4(
  2456. IN PWSTR pName,
  2457. IN DWORD AddrCount,
  2458. IN PIP4_ADDRESS pIpArray
  2459. );
  2460. PSABLOB
  2461. SaBlob_Query(
  2462. IN PWSTR pwsName,
  2463. IN WORD wType,
  2464. IN DWORD Flags,
  2465. IN OUT PVOID * ppMsg, OPTIONAL
  2466. IN INT AddrFamily OPTIONAL
  2467. );
  2468. PHOSTENT
  2469. SaBlob_CreateHostent(
  2470. IN OUT PBYTE * ppBuffer,
  2471. IN OUT PINT pBufferSize,
  2472. OUT PINT pHostentSize,
  2473. IN PSABLOB pBlob,
  2474. IN DNS_CHARSET CharSetTarget,
  2475. IN BOOL fOffsets,
  2476. IN BOOL fAlloc
  2477. );
  2478. //
  2479. // Memory allocation
  2480. //
  2481. // Some DNS library functions -- including the IP array and string utils
  2482. // -- allocate memory. This memory allocation defaults to routines that
  2483. // use LocalAlloc, LocalReAlloc, LocalFree. If you desire alternative
  2484. // memory allocation mechanisms, use this function to override the DNS
  2485. // library defaults. All memory allocated by the DNS library, should
  2486. // then be freed by the corresponding function.
  2487. //
  2488. typedef PVOID (* DNSLIB_ALLOC_FUNCTION)();
  2489. typedef PVOID (* DNSLIB_REALLOC_FUNCTION)();
  2490. typedef VOID (* DNSLIB_FREE_FUNCTION)();
  2491. VOID
  2492. Dns_LibHeapReset(
  2493. IN DNSLIB_ALLOC_FUNCTION pAlloc,
  2494. IN DNSLIB_REALLOC_FUNCTION pRealloc,
  2495. IN DNSLIB_FREE_FUNCTION pFree
  2496. );
  2497. //
  2498. // These routines call the currently registered allocation functions
  2499. // whether default or reset through Dns_ApiHeapReset()
  2500. //
  2501. PVOID
  2502. Dns_Alloc(
  2503. IN INT iSize
  2504. );
  2505. PVOID
  2506. Dns_AllocZero(
  2507. IN INT iSize
  2508. );
  2509. PVOID
  2510. Dns_Realloc(
  2511. IN OUT PVOID pMem,
  2512. IN INT iSize
  2513. );
  2514. VOID
  2515. Dns_Free(
  2516. IN OUT PVOID pMem
  2517. );
  2518. PVOID
  2519. Dns_AllocMemCopy(
  2520. IN PVOID pMem,
  2521. IN INT iSize
  2522. );
  2523. //
  2524. // DNS Test build
  2525. //
  2526. // Allow imbedding of extra info in IP4 arrays to pass to DnsQuery routines.
  2527. //
  2528. #ifdef DNSTEST_BUILD
  2529. typedef struct _DnsImbeddedExtra
  2530. {
  2531. DWORD Tag;
  2532. PDNS_EXTRA_INFO pExtraInfo;
  2533. }
  2534. DNS_IMBEDDED_EXTRA_INFO, *PDNS_IMBEDDED_EXTRA_INFO;
  2535. #define DNS_IMBEDDED_EXTRA_INFO_TAG (0xfedc1234)
  2536. #endif
  2537. //
  2538. // Print routines (print.c)
  2539. //
  2540. // Print routines below use any printf() like function to print.
  2541. // this is typedef that function must match.
  2542. //
  2543. //
  2544. // Print Locking
  2545. //
  2546. VOID
  2547. DnsPrint_InitLocking(
  2548. IN PCRITICAL_SECTION pLock
  2549. );
  2550. VOID
  2551. DnsPrint_Lock(
  2552. VOID
  2553. );
  2554. VOID
  2555. DnsPrint_Unlock(
  2556. VOID
  2557. );
  2558. #define Dns_PrintInitLocking(a) DnsPrint_InitLocking(a)
  2559. #define Dns_PrintLock() DnsPrint_Lock()
  2560. #define Dns_PrintUnlock() DnsPrint_Unlock()
  2561. //
  2562. // Print routines for general types and structures
  2563. //
  2564. VOID
  2565. DnsPrint_String(
  2566. IN PRINT_ROUTINE PrintRoutine,
  2567. IN OUT PPRINT_CONTEXT pContext,
  2568. IN PSTR pszHeader, OPTIONAL
  2569. IN PSTR pszString,
  2570. IN BOOL fUnicode,
  2571. IN PSTR pszTrailer OPTIONAL
  2572. );
  2573. VOID
  2574. DnsPrint_StringCharSet(
  2575. IN PRINT_ROUTINE PrintRoutine,
  2576. IN OUT PPRINT_CONTEXT pContext,
  2577. IN PSTR pszHeader, OPTIONAL
  2578. IN PSTR pszString,
  2579. IN DNS_CHARSET CharSet,
  2580. IN PSTR pszTrailer OPTIONAL
  2581. );
  2582. VOID
  2583. DnsPrint_Utf8StringBytes(
  2584. IN PRINT_ROUTINE PrintRoutine,
  2585. IN OUT PPRINT_CONTEXT pContext,
  2586. IN PSTR pszHeader,
  2587. IN PCHAR pUtf8,
  2588. IN DWORD Length
  2589. );
  2590. VOID
  2591. DnsPrint_UnicodeStringBytes(
  2592. IN PRINT_ROUTINE PrintRoutine,
  2593. IN OUT PPRINT_CONTEXT pContext,
  2594. IN PSTR pszHeader,
  2595. IN PWCHAR pUnicode,
  2596. IN DWORD Length
  2597. );
  2598. VOID
  2599. DnsPrint_StringArray(
  2600. IN PRINT_ROUTINE PrintRoutine,
  2601. IN OUT PPRINT_CONTEXT pContext,
  2602. IN PSTR pszHeader,
  2603. IN PSTR * StringArray,
  2604. IN DWORD Count, OPTIONAL
  2605. IN BOOL fUnicode
  2606. );
  2607. VOID
  2608. DnsPrint_Argv(
  2609. IN PRINT_ROUTINE PrintRoutine,
  2610. IN OUT PPRINT_CONTEXT pContext,
  2611. IN PSTR pszHeader,
  2612. IN CHAR ** Argv,
  2613. IN DWORD Argc, OPTIONAL
  2614. IN BOOL fUnicode
  2615. );
  2616. VOID
  2617. DnsPrint_DwordArray(
  2618. IN PRINT_ROUTINE PrintRoutine,
  2619. IN OUT PPRINT_CONTEXT pContext,
  2620. IN PSTR pszHeader,
  2621. IN PSTR pszName,
  2622. IN DWORD dwCount,
  2623. IN PDWORD adwArray
  2624. );
  2625. VOID
  2626. DnsPrint_Ip4AddressArray(
  2627. IN PRINT_ROUTINE PrintRoutine,
  2628. IN OUT PPRINT_CONTEXT pContext,
  2629. IN PSTR pszHeader,
  2630. IN PSTR pszName,
  2631. IN DWORD dwIpAddrCount,
  2632. IN PIP4_ADDRESS pIpAddrs
  2633. );
  2634. VOID
  2635. DnsPrint_Ip4Array(
  2636. IN PRINT_ROUTINE PrintRoutine,
  2637. IN OUT PPRINT_CONTEXT pContext,
  2638. IN PSTR pszHeader,
  2639. IN PSTR pszName,
  2640. IN PIP4_ARRAY pIpArray
  2641. );
  2642. VOID
  2643. DnsPrint_Ip6Address(
  2644. IN PRINT_ROUTINE PrintRoutine,
  2645. IN OUT PPRINT_CONTEXT pContext,
  2646. IN PSTR pszHeader,
  2647. IN PIP6_ADDRESS pIp6Address,
  2648. IN PSTR pszTrailer
  2649. );
  2650. VOID
  2651. DnsPrint_Ip6Array(
  2652. IN PRINT_ROUTINE PrintRoutine,
  2653. IN OUT PPRINT_CONTEXT pContext,
  2654. IN PSTR pszHeader,
  2655. IN PSTR pszName,
  2656. IN PIP6_ARRAY pIpArray
  2657. );
  2658. VOID
  2659. DnsPrint_Guid(
  2660. IN PRINT_ROUTINE PrintRoutine,
  2661. IN OUT PPRINT_CONTEXT pContext,
  2662. IN PSTR pszHeader,
  2663. IN PGUID pGuid
  2664. );
  2665. //
  2666. // Winsock \ RnR types and structures
  2667. //
  2668. VOID
  2669. DnsPrint_FdSet(
  2670. IN PRINT_ROUTINE PrintRoutine,
  2671. IN OUT PPRINT_CONTEXT pContext,
  2672. IN PSTR pszHeader,
  2673. IN struct fd_set * pFdSet
  2674. );
  2675. VOID
  2676. DnsPrint_Hostent(
  2677. IN PRINT_ROUTINE PrintRoutine,
  2678. IN OUT PPRINT_CONTEXT pContext,
  2679. IN PSTR pszHeader,
  2680. IN PHOSTENT pHostent,
  2681. IN BOOL fUnicode
  2682. );
  2683. VOID
  2684. DnsPrint_Sockaddr(
  2685. IN PRINT_ROUTINE PrintRoutine,
  2686. IN OUT PPRINT_CONTEXT pContext,
  2687. IN PSTR pszHeader,
  2688. IN DWORD Indent,
  2689. IN PSOCKADDR pSockaddr,
  2690. IN INT iSockaddrLength
  2691. );
  2692. #ifdef _WINSOCK2API_
  2693. VOID
  2694. DnsPrint_SocketAddress(
  2695. IN PRINT_ROUTINE PrintRoutine,
  2696. IN OUT PPRINT_CONTEXT pContext,
  2697. IN PSTR pszHeader,
  2698. IN DWORD Indent,
  2699. IN PSOCKET_ADDRESS pSocketAddress
  2700. );
  2701. VOID
  2702. DnsPrint_CsAddr(
  2703. IN PRINT_ROUTINE PrintRoutine,
  2704. IN OUT PPRINT_CONTEXT pContext,
  2705. IN PSTR pszHeader,
  2706. IN DWORD Indent,
  2707. IN PCSADDR_INFO pCsAddrInfo
  2708. );
  2709. VOID
  2710. DnsPrint_AfProtocolsArray(
  2711. IN PRINT_ROUTINE PrintRoutine,
  2712. IN OUT PPRINT_CONTEXT pContext,
  2713. IN PSTR pszHeader,
  2714. IN PAFPROTOCOLS pProtocolArray,
  2715. IN DWORD ProtocolCount
  2716. );
  2717. VOID
  2718. DnsPrint_WsaQuerySet(
  2719. IN PRINT_ROUTINE PrintRoutine,
  2720. IN OUT PPRINT_CONTEXT pContext,
  2721. IN PSTR pszHeader,
  2722. IN LPWSAQUERYSET pQuerySet,
  2723. IN BOOL fUnicode
  2724. );
  2725. VOID
  2726. DnsPrint_WsaNsClassInfo(
  2727. IN PRINT_ROUTINE PrintRoutine,
  2728. IN OUT PPRINT_CONTEXT pContext,
  2729. IN PSTR pszHeader,
  2730. IN PWSANSCLASSINFO pInfo,
  2731. IN BOOL fUnicode
  2732. );
  2733. VOID
  2734. DnsPrint_WsaServiceClassInfo(
  2735. IN PRINT_ROUTINE PrintRoutine,
  2736. IN OUT PPRINT_CONTEXT pContext,
  2737. IN PSTR pszHeader,
  2738. IN LPWSASERVICECLASSINFO pInfo,
  2739. IN BOOL fUnicode
  2740. );
  2741. #endif
  2742. #ifdef _WS2TCPIP_H_
  2743. VOID
  2744. DnsPrint_AddrInfoEx(
  2745. IN PRINT_ROUTINE PrintRoutine,
  2746. IN OUT PPRINT_CONTEXT pContext,
  2747. IN PSTR pszHeader,
  2748. IN DWORD Indent,
  2749. IN PADDRINFO pAddrInfo,
  2750. IN BOOL fUnicode
  2751. );
  2752. VOID
  2753. DnsPrint_AddrInfoListEx(
  2754. IN PRINT_ROUTINE PrintRoutine,
  2755. IN OUT PPRINT_CONTEXT pContext,
  2756. IN PSTR pszHeader,
  2757. IN DWORD Indent,
  2758. IN PADDRINFO pAddrInfo,
  2759. IN BOOL fUnicode
  2760. );
  2761. // ANSI ADDRINFO
  2762. #define DnsPrint_AddrInfo( pr, c, h, i, pa ) \
  2763. DnsPrint_AddrInfoEx( pr, c, h, i, pa, FALSE )
  2764. #define DnsPrint_AddrInfoList( pr, c, h, i, pa ) \
  2765. DnsPrint_AddrInfoListEx( pr, c, h, i, pa, FALSE )
  2766. // Unicode ADDRINFOW
  2767. #define DnsPrint_AddrInfoW( pr, c, h, i, pa ) \
  2768. DnsPrint_AddrInfoEx( pr, c, h, i, pa, TRUE )
  2769. #define DnsPrint_AddrInfoListW( pr, c, h, i, pa ) \
  2770. DnsPrint_AddrInfoListEx( pr, c, h, i, pa, TRUE )
  2771. #endif
  2772. #ifdef IP_TYPES_INCLUDED
  2773. VOID
  2774. DnsPrint_IpAdapterAddress(
  2775. IN PRINT_ROUTINE PrintRoutine,
  2776. IN OUT PPRINT_CONTEXT pContext,
  2777. IN PSTR pszHeader,
  2778. IN PVOID pAddr,
  2779. IN BOOL fUnicast,
  2780. IN BOOL fPrintList
  2781. );
  2782. VOID
  2783. DnsPrint_IpAdapterList(
  2784. IN PRINT_ROUTINE PrintRoutine,
  2785. IN OUT PPRINT_CONTEXT pContext,
  2786. IN PSTR pszHeader,
  2787. IN PIP_ADAPTER_ADDRESSES pAdapt,
  2788. IN BOOL fPrintAddressLists,
  2789. IN BOOL fPrintList
  2790. );
  2791. #endif
  2792. //
  2793. // Print routines for DNS types and structures
  2794. //
  2795. VOID
  2796. DnsPrint_DnsAddrLine(
  2797. IN PRINT_ROUTINE PrintRoutine,
  2798. IN OUT PPRINT_CONTEXT pContext,
  2799. IN PSTR pszHeader,
  2800. IN PDNS_ADDR pAddr,
  2801. IN PSTR pszTrailer
  2802. );
  2803. VOID
  2804. DnsPrint_DnsAddr(
  2805. IN PRINT_ROUTINE PrintRoutine,
  2806. IN OUT PPRINT_CONTEXT pContext,
  2807. IN PSTR pszHeader,
  2808. IN DWORD Indent,
  2809. IN PDNS_ADDR pAddr
  2810. );
  2811. VOID
  2812. DnsPrint_DnsAddrArray(
  2813. IN PRINT_ROUTINE PrintRoutine,
  2814. IN OUT PPRINT_CONTEXT pContext,
  2815. IN PSTR pszHeader,
  2816. IN PSTR pszName,
  2817. IN PDNS_ADDR_ARRAY pArray
  2818. );
  2819. VOID
  2820. DnsPrint_Message(
  2821. IN PRINT_ROUTINE PrintRoutine,
  2822. IN OUT PPRINT_CONTEXT pContext,
  2823. IN PSTR pszHeader,
  2824. IN PDNS_MSG_BUF pMsg
  2825. );
  2826. VOID
  2827. DnsPrint_MessageNoContext(
  2828. IN PRINT_ROUTINE PrintRoutine,
  2829. IN OUT PPRINT_CONTEXT pContext,
  2830. IN PSTR pszHeader,
  2831. IN PDNS_HEADER pMsgHead,
  2832. IN WORD wLength
  2833. );
  2834. INT
  2835. DnsPrint_PacketName(
  2836. IN PRINT_ROUTINE PrintRoutine,
  2837. IN OUT PPRINT_CONTEXT pContext,
  2838. IN PSTR pszHeader, OPTIONAL
  2839. IN PBYTE pMsgName,
  2840. IN PDNS_HEADER pMsgHead, OPTIONAL
  2841. IN PBYTE pMsgEnd, OPTIONAL
  2842. IN PSTR pszTrailer OPTIONAL
  2843. );
  2844. INT
  2845. DnsPrint_PacketRecord(
  2846. IN PRINT_ROUTINE PrintRoutine,
  2847. IN OUT PPRINT_CONTEXT pContext,
  2848. IN PSTR pszHeader,
  2849. IN PDNS_WIRE_RECORD pMsgRR,
  2850. IN PDNS_HEADER pMsgHead, OPTIONAL
  2851. IN PBYTE pMsgEnd OPTIONAL
  2852. );
  2853. VOID
  2854. DnsPrint_ParsedRecord(
  2855. IN PRINT_ROUTINE PrintRoutine,
  2856. IN OUT PPRINT_CONTEXT pContext,
  2857. IN PSTR pszHeader,
  2858. IN PDNS_PARSED_RR pParsedRR
  2859. );
  2860. VOID
  2861. DnsPrint_RawOctets(
  2862. IN PRINT_ROUTINE PrintRoutine,
  2863. IN OUT PPRINT_CONTEXT pContext,
  2864. IN PSTR pszHeader,
  2865. IN PSTR pszLineHeader,
  2866. IN PCHAR pchData,
  2867. IN DWORD dwLength
  2868. );
  2869. VOID
  2870. DnsPrint_ParsedMessage(
  2871. IN PRINT_ROUTINE PrintRoutine,
  2872. IN OUT PPRINT_CONTEXT pContext,
  2873. IN PSTR pszHeader,
  2874. IN PDNS_PARSED_MESSAGE pParsed
  2875. );
  2876. VOID
  2877. DnsPrint_HostentBlob(
  2878. IN PRINT_ROUTINE PrintRoutine,
  2879. IN OUT PPRINT_CONTEXT pContext,
  2880. IN PSTR pszHeader,
  2881. IN PHOSTENT_BLOB pBlob
  2882. );
  2883. VOID
  2884. DnsPrint_SaBlob(
  2885. IN PRINT_ROUTINE PrintRoutine,
  2886. IN OUT PPRINT_CONTEXT pContext,
  2887. IN PSTR pszHeader,
  2888. IN PSABLOB pBlob
  2889. );
  2890. //
  2891. // Print to string
  2892. //
  2893. #define GUID_STRING_BUFFER_LENGTH (80)
  2894. DWORD
  2895. DnsStringPrint_Guid(
  2896. OUT PCHAR pBuffer,
  2897. IN PGUID pGuid
  2898. );
  2899. DWORD
  2900. DnsStringPrint_RawOctets(
  2901. OUT PCHAR pBuffer,
  2902. IN PCHAR pchData,
  2903. IN DWORD dwLength,
  2904. IN PSTR pszLineHeader,
  2905. IN DWORD dwLineLength
  2906. );
  2907. //
  2908. // Print related utilities
  2909. //
  2910. INT
  2911. Dns_WriteFormattedSystemTimeToBuffer(
  2912. OUT PCHAR pBuffer,
  2913. IN PSYSTEMTIME pSystemTime
  2914. );
  2915. INT
  2916. Dns_WritePacketNameToBuffer(
  2917. OUT PCHAR pBuffer,
  2918. OUT PCHAR * ppBufferOut,
  2919. IN PBYTE pMsgName,
  2920. IN PDNS_HEADER pMsgHead, OPTIONAL
  2921. IN PBYTE pMsgEnd OPTIONAL
  2922. );
  2923. PCHAR
  2924. Dns_ResponseCodeString(
  2925. IN INT ResponseCode
  2926. );
  2927. PCHAR
  2928. Dns_ResponseCodeExplanationString(
  2929. IN INT ResponseCode
  2930. );
  2931. PCHAR
  2932. Dns_KeyFlagString(
  2933. IN OUT PCHAR pszBuff,
  2934. IN WORD flags
  2935. );
  2936. PCHAR
  2937. Dns_OpcodeString(
  2938. IN INT Opcode
  2939. );
  2940. CHAR
  2941. Dns_OpcodeCharacter(
  2942. IN INT Opcode
  2943. );
  2944. PCHAR
  2945. Dns_SectionNameString(
  2946. IN INT iSection,
  2947. IN INT iOpcode
  2948. );
  2949. //
  2950. // Record printing (rrprint.c)
  2951. //
  2952. VOID
  2953. DnsPrint_Record(
  2954. IN PRINT_ROUTINE PrintRoutine,
  2955. IN OUT PPRINT_CONTEXT pContext,
  2956. IN PSTR pszHeader,
  2957. IN PDNS_RECORD pRecord,
  2958. IN PDNS_RECORD pPreviousRecord OPTIONAL
  2959. );
  2960. VOID
  2961. DnsPrint_RecordSet(
  2962. IN PRINT_ROUTINE PrintRoutine,
  2963. IN OUT PPRINT_CONTEXT pContext,
  2964. IN PSTR pszHeader,
  2965. IN PDNS_RECORD pRecord
  2966. );
  2967. //
  2968. // Macros to get correct string type (utf8\unicode) for printing.
  2969. //
  2970. // Empty string for simple switching of UTF-8/Unicode print
  2971. extern DWORD DnsEmptyString;
  2972. #define pDnsEmptyString ( (PSTR) &DnsEmptyString )
  2973. #define pDnsEmptyWideString ( (PWSTR) &DnsEmptyString )
  2974. #define DNSSTRING_UTF8( fUnicode, String ) \
  2975. ( (fUnicode) ? pDnsEmptyString : (PSTR)(String) )
  2976. #define DNSSTRING_ANSI( fUnicode, String ) \
  2977. ( (fUnicode) ? pDnsEmptyString : (PSTR)(String) )
  2978. #define DNSSTRING_WIDE( fUnicode, String ) \
  2979. ( (fUnicode) ? (PWSTR)(String) : pDnsEmptyWideString )
  2980. #define RECSTRING_UTF8( pRR, String ) \
  2981. DNSSTRING_UTF8( IS_UNICODE_RECORD(pRR), (String) )
  2982. #define RECSTRING_WIDE( pRR, String ) \
  2983. DNSSTRING_WIDE( IS_UNICODE_RECORD(pRR), (String) )
  2984. #define PRINT_STRING_WIDE_CHARSET( String, CharSet ) \
  2985. ( ((CharSet)==DnsCharSetUnicode) ? (PWSTR)(String) : pDnsEmptyWideString )
  2986. #define PRINT_STRING_ANSI_CHARSET( String, CharSet ) \
  2987. ( ((CharSet)==DnsCharSetUnicode) ? pDnsEmptyString : (PSTR)(String) )
  2988. //
  2989. // Debugging
  2990. //
  2991. // Debug routines.
  2992. //
  2993. VOID
  2994. Dns_StartDebugEx(
  2995. IN DWORD DebugFlag,
  2996. IN PSTR pszFlagFile,
  2997. IN OUT PDWORD pdwExternalFlag,
  2998. IN PSTR pszLogFile,
  2999. IN DWORD WrapSize,
  3000. IN BOOL fUseGlobalFile,
  3001. IN BOOL fUseGlobalFlag,
  3002. IN BOOL fSetGlobals
  3003. );
  3004. VOID
  3005. Dns_StartDebug(
  3006. IN DWORD DebugFlag,
  3007. IN PSTR pszFlagFile,
  3008. IN OUT PDWORD pdwExternalFlag,
  3009. IN PSTR pszLogFile,
  3010. IN DWORD WrapSize
  3011. );
  3012. VOID
  3013. Dns_EndDebug(
  3014. VOID
  3015. );
  3016. VOID
  3017. Dns_Assert(
  3018. IN PSTR pszFile,
  3019. IN INT LineNo,
  3020. IN PSTR pszExpr
  3021. );
  3022. VOID
  3023. DnsDbg_PrintfToDebugger(
  3024. IN PSTR Format,
  3025. ...
  3026. );
  3027. VOID
  3028. DnsDbg_Printf(
  3029. IN PSTR Format,
  3030. ...
  3031. );
  3032. VOID
  3033. DnsDbg_PrintRoutine(
  3034. IN OUT PPRINT_CONTEXT pContext,
  3035. IN PSTR Format,
  3036. ...
  3037. );
  3038. VOID
  3039. DnsDbg_Flush(
  3040. VOID
  3041. );
  3042. VOID
  3043. DnsDbg_WrapLogFile(
  3044. VOID
  3045. );
  3046. VOID
  3047. DnsDbg_CSEnter(
  3048. IN PCRITICAL_SECTION pLock,
  3049. IN PSTR pszLockName,
  3050. IN PSTR pszFile,
  3051. IN INT LineNo
  3052. );
  3053. VOID
  3054. DnsDbg_CSLeave(
  3055. IN PCRITICAL_SECTION pLock,
  3056. IN PSTR pszLockName,
  3057. IN PSTR pszFile,
  3058. IN INT LineNo
  3059. );
  3060. //
  3061. // Debug flag test
  3062. //
  3063. // We make the test against a pointer here which allows library
  3064. // client application to point at a flag that may be dynamically
  3065. // reset.
  3066. //
  3067. extern PDWORD pDnsDebugFlag;
  3068. #define IS_DNSDBG_ON(flag) (*pDnsDebugFlag & DNS_DBG_ ## flag)
  3069. //
  3070. // Debugging Bit Flags
  3071. //
  3072. // These flags control gross output and are the same for all users
  3073. //
  3074. #define DNS_DBG_BREAKPOINTS 0x00000001
  3075. #define DNS_DBG_DEBUGGER 0x00000002
  3076. #define DNS_DBG_FILE 0x00000004
  3077. #define DNS_DBG_EVENTLOG 0x00000008
  3078. #define DNS_DBG_EXCEPT 0x00000008
  3079. #define DNS_DBG_TIMESTAMP 0x10000000
  3080. #define DNS_DBG_CONSOLE 0x20000000
  3081. #define DNS_DBG_START_BREAK 0x40000000
  3082. #define DNS_DBG_FLUSH 0x80000000
  3083. #define DNS_DBG_ANY 0xffffffff
  3084. #define DNS_DBG_ALL 0xffffffff
  3085. #define DNS_DBG_OFF (0x0)
  3086. //
  3087. // Flags specific to library
  3088. //
  3089. #define DNS_DBG_IPARRAY 0x00000020
  3090. #define DNS_DBG_INIT 0x00000040
  3091. #define DNS_DBG_REGISTRY 0x00000040
  3092. #define DNS_DBG_SOCKET 0x00000040
  3093. #define DNS_DBG_WRITE 0x00000080
  3094. #define DNS_DBG_READ 0x00000080
  3095. #define DNS_DBG_RPC 0x00000100
  3096. #define DNS_DBG_STUB 0x00000100
  3097. #define DNS_DBG_RECV 0x00000200
  3098. #define DNS_DBG_SEND 0x00000400
  3099. #define DNS_DBG_TCP 0x00000800
  3100. #define DNS_DBG_TRACE 0x00001000
  3101. #define DNS_DBG_UPDATE 0x00002000
  3102. #define DNS_DBG_FAZ 0x00002000
  3103. #define DNS_DBG_SECURITY 0x00004000
  3104. #define DNS_DBG_QUERY 0x00008000
  3105. #define DNS_DBG_HEAP 0x00010000
  3106. #define DNS_DBG_HEAPDBG 0x00020000
  3107. #define DNS_DBG_NETINFO 0x00040000
  3108. #define DNS_DBG_RNR 0x00080000
  3109. #define DNS_DBG_HOSTENT 0x00080000
  3110. #define DNS_DBG_SABLOB 0x00080000
  3111. //
  3112. // High output detail debugging
  3113. //
  3114. #define DNS_DBG_RECURSE2 0x00100000
  3115. #define DNS_DBG_UPDATE2 0x00200000
  3116. #define DNS_DBG_SECURITY2 0x00400000
  3117. #define DNS_DBG_RPC2 0x01000000
  3118. #define DNS_DBG_STUB2 0x01000000
  3119. #define DNS_DBG_INIT2 0x01000000
  3120. #define DNS_DBG_NETINFO2 0x01000000
  3121. #define DNS_DBG_PARSE2 0x01000000
  3122. #define DNS_DBG_LOOKUP2 0x02000000
  3123. #define DNS_DBG_WRITE2 0x04000000
  3124. #define DNS_DBG_READ2 0x04000000
  3125. #define DNS_DBG_LOCK 0x08000000
  3126. #define DNS_DBG_LOCKS 0x08000000
  3127. #define DNS_DBG_STRING 0x10000000
  3128. #define DNS_DBG_HEAP2 0x10000000
  3129. #define DNS_DBG_HEAP_CHECK 0x10000000
  3130. //
  3131. // Debug macros
  3132. //
  3133. // Macros that include debug code in debug versions only,
  3134. // these macro are NULL for retail versions.
  3135. //
  3136. #if DBG
  3137. #define STATIC
  3138. #define DNS_PRINT(_a_) ( DnsDbg_Printf _a_ )
  3139. #define DnsPrintfPtrToFunc DnsDbg_PrintRoutine
  3140. #define IF_DNSDBG(flag) if ( IS_DNSDBG_ON(flag) )
  3141. #define ELSE_IF_DNSDBG(flag) else if ( IS_DNSDBG_ON(flag) )
  3142. #define ELSE else
  3143. #define DNSDBG(flag, _printlist_) \
  3144. IF_DNSDBG( flag ) \
  3145. { \
  3146. ( DnsDbg_Printf _printlist_ ); \
  3147. }
  3148. // protect debug prints with print lock
  3149. #define DnsDbg_Lock() DnsPrint_Lock()
  3150. #define DnsDbg_Unlock() DnsPrint_Unlock()
  3151. //
  3152. // Probe
  3153. //
  3154. #define PROBE(p) (*p)
  3155. //
  3156. // Assert Macros
  3157. //
  3158. #define DNS_ASSERT( expr ) \
  3159. { \
  3160. if ( !(expr) ) \
  3161. { \
  3162. Dns_Assert( __FILE__, __LINE__, # expr ); \
  3163. } \
  3164. }
  3165. #define TEST_ASSERT( expr ) DNS_ASSERT( expr )
  3166. #define FAIL( msg ) \
  3167. { \
  3168. DNS_PRINT(( "FAILURE: %s\n", msg )); \
  3169. DNS_ASSERT( FALSE ); \
  3170. }
  3171. //
  3172. // Asserts on trailing else
  3173. //
  3174. #define ELSE_ASSERT( expr ) \
  3175. else \
  3176. { \
  3177. DNS_ASSERT( expr ); \
  3178. }
  3179. #define ELSE_ASSERT_FALSE \
  3180. else \
  3181. { \
  3182. DNS_ASSERT( FALSE );\
  3183. }
  3184. #define ELSE_FAIL( msg ) \
  3185. else \
  3186. { \
  3187. FAIL( msg ); \
  3188. }
  3189. //
  3190. // Assert and print message
  3191. //
  3192. #define DNS_MSG_ASSERT( pMsg, expr ) \
  3193. { \
  3194. if ( !(expr) ) \
  3195. { \
  3196. debug_MessageBuffer( "FAILED MESSAGE:", (pMsg) ); \
  3197. Dns_Assert( __FILE__, __LINE__, # expr ); \
  3198. } \
  3199. }
  3200. //
  3201. // Debug types and structures
  3202. //
  3203. #define DnsPR DnsDbg_PrintRoutine
  3204. #define DnsDbg_String(a,b,c,d) DnsPrint_String(DnsPR,NULL,a,b,c,d)
  3205. #define DnsDbg_UnicodeStringBytes(a,b,c) DnsPrint_UnicodeStringBytes(DnsPR,NULL,a,b,c)
  3206. #define DnsDbg_Utf8StringBytes(a,b,c) DnsPrint_Utf8StringBytes(DnsPR,NULL,a,b,c)
  3207. #define DnsDbg_StringArray(a,b,c,d) DnsPrint_StringArray(DnsPR,NULL,a,b,c,d)
  3208. #define DnsDbg_Argv(a,b,c,d) DnsPrint_Argv(DnsPR,NULL,a,b,c,d)
  3209. #define DnsDbg_DwordArray(a,b,c,d) DnsPrint_DwordArray(DnsPR,NULL,a,b,c,d)
  3210. #define DnsDbg_Ip4AddressArray(a,b,c,d) DnsPrint_Ip4AddressArray(DnsPR,NULL,a,b,c,d)
  3211. #define DnsDbg_Ip4Array(a,b,c) DnsPrint_Ip4Array(DnsPR,NULL,a,b,c)
  3212. #define DnsDbg_Ip6Address(a,b,c) DnsPrint_Ip6Address(DnsPR,NULL,a,b,c)
  3213. #define DnsDbg_Ip6Array(a,b,c) DnsPrint_Ip6Array(DnsPR,NULL,a,b,c)
  3214. #define DnsDbg_Guid(a,b) DnsPrint_Guid(DnsPR,NULL,a,b)
  3215. #define DnsDbg_FdSet(a,b) DnsPrint_FdSet(DnsPR,NULL,a,b)
  3216. #define DnsDbg_Sockaddr(a,b,c) DnsPrint_Sockaddr(DnsPR,NULL,a,0,b,c)
  3217. #define DnsDbg_SocketAddress(a,b) DnsPrint_SocketAddress(DnsPR,NULL,a,0,b)
  3218. #define DnsDbg_CsAddr(a,b) DnsPrint_CsAddr(DnsPR,NULL,a,0,b)
  3219. #define DnsDbg_AfProtocolsArray(a,b,c) DnsPrint_AfProtocolsArray(DnsPR,NULL,a,b,c)
  3220. #define DnsDbg_WsaQuerySet(a,b,c) DnsPrint_WsaQuerySet(DnsPR,NULL,a,b,c)
  3221. #define DnsDbg_WsaNsClassInfo(a,b,c) DnsPrint_WsaNsClassInfo(DnsPR,NULL,a,b,c)
  3222. #define DnsDbg_WsaServiceClassInfo(a,b,c) DnsPrint_WsaServiceClassInfo(DnsPR,NULL,a,b,c)
  3223. #define DnsDbg_Hostent(a,b,c) DnsPrint_Hostent(DnsPR,NULL,a,b,c)
  3224. #define DnsDbg_AddrInfo(a,b) DnsPrint_AddrInfo(DnsPR,NULL,a,0,b)
  3225. #define DnsDbg_HostentBlob(a,b) DnsPrint_HostentBlob(DnsPR,NULL,a,b)
  3226. #define DnsDbg_SaBlob(a,b) DnsPrint_SaBlob(DnsPR,NULL,a,b)
  3227. #define DnsDbg_IpAdapterAddress(a,b,c,d) DnsPrint_IpAdapterAddress(DnsPR,NULL,a,b,c,d)
  3228. #define DnsDbg_IpAdapterList(a,b,c,d) DnsPrint_IpAdapterList(DnsPR,NULL,a,b,c,d)
  3229. #define DnsDbg_DnsAddrLine(a,b,c) DnsPrint_DnsAddrLine(DnsPR,NULL,a,b,c)
  3230. #define DnsDbg_DnsAddr(a,b) DnsPrint_DnsAddr(DnsPR,NULL,a,0,b)
  3231. #define DnsDbg_DnsAddrArray(a,b,c) DnsPrint_DnsAddrArray(DnsPR,NULL,a,b,c)
  3232. #define DnsDbg_DnsMessage(a,b) DnsPrint_DnsMessage(DnsPR,NULL,a,b)
  3233. #define DnsDbg_Message(a,b) DnsPrint_Message(DnsPR,NULL,a,b)
  3234. #define DnsDbg_MessageNoContext(a,b,c) DnsPrint_MessageNoContext(DnsPR,NULL,a,b,c)
  3235. #define DnsDbg_Compression(a,b) DnsPrint_Compression(DnsPR,NULL,a,b)
  3236. #define DnsDbg_PacketRecord(a,b,c,d) DnsPrint_PacketRecord(DnsPR,NULL,a,b,c,d)
  3237. #define DnsDbg_PacketName(a,b,c,d,e) DnsPrint_PacketName(DnsPR,NULL,a,b,c,d,e)
  3238. #define DnsDbg_ParsedMessage(a,b) DnsPrint_ParsedMessage(DnsPR,NULL,(a),(b))
  3239. #define DnsDbg_RawOctets(a,b,c,d) DnsPrint_RawOctets(DnsPR,NULL,a,b,c,d)
  3240. #define DnsDbg_Record(a,b) DnsPrint_Record(DnsPR,NULL,a,b,NULL)
  3241. #define DnsDbg_RecordSet(a,b) DnsPrint_RecordSet(DnsPR,NULL,a,b)
  3242. //
  3243. // Non-Debug
  3244. //
  3245. #else
  3246. #define STATIC static
  3247. //
  3248. // Define away debugging operations
  3249. //
  3250. #define IF_DNSDBG(a) if (0)
  3251. #define ELSE_IF_DNSDBG(a) if (0)
  3252. #define ELSE if (0)
  3253. #define DNSDBG(flag, _printlist_)
  3254. #define DNS_PRINT(_printlist_)
  3255. #define DnsDbg_Lock()
  3256. #define DnsDbg_Unlock()
  3257. #define DnsDbg_CSEnter(a,b,c,d)
  3258. #define DnsDbg_CSLeave(a,b,c,d)
  3259. #define DnsDbg_String(a,b,c,d)
  3260. #define DnsDbg_UnicodeStringBytes(a,b,c)
  3261. #define DnsDbg_Utf8StringBytes(a,b,c)
  3262. #define DnsDbg_DwordArray(a,b,c,d)
  3263. #define DnsDbg_StringArray(a,b,c,d)
  3264. #define DnsDbg_Argv(a,b,c,d)
  3265. #define DnsDbg_Ip4AddressArray(a,b,c,d)
  3266. #define DnsDbg_Ip4Array(a,b,c)
  3267. #define DnsDbg_Ip6Address(a,b,c)
  3268. #define DnsDbg_Ip6Array(a,b,c)
  3269. #define DnsDbg_Guid(a,b)
  3270. #define DnsDbg_FdSet(a,b)
  3271. #define DnsDbg_Sockaddr(a,b,c)
  3272. #define DnsDbg_SocketAddress(a,b)
  3273. #define DnsDbg_CsAddr(a,b)
  3274. #define DnsDbg_AfProtocolsArray(a,b,c)
  3275. #define DnsDbg_WsaQuerySet(a,b,c)
  3276. #define DnsDbg_WsaNsClassInfo(a,b,c)
  3277. #define DnsDbg_WsaServiceClassInfo(a,b,c)
  3278. #define DnsDbg_Hostent(a,b,c)
  3279. #define DnsDbg_AddrInfo(a,b)
  3280. #define DnsDbg_HostentBlob(a,b)
  3281. #define DnsDbg_SaBlob(a,b)
  3282. #define DnsDbg_IpAdapterAddress(a,b,c,d)
  3283. #define DnsDbg_IpAdapterList(a,b,c,d)
  3284. #define DnsDbg_DnsAddrLine(a,b,c)
  3285. #define DnsDbg_DnsAddr(a,b)
  3286. #define DnsDbg_DnsAddrArray(a,b,c)
  3287. #define DnsDbg_DnsMessage(a,b)
  3288. #define DnsDbg_Message(a,b)
  3289. #define DnsDbg_MessageNoContext(a,b,c)
  3290. #define DnsDbg_Compression(a,b)
  3291. #define DnsDbg_PacketRecord(a,b,c,d)
  3292. #define DnsDbg_PacketName(a,b,c,d,e)
  3293. #define DnsDbg_ParsedMessage(a,b)
  3294. #define DnsDbg_RawOctets(a,b,c,d)
  3295. #define DnsDbg_Record(a,b)
  3296. #define DnsDbg_RecordSet(a,b)
  3297. // backcompat special on sockaddr
  3298. #define DnsDbg_SockaddrIn(a,b,c)
  3299. //
  3300. // Handle complilation of DnsPrintf used as passed parameter to
  3301. // print routines
  3302. //
  3303. #define DnsPrintfPtrToFunc printf
  3304. //
  3305. // Eliminate ASSERTs in retail product
  3306. //
  3307. #define DNS_ASSERT( expr )
  3308. #define TEST_ASSERT( expr )
  3309. #define ELSE_ASSERT( expr )
  3310. #define ELSE_ASSERT_FALSE
  3311. #define DNS_MSG_ASSERT( expr, pMsg )
  3312. #define FAIL( msg )
  3313. #define ELSE_FAIL( msg )
  3314. #define PROBE(p)
  3315. #endif // non-DBG
  3316. #ifdef __cplusplus
  3317. }
  3318. #endif // __cplusplus
  3319. #endif // _DNSLIB_INCLUDED_