Source code of Windows XP (NT5)
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.

1435 lines
30 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. dnsapi.h
  5. Abstract:
  6. Domain Name System (DNS)
  7. DNS Client API Library
  8. Author:
  9. Jim Gilroy (jamesg) December 7, 1996
  10. Revision History:
  11. --*/
  12. #ifndef _DNSAPI_INCLUDED_
  13. #define _DNSAPI_INCLUDED_
  14. #ifndef _WINSOCK2API_
  15. #ifndef _WINSOCKAPI_
  16. #include <winsock2.h>
  17. #endif
  18. #endif
  19. #include <windns.h>
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif // __cplusplus
  24. //
  25. // do backward compat?
  26. //
  27. #define BACKCOMPAT 1
  28. //
  29. // DCR: add to winerror.h
  30. //
  31. #define DNS_ERROR_REFFERAL_PACKET 9506L
  32. //
  33. // NOTE: DO NOT USE these IP definitions.
  34. //
  35. // They are for backward compatibility only.
  36. // Use the definitions in windns.h instead.
  37. //
  38. //
  39. // IP Address
  40. //
  41. typedef IP4_ADDRESS IP_ADDRESS, *PIP_ADDRESS;
  42. #define SIZEOF_IP_ADDRESS (4)
  43. #define IP_ADDRESS_STRING_LENGTH (15)
  44. #define IP_STRING( IpAddress ) inet_ntoa( *(struct in_addr *)&(IpAddress) )
  45. //
  46. // IP Address Array type
  47. //
  48. typedef IP4_ARRAY IP_ARRAY, *PIP_ARRAY;
  49. //
  50. // IPv6 Address
  51. //
  52. // DCR: remove IPV6_ADDRESS when clean
  53. //
  54. typedef DNS_IP6_ADDRESS IPV6_ADDRESS, *PIPV6_ADDRESS;
  55. //
  56. // Byte flipping macros
  57. //
  58. #define FlipUnalignedDword( pDword ) \
  59. (DWORD)ntohl( *(UNALIGNED DWORD *)(pDword) )
  60. #define FlipUnalignedWord( pWord ) \
  61. (WORD)ntohs( *(UNALIGNED WORD *)(pWord) )
  62. // Inline is faster, but NO side effects allowed in marco argument
  63. #define InlineFlipUnaligned48Bits( pch ) \
  64. ( ( *(PUCHAR)(pch) << 40 ) | \
  65. ( *((PUCHAR)(pch) + 1) << 32 ) | \
  66. ( *((PUCHAR)(pch) + 2) << 24 ) | \
  67. ( *((PUCHAR)(pch) + 3) << 16 ) | \
  68. ( *((PUCHAR)(pch) + 4) << 8 ) | \
  69. ( *((PUCHAR)(pch) + 5) ) )
  70. #define InlineFlipUnalignedDword( pch ) \
  71. ( ( *(PUCHAR)(pch) << 24 ) | \
  72. ( *((PUCHAR)(pch) + 1) << 16 ) | \
  73. ( *((PUCHAR)(pch) + 2) << 8 ) | \
  74. ( *((PUCHAR)(pch) + 3) ) )
  75. #define InlineFlipUnalignedWord( pch ) \
  76. ( ((WORD)*((PUCHAR)(pch)) << 8) + (WORD)*((PUCHAR)(pch) + 1) )
  77. //
  78. // Unaligned write without flipping
  79. //
  80. #define WRITE_UNALIGNED_WORD( pout, word ) \
  81. ( *(UNALIGNED WORD *)(pout) = word )
  82. #define WRITE_UNALIGNED_DWORD( pout, dword ) \
  83. ( *(UNALIGNED DWORD *)(pout) = dword )
  84. //
  85. // Non-wrapping seconds timer (timer.c)
  86. //
  87. DWORD
  88. GetCurrentTimeInSeconds(
  89. VOID
  90. );
  91. //
  92. // General DNS utilities (dnsutil.c)
  93. //
  94. PSTR
  95. _fastcall
  96. DnsGetDomainName(
  97. IN PSTR pszName
  98. );
  99. PSTR
  100. _fastcall
  101. DnsStatusString(
  102. IN DNS_STATUS Status
  103. );
  104. #define DnsStatusToErrorString_A(status) DnsStatusString(status)
  105. DNS_STATUS
  106. _fastcall
  107. DnsMapRcodeToStatus(
  108. IN BYTE ResponseCode
  109. );
  110. BYTE
  111. _fastcall
  112. DnsIsStatusRcode(
  113. IN DNS_STATUS Status
  114. );
  115. //
  116. // Machines IP address list (iplist.c)
  117. //
  118. // Routine to get the current IP addresses from all adapters
  119. // configured for the machine.
  120. //
  121. DWORD
  122. DnsGetIpAddressList(
  123. OUT PIP_ARRAY * ppIpAddresses
  124. );
  125. //
  126. // Routine to get the current IP addresses and subnet masks
  127. // from all adapters configured for the machine.
  128. //
  129. typedef struct _DNS_ADDRESS_INFO_
  130. {
  131. IP_ADDRESS ipAddress;
  132. IP_ADDRESS subnetMask;
  133. }
  134. DNS_ADDRESS_INFO, *PDNS_ADDRESS_INFO;
  135. DWORD
  136. DnsGetIpAddressInfoList(
  137. OUT PDNS_ADDRESS_INFO * ppAddrInfo
  138. );
  139. //
  140. // Routines and structures for getting network configuration information
  141. // for TCPIP interfaces
  142. //
  143. #define NETINFO_FLAG_IS_WAN_ADAPTER (0x00000002)
  144. #define NETINFO_FLAG_IS_AUTONET_ADAPTER (0x00000004)
  145. #define NETINFO_FLAG_IS_DHCP_CFG_ADAPTER (0x00000008)
  146. #define NETINFO_FLAG_REG_ADAPTER_DOMAIN_NAME (0x00000010)
  147. #define NETINFO_FLAG_REG_ADAPTER_ADDRESSES (0x00000020)
  148. typedef struct
  149. {
  150. IP_ADDRESS ipAddress;
  151. DWORD Priority;
  152. }
  153. DNS_SERVER_INFORMATION, *PDNS_SERVER_INFORMATION;
  154. // backcompat
  155. #define NAME_SERVER_INFORMATION DNS_SERVER_INFORMATION
  156. #define PNAME_SERVER_INFORMATION PDNS_SERVER_INFORMATION
  157. typedef struct
  158. {
  159. PSTR pszAdapterGuidName;
  160. PSTR pszDomain;
  161. PIP_ARRAY pIPAddresses;
  162. PIP_ARRAY pIPSubnetMasks;
  163. DWORD InfoFlags;
  164. DWORD cServerCount;
  165. DNS_SERVER_INFORMATION aipServers[1];
  166. }
  167. DNS_ADAPTER_INFORMATION, *PDNS_ADAPTER_INFORMATION;
  168. // backcompat
  169. #define ADAPTER_INFORMATION DNS_ADAPTER_INFORMATION
  170. #define PADAPTER_INFORMATION PDNS_ADAPTER_INFORMATION
  171. typedef struct
  172. {
  173. PSTR pszPrimaryDomainName;
  174. DWORD cNameCount;
  175. PSTR aSearchListNames[1];
  176. }
  177. DNS_SEARCH_INFORMATION, *PDNS_SEARCH_INFORMATION;
  178. // backcompat
  179. #define SEARCH_INFORMATION DNS_SEARCH_INFORMATION
  180. #define PSEARCH_INFORMATION PDNS_SEARCH_INFORMATION
  181. typedef struct
  182. {
  183. PDNS_SEARCH_INFORMATION pSearchInformation;
  184. DWORD cAdapterCount;
  185. PDNS_ADAPTER_INFORMATION aAdapterInfoList[1];
  186. }
  187. DNS_NETWORK_INFORMATION, *PDNS_NETWORK_INFORMATION;
  188. // backcompat
  189. #define NETWORK_INFORMATION DNS_NETWORK_INFORMATION
  190. #define PNETWORK_INFORMATION PDNS_NETWORK_INFORMATION
  191. #if 0
  192. // these are replaced by the DnsQueryConfigAlloc()
  193. // and DnsFreeConfigStructure()
  194. PDNS_NETWORK_INFORMATION
  195. WINAPI
  196. DnsGetNetworkInformation(
  197. void
  198. );
  199. PDNS_SEARCH_INFORMATION
  200. WINAPI
  201. DnsGetSearchInformation(
  202. void
  203. );
  204. //
  205. // DCR: should expose only a single "type free" routine
  206. //
  207. VOID
  208. WINAPI
  209. DnsFreeAdapterInformation(
  210. IN PDNS_ADAPTER_INFORMATION pAdapterInformation
  211. );
  212. VOID
  213. WINAPI
  214. DnsFreeSearchInformation(
  215. IN PDNS_SEARCH_INFORMATION pSearchInformation
  216. );
  217. VOID
  218. WINAPI
  219. DnsFreeNetworkInformation(
  220. IN PDNS_NETWORK_INFORMATION pNetworkInformation
  221. );
  222. #endif
  223. //
  224. // Resource record type utilities (record.c)
  225. //
  226. BOOL
  227. _fastcall
  228. DnsIsAMailboxType(
  229. IN WORD wType
  230. );
  231. WORD
  232. DnsRecordTypeForName(
  233. IN PCHAR pszName,
  234. IN INT cchNameLength
  235. );
  236. PCHAR
  237. DnsRecordStringForType(
  238. IN WORD wType
  239. );
  240. PCHAR
  241. DnsRecordStringForWritableType(
  242. IN WORD wType
  243. );
  244. BOOL
  245. DnsIsStringCountValidForTextType(
  246. IN WORD wType,
  247. IN WORD StringCount
  248. );
  249. BOOL
  250. DnsIpv6StringToAddress(
  251. OUT PIP6_ADDRESS pAddress,
  252. IN PCHAR pchString,
  253. IN DWORD dwStringLength
  254. );
  255. VOID
  256. DnsIpv6AddressToString(
  257. OUT PCHAR pchString,
  258. IN PIP6_ADDRESS pAddress
  259. );
  260. //
  261. // Record building (rralloc.c)
  262. //
  263. PDNS_RECORD
  264. WINAPI
  265. DnsAllocateRecord(
  266. IN WORD wBufferLength
  267. );
  268. PDNS_RECORD
  269. DnsCreatePtrRecord(
  270. IN IP_ADDRESS IpAddress,
  271. IN LPTSTR pszHostName,
  272. IN BOOL fUnicodeName
  273. );
  274. //
  275. // Record build from data strings (rrbuild.c)
  276. //
  277. PDNS_RECORD
  278. DnsRecordBuild_UTF8(
  279. IN OUT PDNS_RRSET pRRSet,
  280. IN PSTR pszOwner,
  281. IN WORD wType,
  282. IN BOOL fAdd,
  283. IN UCHAR Section,
  284. IN INT Argc,
  285. IN PCHAR * Argv
  286. );
  287. PDNS_RECORD
  288. DnsRecordBuild_W(
  289. IN OUT PDNS_RRSET pRRSet,
  290. IN PWSTR pszOwner,
  291. IN WORD wType,
  292. IN BOOL fAdd,
  293. IN UCHAR Section,
  294. IN INT Argc,
  295. IN PWCHAR * Argv
  296. );
  297. //
  298. // Parsing
  299. //
  300. #ifdef PDNS_PARSED_MESSAGE
  301. #undef PDNS_PARSED_MESSAGE
  302. #endif
  303. typedef struct _DnsParseMessage
  304. {
  305. DNS_STATUS Status;
  306. DNS_CHARSET CharSet;
  307. DNS_HEADER Header;
  308. WORD QuestionType;
  309. WORD QuestionClass;
  310. PTSTR pQuestionName;
  311. PDNS_RECORD pAnswerRecords;
  312. PDNS_RECORD pAliasRecords;
  313. PDNS_RECORD pAuthorityRecords;
  314. PDNS_RECORD pAdditionalRecords;
  315. PDNS_RECORD pSigRecords;
  316. }
  317. DNS_PARSED_MESSAGE, *PDNS_PARSED_MESSAGE;
  318. #define DNS_PARSE_FLAG_NO_QUESTION (0x00000001)
  319. #define DNS_PARSE_FLAG_NO_ANSWER (0x00000002)
  320. #define DNS_PARSE_FLAG_NO_AUTHORITY (0x00000004)
  321. #define DNS_PARSE_FLAG_NO_ADDITIONAL (0x00000008)
  322. #define DNS_PARSE_FLAG_NO_SIG (0x00000100)
  323. #define DNS_PARSE_FLAG_NO_KEY (0x00000200)
  324. #define DNS_PARSE_FLAG_NO_DATA (0x0000030f)
  325. #define DNS_PARSE_FLAG_NO_RECORDS (0x0000030e)
  326. #define DNS_PARSE_FLAG_NO_DNSSEC (0x00000300)
  327. #define DNS_PARSE_FLAG_ONLY_QUESTION (0x01000000)
  328. #define DNS_PARSE_FLAG_RCODE_ALL (0x02000000)
  329. DNS_STATUS
  330. Dns_ParseMessage(
  331. OUT PDNS_PARSED_MESSAGE pParse,
  332. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  333. IN WORD wMessageLength,
  334. IN DWORD Flags,
  335. IN DNS_CHARSET CharSet
  336. );
  337. //
  338. // Query
  339. //
  340. //
  341. // Flags NOT in windns.h
  342. //
  343. #define DNS_QUERY_ACCEPT_PARTIAL_UDP DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE
  344. #define DNS_QUERY_MULTICAST_ONLY 0x00040000
  345. #define DNS_QUERY_USE_QUICK_TIMEOUTS 0x00080000
  346. // Exposed in Win2K SDK -- deprecated
  347. //#define DNS_QUERY_SOCKET_KEEPALIVE 0x00000100
  348. #define DNS_QUERY_ALLOW_EMPTY_AUTH_RESP 0x00010000
  349. //
  350. // Extended query
  351. //
  352. typedef struct _DnsQueryInfo
  353. {
  354. LPTSTR pName;
  355. WORD Type;
  356. WORD Rcode;
  357. DWORD Flags;
  358. DNS_STATUS Status;
  359. DNS_CHARSET CharSet;
  360. PDNS_RECORD pAnswerRecords;
  361. PDNS_RECORD pAliasRecords;
  362. PDNS_RECORD pAdditionalRecords;
  363. PDNS_RECORD pAuthorityRecords;
  364. HANDLE hEvent;
  365. PIP4_ARRAY pDnsServers;
  366. PVOID pMessage;
  367. PVOID pReservedName;
  368. }
  369. DNS_QUERY_INFO, *PDNS_QUERY_INFO;
  370. DNS_STATUS
  371. WINAPI
  372. DnsQueryExW(
  373. IN OUT PDNS_QUERY_INFO pQueryInfo
  374. );
  375. DNS_STATUS
  376. WINAPI
  377. DnsQueryExA(
  378. IN OUT PDNS_QUERY_INFO pQueryInfo
  379. );
  380. DNS_STATUS
  381. WINAPI
  382. DnsQueryExUTF8(
  383. IN OUT PDNS_QUERY_INFO pQueryInfo
  384. );
  385. #ifdef UNICODE
  386. #define DnsQueryEx DnsQueryExW
  387. #else
  388. #define DnsQueryEx DnsQueryExA
  389. #endif
  390. //
  391. // Options for DnsCheckNameCollision
  392. //
  393. #define DNS_CHECK_AGAINST_HOST_ANY 0x00000000
  394. #define DNS_CHECK_AGAINST_HOST_ADDRESS 0x00000001
  395. #define DNS_CHECK_AGAINST_HOST_DOMAIN_NAME 0x00000002
  396. DNS_STATUS WINAPI
  397. DnsCheckNameCollision_A(
  398. IN PCSTR pszName,
  399. IN DWORD fOptions
  400. );
  401. DNS_STATUS WINAPI
  402. DnsCheckNameCollision_UTF8(
  403. IN PCSTR pszName,
  404. IN DWORD fOptions
  405. );
  406. DNS_STATUS WINAPI
  407. DnsCheckNameCollision_W(
  408. IN PCWSTR pszName,
  409. IN DWORD fOptions
  410. );
  411. #ifdef UNICODE
  412. #define DnsDnsCheckNameCollision DnsCheckNameCollision_W
  413. #else
  414. #define DnsDnsCheckNameCollision DnsCheckNameCollision_A
  415. #endif
  416. //
  417. // DNS Update API
  418. //
  419. // DnsAcquireContextHandle
  420. // DnsReleaseContextHandle
  421. // DnsModifyRecordsInSet
  422. // DnsReplaceRecordSet
  423. //
  424. //
  425. // Update flags NOT in windns.h
  426. //
  427. #define DNS_UPDATE_SECURITY_CHOICE_MASK 0x000001ff
  428. DNS_STATUS
  429. WINAPI
  430. DnsUpdateTest_A(
  431. IN HANDLE hContextHandle OPTIONAL,
  432. IN PCSTR pszName,
  433. IN DWORD fOptions,
  434. IN PIP_ARRAY aipServers OPTIONAL
  435. );
  436. DNS_STATUS
  437. WINAPI
  438. DnsUpdateTest_UTF8(
  439. IN HANDLE hContextHandle OPTIONAL,
  440. IN PCSTR pszName,
  441. IN DWORD fOptions,
  442. IN PIP_ARRAY aipServers OPTIONAL
  443. );
  444. DNS_STATUS
  445. WINAPI
  446. DnsUpdateTest_W(
  447. IN HANDLE hContextHandle OPTIONAL,
  448. IN PCWSTR pszName,
  449. IN DWORD fOptions,
  450. IN PIP_ARRAY aipServers OPTIONAL
  451. );
  452. #ifdef UNICODE
  453. #define DnsUpdateTest DnsUpdateTest_W
  454. #else
  455. #define DnsUpdateTest DnsUpdateTest_A
  456. #endif
  457. IP_ADDRESS
  458. WINAPI
  459. DnsGetLastServerUpdateIP(
  460. VOID
  461. );
  462. typedef struct _DnsFailedUpdateInfo
  463. {
  464. IP4_ADDRESS Ip4Address;
  465. IP6_ADDRESS Ip6Address;
  466. DNS_STATUS Status;
  467. DWORD Rcode;
  468. }
  469. DNS_FAILED_UPDATE_INFO, *PDNS_FAILED_UPDATE_INFO;
  470. VOID
  471. DnsGetLastFailedUpdateInfo(
  472. OUT PDNS_FAILED_UPDATE_INFO pInfo
  473. );
  474. //
  475. // DNS Update API for DHCP client
  476. //
  477. typedef struct _REGISTER_HOST_ENTRY
  478. {
  479. union
  480. {
  481. IP_ADDRESS ipAddr;
  482. IPV6_ADDRESS ipV6Addr;
  483. } Addr;
  484. DWORD dwOptions;
  485. }
  486. REGISTER_HOST_ENTRY, *PREGISTER_HOST_ENTRY;
  487. //
  488. // Options for above
  489. //
  490. #define REGISTER_HOST_A 0x00000001
  491. #define REGISTER_HOST_PTR 0x00000002
  492. #define REGISTER_HOST_AAAA 0x00000008
  493. #define REGISTER_HOST_RESERVED 0x80000000 // Not used
  494. //
  495. // DNS DHCP Client registration flags
  496. //
  497. #define DYNDNS_REG_FWD 0x0
  498. #define DYNDNS_REG_PTR 0x8
  499. #define DYNDNS_REG_RAS 0x10
  500. #define DYNDNS_DEL_ENTRY 0x20
  501. typedef struct _REGISTER_HOST_STATUS
  502. {
  503. HANDLE hDoneEvent;
  504. DWORD dwStatus;
  505. }
  506. REGISTER_HOST_STATUS, *PREGISTER_HOST_STATUS;
  507. DNS_STATUS
  508. WINAPI
  509. DnsAsyncRegisterInit(
  510. PSTR lpstrRootRegKey
  511. );
  512. DNS_STATUS
  513. WINAPI
  514. DnsAsyncRegisterTerm(
  515. VOID
  516. );
  517. DNS_STATUS WINAPI
  518. DnsRemoveRegistrations(
  519. VOID
  520. );
  521. DNS_STATUS
  522. WINAPI
  523. DnsAsyncRegisterHostAddrs(
  524. IN PWSTR pwsAdapterName,
  525. IN PWSTR pwsHostName,
  526. IN PREGISTER_HOST_ENTRY pHostAddrs,
  527. IN DWORD dwHostAddrCount,
  528. IN PIP_ADDRESS pipDnsServerList,
  529. IN DWORD dwDnsServerCount,
  530. IN PWSTR pwsDomainName,
  531. IN PREGISTER_HOST_STATUS pRegisterStatus,
  532. IN DWORD dwTTL,
  533. IN DWORD dwFlags
  534. );
  535. #define DnsAsyncRegisterHostAddrs_W DnsAsyncRegisterHostAddrs
  536. //
  537. // DNS Update API for DHCP server.
  538. //
  539. //
  540. // Call back function. DHCP Server will pass a function to
  541. // DnsDhcpRegisterHostName and this will be called on successful
  542. // or unsuccessful completion of the task
  543. // If we have a condition like server down/try again later etc we
  544. // won't respond until we have an authoritative answer.
  545. //
  546. typedef VOID(*DHCP_CALLBACK_FN)(DWORD dwStatus, LPVOID pvData);
  547. //
  548. // Callback return codes
  549. //
  550. #define DNSDHCP_SUCCESS 0x0
  551. #define DNSDHCP_FWD_FAILED 0x1
  552. #define DNSDHCP_SUPERCEDED 0x2
  553. #define DNSDHCP_FAILURE (DWORD)-1 //reverse failed
  554. //
  555. // DNS DHCP Server registration function flags
  556. //
  557. #define DYNDNS_DELETE_ENTRY 0x1
  558. #define DYNDNS_ADD_ENTRY 0x2
  559. #define DYNDNS_REG_FORWARD 0x4
  560. typedef struct _DnsCredentials
  561. {
  562. PWSTR pUserName;
  563. PWSTR pDomain;
  564. PWSTR pPassword;
  565. }
  566. DNS_CREDENTIALS, *PDNS_CREDENTIALS;
  567. DNS_STATUS
  568. WINAPI
  569. DnsDhcpSrvRegisterInit(
  570. VOID
  571. );
  572. DNS_STATUS
  573. WINAPI
  574. DnsDhcpSrvRegisterInitialize(
  575. IN PDNS_CREDENTIALS pCredentials
  576. );
  577. DNS_STATUS
  578. WINAPI
  579. DnsDhcpSrvRegisterTerm(
  580. VOID
  581. );
  582. DNS_STATUS
  583. WINAPI
  584. DnsDhcpSrvRegisterHostName(
  585. IN REGISTER_HOST_ENTRY HostAddr,
  586. IN PWSTR pwsName,
  587. IN DWORD dwTTL,
  588. IN DWORD dwFlags,
  589. IN DHCP_CALLBACK_FN pfnDhcpCallBack,
  590. IN PVOID pvData,
  591. IN PIP_ADDRESS pipDnsServerList OPTIONAL,
  592. IN DWORD dwDnsServerCount
  593. );
  594. #define RETRY_TIME_SERVER_FAILURE 5*60 // 5 minutes
  595. #define RETRY_TIME_TRY_AGAIN_LATER 5*60 // 5 minutes
  596. #define RETRY_TIME_TIMEOUT 5*60 // 5 minutes
  597. #define RETRY_TIME_MAX 10*60 // back off to 10 mins if
  598. // repeated failures occur
  599. #define DnsDhcpSrvRegisterHostName_W DnsDhcpSrvRegisterHostName
  600. //
  601. // Memory allocation
  602. //
  603. // Many dnsapi.dll routines allocate memory.
  604. // This memory allocation defaults to routines that use:
  605. // - LocalAlloc,
  606. // - LocalReAlloc,
  607. // - LocalFree.
  608. // If you desire alternative memory allocation mechanisms, use this
  609. // function to override the DNS API defaults. All memory returned by dnsapi.dll
  610. // can then be freed with the specified free function.
  611. //
  612. typedef PVOID (* DNS_ALLOC_FUNCTION)();
  613. typedef PVOID (* DNS_REALLOC_FUNCTION)();
  614. typedef VOID (* DNS_FREE_FUNCTION)();
  615. VOID
  616. DnsApiHeapReset(
  617. IN DNS_ALLOC_FUNCTION pAlloc,
  618. IN DNS_REALLOC_FUNCTION pRealloc,
  619. IN DNS_FREE_FUNCTION pFree
  620. );
  621. //
  622. // Modules using DNSAPI memory should use these routines if
  623. // they are capable of being called by a process that resets
  624. // the dnsapi.dll heap. (Example: the DNS server.)
  625. //
  626. PVOID
  627. DnsApiAlloc(
  628. IN INT iSize
  629. );
  630. PVOID
  631. DnsApiRealloc(
  632. IN OUT PVOID pMem,
  633. IN INT iSize
  634. );
  635. VOID
  636. DnsApiFree(
  637. IN OUT PVOID pMem
  638. );
  639. //
  640. // String utilities (string.c)
  641. //
  642. // Note some of these require memory allocation, see note
  643. // on memory allocation below.
  644. //
  645. PSTR
  646. DnsCreateStringCopy(
  647. IN PCHAR pchString,
  648. IN DWORD cchString
  649. );
  650. DWORD
  651. DnsGetBufferLengthForStringCopy(
  652. IN PCHAR pchString,
  653. IN DWORD cchString,
  654. IN BOOL fUnicodeIn,
  655. IN BOOL fUnicodeOut
  656. );
  657. PVOID
  658. DnsCopyStringEx(
  659. OUT PBYTE pBuffer,
  660. IN PCHAR pchString,
  661. IN DWORD cchString,
  662. IN BOOL fUnicodeIn,
  663. IN BOOL fUnicodeOut
  664. );
  665. PVOID
  666. DnsStringCopyAllocateEx(
  667. IN PCHAR pchString,
  668. IN DWORD cchString,
  669. IN BOOL fUnicodeIn,
  670. IN BOOL fUnicodeOut
  671. );
  672. DWORD
  673. DnsNameCopy(
  674. OUT PBYTE pBuffer,
  675. IN OUT PDWORD pdwBufLength,
  676. IN PCHAR pchString,
  677. IN DWORD cchString,
  678. IN DNS_CHARSET CharSetIn,
  679. IN DNS_CHARSET CharSetOut
  680. );
  681. PVOID
  682. DnsNameCopyAllocate(
  683. IN PCHAR pchString,
  684. IN DWORD cchString,
  685. IN DNS_CHARSET CharSetIn,
  686. IN DNS_CHARSET CharSetOut
  687. );
  688. PCHAR
  689. DnsWriteReverseNameStringForIpAddress(
  690. OUT PCHAR pBuffer,
  691. IN IP_ADDRESS ipAddress
  692. );
  693. PCHAR
  694. DnsCreateReverseNameStringForIpAddress(
  695. IN IP_ADDRESS ipAddress
  696. );
  697. //
  698. // Name validation
  699. //
  700. // Routines are in windns.h
  701. //
  702. //
  703. // Macro away old routines
  704. //
  705. #define DnsValidateDnsName_UTF8(pname) \
  706. DnsValidateName_UTF8( (pname), DnsNameDomain )
  707. #define DnsValidateDnsName_W(pname) \
  708. DnsValidateName_W( (pname), DnsNameDomain )
  709. //
  710. // Name checking -- server name checking levels
  711. //
  712. // DCR_CLEANUP: server name checking levels move to dnsrpc.h?
  713. // but server will need to convert to some flag
  714. // ammenable to downcase\validate routine
  715. //
  716. // DCR: server name checking: perhaps lay out additional detail now?
  717. // or limit to RFC, MS-extended, ALL-binary
  718. //
  719. // DCR: server name checking: perhaps convert to enum type;
  720. // I don't think we should do bitfields here, rather
  721. // have enum type map to bitfields if that's the best
  722. // way to implement underlying check.
  723. //
  724. #define DNS_ALLOW_RFC_NAMES_ONLY (0)
  725. #define DNS_ALLOW_NONRFC_NAMES (1)
  726. #define DNS_ALLOW_MULTIBYTE_NAMES (2)
  727. #define DNS_ALLOW_ALL_NAMES (3)
  728. //
  729. // DNS Name compare
  730. //
  731. // ANSI and unicode names compare routines are in windns.h.
  732. //
  733. BOOL
  734. WINAPI
  735. DnsNameCompare_UTF8(
  736. IN PSTR pName1,
  737. IN PSTR pName2
  738. );
  739. //
  740. // Extended name compare
  741. // Includes determination of name heirarchy.
  742. //
  743. // Note: once sort out RelationalCompare issue,
  744. // better to make Equal == 0;
  745. // this simplifies macroing regular NameCompare
  746. // into a single function;
  747. //
  748. typedef enum _DnsNameCompareStatus
  749. {
  750. DnsNameCompareNotEqual,
  751. DnsNameCompareEqual,
  752. DnsNameCompareLeftParent,
  753. DnsNameCompareRightParent,
  754. DnsNameCompareInvalid
  755. }
  756. DNS_NAME_COMPARE_STATUS, *PDNS_NAME_COMPARE_STATUS;
  757. DNS_NAME_COMPARE_STATUS
  758. DnsNameCompareEx_W(
  759. IN LPCWSTR pszLeftName,
  760. IN LPCWSTR pszRightName,
  761. IN DWORD dwReserved
  762. );
  763. DNS_NAME_COMPARE_STATUS
  764. DnsNameCompareEx_A(
  765. IN LPCSTR pszLeftName,
  766. IN LPCSTR pszRightName,
  767. IN DWORD dwReserved
  768. );
  769. DNS_NAME_COMPARE_STATUS
  770. DnsNameCompareEx_UTF8(
  771. IN LPCSTR pszLeftName,
  772. IN LPCSTR pszRightName,
  773. IN DWORD dwReserved
  774. );
  775. //
  776. // Other string routines
  777. //
  778. DNS_STATUS
  779. DnsValidateDnsString_UTF8(
  780. IN LPCSTR pszName
  781. );
  782. DNS_STATUS
  783. DnsValidateDnsString_W(
  784. IN LPCWSTR pszName
  785. );
  786. PSTR
  787. DnsCreateStandardDnsNameCopy(
  788. IN PCHAR pchName,
  789. IN DWORD cchName,
  790. IN DWORD dwFlag
  791. );
  792. DWORD
  793. DnsDowncaseDnsNameLabel(
  794. OUT PCHAR pchResult,
  795. IN PCHAR pchLabel,
  796. IN DWORD cchLabel,
  797. IN DWORD dwFlags
  798. );
  799. DWORD
  800. _fastcall
  801. DnsUnicodeToUtf8(
  802. IN PWCHAR pwUnicode,
  803. IN DWORD cchUnicode,
  804. OUT PCHAR pchResult,
  805. IN DWORD cchResult
  806. );
  807. DWORD
  808. _fastcall
  809. DnsUtf8ToUnicode(
  810. IN PCHAR pchUtf8,
  811. IN DWORD cchUtf8,
  812. OUT PWCHAR pwResult,
  813. IN DWORD cwResult
  814. );
  815. DNS_STATUS
  816. DnsValidateUtf8Byte(
  817. IN BYTE chUtf8,
  818. IN OUT PDWORD pdwTrailCount
  819. );
  820. //
  821. // Service control
  822. //
  823. //
  824. // DNS server startup service control event.
  825. //
  826. // Services (ex. netlogon) that want notification of DNS server start
  827. // need to register to get notification of this user defined control code.
  828. //
  829. #define SERVICE_CONTROL_DNS_SERVER_START (200)
  830. //
  831. // Resolver service
  832. //
  833. // General "wake-up-something-has-changed" call.
  834. // This was put in for cluster team to alert us to plumbing new
  835. // addresses. Later we will move to model of picking up
  836. // these changes ourselves.
  837. //
  838. VOID
  839. DnsNotifyResolver(
  840. IN DWORD Flag,
  841. IN PVOID pReserved
  842. );
  843. VOID
  844. DnsNotifyResolverEx(
  845. IN DWORD Id,
  846. IN DWORD Flag,
  847. IN DWORD Cookie,
  848. IN PVOID pReserved
  849. );
  850. //
  851. // Cluster mappings
  852. //
  853. #define DNS_CLUSTER_ADD (0)
  854. #define DNS_CLUSTER_DELETE_NAME (1)
  855. #define DNS_CLUSTER_DELETE_IP (2)
  856. DNS_STATUS
  857. DnsRegisterClusterAddress(
  858. IN DWORD Tag,
  859. IN PWSTR pwsName,
  860. IN PSOCKADDR pSockaddr,
  861. IN DWORD Flag
  862. );
  863. // Remove once cluster upgraded
  864. VOID
  865. DnsNotifyResolverClusterIp(
  866. IN IP_ADDRESS ClusterIp,
  867. IN BOOL fAdd
  868. );
  869. //
  870. // Routines to clear all cached entries in the DNS Resolver Cache, this is
  871. // called by ipconfig /flushdns, and add record sets to the cache.
  872. //
  873. BOOL WINAPI
  874. DnsFlushResolverCache(
  875. VOID
  876. );
  877. BOOL WINAPI
  878. DnsFlushResolverCacheEntry_W(
  879. IN PWSTR pszName
  880. );
  881. BOOL WINAPI
  882. DnsFlushResolverCacheEntry_UTF8(
  883. IN PSTR pszName
  884. );
  885. BOOL WINAPI
  886. DnsFlushResolverCacheEntry_A(
  887. IN PSTR pszName
  888. );
  889. #ifdef UNICODE
  890. #define DnsFlushResolverCacheEntry DnsFlushResolverCacheEntry_W
  891. #else
  892. #define DnsFlushResolverCacheEntry DnsFlushResolverCacheEntry_A
  893. #endif
  894. DNS_STATUS WINAPI
  895. DnsCacheRecordSet_W(
  896. IN PWSTR lpstrName,
  897. IN WORD wType,
  898. IN DWORD fOptions,
  899. IN OUT PDNS_RECORD pRRSet
  900. );
  901. //
  902. // DO NOT USE!!! -- This is weak, i just haven't tested the replacement yet.
  903. //
  904. // Routine to read the contents of the DNS Resolver Cache. The resulting
  905. // table contains a list of record names and types stored in the cache.
  906. // Each of these name/type records can be queried with DnsQuery with the
  907. // option DNS_QUERY_CACHE_ONLY.
  908. //
  909. // Note: this is used in ipconfig for /displaydns. Can not pull until fixed.
  910. //
  911. typedef struct _DNS_CACHE_TABLE_
  912. {
  913. struct _DNS_CACHE_TABLE_ * pNext;
  914. PWSTR Name;
  915. WORD Type1;
  916. WORD Type2;
  917. WORD Type3;
  918. }
  919. DNS_CACHE_TABLE, *PDNS_CACHE_TABLE;
  920. BOOL
  921. WINAPI
  922. DnsGetCacheDataTable(
  923. OUT PDNS_CACHE_TABLE * pTable
  924. );
  925. //
  926. // Config info
  927. //
  928. //
  929. // Alloc flag types for DnsQueryConfig()
  930. //
  931. // DCR: move to windns.h if supported
  932. //
  933. #define DNS_CONFIG_FLAG_LOCAL_ALLOC (DNS_CONFIG_FLAG_ALLOC)
  934. #define DNS_CONFIG_FLAG_DNSAPI_ALLOC (DNS_CONFIG_FLAG_ALLOC+1)
  935. //
  936. // System public config -- not available in SDK
  937. // This is stuff for
  938. // - config UI
  939. // - ipconfig
  940. // - test code
  941. //
  942. #define DnsConfigSystemBase ((DNS_CONFIG_TYPE) 0x00010000)
  943. #define DnsConfigNetworkInformation ((DNS_CONFIG_TYPE) 0x00010001)
  944. #define DnsConfigAdapterInformation ((DNS_CONFIG_TYPE) 0x00010002)
  945. #define DnsConfigSearchInformation ((DNS_CONFIG_TYPE) 0x00010003)
  946. #define DnsConfigIp4AddressArray ((DNS_CONFIG_TYPE) 0x00010004)
  947. #define DnsConfigRegistrationEnabled ((DNS_CONFIG_TYPE) 0x00010010)
  948. #define DnsConfigWaitForNameErrorOnAll ((DNS_CONFIG_TYPE) 0x00010011)
  949. // these completely backpat -- shouldn't even be public
  950. #define DnsConfigNetInfo ((DNS_CONFIG_TYPE) 0x00020001)
  951. PVOID
  952. WINAPI
  953. DnsQueryConfigAllocEx(
  954. IN DNS_CONFIG_TYPE Config,
  955. IN PWSTR pwsAdapterName,
  956. IN BOOL fLocalAlloc
  957. );
  958. // Desired routine has dnsapi.dll alloc
  959. #define DnsQueryConfigAlloc( Id, pAN ) \
  960. DnsQueryConfigAllocEx( Id, pAN, FALSE )
  961. VOID
  962. WINAPI
  963. DnsFreeConfigStructure(
  964. IN OUT PVOID pData,
  965. IN DNS_CONFIG_TYPE ConfigId
  966. );
  967. //
  968. // DWORD config get\set
  969. //
  970. DWORD
  971. WINAPI
  972. DnsQueryConfigDword(
  973. IN DNS_CONFIG_TYPE Config,
  974. IN PWSTR pwsAdapterName
  975. );
  976. DNS_STATUS
  977. WINAPI
  978. DnsSetConfigDword(
  979. IN DNS_CONFIG_TYPE Config,
  980. IN PWSTR pwsAdapterName,
  981. IN DWORD NewValue
  982. );
  983. //
  984. // Macro old routines
  985. // - system-public config allocator
  986. // - global free routine
  987. // - these were structure allocs so were not being freed with LocalFree
  988. //
  989. #ifdef BACKCOMPAT
  990. #define DnsGetNetworkInformation() DnsQueryConfigAlloc( DnsConfigNetworkInformation, NULL )
  991. #define DnsGetSearchInformation() DnsQueryConfigAlloc( DnsConfigSearchInformation, NULL )
  992. #define Dns_GetDnsNetworkInfo(f,g) DnsQueryConfigAlloc( DnsConfigNetInfo, NULL )
  993. #define DnsFreeNetworkInformation(p) DnsFreeConfigStructure( p, DnsConfigNetworkInformation )
  994. #define DnsFreeSearchInformation(p) DnsFreeConfigStructure( p, DnsConfigSearchInformation )
  995. #define DnsFreeAdapterInformation(p) DnsFreeConfigStructure( p, DnsConfigAdapterInformation )
  996. #define Dns_FreeNetworkInfo(p) DnsFreeConfigStructure( p, DnsConfigNetInfo )
  997. //
  998. // Macro old config string allocating routines
  999. // - no adapter name
  1000. // - allocating from dnsapi heap as main caller -- RnR -- seems to be
  1001. // using DnsApiFree
  1002. //
  1003. #define BackpatAlloc( Id ) DnsQueryConfigAllocEx( Id, NULL, FALSE )
  1004. // Public structures
  1005. #define DnsGetHostName_A() BackpatAlloc( DnsConfigHostName_A )
  1006. #define DnsGetHostName_UTF8() BackpatAlloc( DnsConfigHostName_UTF8 )
  1007. #define DnsGetHostName_W() ((PWSTR)BackpatAlloc( DnsConfigHostName_W ))
  1008. #ifdef UNICODE
  1009. #define DnsGetHostName DnsGetHostName_W
  1010. #else
  1011. #define DnsGetHostName DnsGetHostName_A
  1012. #endif
  1013. #define DnsGetPrimaryDomainName_A() BackpatAlloc( DnsConfigPrimaryDomainName_A )
  1014. #define DnsGetPrimaryDomainName_UTF8() BackpatAlloc( DnsConfigPrimaryDomainName_UTF8 )
  1015. #define DnsGetPrimaryDomainName_W() ((PWSTR)BackpatAlloc( DnsConfigPrimaryDomainName_W ))
  1016. #ifdef UNICODE
  1017. #define DnsGetPrimaryDomainName DnsGetPrimaryDomainName_W
  1018. #else
  1019. #define DnsGetPrimaryDomainName DnsGetPrimaryDomainName_A
  1020. #endif
  1021. //
  1022. // DWORD get\set backcompat
  1023. //
  1024. //
  1025. // DCR: there is a possible problem with these mappings handles generic\adapter
  1026. // difference -- not sure the mapping is complete
  1027. // may need switches -- see which are even in use with BACKCOMPAT off
  1028. //
  1029. #define DnsIsDynamicRegistrationEnabled(pA) \
  1030. (BOOL)DnsQueryConfigDword( DnsConfigRegistrationEnabled, (pA) )
  1031. #define DnsIsAdapterDomainNameRegistrationEnabled(pA) \
  1032. (BOOL)DnsQueryConfigDword( DnsConfigAdapterHostNameRegistrationEnabled, (pA) )
  1033. #define DnsGetMaxNumberOfAddressesToRegister(pA) \
  1034. DnsQueryConfigDword( DnsConfigAddressRegistrationMaxCount, (pA) )
  1035. // DWORD reg value set
  1036. #define DnsEnableDynamicRegistration(pA) \
  1037. DnsSetConfigDword( DnsConfigRegistrationEnabled, pA, (DWORD)TRUE )
  1038. #define DnsDisableDynamicRegistration(pA) \
  1039. DnsSetConfigDword( DnsConfigRegistrationEnabled, pA, (DWORD)FALSE )
  1040. #define DnsEnableAdapterDomainNameRegistration(pA) \
  1041. DnsSetConfigDword( DnsConfigAdapterHostNameRegistrationEnabled, pA, (DWORD)TRUE )
  1042. #define DnsDisableAdapterDomainNameRegistration(pA) \
  1043. DnsSetConfigDword( DnsConfigAdapterHostNameRegistrationEnabled, pA, (DWORD)FALSE )
  1044. #define DnsSetMaxNumberOfAddressesToRegister(pA, MaxCount) \
  1045. (NO_ERROR == DnsSetConfigDword( DnsConfigAddressRegistrationMaxCount, pA, MaxCount ))
  1046. //
  1047. // DNS server list backcompat
  1048. //
  1049. #define Dns_GetDnsServerList(flag) ((PIP4_ARRAY)BackpatAlloc( DnsConfigDnsServerList ))
  1050. #ifndef MIDL_PASS
  1051. __inline
  1052. DWORD
  1053. inline_DnsGetDnsServerList(
  1054. OUT PIP4_ARRAY * ppDnsArray
  1055. )
  1056. {
  1057. *ppDnsArray = Dns_GetDnsServerList( TRUE );
  1058. return ( *ppDnsArray ? (*ppDnsArray)->AddrCount : 0 );
  1059. }
  1060. #endif // MIDL
  1061. #define DnsGetDnsServerList(p) inline_DnsGetDnsServerList(p)
  1062. //
  1063. // IP list backcompat
  1064. //
  1065. #ifndef MIDL_PASS
  1066. __inline
  1067. DWORD
  1068. inline_DnsGetIpAddressList(
  1069. OUT PIP4_ARRAY * ppIpArray
  1070. )
  1071. {
  1072. *ppIpArray = (PIP4_ARRAY) BackpatAlloc( DnsConfigIp4AddressArray );
  1073. return( *ppIpArray ? (*ppIpArray)->AddrCount : 0 );
  1074. }
  1075. #endif // MIDL
  1076. #define DnsGetIpAddressList(p) inline_DnsGetIpAddressList(p)
  1077. //
  1078. // For netdiag
  1079. //
  1080. #define Dns_IsUpdateNetworkInfo(pni) NetInfo_IsForUpdate( pni )
  1081. //
  1082. // DO NOT USE!!!!
  1083. //
  1084. // This is backward compatibility only.
  1085. // I've switched the DCPromo stuff. Need to verify with clean system
  1086. // build that it's completely gone, then pull.
  1087. //
  1088. #ifdef BACKCOMPAT
  1089. #define DNS_RELATE_NEQ DnsNameCompareNotEqual
  1090. #define DNS_RELATE_EQL DnsNameCompareEqual
  1091. #define DNS_RELATE_LGT DnsNameCompareLeftParent
  1092. #define DNS_RELATE_RGT DnsNameCompareRightParent
  1093. #define DNS_RELATE_INVALID DnsNameCompareInvalid
  1094. typedef DNS_NAME_COMPARE_STATUS DNS_RELATE_STATUS, *PDNS_RELATE_STATUS;
  1095. #endif
  1096. #endif // BACKCOMPAT
  1097. #ifdef __cplusplus
  1098. }
  1099. #endif // __cplusplus
  1100. #endif // _DNSAPI_INCLUDED_