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.

1994 lines
50 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. remote.c
  5. Abstract:
  6. Domain Name System (DNS) Server -- Admin Client API
  7. Remote API that are not direct calls to RPC stubs.
  8. Author:
  9. Jim Gilroy (jamesg) April 1997
  10. Environment:
  11. User Mode - Win32
  12. Revision History:
  13. --*/
  14. #include "dnsclip.h"
  15. #include <ntdsapi.h>
  16. #include <dsgetdc.h>
  17. #include <lmapibuf.h>
  18. //
  19. // Error indicating talking to old server
  20. //
  21. #define DNS_ERROR_NT4 RPC_S_UNKNOWN_IF
  22. //
  23. // Macro to set up RPC structure header fields.
  24. //
  25. // Sample:
  26. // DNS_RPC_FORWARDERS forwarders;
  27. // INITIALIZE_RPC_STRUCT( FORWARDERS, forwarders );
  28. //
  29. #define INITIALIZE_RPC_STRUCT( rpcStructType, rpcStruct ) \
  30. * ( DWORD * ) &( rpcStruct ) = \
  31. DNS_RPC_## rpcStructType ##_VER; \
  32. * ( ( ( DWORD * ) &( rpcStruct ) ) + 1 ) = 0;
  33. //
  34. // DNS_VERBOSE_ macros
  35. //
  36. #define DNS_DBG( _Level, _PrintArgs ) \
  37. if ( _Level >= dwVerbose ) \
  38. { \
  39. printf _PrintArgs; \
  40. }
  41. //
  42. // General Server\Zone, Query\Operation for DWORD properties
  43. //
  44. DNS_STATUS
  45. DNS_API_FUNCTION
  46. DnssrvQueryDwordPropertyEx(
  47. IN DWORD dwClientVersion,
  48. IN DWORD dwSettingFlags,
  49. IN LPCWSTR Server,
  50. IN LPCSTR pszZone,
  51. IN LPCSTR pszProperty,
  52. OUT PDWORD pdwResult
  53. )
  54. {
  55. DNS_STATUS status;
  56. DWORD typeId;
  57. DNSDBG( STUB, (
  58. "Enter DnssrvQueryDwordProperty()\n"
  59. " Client ver = 0x%X\n"
  60. " Server = %s\n"
  61. " ZoneName = %s\n"
  62. " Property = %s\n"
  63. " pResult = %p\n",
  64. dwClientVersion,
  65. Server,
  66. pszZone,
  67. pszProperty,
  68. pdwResult ));
  69. status = DnssrvComplexOperationEx(
  70. dwClientVersion,
  71. dwSettingFlags,
  72. Server,
  73. pszZone,
  74. DNSSRV_QUERY_DWORD_PROPERTY,
  75. DNSSRV_TYPEID_LPSTR, // property name as string
  76. (LPSTR) pszProperty,
  77. & typeId, // DWORD property value back out
  78. (PVOID *) pdwResult );
  79. DNSDBG( STUB, (
  80. "Leave DnssrvQueryDwordProperty(): status %d (%p)\n"
  81. " Server = %s\n"
  82. " ZoneName = %s\n"
  83. " Property = %s\n"
  84. " TypeId = %d\n"
  85. " Result = %d (%p)\n",
  86. status, status,
  87. Server,
  88. pszZone,
  89. pszProperty,
  90. typeId,
  91. *pdwResult, *pdwResult ));
  92. ASSERT(
  93. (status == ERROR_SUCCESS && typeId == DNSSRV_TYPEID_DWORD) ||
  94. (status != ERROR_SUCCESS && *pdwResult == 0 ) );
  95. return( status );
  96. }
  97. DNS_STATUS
  98. DNS_API_FUNCTION
  99. DnssrvResetDwordPropertyEx(
  100. IN DWORD dwClientVersion,
  101. IN DWORD dwSettingFlags,
  102. IN LPCWSTR Server,
  103. IN LPCSTR pszZone,
  104. IN DWORD dwContext,
  105. IN LPCSTR pszProperty,
  106. IN DWORD dwPropertyValue
  107. )
  108. {
  109. DNS_STATUS status;
  110. DNS_RPC_NAME_AND_PARAM param;
  111. param.dwParam = dwPropertyValue;
  112. param.pszNodeName = (LPSTR) pszProperty;
  113. DNSDBG( STUB, (
  114. "Enter DnssrvResetDwordPropertyEx()\n"
  115. " Client ver = 0x%X\n"
  116. " Server = %S\n"
  117. " ZoneName = %s\n"
  118. " Context = %p\n"
  119. " PropertyName = %s\n"
  120. " PropertyValue = %d (%p)\n",
  121. dwClientVersion,
  122. Server,
  123. pszZone,
  124. dwContext,
  125. pszProperty,
  126. dwPropertyValue,
  127. dwPropertyValue ));
  128. status = DnssrvOperationEx(
  129. dwClientVersion,
  130. dwSettingFlags,
  131. Server,
  132. pszZone,
  133. dwContext,
  134. DNSSRV_OP_RESET_DWORD_PROPERTY,
  135. DNSSRV_TYPEID_NAME_AND_PARAM,
  136. &param );
  137. DNSDBG( STUB, (
  138. "Leaving DnssrvResetDwordPropertyEx(): status = %d (%p)\n",
  139. status, status ));
  140. return( status );
  141. }
  142. DNS_STATUS
  143. DNS_API_FUNCTION
  144. DnssrvResetStringPropertyEx(
  145. IN DWORD dwClientVersion,
  146. IN DWORD dwSettingFlags,
  147. IN LPCWSTR pwszServerName,
  148. IN LPCSTR pszZone,
  149. IN DWORD dwContext,
  150. IN LPCSTR pszProperty,
  151. IN LPCWSTR pswzPropertyValue,
  152. IN DWORD dwFlags
  153. )
  154. /*++
  155. Routine Description:
  156. Set a string property on the server. The property value is
  157. unicode.
  158. Arguments:
  159. Server - server name
  160. pszZone - pointer to zone
  161. dwContext - context
  162. pszProperty - name of property to set
  163. pswzPropertyValue - unicode property value
  164. dwFlags - flags, may be combination of:
  165. DNSSRV_OP_PARAM_APPLY_ALL_ZONES
  166. Return Value:
  167. None
  168. --*/
  169. {
  170. DNS_STATUS status;
  171. DNSDBG( STUB, (
  172. "Enter DnssrvResetStringPropertyEx()\n"
  173. " Client ver = 0x%X\n"
  174. " Server = %S\n"
  175. " ZoneName = %s\n"
  176. " Context = %p\n"
  177. " PropertyName = %s\n"
  178. " PropertyValue = %S\n",
  179. dwClientVersion,
  180. pwszServerName,
  181. pszZone,
  182. dwContext,
  183. pszProperty,
  184. pswzPropertyValue ));
  185. status = DnssrvOperationEx(
  186. dwClientVersion,
  187. dwSettingFlags,
  188. pwszServerName,
  189. pszZone,
  190. dwContext,
  191. pszProperty,
  192. DNSSRV_TYPEID_LPWSTR,
  193. ( PVOID ) pswzPropertyValue );
  194. DNSDBG( STUB, (
  195. "Leaving DnssrvResetDwordPropertyEx(): status = %d (%p)\n",
  196. status, status ));
  197. return status;
  198. }
  199. DNS_STATUS
  200. DNS_API_FUNCTION
  201. DnssrvResetIPListPropertyEx(
  202. IN DWORD dwClientVersion,
  203. IN DWORD dwSettingFlags,
  204. IN LPCWSTR pwszServerName,
  205. IN LPCSTR pszZone,
  206. IN DWORD dwContext,
  207. IN LPCSTR pszProperty,
  208. IN PIP_ARRAY pipArray,
  209. IN DWORD dwFlags
  210. )
  211. /*++
  212. Routine Description:
  213. Set an IP list property on the server.
  214. Arguments:
  215. Server - server name
  216. pszZone - pointer to zone
  217. dwContext - context
  218. pszProperty - name of property to set
  219. pipArray - new IP array property value
  220. dwFlags - flags, may be combination of:
  221. DNSSRV_OP_PARAM_APPLY_ALL_ZONES
  222. Return Value:
  223. None
  224. --*/
  225. {
  226. DNS_STATUS status;
  227. DNSDBG( STUB, (
  228. "Enter DnssrvResetIPListPropertyEx()\n"
  229. " Client ver = 0x%X\n"
  230. " Server = %S\n"
  231. " ZoneName = %s\n"
  232. " Context = %p\n"
  233. " PropertyName = %s\n"
  234. " pipArray = %p\n",
  235. dwClientVersion,
  236. pwszServerName,
  237. pszZone,
  238. dwContext,
  239. pszProperty,
  240. pipArray ));
  241. DnsDbg_Ip4Array(
  242. "DnssrvResetIPListPropertyEx\n",
  243. NULL,
  244. pipArray );
  245. status = DnssrvOperationEx(
  246. dwClientVersion,
  247. dwSettingFlags,
  248. pwszServerName,
  249. pszZone,
  250. dwContext,
  251. pszProperty,
  252. DNSSRV_TYPEID_IPARRAY,
  253. ( pipArray && pipArray->AddrCount ) ?
  254. pipArray :
  255. NULL );
  256. DNSDBG( STUB, (
  257. "Leaving DnssrvResetIPListPropertyEx(): status = %d (%p)\n",
  258. status, status ));
  259. return status;
  260. } // DnssrvResetIPListPropertyEx
  261. //
  262. // Server Queries
  263. //
  264. DNS_STATUS
  265. DNS_API_FUNCTION
  266. DnssrvGetServerInfo(
  267. IN LPCWSTR Server,
  268. OUT PDNS_RPC_SERVER_INFO * ppServerInfo
  269. )
  270. {
  271. DNS_STATUS status;
  272. DWORD typeId;
  273. status = DnssrvQuery(
  274. Server,
  275. NULL,
  276. DNSSRV_QUERY_SERVER_INFO,
  277. &typeId,
  278. ppServerInfo );
  279. ASSERT(
  280. (status == ERROR_SUCCESS && typeId == DNSSRV_TYPEID_SERVER_INFO) ||
  281. (status != ERROR_SUCCESS && *ppServerInfo == NULL ) );
  282. return( status );
  283. }
  284. DNS_STATUS
  285. DNS_API_FUNCTION
  286. DnssrvQueryZoneDwordProperty(
  287. IN LPCWSTR Server,
  288. IN LPCSTR pszZoneName,
  289. IN LPCSTR pszProperty,
  290. OUT PDWORD pdwResult
  291. )
  292. {
  293. DNS_STATUS status;
  294. DWORD typeId;
  295. IF_DNSDBG( STUB )
  296. {
  297. DNS_PRINT((
  298. "Enter DnssrvQueryDwordProperty()\n"
  299. " Server = %s\n"
  300. " pszProperty = %s\n"
  301. " pResult = %p\n",
  302. Server,
  303. pszZoneName,
  304. pszProperty,
  305. pdwResult ));
  306. }
  307. status = DnssrvQuery(
  308. Server,
  309. pszZoneName,
  310. pszProperty,
  311. & typeId,
  312. (PVOID *) pdwResult );
  313. IF_DNSDBG( STUB )
  314. {
  315. DNS_PRINT((
  316. "Leave DnssrvQueryZoneDwordProperty(): status %d (%p)\n"
  317. " Server = %s\n"
  318. " pszProperty = %s\n"
  319. " TypeId = %d\n"
  320. " Result = %d (%p)\n",
  321. status, status,
  322. Server,
  323. pszProperty,
  324. typeId,
  325. *pdwResult, *pdwResult ));
  326. ASSERT(
  327. (status == ERROR_SUCCESS && typeId == DNSSRV_TYPEID_DWORD) ||
  328. (status != ERROR_SUCCESS && *pdwResult == 0 ) );
  329. }
  330. return( status );
  331. }
  332. //
  333. // Server Operations
  334. //
  335. DNS_STATUS
  336. DNS_API_FUNCTION
  337. DnssrvResetServerDwordProperty(
  338. IN LPCWSTR Server,
  339. IN LPCSTR pszProperty,
  340. IN DWORD dwPropertyValue
  341. )
  342. {
  343. DNS_STATUS status;
  344. DNSDBG( STUB, (
  345. "Enter DnssrvResetServerDwordProperty()\n"
  346. " Server = %s\n"
  347. " pszPropertyName = %s\n"
  348. " dwPropertyValue = %p\n",
  349. Server,
  350. pszProperty,
  351. dwPropertyValue ));
  352. status = DnssrvOperation(
  353. Server,
  354. NULL,
  355. pszProperty,
  356. DNSSRV_TYPEID_DWORD,
  357. (PVOID) (DWORD_PTR) dwPropertyValue );
  358. DNSDBG( STUB, (
  359. "Leaving DnssrvResetServerDwordProperty: status = %d (%p)\n",
  360. status, status ));
  361. return( status );
  362. }
  363. DNS_STATUS
  364. DNS_API_FUNCTION
  365. DnssrvCreateZoneEx(
  366. IN LPCWSTR Server,
  367. IN LPCSTR pszZoneName,
  368. IN DWORD dwZoneType,
  369. IN DWORD fAllowUpdate,
  370. IN DWORD dwCreateFlags,
  371. IN LPCSTR pszAdminEmailName,
  372. IN DWORD cMasters,
  373. IN PIP_ADDRESS aipMasters,
  374. IN BOOL bDsIntegrated,
  375. IN LPCSTR pszDataFile,
  376. IN DWORD dwTimeout, // for forwarder zones
  377. IN DWORD fSlave, // for forwarder zones
  378. IN DWORD dwDpFlags, // for directory partition
  379. IN LPCSTR pszDpFqdn // for directory partition
  380. )
  381. {
  382. DNS_STATUS status;
  383. DNS_RPC_ZONE_CREATE_INFO zoneInfo;
  384. PIP_ARRAY arrayIp = NULL;
  385. RtlZeroMemory(
  386. &zoneInfo,
  387. sizeof( DNS_RPC_ZONE_CREATE_INFO ) );
  388. INITIALIZE_RPC_STRUCT( ZONE_CREATE_INFO, zoneInfo );
  389. if ( cMasters && aipMasters )
  390. {
  391. arrayIp = Dns_BuildIpArray(
  392. cMasters,
  393. aipMasters );
  394. if ( !arrayIp && cMasters )
  395. {
  396. return( DNS_ERROR_NO_MEMORY );
  397. }
  398. }
  399. zoneInfo.pszZoneName = (LPSTR) pszZoneName;
  400. zoneInfo.dwZoneType = dwZoneType;
  401. zoneInfo.fAllowUpdate = fAllowUpdate;
  402. zoneInfo.fAging = 0;
  403. zoneInfo.dwFlags = dwCreateFlags;
  404. zoneInfo.fDsIntegrated = (DWORD) bDsIntegrated;
  405. // temp backward compat
  406. zoneInfo.fLoadExisting = !!(dwCreateFlags & DNS_ZONE_LOAD_EXISTING);
  407. zoneInfo.pszDataFile = (LPSTR) pszDataFile;
  408. zoneInfo.pszAdmin = (LPSTR) pszAdminEmailName;
  409. zoneInfo.aipMasters = arrayIp;
  410. zoneInfo.dwTimeout = dwTimeout;
  411. zoneInfo.fSlave = fSlave;
  412. zoneInfo.dwDpFlags = dwDpFlags;
  413. zoneInfo.pszDpFqdn = ( LPSTR ) pszDpFqdn;
  414. status = DnssrvOperation(
  415. Server,
  416. NULL, // server operation
  417. DNSSRV_OP_ZONE_CREATE,
  418. DNSSRV_TYPEID_ZONE_CREATE,
  419. (PVOID) &zoneInfo
  420. );
  421. FREE_HEAP( arrayIp );
  422. return( status );
  423. }
  424. DNS_STATUS
  425. DNS_API_FUNCTION
  426. DnssrvCreateZone(
  427. IN LPCWSTR Server,
  428. IN LPCSTR pszZoneName,
  429. IN DWORD dwZoneType,
  430. IN LPCSTR pszAdminEmailName,
  431. IN DWORD cMasters,
  432. IN PIP_ADDRESS aipMasters,
  433. IN DWORD fLoadExisting,
  434. IN DWORD fDsIntegrated,
  435. IN LPCSTR pszDataFile,
  436. IN DWORD dwTimeout,
  437. IN DWORD fSlave
  438. )
  439. {
  440. DWORD flags = 0;
  441. DWORD dpFlags = 0;
  442. if ( fLoadExisting )
  443. {
  444. flags = DNS_ZONE_LOAD_EXISTING;
  445. }
  446. return DnssrvCreateZoneEx(
  447. Server,
  448. pszZoneName,
  449. dwZoneType,
  450. 0, // update unknown, send off
  451. flags, // load flags
  452. pszAdminEmailName,
  453. cMasters,
  454. aipMasters,
  455. fDsIntegrated,
  456. pszDataFile,
  457. dwTimeout,
  458. fSlave,
  459. dpFlags, // dwDirPartFlag
  460. NULL // pszDirPartFqdn
  461. );
  462. }
  463. DNS_STATUS
  464. DNS_API_FUNCTION
  465. DnssrvCreateZoneForDcPromoEx(
  466. IN LPCWSTR Server,
  467. IN LPCSTR pszZoneName,
  468. IN LPCSTR pszDataFile,
  469. IN DWORD dwFlags
  470. )
  471. /*++
  472. Routine Description:
  473. Create a zone during dcpromo. The DNS server will automagically move
  474. this zone to Active Directory when the directoy becomes available after
  475. reboot.
  476. Arguments:
  477. Server -- server to send request to
  478. pszZoneName -- UTF-8 name of the new zone
  479. pszDataFile -- UTF-8 zone file name
  480. dwFlags -- zone creation flags, pass zero or one of:
  481. DNS_ZONE_CREATE_FOR_DCPROMO
  482. DNS_ZONE_CREATE_FOR_DCPROMO_FOREST
  483. Return Value:
  484. None
  485. --*/
  486. {
  487. //
  488. // By default the new zone must be a dcpromo zone so make sure that
  489. // flag is turned on. For a new forest dcpromo zone both this flag
  490. // and DNS_ZONE_CREATE_FOR_NEW_FOREST_DCPROMO should be set.
  491. //
  492. dwFlags |= DNS_ZONE_CREATE_FOR_DCPROMO;
  493. //
  494. // Create the zone.
  495. //
  496. return DnssrvCreateZoneEx(
  497. Server,
  498. pszZoneName,
  499. 1, // primary
  500. 0, // update unknown, send off
  501. dwFlags,
  502. NULL, // no admin name
  503. 0, // no masters
  504. NULL,
  505. FALSE, // not DS integrated
  506. pszDataFile,
  507. 0, // timeout - for forwarder zones
  508. 0, // slave - for forwarder zones
  509. 0, // dwDirPartFlag
  510. NULL ); // pszDirPartFqdn
  511. } // DnssrvCreateZoneForDcPromoEx
  512. DNS_STATUS
  513. DNS_API_FUNCTION
  514. DnssrvCreateZoneForDcPromo(
  515. IN LPCWSTR Server,
  516. IN LPCSTR pszZoneName,
  517. IN LPCSTR pszDataFile
  518. )
  519. {
  520. return DnssrvCreateZoneForDcPromoEx(
  521. Server,
  522. pszZoneName,
  523. pszDataFile,
  524. 0 ); // flags
  525. }
  526. DNS_STATUS
  527. DNS_API_FUNCTION
  528. DnssrvCreateZoneInDirectoryPartition(
  529. IN LPCWSTR pwszServer,
  530. IN LPCSTR pszZoneName,
  531. IN DWORD dwZoneType,
  532. IN LPCSTR pszAdminEmailName,
  533. IN DWORD cMasters,
  534. IN PIP_ADDRESS aipMasters,
  535. IN DWORD fLoadExisting,
  536. IN DWORD dwTimeout,
  537. IN DWORD fSlave,
  538. IN DWORD dwDirPartFlags,
  539. IN LPCSTR pszDirPartFqdn
  540. )
  541. {
  542. DWORD dwFlags = 0;
  543. if ( fLoadExisting )
  544. {
  545. dwFlags = DNS_ZONE_LOAD_EXISTING;
  546. }
  547. return DnssrvCreateZoneEx(
  548. pwszServer,
  549. pszZoneName,
  550. dwZoneType,
  551. 0, // allow update
  552. dwFlags,
  553. pszAdminEmailName,
  554. cMasters, // masters count
  555. aipMasters, // masters array
  556. TRUE, // DS integrated
  557. NULL, // data file
  558. dwTimeout, // for forwarder zones
  559. fSlave, // for forwarder zones
  560. dwDirPartFlags,
  561. pszDirPartFqdn );
  562. }
  563. DNS_STATUS
  564. DNS_API_FUNCTION
  565. DnssrvClearStatistics(
  566. IN LPCWSTR Server
  567. )
  568. {
  569. DNS_STATUS status;
  570. status = DnssrvOperation(
  571. Server,
  572. NULL,
  573. DNSSRV_OP_CLEAR_STATISTICS,
  574. DNSSRV_TYPEID_NULL,
  575. (PVOID) NULL
  576. );
  577. return( status );
  578. }
  579. DNS_STATUS
  580. DNS_API_FUNCTION
  581. DnssrvResetServerListenAddresses(
  582. IN LPCWSTR Server,
  583. IN DWORD cListenAddrs,
  584. IN PIP_ADDRESS aipListenAddrs
  585. )
  586. {
  587. DNS_STATUS status;
  588. PIP_ARRAY arrayIp;
  589. arrayIp = Dns_BuildIpArray(
  590. cListenAddrs,
  591. aipListenAddrs );
  592. if ( !arrayIp && cListenAddrs )
  593. {
  594. return( DNS_ERROR_NO_MEMORY );
  595. }
  596. status = DnssrvOperation(
  597. Server,
  598. NULL,
  599. DNS_REGKEY_LISTEN_ADDRESSES,
  600. DNSSRV_TYPEID_IPARRAY,
  601. (PVOID) arrayIp
  602. );
  603. FREE_HEAP( arrayIp );
  604. return( status );
  605. }
  606. DNS_STATUS
  607. DNS_API_FUNCTION
  608. DnssrvResetForwarders(
  609. IN LPCWSTR Server,
  610. IN DWORD cForwarders,
  611. IN PIP_ADDRESS aipForwarders,
  612. IN DWORD dwForwardTimeout,
  613. IN DWORD fSlave
  614. )
  615. {
  616. DNS_STATUS status;
  617. DNS_RPC_FORWARDERS forwarders;
  618. PIP_ARRAY arrayIp;
  619. INITIALIZE_RPC_STRUCT( FORWARDERS, forwarders );
  620. arrayIp = Dns_BuildIpArray(
  621. cForwarders,
  622. aipForwarders );
  623. if ( !arrayIp && cForwarders )
  624. {
  625. return( DNS_ERROR_NO_MEMORY );
  626. }
  627. forwarders.fSlave = fSlave;
  628. forwarders.dwForwardTimeout = dwForwardTimeout;
  629. forwarders.aipForwarders = arrayIp;
  630. status = DnssrvOperation(
  631. Server,
  632. NULL,
  633. DNS_REGKEY_FORWARDERS,
  634. DNSSRV_TYPEID_FORWARDERS,
  635. (PVOID) &forwarders
  636. );
  637. FREE_HEAP( arrayIp );
  638. return( status );
  639. }
  640. //
  641. // Zone Queries
  642. //
  643. DNS_STATUS
  644. DNS_API_FUNCTION
  645. DnssrvGetZoneInfo(
  646. IN LPCWSTR Server,
  647. IN LPCSTR pszZone,
  648. OUT PDNS_RPC_ZONE_INFO * ppZoneInfo
  649. )
  650. {
  651. DNS_STATUS status;
  652. DWORD typeId;
  653. status = DnssrvQuery(
  654. Server,
  655. pszZone,
  656. DNSSRV_QUERY_ZONE_INFO,
  657. & typeId,
  658. ppZoneInfo
  659. );
  660. ASSERT(
  661. (status == ERROR_SUCCESS && typeId == DNSSRV_TYPEID_ZONE_INFO) ||
  662. (status != ERROR_SUCCESS && *ppZoneInfo == NULL ) );
  663. return( status );
  664. }
  665. //
  666. // Zone Operations
  667. //
  668. DNS_STATUS
  669. DNS_API_FUNCTION
  670. DnssrvResetZoneTypeEx(
  671. IN LPCWSTR Server,
  672. IN LPCSTR pszZoneName,
  673. IN DWORD dwZoneType,
  674. IN DWORD cMasters,
  675. IN PIP_ADDRESS aipMasters,
  676. IN DWORD dwLoadOptions,
  677. IN DWORD fDsIntegrated,
  678. IN LPCSTR pszDataFile,
  679. IN DWORD dwDpFlags,
  680. IN LPCSTR pszDpFqdn
  681. )
  682. {
  683. DNS_STATUS status;
  684. DNS_RPC_ZONE_CREATE_INFO zoneInfo;
  685. PIP_ARRAY arrayIp = NULL;
  686. RtlZeroMemory(
  687. &zoneInfo,
  688. sizeof( DNS_RPC_ZONE_CREATE_INFO ) );
  689. INITIALIZE_RPC_STRUCT( ZONE_CREATE_INFO, zoneInfo );
  690. if ( cMasters )
  691. {
  692. arrayIp = Dns_BuildIpArray(
  693. cMasters,
  694. aipMasters );
  695. if ( !arrayIp )
  696. {
  697. return( DNS_ERROR_NO_MEMORY );
  698. }
  699. }
  700. zoneInfo.pszZoneName = ( LPSTR ) pszZoneName;
  701. zoneInfo.dwZoneType = dwZoneType;
  702. zoneInfo.fDsIntegrated = fDsIntegrated;
  703. zoneInfo.fLoadExisting = dwLoadOptions;
  704. zoneInfo.pszDataFile = ( LPSTR ) pszDataFile;
  705. zoneInfo.pszAdmin = NULL;
  706. zoneInfo.aipMasters = arrayIp;
  707. zoneInfo.dwDpFlags = dwDpFlags;
  708. zoneInfo.pszDpFqdn = ( LPSTR ) pszDpFqdn;
  709. status = DnssrvOperation(
  710. Server,
  711. pszZoneName,
  712. DNSSRV_OP_ZONE_TYPE_RESET,
  713. DNSSRV_TYPEID_ZONE_CREATE,
  714. ( PVOID ) &zoneInfo );
  715. FREE_HEAP( arrayIp );
  716. return status;
  717. }
  718. DNS_STATUS
  719. DNS_API_FUNCTION
  720. DnssrvRenameZone(
  721. IN LPCWSTR Server,
  722. IN LPCSTR pszCurrentZoneName,
  723. IN LPCSTR pszNewZoneName,
  724. IN LPCSTR pszNewFileName
  725. )
  726. {
  727. DNS_STATUS status;
  728. DNS_RPC_ZONE_RENAME_INFO renameInfo;
  729. RtlZeroMemory(
  730. &renameInfo,
  731. sizeof( DNS_RPC_ZONE_RENAME_INFO ) );
  732. INITIALIZE_RPC_STRUCT( ZONE_RENAME_INFO, renameInfo );
  733. renameInfo.pszNewZoneName = ( LPSTR ) pszNewZoneName;
  734. renameInfo.pszNewFileName = ( LPSTR ) pszNewFileName;
  735. status = DnssrvOperation(
  736. Server,
  737. pszCurrentZoneName,
  738. DNSSRV_OP_ZONE_RENAME,
  739. DNSSRV_TYPEID_ZONE_RENAME,
  740. ( PVOID ) &renameInfo );
  741. return status;
  742. }
  743. DNS_STATUS
  744. DNS_API_FUNCTION
  745. DnssrvChangeZoneDirectoryPartition(
  746. IN LPCWSTR Server,
  747. IN LPCSTR pszZoneName,
  748. IN LPCSTR pszNewPartitionName
  749. )
  750. {
  751. DNS_STATUS status;
  752. DNS_RPC_ZONE_CHANGE_DP rpcInfo;
  753. RtlZeroMemory(
  754. &rpcInfo,
  755. sizeof( DNS_RPC_ZONE_CHANGE_DP ) );
  756. INITIALIZE_RPC_STRUCT( ZONE_RENAME_INFO, rpcInfo );
  757. rpcInfo.pszDestPartition = ( LPSTR ) pszNewPartitionName;
  758. status = DnssrvOperation(
  759. Server,
  760. pszZoneName,
  761. DNSSRV_OP_ZONE_CHANGE_DP,
  762. DNSSRV_TYPEID_ZONE_CHANGE_DP,
  763. ( PVOID ) &rpcInfo );
  764. return status;
  765. }
  766. DNS_STATUS
  767. DNS_API_FUNCTION
  768. DnssrvExportZone(
  769. IN LPCWSTR Server,
  770. IN LPCSTR pszZoneName,
  771. IN LPCSTR pszZoneExportFile
  772. )
  773. {
  774. DNS_STATUS status;
  775. DNS_RPC_ZONE_EXPORT_INFO info;
  776. RtlZeroMemory(
  777. &info,
  778. sizeof( DNS_RPC_ZONE_EXPORT_INFO ) );
  779. INITIALIZE_RPC_STRUCT( ZONE_EXPORT_INFO, info );
  780. info.pszZoneExportFile = ( LPSTR ) pszZoneExportFile;
  781. status = DnssrvOperation(
  782. Server,
  783. pszZoneName,
  784. DNSSRV_OP_ZONE_EXPORT,
  785. DNSSRV_TYPEID_ZONE_EXPORT,
  786. ( PVOID ) &info );
  787. return status;
  788. }
  789. DNS_STATUS
  790. DNS_API_FUNCTION
  791. DnssrvResetZoneMastersEx(
  792. IN LPCWSTR Server,
  793. IN LPCSTR pszZone,
  794. IN DWORD cMasters,
  795. IN PIP_ADDRESS aipMasters,
  796. IN DWORD fSetLocalMasters
  797. )
  798. {
  799. DNS_STATUS status;
  800. PIP_ARRAY arrayIp;
  801. arrayIp = Dns_BuildIpArray(
  802. cMasters,
  803. aipMasters );
  804. if ( !arrayIp && cMasters )
  805. {
  806. return( DNS_ERROR_NO_MEMORY );
  807. }
  808. status = DnssrvOperation(
  809. Server,
  810. pszZone,
  811. fSetLocalMasters ?
  812. DNS_REGKEY_ZONE_LOCAL_MASTERS :
  813. DNS_REGKEY_ZONE_MASTERS,
  814. DNSSRV_TYPEID_IPARRAY,
  815. (PVOID) arrayIp );
  816. FREE_HEAP( arrayIp );
  817. return( status );
  818. }
  819. DNS_STATUS
  820. DNS_API_FUNCTION
  821. DnssrvResetZoneMasters(
  822. IN LPCWSTR Server,
  823. IN LPCSTR pszZone,
  824. IN DWORD cMasters,
  825. IN PIP_ADDRESS aipMasters
  826. )
  827. {
  828. DNS_STATUS status;
  829. PIP_ARRAY arrayIp;
  830. arrayIp = Dns_BuildIpArray(
  831. cMasters,
  832. aipMasters );
  833. if ( !arrayIp && cMasters )
  834. {
  835. return( DNS_ERROR_NO_MEMORY );
  836. }
  837. status = DnssrvOperation(
  838. Server,
  839. pszZone,
  840. DNS_REGKEY_ZONE_MASTERS,
  841. DNSSRV_TYPEID_IPARRAY,
  842. (PVOID) arrayIp
  843. );
  844. FREE_HEAP( arrayIp );
  845. return( status );
  846. }
  847. DNS_STATUS
  848. DNS_API_FUNCTION
  849. DnssrvResetZoneSecondaries(
  850. IN LPCWSTR Server,
  851. IN LPCSTR pszZone,
  852. IN DWORD fSecureSecondaries,
  853. IN DWORD cSecondaries,
  854. IN PIP_ADDRESS aipSecondaries,
  855. IN DWORD fNotifyLevel,
  856. IN DWORD cNotify,
  857. IN PIP_ADDRESS aipNotify
  858. )
  859. {
  860. DNS_STATUS status;
  861. DNS_RPC_ZONE_SECONDARIES secondaryInfo;
  862. PIP_ARRAY arrayIp;
  863. INITIALIZE_RPC_STRUCT( ZONE_SECONDARIES, secondaryInfo );
  864. arrayIp = Dns_BuildIpArray(
  865. cSecondaries,
  866. aipSecondaries );
  867. if ( !arrayIp && cSecondaries )
  868. {
  869. return( DNS_ERROR_NO_MEMORY );
  870. }
  871. secondaryInfo.fSecureSecondaries = fSecureSecondaries;
  872. secondaryInfo.aipSecondaries = arrayIp;
  873. arrayIp = Dns_BuildIpArray(
  874. cNotify,
  875. aipNotify );
  876. if ( !arrayIp && cNotify )
  877. {
  878. return( DNS_ERROR_NO_MEMORY );
  879. }
  880. secondaryInfo.aipNotify = arrayIp;
  881. secondaryInfo.fNotifyLevel = fNotifyLevel;
  882. status = DnssrvOperation(
  883. Server,
  884. pszZone,
  885. DNS_REGKEY_ZONE_SECONDARIES,
  886. DNSSRV_TYPEID_ZONE_SECONDARIES,
  887. (PVOID) &secondaryInfo
  888. );
  889. FREE_HEAP( secondaryInfo.aipNotify );
  890. FREE_HEAP( secondaryInfo.aipSecondaries );
  891. return( status );
  892. }
  893. #if 0
  894. DNS_STATUS
  895. DNS_API_FUNCTION
  896. DnssrvResetZoneScavengeServers(
  897. IN LPCWSTR Server,
  898. IN LPCSTR pszZone,
  899. IN DWORD cServers,
  900. IN PIP_ADDRESS aipServers
  901. )
  902. {
  903. DNS_STATUS status;
  904. PIP_ARRAY arrayIp;
  905. arrayIp = Dns_BuildIpArray(
  906. cServers,
  907. aipServers );
  908. if ( !arrayIp && cSecondaries )
  909. {
  910. return( DNS_ERROR_NO_MEMORY );
  911. }
  912. status = DnssrvOperation(
  913. Server,
  914. pszZone,
  915. DNS_REGKEY_ZONE_SCAVENGE_SERVERS,
  916. DNSSRV_TYPEID_IPARRAY,
  917. arrayIp
  918. );
  919. FREE_HEAP( arrayIp );
  920. return( status );
  921. }
  922. #endif
  923. //
  924. // Zone management API
  925. //
  926. DNS_STATUS
  927. DNS_API_FUNCTION
  928. DnssrvIncrementZoneVersion(
  929. IN LPCWSTR Server,
  930. IN LPCSTR pszZone
  931. )
  932. {
  933. return DnssrvOperation(
  934. Server,
  935. pszZone,
  936. DNSSRV_OP_ZONE_INCREMENT_VERSION,
  937. DNSSRV_TYPEID_NULL,
  938. (PVOID) NULL
  939. );
  940. }
  941. DNS_STATUS
  942. DNS_API_FUNCTION
  943. DnssrvDeleteZone(
  944. IN LPCWSTR Server,
  945. IN LPCSTR pszZone
  946. )
  947. {
  948. return DnssrvOperation(
  949. Server,
  950. pszZone,
  951. DNSSRV_OP_ZONE_DELETE,
  952. DNSSRV_TYPEID_NULL,
  953. (PVOID) NULL
  954. );
  955. }
  956. DNS_STATUS
  957. DNS_API_FUNCTION
  958. DnssrvPauseZone(
  959. IN LPCWSTR Server,
  960. IN LPCSTR pszZone
  961. )
  962. {
  963. return DnssrvOperation(
  964. Server,
  965. pszZone,
  966. DNSSRV_OP_ZONE_PAUSE,
  967. DNSSRV_TYPEID_NULL,
  968. (PVOID) NULL
  969. );
  970. }
  971. DNS_STATUS
  972. DNS_API_FUNCTION
  973. DnssrvResumeZone(
  974. IN LPCWSTR Server,
  975. IN LPCSTR pszZone
  976. )
  977. {
  978. return DnssrvOperation(
  979. Server,
  980. pszZone,
  981. DNSSRV_OP_ZONE_RESUME,
  982. DNSSRV_TYPEID_NULL,
  983. (PVOID) NULL
  984. );
  985. }
  986. //
  987. // Record viewing API
  988. //
  989. DNS_STATUS
  990. DNS_API_FUNCTION
  991. DnssrvEnumRecordsAndConvertNodes(
  992. IN LPCWSTR pszServer,
  993. IN LPCSTR pszZoneName,
  994. IN LPCSTR pszNodeName,
  995. IN LPCSTR pszStartChild,
  996. IN WORD wRecordType,
  997. IN DWORD dwSelectFlag,
  998. IN LPCSTR pszFilterStart,
  999. IN LPCSTR pszFilterStop,
  1000. OUT PDNS_NODE * ppNodeFirst,
  1001. OUT PDNS_NODE * ppNodeLast
  1002. )
  1003. {
  1004. DNS_STATUS status;
  1005. PDNS_NODE pnode;
  1006. PDNS_NODE pnodeLast;
  1007. PBYTE pbuffer;
  1008. DWORD bufferLength;
  1009. //
  1010. // get records from server
  1011. //
  1012. status = DnssrvEnumRecords(
  1013. pszServer,
  1014. pszZoneName,
  1015. pszNodeName,
  1016. pszStartChild,
  1017. wRecordType,
  1018. dwSelectFlag,
  1019. pszFilterStart,
  1020. pszFilterStop,
  1021. & bufferLength,
  1022. & pbuffer );
  1023. if ( status != ERROR_SUCCESS && status != ERROR_MORE_DATA )
  1024. {
  1025. return( status );
  1026. }
  1027. //
  1028. // pull nodes and records out of RPC buffer
  1029. //
  1030. pnode = DnsConvertRpcBuffer(
  1031. & pnodeLast,
  1032. bufferLength,
  1033. pbuffer,
  1034. TRUE // convert unicode
  1035. );
  1036. if ( !pnode )
  1037. {
  1038. DNS_PRINT((
  1039. "ERROR: failure converting RPC buffer to DNS records\n"
  1040. " status = %p\n",
  1041. GetLastError() ));
  1042. ASSERT( FALSE );
  1043. return( ERROR_INVALID_DATA );
  1044. }
  1045. *ppNodeFirst = pnode;
  1046. *ppNodeLast = pnodeLast;
  1047. return( status );
  1048. }
  1049. //
  1050. // Record management API
  1051. //
  1052. DNS_STATUS
  1053. DNS_API_FUNCTION
  1054. DnssrvDeleteNode(
  1055. IN LPCWSTR Server,
  1056. IN LPCSTR pszZoneName,
  1057. IN LPCSTR pszNodeName,
  1058. IN BOOL bDeleteSubtree
  1059. )
  1060. {
  1061. DNS_RPC_NAME_AND_PARAM param;
  1062. param.dwParam = (DWORD) bDeleteSubtree;
  1063. param.pszNodeName = (LPSTR) pszNodeName;
  1064. return DnssrvOperation(
  1065. Server,
  1066. pszZoneName,
  1067. DNSSRV_OP_DELETE_NODE,
  1068. DNSSRV_TYPEID_NAME_AND_PARAM,
  1069. (PVOID) &param
  1070. );
  1071. }
  1072. DNS_STATUS
  1073. DNS_API_FUNCTION
  1074. DnssrvDeleteRecordSet(
  1075. IN LPCWSTR Server,
  1076. IN LPCSTR pszZoneName,
  1077. IN LPCSTR pszNodeName,
  1078. IN WORD wType
  1079. )
  1080. {
  1081. DNS_RPC_NAME_AND_PARAM param;
  1082. param.dwParam = (DWORD) wType;
  1083. param.pszNodeName = (LPSTR) pszNodeName;
  1084. return DnssrvOperation(
  1085. Server,
  1086. pszZoneName,
  1087. DNSSRV_OP_DELETE_RECORD_SET,
  1088. DNSSRV_TYPEID_NAME_AND_PARAM,
  1089. (PVOID) &param
  1090. );
  1091. }
  1092. DNS_STATUS
  1093. DNS_API_FUNCTION
  1094. DnssrvForceAging(
  1095. IN LPCWSTR Server,
  1096. IN LPCSTR pszZoneName,
  1097. IN LPCSTR pszNodeName,
  1098. IN BOOL bAgeSubtree
  1099. )
  1100. {
  1101. DNS_RPC_NAME_AND_PARAM param;
  1102. param.dwParam = (DWORD) bAgeSubtree;
  1103. param.pszNodeName = (LPSTR) pszNodeName;
  1104. return DnssrvOperation(
  1105. Server,
  1106. pszZoneName,
  1107. DNSSRV_OP_FORCE_AGING_ON_NODE,
  1108. DNSSRV_TYPEID_NAME_AND_PARAM,
  1109. (PVOID) &param
  1110. );
  1111. }
  1112. //
  1113. // Server API
  1114. //
  1115. DNS_STATUS
  1116. DNS_API_FUNCTION
  1117. DnssrvEnumZonesEx(
  1118. IN LPCWSTR Server,
  1119. IN DWORD dwFilter,
  1120. IN LPCSTR pszDirectoryPartitionFqdn,
  1121. IN LPCSTR pszQueryString,
  1122. IN LPCSTR pszLastZone,
  1123. OUT PDNS_RPC_ZONE_LIST * ppZoneList
  1124. )
  1125. {
  1126. DNS_STATUS status;
  1127. DWORD typeId;
  1128. PDNS_RPC_ZONE_LIST pzoneEnum = NULL;
  1129. IF_DNSDBG( STUB )
  1130. {
  1131. DNS_PRINT((
  1132. "Enter DnssrvEnumZones()\n"
  1133. " Server = %s\n"
  1134. " Filter = 0x%08X\n"
  1135. " Partition = %s\n"
  1136. " Query string = %s\n"
  1137. " LastZone = %s\n"
  1138. " ppZoneList = %p\n",
  1139. Server,
  1140. dwFilter,
  1141. pszDirectoryPartitionFqdn,
  1142. pszQueryString,
  1143. pszLastZone,
  1144. ppZoneList ));
  1145. }
  1146. if ( pszDirectoryPartitionFqdn || pszQueryString )
  1147. {
  1148. DNS_RPC_ENUM_ZONES_FILTER ezfilter = { 0 };
  1149. ezfilter.dwRpcStructureVersion = DNS_RPC_ENUM_ZONES_FILTER_VER;
  1150. ezfilter.dwFilter = dwFilter;
  1151. ezfilter.pszPartitionFqdn = ( LPSTR ) pszDirectoryPartitionFqdn;
  1152. ezfilter.pszQueryString = ( LPSTR ) pszQueryString;
  1153. status = DnssrvComplexOperation(
  1154. Server,
  1155. NULL,
  1156. DNSSRV_OP_ENUM_ZONES2,
  1157. DNSSRV_TYPEID_ENUM_ZONES_FILTER,
  1158. ( PVOID ) &ezfilter,
  1159. &typeId,
  1160. ( PVOID * ) &pzoneEnum );
  1161. }
  1162. else
  1163. {
  1164. status = DnssrvComplexOperation(
  1165. Server,
  1166. NULL,
  1167. DNSSRV_OP_ENUM_ZONES,
  1168. DNSSRV_TYPEID_DWORD,
  1169. ( PVOID ) ( DWORD_PTR ) dwFilter,
  1170. & typeId,
  1171. ( PVOID * ) &pzoneEnum );
  1172. }
  1173. if ( status != DNS_ERROR_NT4 )
  1174. {
  1175. ASSERT(
  1176. ( status == ERROR_SUCCESS && typeId == DNSSRV_TYPEID_ZONE_LIST ) ||
  1177. ( status != ERROR_SUCCESS && pzoneEnum == NULL ) );
  1178. *ppZoneList = pzoneEnum;
  1179. }
  1180. return status;
  1181. }
  1182. DNS_STATUS
  1183. DNS_API_FUNCTION
  1184. DnssrvEnumDirectoryPartitions(
  1185. IN LPCWSTR Server,
  1186. IN DWORD dwFilter,
  1187. OUT PDNS_RPC_DP_LIST * ppDpList
  1188. )
  1189. {
  1190. DNS_STATUS status;
  1191. PDNS_RPC_DP_LIST pdpList = NULL;
  1192. DWORD dwtypeId;
  1193. IF_DNSDBG( STUB )
  1194. {
  1195. DNS_PRINT((
  1196. "Enter DnssrvEnumDirectoryPartitions()\n"
  1197. "\tServer = %S\n"
  1198. "\tppDpList = %p\n",
  1199. Server,
  1200. ppDpList ));
  1201. }
  1202. status = DnssrvComplexOperation(
  1203. Server,
  1204. NULL,
  1205. DNSSRV_OP_ENUM_DPS,
  1206. DNSSRV_TYPEID_DWORD,
  1207. ( PVOID ) ( DWORD_PTR ) dwFilter,
  1208. &dwtypeId,
  1209. ( PVOID * ) &pdpList );
  1210. ASSERT( ( status == ERROR_SUCCESS &&
  1211. dwtypeId == DNSSRV_TYPEID_DP_LIST ) ||
  1212. ( status != ERROR_SUCCESS && pdpList == NULL ) );
  1213. *ppDpList = pdpList;
  1214. return status;
  1215. } // DnssrvEnumDirectoryPartitions
  1216. DNS_STATUS
  1217. DNS_API_FUNCTION
  1218. DnssrvEnlistDirectoryPartition(
  1219. IN LPCWSTR pszServer,
  1220. IN DWORD dwOperation,
  1221. IN LPCSTR pszDirPartFqdn
  1222. )
  1223. {
  1224. DNS_STATUS status;
  1225. IF_DNSDBG( STUB )
  1226. {
  1227. DNS_PRINT((
  1228. "Enter DnssrvEnlistDirectoryPartition()\n"
  1229. " pszServer = %S\n"
  1230. " dwOperation = %d\n"
  1231. " pszDirPartFqdn = %s\n",
  1232. pszServer,
  1233. dwOperation,
  1234. pszDirPartFqdn ));
  1235. }
  1236. if ( dwOperation == DNS_DP_OP_CREATE_ALL_DOMAINS )
  1237. {
  1238. //
  1239. // This operation is not specific to any DNS server.
  1240. //
  1241. status = DnssrvCreateAllDomainDirectoryPartitions(
  1242. pszServer,
  1243. DNS_VERBOSE_PROGRESS );
  1244. }
  1245. else
  1246. {
  1247. //
  1248. // This operation should be sent directly to pszServer.
  1249. //
  1250. DNS_RPC_ENLIST_DP param;
  1251. INITIALIZE_RPC_STRUCT( ENLIST_DP, param );
  1252. param.pszDpFqdn = ( LPSTR ) pszDirPartFqdn;
  1253. param.dwOperation = dwOperation;
  1254. status = DnssrvOperation(
  1255. pszServer,
  1256. NULL,
  1257. DNSSRV_OP_ENLIST_DP,
  1258. DNSSRV_TYPEID_ENLIST_DP,
  1259. &param );
  1260. }
  1261. return status;
  1262. } // DnssrvEnlistDirectoryPartition
  1263. DNS_STATUS
  1264. DNS_API_FUNCTION
  1265. DnssrvSetupDefaultDirectoryPartitions(
  1266. IN LPCWSTR pszServer,
  1267. IN DWORD dwParam
  1268. )
  1269. {
  1270. DNS_STATUS status;
  1271. DNS_RPC_ENLIST_DP param;
  1272. INITIALIZE_RPC_STRUCT( ENLIST_DP, param );
  1273. param.pszDpFqdn = NULL;
  1274. param.dwOperation = dwParam;
  1275. IF_DNSDBG( STUB )
  1276. {
  1277. DNS_PRINT((
  1278. "Enter DnssrvSetupDefaultDirectoryPartitions()\n"
  1279. " pszServer = %S\n"
  1280. " dwParam = %d\n",
  1281. pszServer,
  1282. dwParam ));
  1283. }
  1284. status = DnssrvOperation(
  1285. pszServer,
  1286. NULL,
  1287. DNSSRV_OP_ENLIST_DP,
  1288. DNSSRV_TYPEID_ENLIST_DP,
  1289. &param );
  1290. return status;
  1291. } // DnssrvSetupDefaultDirectoryPartitions
  1292. DNS_STATUS
  1293. DNS_API_FUNCTION
  1294. DnssrvDirectoryPartitionInfo(
  1295. IN LPCWSTR Server,
  1296. IN LPSTR pszDpFqdn,
  1297. OUT PDNS_RPC_DP_INFO * ppDpInfo
  1298. )
  1299. {
  1300. DNS_STATUS status;
  1301. DWORD dwTypeId;
  1302. PDNS_RPC_DP_INFO pDpInfo = NULL;
  1303. IF_DNSDBG( STUB )
  1304. {
  1305. DNS_PRINT((
  1306. "Enter DnssrvDirectoryPartitionInfo()\n"
  1307. " Server = %S\n"
  1308. " pszDpFqdn = %s\n"
  1309. " ppDpInfo = %p\n",
  1310. Server,
  1311. pszDpFqdn,
  1312. ppDpInfo ));
  1313. }
  1314. status = DnssrvComplexOperation(
  1315. Server,
  1316. NULL,
  1317. DNSSRV_OP_DP_INFO,
  1318. DNSSRV_TYPEID_LPSTR,
  1319. ( PVOID ) ( DWORD_PTR ) pszDpFqdn,
  1320. &dwTypeId,
  1321. ( PVOID * ) &pDpInfo );
  1322. ASSERT( ( status == ERROR_SUCCESS &&
  1323. dwTypeId == DNSSRV_TYPEID_DP_INFO ) ||
  1324. status != ERROR_SUCCESS );
  1325. *ppDpInfo = pDpInfo;
  1326. return status;
  1327. } // DnssrvDirectoryPartitionInfo
  1328. /*++
  1329. Routine Description:
  1330. This function iterates all domains in the forest and creates
  1331. any missing built-in DNS directory partitions that cannot be
  1332. found.
  1333. Arguments:
  1334. pszServer -- host name of DC to contact for initial queries
  1335. dwVerbose -- output level via printf
  1336. Return Value:
  1337. DNS_STATUS return code
  1338. --*/
  1339. DNS_STATUS
  1340. DNS_API_FUNCTION
  1341. DnssrvCreateAllDomainDirectoryPartitions(
  1342. IN LPCWSTR pszServer,
  1343. IN DWORD dwVerbose
  1344. )
  1345. {
  1346. DNS_STATUS status = ERROR_SUCCESS;
  1347. HANDLE hds = NULL;
  1348. PDS_DOMAIN_TRUSTS pdomainTrusts = NULL;
  1349. ULONG domainCount = 0;
  1350. ULONG idomain;
  1351. PDNS_RECORD pdnsRecordList = NULL;
  1352. PDNS_RECORD pdnsRecord = NULL;
  1353. //
  1354. // Get domain list.
  1355. //
  1356. status = DsEnumerateDomainTrustsA(
  1357. NULL,
  1358. DS_DOMAIN_IN_FOREST,
  1359. &pdomainTrusts,
  1360. &domainCount );
  1361. if ( status != ERROR_SUCCESS )
  1362. {
  1363. DNS_DBG( DNS_VERBOSE_ERROR, (
  1364. "Error 0x%X enumerating domains in the forest\n",
  1365. status ));
  1366. goto Done;
  1367. }
  1368. //
  1369. // Iterate domains.
  1370. //
  1371. for ( idomain = 0; idomain < domainCount; ++idomain )
  1372. {
  1373. int insCount = 0;
  1374. PSTR pszdomainName = pdomainTrusts[ idomain ].DnsDomainName;
  1375. if ( !pszdomainName )
  1376. {
  1377. continue;
  1378. }
  1379. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1380. "\n\nFound domain: %s\n",
  1381. pszdomainName ));
  1382. //
  1383. // Get the DNS server list for this domain.
  1384. //
  1385. status = DnsQuery_UTF8(
  1386. pszdomainName,
  1387. DNS_TYPE_NS,
  1388. DNS_QUERY_STANDARD,
  1389. NULL, // DNS server list
  1390. &pdnsRecordList,
  1391. NULL ); // reserved
  1392. if ( status != ERROR_SUCCESS )
  1393. {
  1394. if ( status == DNS_INFO_NO_RECORDS )
  1395. {
  1396. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1397. "%s: no DNS servers could be found\n", pszdomainName ));
  1398. }
  1399. else
  1400. {
  1401. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1402. "%s: error 0x%X from query for DNS servers\n",
  1403. pszdomainName,
  1404. status ));
  1405. }
  1406. continue;
  1407. }
  1408. for ( pdnsRecord = pdnsRecordList;
  1409. pdnsRecord != NULL;
  1410. pdnsRecord = pdnsRecord->pNext )
  1411. {
  1412. PWSTR pwszserverName;
  1413. DWORD dwtypeid;
  1414. PDNS_RPC_SERVER_INFO pdata;
  1415. DWORD dwmajorVersion;
  1416. DWORD dwminorVersion;
  1417. DWORD dwbuildNum;
  1418. if ( pdnsRecord->wType != DNS_TYPE_NS )
  1419. {
  1420. continue;
  1421. }
  1422. ++insCount;
  1423. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1424. "\n%s: found DNS server %s\n",
  1425. pszdomainName,
  1426. pdnsRecord->Data.NS.pNameHost ));
  1427. pwszserverName = Dns_NameCopyAllocate(
  1428. ( PSTR ) pdnsRecord->Data.NS.pNameHost,
  1429. 0,
  1430. DnsCharSetUtf8,
  1431. DnsCharSetUnicode );
  1432. if ( !pwszserverName )
  1433. {
  1434. status = DNS_ERROR_NO_MEMORY;
  1435. goto Done;
  1436. }
  1437. //
  1438. // "Ping" the DNS server with a server info query to get its
  1439. // version. This is not strictly necessary but it does allow us
  1440. // to find out if the server is up and of good version before
  1441. // we actually think about creating partitions.
  1442. //
  1443. status = DnssrvQuery(
  1444. pwszserverName,
  1445. NULL,
  1446. DNSSRV_QUERY_SERVER_INFO,
  1447. &dwtypeid,
  1448. &pdata );
  1449. if ( status != ERROR_SUCCESS )
  1450. {
  1451. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1452. "DNS server %S returned RPC error %d\n"
  1453. " directory partitions cannot be created on this server\n",
  1454. pwszserverName,
  1455. status ));
  1456. continue;
  1457. }
  1458. dwmajorVersion = pdata->dwVersion & 0x000000FF;
  1459. dwminorVersion = ( pdata->dwVersion & 0x0000FF00 ) >> 8;
  1460. dwbuildNum = pdata->dwVersion >> 16;
  1461. if ( dwbuildNum > 10000 ||
  1462. dwmajorVersion < 5 ||
  1463. dwmajorVersion == 5 && dwminorVersion < 1 )
  1464. {
  1465. //
  1466. // This is a W2K server so do nothing.
  1467. //
  1468. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1469. "DNS Server %S is version %u.%u\n"
  1470. " directory partitions cannot be created on this server\n",
  1471. pwszserverName,
  1472. dwmajorVersion,
  1473. dwminorVersion ));
  1474. }
  1475. else
  1476. {
  1477. //
  1478. // This is a Whistler server so attempt to create domain partition.
  1479. //
  1480. #if 0
  1481. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1482. "DNS Server %S is version %u.%u build %u\n",
  1483. pwszserverName,
  1484. dwmajorVersion,
  1485. dwminorVersion,
  1486. dwbuildNum ));
  1487. #endif
  1488. status = DnssrvEnlistDirectoryPartition(
  1489. pwszserverName,
  1490. DNS_DP_OP_CREATE_DOMAIN,
  1491. NULL );
  1492. if ( status == ERROR_SUCCESS )
  1493. {
  1494. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1495. "DNS server %S successfully created the built-in\n"
  1496. " domain directory partition for domain %s\n",
  1497. pwszserverName,
  1498. pszdomainName ));
  1499. break;
  1500. }
  1501. else
  1502. {
  1503. DNS_DBG( DNS_VERBOSE_PROGRESS, (
  1504. "DNS server %S returned error %d\n"
  1505. " will attempt to create built-in domain partition on another\n"
  1506. " DNS server for this domain\n",
  1507. pwszserverName,
  1508. status ));
  1509. }
  1510. }
  1511. }
  1512. }
  1513. //
  1514. // Cleanup and return
  1515. //
  1516. Done:
  1517. DnsRecordListFree( pdnsRecordList, 0 );
  1518. if ( pdomainTrusts )
  1519. {
  1520. NetApiBufferFree( pdomainTrusts );
  1521. }
  1522. return status;
  1523. } // DnssrvCreateAllDomainDirectoryPartitions
  1524. DNS_STATUS
  1525. DNS_API_FUNCTION
  1526. DnssrvGetStatistics(
  1527. IN LPCWSTR Server,
  1528. IN DWORD dwFilter,
  1529. OUT PDNS_RPC_BUFFER * ppStatsBuffer
  1530. )
  1531. {
  1532. DNS_STATUS status;
  1533. DWORD typeId;
  1534. PDNS_RPC_BUFFER pstatsBuf = NULL;
  1535. IF_DNSDBG( STUB )
  1536. {
  1537. DNS_PRINT((
  1538. "Enter DnssrvGetStatistics()\n"
  1539. " Server = %S\n"
  1540. " Filter = %p\n"
  1541. " ppStatsBuf = %p\n",
  1542. Server,
  1543. dwFilter,
  1544. ppStatsBuffer
  1545. ));
  1546. }
  1547. status = DnssrvComplexOperation(
  1548. Server,
  1549. NULL,
  1550. DNSSRV_QUERY_STATISTICS,
  1551. DNSSRV_TYPEID_DWORD, // DWORD filter in
  1552. (PVOID) (DWORD_PTR) dwFilter,
  1553. & typeId, // enumeration out
  1554. (PVOID*) &pstatsBuf
  1555. );
  1556. ASSERT( (status == ERROR_SUCCESS && typeId == DNSSRV_TYPEID_BUFFER )
  1557. || (status != ERROR_SUCCESS && pstatsBuf == NULL ) );
  1558. *ppStatsBuffer = pstatsBuf;
  1559. return( status );
  1560. }
  1561. DNS_STATUS
  1562. DNS_API_FUNCTION
  1563. DnssrvWriteDirtyZones(
  1564. IN LPCWSTR Server
  1565. )
  1566. {
  1567. DNS_STATUS status;
  1568. status = DnssrvOperation(
  1569. Server,
  1570. NULL,
  1571. DNSSRV_OP_WRITE_DIRTY_ZONES,
  1572. DNSSRV_TYPEID_NULL,
  1573. NULL
  1574. );
  1575. return( status );
  1576. }
  1577. //
  1578. // Old zone API -- discontinued
  1579. //
  1580. DNS_STATUS
  1581. DNS_API_FUNCTION
  1582. DnssrvResetZoneType(
  1583. IN LPCWSTR Server,
  1584. IN LPCSTR pszZone,
  1585. IN DWORD dwZoneType,
  1586. IN DWORD cMasters,
  1587. IN PIP_ADDRESS aipMasters
  1588. )
  1589. {
  1590. DNS_STATUS status;
  1591. DNS_RPC_ZONE_TYPE_RESET typeReset;
  1592. PIP_ARRAY arrayIp;
  1593. INITIALIZE_RPC_STRUCT( ZONE_TYPE_RESET, typeReset );
  1594. arrayIp = Dns_BuildIpArray(
  1595. cMasters,
  1596. aipMasters );
  1597. if ( !arrayIp && cMasters )
  1598. {
  1599. return( DNS_ERROR_NO_MEMORY );
  1600. }
  1601. typeReset.dwZoneType = dwZoneType;
  1602. typeReset.aipMasters = arrayIp;
  1603. status = DnssrvOperation(
  1604. Server,
  1605. pszZone,
  1606. DNS_REGKEY_ZONE_TYPE,
  1607. DNSSRV_TYPEID_ZONE_TYPE_RESET,
  1608. (PVOID) &typeReset
  1609. );
  1610. FREE_HEAP( arrayIp );
  1611. return( status );
  1612. }
  1613. DNS_STATUS
  1614. DNS_API_FUNCTION
  1615. DnssrvResetZoneDatabase(
  1616. IN LPCWSTR Server,
  1617. IN LPCSTR pszZone,
  1618. IN DWORD fDsIntegrated,
  1619. IN LPCSTR pszDataFile
  1620. )
  1621. {
  1622. DNS_STATUS status;
  1623. DNS_RPC_ZONE_DATABASE dbase;
  1624. INITIALIZE_RPC_STRUCT( ZONE_DATABASE, dbase );
  1625. dbase.fDsIntegrated = fDsIntegrated;
  1626. dbase.pszFileName = (LPSTR) pszDataFile;
  1627. return DnssrvOperation(
  1628. Server,
  1629. pszZone,
  1630. DNS_REGKEY_ZONE_FILE,
  1631. DNSSRV_TYPEID_ZONE_DATABASE,
  1632. (PVOID) &dbase
  1633. );
  1634. }
  1635. //
  1636. // End remote.c
  1637. //