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.

888 lines
15 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. export.c
  5. Abstract:
  6. Domain Name System (DNS) API
  7. Covering functions for exported routines that are actually in
  8. dnslib.lib.
  9. Author:
  10. Jim Gilroy (jamesg) November, 1997
  11. Environment:
  12. User Mode - Win32
  13. Revision History:
  14. --*/
  15. #include "local.h"
  16. //
  17. // SDK routines
  18. //
  19. //
  20. // Name comparison
  21. //
  22. BOOL
  23. WINAPI
  24. DnsNameCompare_A(
  25. IN LPSTR pName1,
  26. IN LPSTR pName2
  27. )
  28. {
  29. return Dns_NameCompare_A( pName1, pName2 );
  30. }
  31. BOOL
  32. WINAPI
  33. DnsNameCompare_UTF8(
  34. IN LPSTR pName1,
  35. IN LPSTR pName2
  36. )
  37. {
  38. return Dns_NameCompare_UTF8( pName1, pName2 );
  39. }
  40. BOOL
  41. WINAPI
  42. DnsNameCompare_W(
  43. IN LPWSTR pName1,
  44. IN LPWSTR pName2
  45. )
  46. {
  47. return Dns_NameCompare_W( pName1, pName2 );
  48. }
  49. DNS_NAME_COMPARE_STATUS
  50. DnsNameCompareEx_A(
  51. IN LPCSTR pszLeftName,
  52. IN LPCSTR pszRightName,
  53. IN DWORD dwReserved
  54. )
  55. {
  56. return Dns_NameCompareEx(
  57. pszLeftName,
  58. pszRightName,
  59. dwReserved,
  60. DnsCharSetAnsi );
  61. }
  62. DNS_NAME_COMPARE_STATUS
  63. DnsNameCompareEx_UTF8(
  64. IN LPCSTR pszLeftName,
  65. IN LPCSTR pszRightName,
  66. IN DWORD dwReserved
  67. )
  68. {
  69. return Dns_NameCompareEx(
  70. pszLeftName,
  71. pszRightName,
  72. dwReserved,
  73. DnsCharSetUtf8 );
  74. }
  75. DNS_NAME_COMPARE_STATUS
  76. DnsNameCompareEx_W(
  77. IN LPCWSTR pszLeftName,
  78. IN LPCWSTR pszRightName,
  79. IN DWORD dwReserved
  80. )
  81. {
  82. return Dns_NameCompareEx(
  83. (LPSTR) pszLeftName,
  84. (LPSTR) pszRightName,
  85. dwReserved,
  86. DnsCharSetUnicode );
  87. }
  88. //
  89. // Name validation
  90. //
  91. DNS_STATUS
  92. DnsValidateName_UTF8(
  93. IN LPCSTR pszName,
  94. IN DNS_NAME_FORMAT Format
  95. )
  96. {
  97. return Dns_ValidateName_UTF8( pszName, Format );
  98. }
  99. DNS_STATUS
  100. DnsValidateName_W(
  101. IN LPCWSTR pszName,
  102. IN DNS_NAME_FORMAT Format
  103. )
  104. {
  105. return Dns_ValidateName_W( pszName, Format );
  106. }
  107. DNS_STATUS
  108. DnsValidateName_A(
  109. IN LPCSTR pszName,
  110. IN DNS_NAME_FORMAT Format
  111. )
  112. {
  113. return Dns_ValidateName_A( pszName, Format );
  114. }
  115. //
  116. // Record List
  117. //
  118. BOOL
  119. DnsRecordCompare(
  120. IN PDNS_RECORD pRecord1,
  121. IN PDNS_RECORD pRecord2
  122. )
  123. {
  124. return Dns_RecordCompare(
  125. pRecord1,
  126. pRecord2 );
  127. }
  128. BOOL
  129. WINAPI
  130. DnsRecordSetCompare(
  131. IN OUT PDNS_RECORD pRR1,
  132. IN OUT PDNS_RECORD pRR2,
  133. OUT PDNS_RECORD * ppDiff1,
  134. OUT PDNS_RECORD * ppDiff2
  135. )
  136. {
  137. return Dns_RecordSetCompare(
  138. pRR1,
  139. pRR2,
  140. ppDiff1,
  141. ppDiff2
  142. );
  143. }
  144. PDNS_RECORD
  145. WINAPI
  146. DnsRecordCopyEx(
  147. IN PDNS_RECORD pRecord,
  148. IN DNS_CHARSET CharSetIn,
  149. IN DNS_CHARSET CharSetOut
  150. )
  151. {
  152. return Dns_RecordCopyEx( pRecord, CharSetIn, CharSetOut );
  153. }
  154. PDNS_RECORD
  155. WINAPI
  156. DnsRecordSetCopyEx(
  157. IN PDNS_RECORD pRecordSet,
  158. IN DNS_CHARSET CharSetIn,
  159. IN DNS_CHARSET CharSetOut
  160. )
  161. {
  162. return Dns_RecordSetCopyEx( pRecordSet, CharSetIn, CharSetOut );
  163. }
  164. VOID
  165. WINAPI
  166. DnsRecordListFree(
  167. IN OUT PDNS_RECORD pRecordList,
  168. IN DNS_FREE_TYPE FreeType
  169. )
  170. {
  171. Dns_RecordListFreeEx(
  172. pRecordList,
  173. (BOOL)FreeType );
  174. }
  175. PDNS_RECORD
  176. WINAPI
  177. DnsRecordSetDetach(
  178. IN OUT PDNS_RECORD pRR
  179. )
  180. {
  181. return Dns_RecordSetDetach( pRR );
  182. }
  183. //
  184. // Timer (timer.c)
  185. //
  186. DWORD
  187. GetCurrentTimeInSeconds(
  188. VOID
  189. )
  190. {
  191. return Dns_GetCurrentTimeInSeconds();
  192. }
  193. //
  194. // Resource record type utilities (record.c)
  195. //
  196. BOOL _fastcall
  197. DnsIsAMailboxType(
  198. IN WORD wType
  199. )
  200. {
  201. return Dns_IsAMailboxType( wType );
  202. }
  203. WORD
  204. DnsRecordTypeForName(
  205. IN PCHAR pszName,
  206. IN INT cchNameLength
  207. )
  208. {
  209. return Dns_RecordTypeForName( pszName, cchNameLength );
  210. }
  211. PCHAR
  212. DnsRecordStringForType(
  213. IN WORD wType
  214. )
  215. {
  216. return Dns_RecordStringForType( wType );
  217. }
  218. PCHAR
  219. DnsRecordStringForWritableType(
  220. IN WORD wType
  221. )
  222. {
  223. return Dns_RecordStringForWritableType( wType );
  224. }
  225. BOOL
  226. DnsIsStringCountValidForTextType(
  227. IN WORD wType,
  228. IN WORD StringCount )
  229. {
  230. return Dns_IsStringCountValidForTextType( wType, StringCount );
  231. }
  232. //
  233. // DCR_CLEANUP: these probably don't need exporting
  234. //
  235. DWORD
  236. DnsWinsRecordFlagForString(
  237. IN PCHAR pchName,
  238. IN INT cchNameLength
  239. )
  240. {
  241. return Dns_WinsRecordFlagForString( pchName, cchNameLength );
  242. }
  243. PCHAR
  244. DnsWinsRecordFlagString(
  245. IN DWORD dwFlag,
  246. IN OUT PCHAR pchFlag
  247. )
  248. {
  249. return Dns_WinsRecordFlagString( dwFlag, pchFlag );
  250. }
  251. //
  252. // DNS utilities (dnsutil.c)
  253. //
  254. // DCR_DELETE: DnsStatusString routines should be able to use win32 API
  255. //
  256. //
  257. // Remove marco definitions so we can compile
  258. // The idea here is we can have the entry points in the Dll
  259. // for any old code, BUT the macros (dnsapi.h) point at new entry points
  260. // for freshly built modules.
  261. //
  262. #ifdef DnsStatusToErrorString_A
  263. #undef DnsStatusToErrorString_A
  264. #endif
  265. LPSTR
  266. _fastcall
  267. DnsStatusString(
  268. IN DNS_STATUS Status
  269. )
  270. {
  271. return Dns_StatusString( Status );
  272. }
  273. DNS_STATUS
  274. _fastcall
  275. DnsMapRcodeToStatus(
  276. IN BYTE ResponseCode
  277. )
  278. {
  279. return Dns_MapRcodeToStatus( ResponseCode );
  280. }
  281. BYTE
  282. _fastcall
  283. DnsIsStatusRcode(
  284. IN DNS_STATUS Status
  285. )
  286. {
  287. return Dns_IsStatusRcode( Status );
  288. }
  289. //
  290. // Name routines (string.c and dnsutil.c)
  291. //
  292. LPSTR _fastcall
  293. DnsGetDomainName(
  294. IN LPSTR pszName
  295. )
  296. {
  297. return Dns_GetDomainName( pszName );
  298. }
  299. //
  300. // String routines (string.c)
  301. //
  302. LPSTR
  303. DnsCreateStringCopy(
  304. IN PCHAR pchString,
  305. IN DWORD cchString
  306. )
  307. {
  308. return Dns_CreateStringCopy(
  309. pchString,
  310. cchString );
  311. }
  312. DWORD
  313. DnsGetBufferLengthForStringCopy(
  314. IN PCHAR pchString,
  315. IN DWORD cchString,
  316. IN BOOL fUnicodeIn,
  317. IN BOOL fUnicodeOut
  318. )
  319. {
  320. return (WORD) Dns_GetBufferLengthForStringCopy(
  321. pchString,
  322. cchString,
  323. fUnicodeIn ? DnsCharSetUnicode : DnsCharSetUtf8,
  324. fUnicodeOut ? DnsCharSetUnicode : DnsCharSetUtf8
  325. );
  326. }
  327. //
  328. // Need to
  329. // - get this unexported or
  330. // - real verions or
  331. // - explicit UTF8-unicode converter if thats what's desired
  332. //
  333. PVOID
  334. DnsCopyStringEx(
  335. OUT PBYTE pBuffer,
  336. IN PCHAR pchString,
  337. IN DWORD cchString,
  338. IN BOOL fUnicodeIn,
  339. IN BOOL fUnicodeOut
  340. )
  341. {
  342. DWORD resultLength;
  343. resultLength =
  344. Dns_StringCopy(
  345. pBuffer,
  346. NULL,
  347. pchString,
  348. cchString,
  349. fUnicodeIn ? DnsCharSetUnicode : DnsCharSetUtf8,
  350. fUnicodeOut ? DnsCharSetUnicode : DnsCharSetUtf8
  351. );
  352. return( pBuffer + resultLength );
  353. }
  354. PVOID
  355. DnsStringCopyAllocateEx(
  356. IN PCHAR pchString,
  357. IN DWORD cchString,
  358. IN BOOL fUnicodeIn,
  359. IN BOOL fUnicodeOut
  360. )
  361. {
  362. return Dns_StringCopyAllocate(
  363. pchString,
  364. cchString,
  365. fUnicodeIn ? DnsCharSetUnicode : DnsCharSetUtf8,
  366. fUnicodeOut ? DnsCharSetUnicode : DnsCharSetUtf8
  367. );
  368. }
  369. //
  370. // The new and improved string copy routines . . .
  371. //
  372. DWORD
  373. DnsNameCopy(
  374. OUT PBYTE pBuffer,
  375. IN OUT PDWORD pdwBufLength,
  376. IN PCHAR pchString,
  377. IN DWORD cchString,
  378. IN DNS_CHARSET CharSetIn,
  379. IN DNS_CHARSET CharSetOut
  380. )
  381. {
  382. return Dns_NameCopy( pBuffer,
  383. pdwBufLength,
  384. pchString,
  385. cchString,
  386. CharSetIn,
  387. CharSetOut );
  388. }
  389. PVOID
  390. DnsNameCopyAllocate(
  391. IN PCHAR pchString,
  392. IN DWORD cchString,
  393. IN DNS_CHARSET CharSetIn,
  394. IN DNS_CHARSET CharSetOut
  395. )
  396. {
  397. return Dns_NameCopyAllocate ( pchString,
  398. cchString,
  399. CharSetIn,
  400. CharSetOut );
  401. }
  402. //
  403. // String\Address mapping
  404. //
  405. // DCR: eliminate these exports
  406. // DCR: fix these to SDK the real deal
  407. //
  408. // DCR: probably shouldn't expose alloc -- easy workaround for caller
  409. //
  410. PCHAR
  411. DnsWriteReverseNameStringForIpAddress(
  412. OUT PCHAR pBuffer,
  413. IN IP4_ADDRESS Ip4Addr
  414. )
  415. {
  416. return Dns_Ip4AddressToReverseName_A(
  417. pBuffer,
  418. Ip4Addr );
  419. }
  420. PCHAR
  421. DnsCreateReverseNameStringForIpAddress(
  422. IN IP4_ADDRESS Ip4Addr
  423. )
  424. {
  425. return Dns_Ip4AddressToReverseNameAlloc_A( Ip4Addr );
  426. }
  427. //
  428. // DCR_CLEANUP: pull these in favor of winsock IPv6 string routines
  429. //
  430. BOOL
  431. DnsIpv6StringToAddress(
  432. OUT PIP6_ADDRESS pIp6Addr,
  433. IN PCHAR pchString,
  434. IN DWORD dwStringLength
  435. )
  436. {
  437. return Dns_Ip6StringToAddressEx_A(
  438. pIp6Addr,
  439. pchString,
  440. dwStringLength );
  441. }
  442. VOID
  443. DnsIpv6AddressToString(
  444. OUT PCHAR pchString,
  445. IN PIP6_ADDRESS pIp6Addr
  446. )
  447. {
  448. Dns_Ip6AddressToString_A(
  449. pchString,
  450. pIp6Addr );
  451. }
  452. DNS_STATUS
  453. DnsValidateDnsString_UTF8(
  454. IN LPCSTR pszName
  455. )
  456. {
  457. return Dns_ValidateDnsString_UTF8( pszName );
  458. }
  459. DNS_STATUS
  460. DnsValidateDnsString_W(
  461. IN LPCWSTR pszName
  462. )
  463. {
  464. return Dns_ValidateDnsString_W( pszName );
  465. }
  466. //
  467. // Resource record utilities (rr*.c)
  468. //
  469. PDNS_RECORD
  470. WINAPI
  471. DnsAllocateRecord(
  472. IN WORD wBufferLength
  473. )
  474. {
  475. return Dns_AllocateRecord( wBufferLength );
  476. }
  477. PDNS_RECORD
  478. DnsRecordBuild_UTF8(
  479. IN OUT PDNS_RRSET pRRSet,
  480. IN LPSTR pszOwner,
  481. IN WORD wType,
  482. IN BOOL fAdd,
  483. IN UCHAR Section,
  484. IN INT Argc,
  485. IN PCHAR * Argv
  486. )
  487. {
  488. return Dns_RecordBuild_A(
  489. pRRSet,
  490. pszOwner,
  491. wType,
  492. fAdd,
  493. Section,
  494. Argc,
  495. Argv );
  496. }
  497. PDNS_RECORD
  498. DnsRecordBuild_W(
  499. IN OUT PDNS_RRSET pRRSet,
  500. IN LPWSTR pszOwner,
  501. IN WORD wType,
  502. IN BOOL fAdd,
  503. IN UCHAR Section,
  504. IN INT Argc,
  505. IN PWCHAR * Argv
  506. )
  507. {
  508. return Dns_RecordBuild_W(
  509. pRRSet,
  510. pszOwner,
  511. wType,
  512. fAdd,
  513. Section,
  514. Argc,
  515. Argv );
  516. }
  517. //
  518. // Message processing
  519. //
  520. DNS_STATUS
  521. WINAPI
  522. DnsExtractRecordsFromMessage_W(
  523. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  524. IN WORD wMessageLength,
  525. OUT PDNS_RECORD * ppRecord
  526. )
  527. /*++
  528. Routine Description:
  529. None.
  530. Arguments:
  531. None.
  532. Return Value:
  533. None.
  534. --*/
  535. {
  536. return Dns_ExtractRecordsFromBuffer(
  537. pDnsBuffer,
  538. wMessageLength,
  539. TRUE,
  540. ppRecord );
  541. }
  542. DNS_STATUS
  543. WINAPI
  544. DnsExtractRecordsFromMessage_UTF8(
  545. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  546. IN WORD wMessageLength,
  547. OUT PDNS_RECORD * ppRecord
  548. )
  549. /*++
  550. Routine Description:
  551. None.
  552. Arguments:
  553. None.
  554. Return Value:
  555. None.
  556. --*/
  557. {
  558. return Dns_ExtractRecordsFromBuffer(
  559. pDnsBuffer,
  560. wMessageLength,
  561. FALSE,
  562. ppRecord );
  563. }
  564. //
  565. // Debug sharing
  566. //
  567. PDNS_DEBUG_INFO
  568. DnsApiSetDebugGlobals(
  569. IN OUT PDNS_DEBUG_INFO pInfo
  570. )
  571. {
  572. return Dns_SetDebugGlobals( pInfo );
  573. }
  574. //
  575. // Config UI, ipconfig backcompat
  576. //
  577. // DCR_CLEANUP: Backcompat query config stuff -- yank once clean cycle
  578. //
  579. //
  580. // DCR: Questionable exports
  581. //
  582. LPSTR
  583. DnsCreateStandardDnsNameCopy(
  584. IN PCHAR pchName,
  585. IN DWORD cchName,
  586. IN DWORD dwFlag
  587. )
  588. {
  589. return Dns_CreateStandardDnsNameCopy(
  590. pchName,
  591. cchName,
  592. dwFlag );
  593. }
  594. //
  595. // DCR_CLEANUP: who is using this?
  596. //
  597. DWORD
  598. DnsDowncaseDnsNameLabel(
  599. OUT PCHAR pchResult,
  600. IN PCHAR pchLabel,
  601. IN DWORD cchLabel,
  602. IN DWORD dwFlags
  603. )
  604. {
  605. return Dns_DowncaseNameLabel(
  606. pchResult,
  607. pchLabel,
  608. cchLabel,
  609. dwFlags );
  610. }
  611. //
  612. // DCR_CLEANUP: who is using my direct UTF8 conversions AS API!
  613. //
  614. DWORD
  615. _fastcall
  616. DnsUnicodeToUtf8(
  617. IN PWCHAR pwUnicode,
  618. IN DWORD cchUnicode,
  619. OUT PCHAR pchResult,
  620. IN DWORD cchResult
  621. )
  622. {
  623. return Dns_UnicodeToUtf8(
  624. pwUnicode,
  625. cchUnicode,
  626. pchResult,
  627. cchResult );
  628. }
  629. DWORD
  630. _fastcall
  631. DnsUtf8ToUnicode(
  632. IN PCHAR pchUtf8,
  633. IN DWORD cchUtf8,
  634. OUT PWCHAR pwResult,
  635. IN DWORD cwResult
  636. )
  637. {
  638. return Dns_Utf8ToUnicode(
  639. pchUtf8,
  640. cchUtf8,
  641. pwResult,
  642. cwResult );
  643. }
  644. DNS_STATUS
  645. DnsValidateUtf8Byte(
  646. IN BYTE chUtf8,
  647. IN OUT PDWORD pdwTrailCount
  648. )
  649. {
  650. return Dns_ValidateUtf8Byte(
  651. chUtf8,
  652. pdwTrailCount );
  653. }
  654. //
  655. // Old cluster call
  656. //
  657. // DCR: cleanup -- remove once cluster fixed up
  658. //
  659. VOID
  660. DnsNotifyResolverClusterIp(
  661. IN IP_ADDRESS ClusterIp,
  662. IN BOOL fAdd
  663. )
  664. /*++
  665. Routine Description:
  666. Notify resolver of cluster IP coming on\offline.
  667. Arguments:
  668. ClusterIp -- cluster IP
  669. fAdd -- TRUE if coming online; FALSE if offline.
  670. Return Value:
  671. None
  672. --*/
  673. {
  674. SOCKADDR_IN sockaddrIn;
  675. DNSDBG( TRACE, (
  676. "DnsNotifyResolverClusterIp( %08x, %d )\n",
  677. ClusterIp,
  678. fAdd ));
  679. sockaddrIn.sin_family = AF_INET;
  680. sockaddrIn.sin_addr.s_addr = ClusterIp;
  681. DnsRegisterClusterAddress(
  682. 0xd734453d,
  683. NULL, // no name
  684. (PSOCKADDR) & sockaddrIn,
  685. fAdd
  686. ? DNS_CLUSTER_ADD
  687. : DNS_CLUSTER_DELETE_IP
  688. );
  689. }
  690. //
  691. // backcompat for macros
  692. // - DNS server list
  693. //
  694. // this is called without dnsapi.h include somewhere in IIS
  695. //
  696. #undef DnsGetDnsServerList
  697. DWORD
  698. DnsGetDnsServerList(
  699. OUT PIP4_ARRAY * ppDnsArray
  700. )
  701. {
  702. *ppDnsArray = GetDnsServerList( TRUE );
  703. // if no servers read, return
  704. if ( !*ppDnsArray )
  705. {
  706. return 0;
  707. }
  708. return( (*ppDnsArray)->AddrCount );
  709. }
  710. //
  711. // Config UI, ipconfig backcompat
  712. //
  713. // DCR_CLEANUP: this is called without dnsapi.h include somewhere in DHCP
  714. //
  715. #undef DnsGetPrimaryDomainName_A
  716. #define PrivateQueryConfig( Id ) DnsQueryConfigAllocEx( Id, NULL, FALSE )
  717. PSTR
  718. WINAPI
  719. DnsGetPrimaryDomainName_A(
  720. VOID
  721. )
  722. {
  723. return PrivateQueryConfig( DnsConfigPrimaryDomainName_A );
  724. }
  725. //
  726. // End export.c
  727. //