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.

1454 lines
27 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. #define DNSAPI_XP_ENTRY 1
  17. //
  18. // SDK routines
  19. //
  20. //
  21. // Name comparison
  22. //
  23. BOOL
  24. WINAPI
  25. DnsNameCompare_A(
  26. IN LPSTR pName1,
  27. IN LPSTR pName2
  28. )
  29. {
  30. return Dns_NameCompare_A( pName1, pName2 );
  31. }
  32. BOOL
  33. WINAPI
  34. DnsNameCompare_UTF8(
  35. IN LPSTR pName1,
  36. IN LPSTR pName2
  37. )
  38. {
  39. return Dns_NameCompare_UTF8( pName1, pName2 );
  40. }
  41. BOOL
  42. WINAPI
  43. DnsNameCompare_W(
  44. IN LPWSTR pName1,
  45. IN LPWSTR pName2
  46. )
  47. {
  48. return Dns_NameCompare_W( pName1, pName2 );
  49. }
  50. DNS_NAME_COMPARE_STATUS
  51. DnsNameCompareEx_A(
  52. IN LPCSTR pszLeftName,
  53. IN LPCSTR pszRightName,
  54. IN DWORD dwReserved
  55. )
  56. {
  57. return Dns_NameCompareEx(
  58. pszLeftName,
  59. pszRightName,
  60. dwReserved,
  61. DnsCharSetAnsi );
  62. }
  63. DNS_NAME_COMPARE_STATUS
  64. DnsNameCompareEx_UTF8(
  65. IN LPCSTR pszLeftName,
  66. IN LPCSTR pszRightName,
  67. IN DWORD dwReserved
  68. )
  69. {
  70. return Dns_NameCompareEx(
  71. pszLeftName,
  72. pszRightName,
  73. dwReserved,
  74. DnsCharSetUtf8 );
  75. }
  76. DNS_NAME_COMPARE_STATUS
  77. DnsNameCompareEx_W(
  78. IN LPCWSTR pszLeftName,
  79. IN LPCWSTR pszRightName,
  80. IN DWORD dwReserved
  81. )
  82. {
  83. return Dns_NameCompareEx(
  84. (LPSTR) pszLeftName,
  85. (LPSTR) pszRightName,
  86. dwReserved,
  87. DnsCharSetUnicode );
  88. }
  89. //
  90. // Name validation
  91. //
  92. DNS_STATUS
  93. DnsValidateName_UTF8(
  94. IN LPCSTR pszName,
  95. IN DNS_NAME_FORMAT Format
  96. )
  97. {
  98. return Dns_ValidateName_UTF8( pszName, Format );
  99. }
  100. DNS_STATUS
  101. DnsValidateName_W(
  102. IN LPCWSTR pszName,
  103. IN DNS_NAME_FORMAT Format
  104. )
  105. {
  106. return Dns_ValidateName_W( pszName, Format );
  107. }
  108. DNS_STATUS
  109. DnsValidateName_A(
  110. IN LPCSTR pszName,
  111. IN DNS_NAME_FORMAT Format
  112. )
  113. {
  114. return Dns_ValidateName_A( pszName, Format );
  115. }
  116. //
  117. // Record List
  118. //
  119. BOOL
  120. DnsRecordCompare(
  121. IN PDNS_RECORD pRecord1,
  122. IN PDNS_RECORD pRecord2
  123. )
  124. {
  125. return Dns_RecordCompare(
  126. pRecord1,
  127. pRecord2 );
  128. }
  129. BOOL
  130. WINAPI
  131. DnsRecordSetCompare(
  132. IN OUT PDNS_RECORD pRR1,
  133. IN OUT PDNS_RECORD pRR2,
  134. OUT PDNS_RECORD * ppDiff1,
  135. OUT PDNS_RECORD * ppDiff2
  136. )
  137. {
  138. return Dns_RecordSetCompare(
  139. pRR1,
  140. pRR2,
  141. ppDiff1,
  142. ppDiff2
  143. );
  144. }
  145. PDNS_RECORD
  146. WINAPI
  147. DnsRecordCopyEx(
  148. IN PDNS_RECORD pRecord,
  149. IN DNS_CHARSET CharSetIn,
  150. IN DNS_CHARSET CharSetOut
  151. )
  152. {
  153. return Dns_RecordCopyEx( pRecord, CharSetIn, CharSetOut );
  154. }
  155. PDNS_RECORD
  156. WINAPI
  157. DnsRecordSetCopyEx(
  158. IN PDNS_RECORD pRecordSet,
  159. IN DNS_CHARSET CharSetIn,
  160. IN DNS_CHARSET CharSetOut
  161. )
  162. {
  163. return Dns_RecordSetCopyEx( pRecordSet, CharSetIn, CharSetOut );
  164. }
  165. PDNS_RECORD
  166. WINAPI
  167. DnsRecordSetDetach(
  168. IN OUT PDNS_RECORD pRR
  169. )
  170. {
  171. return Dns_RecordSetDetach( pRR );
  172. }
  173. //
  174. // Backward compatibility
  175. //
  176. #undef DnsRecordListFree
  177. VOID
  178. WINAPI
  179. DnsRecordListFree(
  180. IN OUT PDNS_RECORD pRecordList,
  181. IN DNS_FREE_TYPE FreeType
  182. )
  183. {
  184. Dns_RecordListFreeEx(
  185. pRecordList,
  186. (BOOL)FreeType );
  187. }
  188. //
  189. // Timer (timer.c)
  190. //
  191. DWORD
  192. GetCurrentTimeInSeconds(
  193. VOID
  194. )
  195. {
  196. return Dns_GetCurrentTimeInSeconds();
  197. }
  198. //
  199. // Resource record type utilities (record.c)
  200. //
  201. BOOL _fastcall
  202. DnsIsAMailboxType(
  203. IN WORD wType
  204. )
  205. {
  206. return Dns_IsAMailboxType( wType );
  207. }
  208. WORD
  209. DnsRecordTypeForName(
  210. IN PCHAR pszName,
  211. IN INT cchNameLength
  212. )
  213. {
  214. return Dns_RecordTypeForName( pszName, cchNameLength );
  215. }
  216. PCHAR
  217. DnsRecordStringForType(
  218. IN WORD wType
  219. )
  220. {
  221. return Dns_RecordStringForType( wType );
  222. }
  223. PCHAR
  224. DnsRecordStringForWritableType(
  225. IN WORD wType
  226. )
  227. {
  228. return Dns_RecordStringForWritableType( wType );
  229. }
  230. BOOL
  231. DnsIsStringCountValidForTextType(
  232. IN WORD wType,
  233. IN WORD StringCount )
  234. {
  235. return Dns_IsStringCountValidForTextType( wType, StringCount );
  236. }
  237. //
  238. // DCR_CLEANUP: these probably don't need exporting
  239. //
  240. DWORD
  241. DnsWinsRecordFlagForString(
  242. IN PCHAR pchName,
  243. IN INT cchNameLength
  244. )
  245. {
  246. return Dns_WinsRecordFlagForString( pchName, cchNameLength );
  247. }
  248. PCHAR
  249. DnsWinsRecordFlagString(
  250. IN DWORD dwFlag,
  251. IN OUT PCHAR pchFlag
  252. )
  253. {
  254. return Dns_WinsRecordFlagString( dwFlag, pchFlag );
  255. }
  256. //
  257. // DNS utilities (dnsutil.c)
  258. //
  259. // DCR_DELETE: DnsStatusString routines should be able to use win32 API
  260. //
  261. //
  262. // Remove marco definitions so we can compile
  263. // The idea here is we can have the entry points in the Dll
  264. // for any old code, BUT the macros (dnsapi.h) point at new entry points
  265. // for freshly built modules.
  266. //
  267. #ifdef DnsStatusToErrorString_A
  268. #undef DnsStatusToErrorString_A
  269. #endif
  270. LPSTR
  271. _fastcall
  272. DnsStatusString(
  273. IN DNS_STATUS Status
  274. )
  275. {
  276. return Dns_StatusString( Status );
  277. }
  278. DNS_STATUS
  279. _fastcall
  280. DnsMapRcodeToStatus(
  281. IN BYTE ResponseCode
  282. )
  283. {
  284. return Dns_MapRcodeToStatus( ResponseCode );
  285. }
  286. BYTE
  287. _fastcall
  288. DnsIsStatusRcode(
  289. IN DNS_STATUS Status
  290. )
  291. {
  292. return Dns_IsStatusRcode( Status );
  293. }
  294. //
  295. // Name routines (string.c and dnsutil.c)
  296. //
  297. LPSTR
  298. _fastcall
  299. DnsGetDomainName(
  300. IN LPSTR pszName
  301. )
  302. {
  303. return Dns_GetDomainNameA( pszName );
  304. }
  305. //
  306. // String routines (string.c)
  307. //
  308. LPSTR
  309. DnsCreateStringCopy(
  310. IN PCHAR pchString,
  311. IN DWORD cchString
  312. )
  313. {
  314. return Dns_CreateStringCopy(
  315. pchString,
  316. cchString );
  317. }
  318. DWORD
  319. DnsGetBufferLengthForStringCopy(
  320. IN PCHAR pchString,
  321. IN DWORD cchString,
  322. IN BOOL fUnicodeIn,
  323. IN BOOL fUnicodeOut
  324. )
  325. {
  326. return (WORD) Dns_GetBufferLengthForStringCopy(
  327. pchString,
  328. cchString,
  329. fUnicodeIn ? DnsCharSetUnicode : DnsCharSetUtf8,
  330. fUnicodeOut ? DnsCharSetUnicode : DnsCharSetUtf8
  331. );
  332. }
  333. //
  334. // Need to
  335. // - get this unexported or
  336. // - real verions or
  337. // - explicit UTF8-unicode converter if thats what's desired
  338. //
  339. PVOID
  340. DnsCopyStringEx(
  341. OUT PBYTE pBuffer,
  342. IN PCHAR pchString,
  343. IN DWORD cchString,
  344. IN BOOL fUnicodeIn,
  345. IN BOOL fUnicodeOut
  346. )
  347. {
  348. DWORD resultLength;
  349. resultLength =
  350. Dns_StringCopy(
  351. pBuffer,
  352. NULL,
  353. pchString,
  354. cchString,
  355. fUnicodeIn ? DnsCharSetUnicode : DnsCharSetUtf8,
  356. fUnicodeOut ? DnsCharSetUnicode : DnsCharSetUtf8
  357. );
  358. return( pBuffer + resultLength );
  359. }
  360. PVOID
  361. DnsStringCopyAllocateEx(
  362. IN PCHAR pchString,
  363. IN DWORD cchString,
  364. IN BOOL fUnicodeIn,
  365. IN BOOL fUnicodeOut
  366. )
  367. {
  368. return Dns_StringCopyAllocate(
  369. pchString,
  370. cchString,
  371. fUnicodeIn ? DnsCharSetUnicode : DnsCharSetUtf8,
  372. fUnicodeOut ? DnsCharSetUnicode : DnsCharSetUtf8
  373. );
  374. }
  375. //
  376. // The new and improved string copy routines . . .
  377. //
  378. DWORD
  379. DnsNameCopy(
  380. OUT PBYTE pBuffer,
  381. IN OUT PDWORD pdwBufLength,
  382. IN PCHAR pchString,
  383. IN DWORD cchString,
  384. IN DNS_CHARSET CharSetIn,
  385. IN DNS_CHARSET CharSetOut
  386. )
  387. {
  388. return Dns_NameCopy( pBuffer,
  389. pdwBufLength,
  390. pchString,
  391. cchString,
  392. CharSetIn,
  393. CharSetOut );
  394. }
  395. PVOID
  396. DnsNameCopyAllocate(
  397. IN PCHAR pchString,
  398. IN DWORD cchString,
  399. IN DNS_CHARSET CharSetIn,
  400. IN DNS_CHARSET CharSetOut
  401. )
  402. {
  403. return Dns_NameCopyAllocate ( pchString,
  404. cchString,
  405. CharSetIn,
  406. CharSetOut );
  407. }
  408. //
  409. // String\Address mapping
  410. //
  411. // DCR: eliminate these exports
  412. // DCR: fix these to SDK the real deal
  413. //
  414. // DCR: probably shouldn't expose alloc -- easy workaround for caller
  415. //
  416. PCHAR
  417. DnsWriteReverseNameStringForIpAddress(
  418. OUT PCHAR pBuffer,
  419. IN IP4_ADDRESS Ip4Addr
  420. )
  421. {
  422. return Dns_Ip4AddressToReverseName_A(
  423. pBuffer,
  424. Ip4Addr );
  425. }
  426. PCHAR
  427. DnsCreateReverseNameStringForIpAddress(
  428. IN IP4_ADDRESS Ip4Addr
  429. )
  430. {
  431. return Dns_Ip4AddressToReverseNameAlloc_A( Ip4Addr );
  432. }
  433. //
  434. // DCR_CLEANUP: pull these in favor of winsock IPv6 string routines
  435. //
  436. BOOL
  437. DnsIpv6StringToAddress(
  438. OUT PIP6_ADDRESS pIp6Addr,
  439. IN PCHAR pchString,
  440. IN DWORD dwStringLength
  441. )
  442. {
  443. return Dns_Ip6StringToAddressEx_A(
  444. pIp6Addr,
  445. pchString,
  446. dwStringLength );
  447. }
  448. VOID
  449. DnsIpv6AddressToString(
  450. OUT PCHAR pchString,
  451. IN PIP6_ADDRESS pIp6Addr
  452. )
  453. {
  454. Dns_Ip6AddressToString_A(
  455. pchString,
  456. pIp6Addr );
  457. }
  458. DNS_STATUS
  459. DnsValidateDnsString_UTF8(
  460. IN LPCSTR pszName
  461. )
  462. {
  463. return Dns_ValidateDnsString_UTF8( pszName );
  464. }
  465. DNS_STATUS
  466. DnsValidateDnsString_W(
  467. IN LPCWSTR pszName
  468. )
  469. {
  470. return Dns_ValidateDnsString_W( pszName );
  471. }
  472. //
  473. // Resource record utilities (rr*.c)
  474. //
  475. PDNS_RECORD
  476. WINAPI
  477. DnsAllocateRecord(
  478. IN WORD wBufferLength
  479. )
  480. {
  481. return Dns_AllocateRecord( wBufferLength );
  482. }
  483. PDNS_RECORD
  484. DnsRecordBuild_UTF8(
  485. IN OUT PDNS_RRSET pRRSet,
  486. IN LPSTR pszOwner,
  487. IN WORD wType,
  488. IN BOOL fAdd,
  489. IN UCHAR Section,
  490. IN INT Argc,
  491. IN PCHAR * Argv
  492. )
  493. {
  494. return Dns_RecordBuild_A(
  495. pRRSet,
  496. pszOwner,
  497. wType,
  498. fAdd,
  499. Section,
  500. Argc,
  501. Argv );
  502. }
  503. PDNS_RECORD
  504. DnsRecordBuild_W(
  505. IN OUT PDNS_RRSET pRRSet,
  506. IN LPWSTR pszOwner,
  507. IN WORD wType,
  508. IN BOOL fAdd,
  509. IN UCHAR Section,
  510. IN INT Argc,
  511. IN PWCHAR * Argv
  512. )
  513. {
  514. return Dns_RecordBuild_W(
  515. pRRSet,
  516. pszOwner,
  517. wType,
  518. fAdd,
  519. Section,
  520. Argc,
  521. Argv );
  522. }
  523. //
  524. // Message processing
  525. //
  526. DNS_STATUS
  527. WINAPI
  528. DnsExtractRecordsFromMessage_W(
  529. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  530. IN WORD wMessageLength,
  531. OUT PDNS_RECORD * ppRecord
  532. )
  533. /*++
  534. Routine Description:
  535. None.
  536. Arguments:
  537. None.
  538. Return Value:
  539. None.
  540. --*/
  541. {
  542. return Dns_ExtractRecordsFromBuffer(
  543. pDnsBuffer,
  544. wMessageLength,
  545. TRUE,
  546. ppRecord );
  547. }
  548. DNS_STATUS
  549. WINAPI
  550. DnsExtractRecordsFromMessage_UTF8(
  551. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  552. IN WORD wMessageLength,
  553. OUT PDNS_RECORD * ppRecord
  554. )
  555. /*++
  556. Routine Description:
  557. None.
  558. Arguments:
  559. None.
  560. Return Value:
  561. None.
  562. --*/
  563. {
  564. return Dns_ExtractRecordsFromBuffer(
  565. pDnsBuffer,
  566. wMessageLength,
  567. FALSE,
  568. ppRecord );
  569. }
  570. //
  571. // Debug sharing
  572. //
  573. PDNS_DEBUG_INFO
  574. DnsApiSetDebugGlobals(
  575. IN OUT PDNS_DEBUG_INFO pInfo
  576. )
  577. {
  578. return Dns_SetDebugGlobals( pInfo );
  579. }
  580. //
  581. // Config UI, ipconfig backcompat
  582. //
  583. // DCR_CLEANUP: Backcompat query config stuff -- yank once clean cycle
  584. //
  585. //
  586. // DCR: Questionable exports
  587. //
  588. LPSTR
  589. DnsCreateStandardDnsNameCopy(
  590. IN PCHAR pchName,
  591. IN DWORD cchName,
  592. IN DWORD dwFlag
  593. )
  594. {
  595. return Dns_CreateStandardDnsNameCopy(
  596. pchName,
  597. cchName,
  598. dwFlag );
  599. }
  600. //
  601. // DCR_CLEANUP: who is using this?
  602. //
  603. DWORD
  604. DnsDowncaseDnsNameLabel(
  605. OUT PCHAR pchResult,
  606. IN PCHAR pchLabel,
  607. IN DWORD cchLabel,
  608. IN DWORD dwFlags
  609. )
  610. {
  611. return Dns_DowncaseNameLabel(
  612. pchResult,
  613. pchLabel,
  614. cchLabel,
  615. dwFlags );
  616. }
  617. //
  618. // DCR_CLEANUP: who is using my direct UTF8 conversions AS API!
  619. //
  620. DWORD
  621. _fastcall
  622. DnsUnicodeToUtf8(
  623. IN PWCHAR pwUnicode,
  624. IN DWORD cchUnicode,
  625. OUT PCHAR pchResult,
  626. IN DWORD cchResult
  627. )
  628. {
  629. return Dns_UnicodeToUtf8(
  630. pwUnicode,
  631. cchUnicode,
  632. pchResult,
  633. cchResult );
  634. }
  635. DWORD
  636. _fastcall
  637. DnsUtf8ToUnicode(
  638. IN PCHAR pchUtf8,
  639. IN DWORD cchUtf8,
  640. OUT PWCHAR pwResult,
  641. IN DWORD cwResult
  642. )
  643. {
  644. return Dns_Utf8ToUnicode(
  645. pchUtf8,
  646. cchUtf8,
  647. pwResult,
  648. cwResult );
  649. }
  650. DNS_STATUS
  651. DnsValidateUtf8Byte(
  652. IN BYTE chUtf8,
  653. IN OUT PDWORD pdwTrailCount
  654. )
  655. {
  656. return Dns_ValidateUtf8Byte(
  657. chUtf8,
  658. pdwTrailCount );
  659. }
  660. //
  661. // Old cluster call
  662. //
  663. // DCR: cleanup -- remove once cluster fixed up
  664. //
  665. VOID
  666. DnsNotifyResolverClusterIp(
  667. IN IP4_ADDRESS ClusterIp,
  668. IN BOOL fAdd
  669. )
  670. /*++
  671. Routine Description:
  672. Notify resolver of cluster IP coming on\offline.
  673. Arguments:
  674. ClusterIp -- cluster IP
  675. fAdd -- TRUE if coming online; FALSE if offline.
  676. Return Value:
  677. None
  678. --*/
  679. {
  680. // dumb stub
  681. // cluster folks need to call RegisterCluster() to do anything useful
  682. }
  683. //
  684. // backcompat for macros
  685. // - DNS server list
  686. //
  687. // this is called without dnsapi.h include somewhere in IIS
  688. // search and try and find it
  689. //
  690. #undef DnsGetDnsServerList
  691. DWORD
  692. DnsGetDnsServerList(
  693. OUT PIP4_ARRAY * ppDnsArray
  694. )
  695. {
  696. *ppDnsArray = Config_GetDnsServerListIp4(
  697. NULL, // no adapter name
  698. TRUE // force reread
  699. );
  700. // if no servers read, return
  701. if ( !*ppDnsArray )
  702. {
  703. return 0;
  704. }
  705. return( (*ppDnsArray)->AddrCount );
  706. }
  707. //
  708. // Config UI, ipconfig backcompat
  709. //
  710. // DCR_CLEANUP: this is called without dnsapi.h include somewhere in DHCP
  711. // search and try and find it
  712. //
  713. #undef DnsGetPrimaryDomainName_A
  714. #define PrivateQueryConfig( Id ) DnsQueryConfigAllocEx( Id, NULL, FALSE )
  715. PSTR
  716. WINAPI
  717. DnsGetPrimaryDomainName_A(
  718. VOID
  719. )
  720. {
  721. return PrivateQueryConfig( DnsConfigPrimaryDomainName_A );
  722. }
  723. //
  724. // Delete once clear
  725. //
  726. #ifndef DEFINED_DNS_FAILED_UPDATE_INFO
  727. typedef struct _DnsFailedUpdateInfo
  728. {
  729. IP4_ADDRESS Ip4Address;
  730. IP6_ADDRESS Ip6Address;
  731. DNS_STATUS Status;
  732. DWORD Rcode;
  733. }
  734. DNS_FAILED_UPDATE_INFO, *PDNS_FAILED_UPDATE_INFO;
  735. #endif
  736. VOID
  737. DnsGetLastFailedUpdateInfo(
  738. OUT PDNS_FAILED_UPDATE_INFO pInfo
  739. )
  740. {
  741. // fill in last info
  742. RtlZeroMemory(
  743. pInfo,
  744. sizeof(*pInfo) );
  745. }
  746. //
  747. // End export.c
  748. //
  749. BOOL
  750. ConvertAnsiToUnicodeInPlace(
  751. IN OUT PWCHAR pString,
  752. IN DWORD BufferSize
  753. )
  754. /*++
  755. Routine Description:
  756. Convert ANSI string in buffer to unicode in place.
  757. Arguments:
  758. pString -- buffer with ANSI string
  759. BufferSize -- size of buffer
  760. Return Value:
  761. TRUE if successful.
  762. FALSE on error.
  763. --*/
  764. {
  765. DWORD size;
  766. DWORD length;
  767. PSTR pansiString = NULL;
  768. //
  769. // make string copy
  770. //
  771. size = strlen( (PSTR)pString ) + 1;
  772. pansiString = ALLOCATE_HEAP( size );
  773. if ( !pansiString )
  774. {
  775. return FALSE;
  776. }
  777. RtlCopyMemory(
  778. pansiString,
  779. pString,
  780. size );
  781. //
  782. // convert to unicode
  783. //
  784. // DCR: MBTWC might take size that includes NULL and return that size
  785. //
  786. size--;
  787. length = MultiByteToWideChar(
  788. CP_ACP,
  789. 0, // no flags
  790. (PCHAR) pansiString,
  791. (INT) size,
  792. pString,
  793. BufferSize // assuming adequate length
  794. );
  795. pString[length] = 0;
  796. // cleanup
  797. FREE_HEAP( pansiString );
  798. // return
  799. // - length == 0 is failure unless input length was zero
  800. // unless input length was zero
  801. return( length != 0 || size==0 );
  802. }
  803. INT
  804. WSAAPI
  805. getnameinfoW(
  806. IN const struct sockaddr * pSockaddr,
  807. IN socklen_t SockaddrLength,
  808. OUT PWCHAR pNodeName,
  809. IN DWORD NodeBufferSize,
  810. OUT PWCHAR pServiceName,
  811. IN DWORD ServiceBufferSize,
  812. IN INT Flags
  813. )
  814. /*++
  815. Routine Description:
  816. Unicode version of getnameinfo()
  817. Protocol independent address-to-name translation routine.
  818. Spec'd in RFC 2553, section 6.5.
  819. Arguments:
  820. pSockaddr - sockaddr to translate
  821. SockaddrLength - length of sockaddr
  822. pNodeName - ptr to buffer to recv node name
  823. NodeBufferSize - size of NodeName buffer
  824. pServiceName - ptr to buffer to recv the service name.
  825. ServiceBufferSize - size of ServiceName buffer
  826. Flags - flags of type NI_*.
  827. Return Value:
  828. ERROR_SUCCESS if successful.
  829. Winsock error code on failure.
  830. --*/
  831. {
  832. INT status;
  833. //
  834. // zero result buffers
  835. //
  836. // this is a multi-step call, so some buffers may be filled
  837. // in even if there is an error doing the second call
  838. //
  839. if ( pNodeName )
  840. {
  841. *pNodeName = 0;
  842. }
  843. if ( pServiceName )
  844. {
  845. *pServiceName = 0;
  846. }
  847. //
  848. // call ANSI getnameinfo()
  849. //
  850. status = getnameinfo(
  851. pSockaddr,
  852. SockaddrLength,
  853. (PCHAR) pNodeName,
  854. NodeBufferSize,
  855. (PCHAR) pServiceName,
  856. ServiceBufferSize,
  857. Flags );
  858. if ( pNodeName && *pNodeName != 0 )
  859. {
  860. if ( ! ConvertAnsiToUnicodeInPlace(
  861. pNodeName,
  862. NodeBufferSize ) )
  863. {
  864. if ( status == NO_ERROR )
  865. {
  866. status = WSAEFAULT;
  867. }
  868. }
  869. }
  870. if ( pServiceName && *pServiceName != 0 )
  871. {
  872. if ( ! ConvertAnsiToUnicodeInPlace(
  873. pServiceName,
  874. ServiceBufferSize ) )
  875. {
  876. if ( status == NO_ERROR )
  877. {
  878. status = WSAEFAULT;
  879. }
  880. }
  881. }
  882. return status;
  883. }
  884. //
  885. // DCR_CLEANUP: who is using this?
  886. // No longer used in netdiag
  887. // May delete if not used by test
  888. //
  889. DNS_STATUS
  890. DnsFindAuthoritativeZone(
  891. IN PDNS_NAME pszName,
  892. IN DWORD dwFlags,
  893. IN PIP4_ARRAY pIp4Servers,
  894. OUT PDNS_NETINFO * ppNetworkInfo
  895. )
  896. /*++
  897. Routine Description:
  898. Find name of authoritative zone.
  899. Result of FAZ:
  900. - zone name
  901. - primary DNS server name
  902. - primary DNS IP list
  903. EXPORTED function!
  904. Arguments:
  905. pszName -- name to find authoritative zone for
  906. dwFlags -- flags to use for DnsQuery
  907. aipQueryServers -- servers to query, defaults used if NULL
  908. ppNetworkInfo -- ptr to adapter list built for FAZ
  909. Return Value:
  910. ERROR_SUCCESS if successful.
  911. Error code on failure.
  912. --*/
  913. {
  914. PDNS_ADDR_ARRAY parray = NULL;
  915. if ( pIp4Servers )
  916. {
  917. parray = DnsAddrArray_CreateFromIp4Array( pIp4Servers );
  918. if ( !parray )
  919. {
  920. return DNS_ERROR_NO_MEMORY;
  921. }
  922. }
  923. return Faz_Private(
  924. pszName,
  925. dwFlags,
  926. parray,
  927. ppNetworkInfo );
  928. }
  929. //
  930. // DCR_CLEANUP: who is using this?
  931. // May delete if not used in test
  932. //
  933. DNS_STATUS
  934. Dns_FindAuthoritativeZoneLib(
  935. IN PDNS_NAME pszName,
  936. IN DWORD dwFlags,
  937. IN PIP4_ARRAY aipQueryServers,
  938. OUT PDNS_NETINFO * ppNetworkInfo
  939. )
  940. {
  941. return DnsFindAuthoritativeZone(
  942. pszName,
  943. dwFlags,
  944. aipQueryServers,
  945. ppNetworkInfo );
  946. }
  947. //
  948. // DHCP backcompat -- really only for test dll; kill after clean build propagates
  949. //
  950. #if DNSAPI_XP_ENTRY
  951. DNS_STATUS
  952. WINAPI
  953. DnsAsyncRegisterInit(
  954. IN PSTR pszIgnored
  955. )
  956. {
  957. return DnsDhcpRegisterInit();
  958. }
  959. DNS_STATUS
  960. WINAPI
  961. DnsAsyncRegisterTerm(
  962. VOID
  963. )
  964. {
  965. return DnsDhcpRegisterTerm();
  966. }
  967. DNS_STATUS
  968. WINAPI
  969. DnsRemoveRegistrations(
  970. VOID
  971. )
  972. {
  973. return DnsDhcpRemoveRegistrations();
  974. }
  975. DNS_STATUS
  976. WINAPI
  977. DnsAsyncRegisterHostAddrs(
  978. IN PWSTR pszAdapterName,
  979. IN PWSTR pszHostName,
  980. IN PREGISTER_HOST_ENTRY pHostAddrs,
  981. IN DWORD dwHostAddrCount,
  982. IN PIP4_ADDRESS pipDnsServerList,
  983. IN DWORD dwDnsServerCount,
  984. IN PWSTR pszDomainName,
  985. IN PREGISTER_HOST_STATUS pRegisterStatus,
  986. IN DWORD dwTTL,
  987. IN DWORD dwFlags
  988. )
  989. {
  990. return DnsDhcpRegisterHostAddrs(
  991. pszAdapterName,
  992. pszHostName,
  993. pHostAddrs,
  994. dwHostAddrCount,
  995. pipDnsServerList,
  996. dwDnsServerCount,
  997. pszDomainName,
  998. pRegisterStatus,
  999. dwTTL,
  1000. dwFlags );
  1001. }
  1002. DNS_STATUS
  1003. WINAPI
  1004. DnsDhcpSrvRegisterInitialize(
  1005. IN PDNS_CREDENTIALS pCredentials
  1006. )
  1007. {
  1008. return DnsDhcpSrvRegisterInit(
  1009. pCredentials,
  1010. 0 // default queue length
  1011. );
  1012. }
  1013. #endif
  1014. #if DNSAPI_XP_ENTRY
  1015. //
  1016. // Socket routines
  1017. //
  1018. // Note: i don't believe these were used outside dns (resolver, dnslib, dnsup)
  1019. // so could probably delete
  1020. //
  1021. DNS_STATUS
  1022. Dns_InitializeWinsock(
  1023. VOID
  1024. )
  1025. {
  1026. return Socket_InitWinsock();
  1027. }
  1028. DNS_STATUS
  1029. Dns_InitializeWinsockEx(
  1030. IN BOOL fForce
  1031. )
  1032. {
  1033. return Socket_InitWinsock();
  1034. }
  1035. VOID
  1036. Dns_CleanupWinsock(
  1037. VOID
  1038. )
  1039. {
  1040. Socket_CleanupWinsock();
  1041. }
  1042. #undef Dns_CloseSocket
  1043. #undef Dns_CloseConnection
  1044. VOID
  1045. Dns_CloseConnection(
  1046. IN SOCKET Socket
  1047. )
  1048. {
  1049. Socket_CloseEx( Socket, TRUE );
  1050. }
  1051. VOID
  1052. Dns_CloseSocket(
  1053. IN SOCKET Socket
  1054. )
  1055. {
  1056. Socket_CloseEx( Socket, FALSE );
  1057. }
  1058. SOCKET
  1059. Dns_CreateSocketEx(
  1060. IN INT Family,
  1061. IN INT SockType,
  1062. IN IP4_ADDRESS IpAddress,
  1063. IN USHORT Port,
  1064. IN DWORD dwFlags
  1065. )
  1066. /*++
  1067. Routine Description:
  1068. Create socket.
  1069. EXPORTED (ICS?) Dns_CreateSocket -- needs removal
  1070. Arguments:
  1071. Family -- socket family AF_INET or AF_INET6
  1072. SockType -- SOCK_DGRAM or SOCK_STREAM
  1073. IpAddress -- IP address to listen on (net byte order)
  1074. Port -- desired port in net order
  1075. - NET_ORDER_DNS_PORT for DNS listen sockets
  1076. - 0 for any port
  1077. dwFlags -- specifiy the attributes of the sockets
  1078. Return Value:
  1079. Socket if successful.
  1080. Otherwise INVALID_SOCKET.
  1081. --*/
  1082. {
  1083. SOCKET sock;
  1084. DNS_ADDR addr;
  1085. PDNS_ADDR paddr = NULL;
  1086. // if address, convert
  1087. if ( IpAddress )
  1088. {
  1089. paddr = &addr;
  1090. DnsAddr_BuildFromIp4(
  1091. paddr,
  1092. IpAddress,
  1093. 0 );
  1094. }
  1095. // real call
  1096. // - map error back into INVALID_SOCKET
  1097. sock = Socket_Create(
  1098. Family,
  1099. SockType,
  1100. paddr,
  1101. Port,
  1102. dwFlags );
  1103. if ( sock == 0 )
  1104. {
  1105. sock = INVALID_SOCKET;
  1106. }
  1107. return sock;
  1108. }
  1109. SOCKET
  1110. Dns_CreateSocket(
  1111. IN INT SockType,
  1112. IN IP4_ADDRESS IpAddress,
  1113. IN USHORT Port
  1114. )
  1115. /*++
  1116. Routine Description:
  1117. Wrapper function for CreateSocketEx. Passes in 0 for dwFlags (as opposed
  1118. to Dns_CreateMulticastSocket, which passes in flags to specify that
  1119. the socket is to be used for multicasting).
  1120. EXPORTED (ICS)! Delete Dns_CreateSocket() when clear.
  1121. Arguments:
  1122. SockType -- SOCK_DGRAM or SOCK_STREAM
  1123. IpAddress -- IP address to listen on (net byte order)
  1124. Port -- desired port in net order
  1125. - NET_ORDER_DNS_PORT for DNS listen sockets
  1126. - 0 for any port
  1127. Return Value:
  1128. socket if successful.
  1129. Otherwise INVALID_SOCKET.
  1130. --*/
  1131. {
  1132. return Dns_CreateSocketEx(
  1133. AF_INET,
  1134. SockType,
  1135. IpAddress,
  1136. Port,
  1137. 0 // no flags
  1138. );
  1139. }
  1140. //
  1141. // Dummy -- here only to keep same def file
  1142. // delete once clean build world
  1143. //
  1144. // Note: do not believe this was used period in XP
  1145. //
  1146. // Once verify can delete
  1147. //
  1148. SOCKET
  1149. Dns_CreateMulticastSocket(
  1150. IN INT SockType,
  1151. IN IP4_ADDRESS ipAddress,
  1152. IN USHORT Port,
  1153. IN BOOL fSend,
  1154. IN BOOL fReceive
  1155. )
  1156. {
  1157. return (SOCKET) INVALID_SOCKET;
  1158. }
  1159. #endif
  1160. //
  1161. // End export.c
  1162. //