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.

1293 lines
30 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. netioctl.c
  5. Abstract:
  6. Network control functions.
  7. Author:
  8. John Vert (jvert) 2-Mar-1997
  9. Revision History:
  10. --*/
  11. #include "nmp.h"
  12. //
  13. // Network Common properties.
  14. //
  15. //
  16. // Read-Write Common Properties.
  17. //
  18. RESUTIL_PROPERTY_ITEM
  19. NmpNetworkCommonProperties[] =
  20. {
  21. {
  22. CLUSREG_NAME_NET_DESC, NULL, CLUSPROP_FORMAT_SZ,
  23. (DWORD_PTR) NmpNullString, 0, 0,
  24. 0,
  25. FIELD_OFFSET(NM_NETWORK_INFO, Description)
  26. },
  27. {
  28. CLUSREG_NAME_NET_ROLE, NULL, CLUSPROP_FORMAT_DWORD,
  29. ClusterNetworkRoleClientAccess,
  30. ClusterNetworkRoleNone,
  31. ClusterNetworkRoleInternalAndClient,
  32. 0,
  33. FIELD_OFFSET(NM_NETWORK_INFO, Role)
  34. },
  35. {
  36. 0
  37. }
  38. };
  39. //
  40. // Read-Only Common Properties.
  41. //
  42. RESUTIL_PROPERTY_ITEM
  43. NmpNetworkROCommonProperties[] =
  44. {
  45. {
  46. CLUSREG_NAME_NET_NAME, NULL, CLUSPROP_FORMAT_SZ,
  47. 0, 0, 0,
  48. RESUTIL_PROPITEM_READ_ONLY,
  49. FIELD_OFFSET(NM_NETWORK_INFO, Name)
  50. },
  51. {
  52. CLUSREG_NAME_NET_ADDRESS, NULL, CLUSPROP_FORMAT_SZ,
  53. 0, 0, 0,
  54. RESUTIL_PROPITEM_READ_ONLY,
  55. FIELD_OFFSET(NM_NETWORK_INFO, Address)
  56. },
  57. {
  58. CLUSREG_NAME_NET_ADDRESS_MASK, NULL, CLUSPROP_FORMAT_SZ,
  59. 0, 0, 0,
  60. RESUTIL_PROPITEM_READ_ONLY,
  61. FIELD_OFFSET(NM_NETWORK_INFO, AddressMask)
  62. },
  63. {
  64. 0
  65. }
  66. };
  67. //
  68. // Cluster registry API function pointers.
  69. // defined in ioctl.c
  70. //
  71. extern CLUSTER_REG_APIS NmpClusterRegApis;
  72. //
  73. // Local Functions
  74. //
  75. DWORD
  76. NmpNetworkControl(
  77. IN PNM_NETWORK Network,
  78. IN DWORD ControlCode,
  79. IN PUCHAR InBuffer,
  80. IN DWORD InBufferSize,
  81. OUT PUCHAR OutBuffer,
  82. IN DWORD OutBufferSize,
  83. OUT LPDWORD BytesReturned,
  84. OUT LPDWORD Required
  85. );
  86. DWORD
  87. NmpNetworkEnumCommonProperties(
  88. OUT PVOID OutBuffer,
  89. IN DWORD OutBufferSize,
  90. OUT LPDWORD BytesReturned,
  91. OUT LPDWORD Required
  92. );
  93. DWORD
  94. NmpNetworkGetCommonProperties(
  95. IN PNM_NETWORK Network,
  96. IN BOOL ReadOnly,
  97. IN HDMKEY RegistryKey,
  98. OUT PVOID OutBuffer,
  99. IN DWORD OutBufferSize,
  100. OUT LPDWORD BytesReturned,
  101. OUT LPDWORD Required
  102. );
  103. DWORD
  104. NmpNetworkValidateCommonProperties(
  105. IN PNM_NETWORK Network,
  106. IN PVOID InBuffer,
  107. IN DWORD InBufferSize,
  108. OUT PNM_NETWORK_INFO NetworkInfo OPTIONAL
  109. );
  110. DWORD
  111. NmpNetworkSetCommonProperties(
  112. IN PNM_NETWORK Network,
  113. IN HDMKEY RegistryKey,
  114. IN PVOID InBuffer,
  115. IN DWORD InBufferSize
  116. );
  117. DWORD
  118. NmpNetworkEnumPrivateProperties(
  119. IN PNM_NETWORK Network,
  120. IN HDMKEY RegistryKey,
  121. OUT PVOID OutBuffer,
  122. IN DWORD OutBufferSize,
  123. OUT LPDWORD BytesReturned,
  124. OUT LPDWORD Required
  125. );
  126. DWORD
  127. NmpNetworkGetPrivateProperties(
  128. IN PNM_NETWORK Network,
  129. IN HDMKEY RegistryKey,
  130. OUT PVOID OutBuffer,
  131. IN DWORD OutBufferSize,
  132. OUT LPDWORD BytesReturned,
  133. OUT LPDWORD Required
  134. );
  135. DWORD
  136. NmpNetworkValidatePrivateProperties(
  137. IN PNM_NETWORK Network,
  138. IN HDMKEY RegistryKey,
  139. IN PVOID InBuffer,
  140. IN DWORD InBufferSize
  141. );
  142. DWORD
  143. NmpNetworkSetPrivateProperties(
  144. IN PNM_NETWORK Network,
  145. IN HDMKEY RegistryKey,
  146. IN PVOID InBuffer,
  147. IN DWORD InBufferSize
  148. );
  149. DWORD
  150. NmpNetworkGetFlags(
  151. IN PNM_NETWORK Network,
  152. IN HDMKEY RegistryKey,
  153. OUT PVOID OutBuffer,
  154. IN DWORD OutBufferSize,
  155. OUT LPDWORD BytesReturned,
  156. OUT LPDWORD Required
  157. );
  158. DWORD
  159. WINAPI
  160. NmNetworkControl(
  161. IN PNM_NETWORK Network,
  162. IN PNM_NODE HostNode OPTIONAL,
  163. IN DWORD ControlCode,
  164. IN PUCHAR InBuffer,
  165. IN DWORD InBufferSize,
  166. OUT PUCHAR OutBuffer,
  167. IN DWORD OutBufferSize,
  168. OUT LPDWORD BytesReturned,
  169. OUT LPDWORD Required
  170. )
  171. /*++
  172. Routine Description:
  173. Provides for arbitrary communication and control between an application
  174. and a specific instance of a network.
  175. Arguments:
  176. Network - Supplies the network to be controlled.
  177. HostNode - Supplies the host node on which the resource control should
  178. be delivered. If this is NULL, the local node is used. Not honored!
  179. ControlCode- Supplies the control code that defines the
  180. structure and action of the resource control.
  181. Values of ControlCode between 0 and 0x10000000 are reserved
  182. for future definition and use by Microsoft. All other values
  183. are available for use by ISVs
  184. InBuffer- Supplies a pointer to the input buffer to be passed
  185. to the resource.
  186. InBufferSize- Supplies the size, in bytes, of the data pointed
  187. to by lpInBuffer..
  188. OutBuffer- Supplies a pointer to the output buffer to be
  189. filled in by the resource..
  190. OutBufferSize- Supplies the size, in bytes, of the available
  191. space pointed to by lpOutBuffer.
  192. BytesReturned - Returns the number of bytes of lpOutBuffer
  193. actually filled in by the resource..
  194. Required - Returns the number of bytes if the OutBuffer is not big
  195. enough.
  196. Return Value:
  197. ERROR_SUCCESS if successful
  198. Win32 error code otherwise
  199. --*/
  200. {
  201. DWORD status;
  202. //
  203. // Cluster service ioctls were designed to have access modes, e.g.
  204. // read-only, read-write, etc. These access modes are not implemented.
  205. // If eventually they are implemented, an access mode check should be
  206. // placed here.
  207. //
  208. if ( CLUSCTL_GET_CONTROL_OBJECT( ControlCode ) != CLUS_OBJECT_NETWORK ) {
  209. return(ERROR_INVALID_FUNCTION);
  210. }
  211. if (NmpEnterApi(NmStateOnline)) {
  212. status = NmpNetworkControl(
  213. Network,
  214. ControlCode,
  215. InBuffer,
  216. InBufferSize,
  217. OutBuffer,
  218. OutBufferSize,
  219. BytesReturned,
  220. Required
  221. );
  222. NmpLeaveApi();
  223. }
  224. else {
  225. status = ERROR_NODE_NOT_AVAILABLE;
  226. ClRtlLogPrint(LOG_NOISE,
  227. "[NM] Not in valid state to process NetworkControl request.\n"
  228. );
  229. }
  230. return(status);
  231. } // NmNetworkControl
  232. DWORD
  233. NmpNetworkControl(
  234. IN PNM_NETWORK Network,
  235. IN DWORD ControlCode,
  236. IN PUCHAR InBuffer,
  237. IN DWORD InBufferSize,
  238. OUT PUCHAR OutBuffer,
  239. IN DWORD OutBufferSize,
  240. OUT LPDWORD BytesReturned,
  241. OUT LPDWORD Required
  242. )
  243. /*++
  244. Routine Description:
  245. Provides for arbitrary communication and control between an application
  246. and a specific instance of a network.
  247. Arguments:
  248. Network - Supplies the network to be controlled.
  249. ControlCode- Supplies the control code that defines the
  250. structure and action of the network control.
  251. Values of ControlCode between 0 and 0x10000000 are reserved
  252. for future definition and use by Microsoft. All other values
  253. are available for use by ISVs
  254. InBuffer- Supplies a pointer to the input buffer to be passed
  255. to the network.
  256. InBufferSize- Supplies the size, in bytes, of the data pointed
  257. to by lpInBuffer.
  258. OutBuffer- Supplies a pointer to the output buffer to be
  259. filled in by the network.
  260. OutBufferSize- Supplies the size, in bytes, of the available
  261. space pointed to by lpOutBuffer.
  262. BytesReturned - Returns the number of bytes of lpOutBuffer
  263. actually filled in by the network.
  264. Required - Returns the number of bytes if the OutBuffer is not big
  265. enough.
  266. Return Value:
  267. ERROR_SUCCESS if successful
  268. Win32 error code otherwise
  269. --*/
  270. {
  271. DWORD status;
  272. HDMKEY networkKey;
  273. CLUSPROP_BUFFER_HELPER props;
  274. DWORD bufSize;
  275. networkKey = DmOpenKey( DmNetworksKey,
  276. OmObjectId( Network ),
  277. MAXIMUM_ALLOWED
  278. );
  279. if ( networkKey == NULL ) {
  280. return(GetLastError());
  281. }
  282. switch ( ControlCode ) {
  283. case CLUSCTL_NETWORK_UNKNOWN:
  284. *BytesReturned = 0;
  285. status = ERROR_SUCCESS;
  286. break;
  287. case CLUSCTL_NETWORK_GET_NAME:
  288. if ( OmObjectName( Network ) == NULL ) {
  289. return(ERROR_NOT_READY);
  290. }
  291. props.pb = OutBuffer;
  292. bufSize = (lstrlenW( OmObjectName( Network ) ) + 1) * sizeof(WCHAR);
  293. if ( bufSize > OutBufferSize ) {
  294. *Required = bufSize;
  295. *BytesReturned = 0;
  296. status = ERROR_MORE_DATA;
  297. } else {
  298. lstrcpyW( props.psz, OmObjectName( Network ) );
  299. *BytesReturned = bufSize;
  300. *Required = 0;
  301. status = ERROR_SUCCESS;
  302. }
  303. break;
  304. case CLUSCTL_NETWORK_GET_ID:
  305. if ( OmObjectId( Network ) == NULL ) {
  306. return(ERROR_NOT_READY);
  307. }
  308. props.pb = OutBuffer;
  309. bufSize = (lstrlenW( OmObjectId( Network ) ) + 1) * sizeof(WCHAR);
  310. if ( bufSize > OutBufferSize ) {
  311. *Required = bufSize;
  312. *BytesReturned = 0;
  313. status = ERROR_MORE_DATA;
  314. } else {
  315. lstrcpyW( props.psz, OmObjectId( Network ) );
  316. *BytesReturned = bufSize;
  317. *Required = 0;
  318. status = ERROR_SUCCESS;
  319. }
  320. break;
  321. case CLUSCTL_NETWORK_ENUM_COMMON_PROPERTIES:
  322. status = NmpNetworkEnumCommonProperties(
  323. OutBuffer,
  324. OutBufferSize,
  325. BytesReturned,
  326. Required
  327. );
  328. break;
  329. case CLUSCTL_NETWORK_GET_RO_COMMON_PROPERTIES:
  330. status = NmpNetworkGetCommonProperties(
  331. Network,
  332. TRUE, // ReadOnly
  333. networkKey,
  334. OutBuffer,
  335. OutBufferSize,
  336. BytesReturned,
  337. Required
  338. );
  339. break;
  340. case CLUSCTL_NETWORK_GET_COMMON_PROPERTIES:
  341. status = NmpNetworkGetCommonProperties(
  342. Network,
  343. FALSE, // ReadOnly
  344. networkKey,
  345. OutBuffer,
  346. OutBufferSize,
  347. BytesReturned,
  348. Required
  349. );
  350. break;
  351. case CLUSCTL_NETWORK_VALIDATE_COMMON_PROPERTIES:
  352. NmpAcquireLock();
  353. status = NmpNetworkValidateCommonProperties(
  354. Network,
  355. InBuffer,
  356. InBufferSize,
  357. NULL
  358. );
  359. NmpReleaseLock();
  360. break;
  361. case CLUSCTL_NETWORK_SET_COMMON_PROPERTIES:
  362. status = NmpNetworkSetCommonProperties(
  363. Network,
  364. networkKey,
  365. InBuffer,
  366. InBufferSize
  367. );
  368. break;
  369. case CLUSCTL_NETWORK_GET_RO_PRIVATE_PROPERTIES:
  370. if ( OutBufferSize < sizeof(DWORD) ) {
  371. *BytesReturned = 0;
  372. *Required = sizeof(DWORD);
  373. if ( OutBuffer == NULL ) {
  374. status = ERROR_SUCCESS;
  375. } else {
  376. status = ERROR_MORE_DATA;
  377. }
  378. } else {
  379. LPDWORD ptrDword = (LPDWORD) OutBuffer;
  380. *ptrDword = 0;
  381. *BytesReturned = sizeof(DWORD);
  382. status = ERROR_SUCCESS;
  383. }
  384. break;
  385. case CLUSCTL_NETWORK_GET_PRIVATE_PROPERTIES:
  386. status = NmpNetworkGetPrivateProperties(
  387. Network,
  388. networkKey,
  389. OutBuffer,
  390. OutBufferSize,
  391. BytesReturned,
  392. Required
  393. );
  394. break;
  395. case CLUSCTL_NETWORK_VALIDATE_PRIVATE_PROPERTIES:
  396. status = NmpNetworkValidatePrivateProperties(
  397. Network,
  398. networkKey,
  399. InBuffer,
  400. InBufferSize
  401. );
  402. break;
  403. case CLUSCTL_NETWORK_SET_PRIVATE_PROPERTIES:
  404. status = NmpNetworkSetPrivateProperties(
  405. Network,
  406. networkKey,
  407. InBuffer,
  408. InBufferSize
  409. );
  410. break;
  411. case CLUSCTL_NETWORK_GET_CHARACTERISTICS:
  412. if ( OutBufferSize < sizeof(DWORD) ) {
  413. *BytesReturned = 0;
  414. *Required = sizeof(DWORD);
  415. if ( OutBuffer == NULL ) {
  416. status = ERROR_SUCCESS;
  417. } else {
  418. status = ERROR_MORE_DATA;
  419. }
  420. } else {
  421. *BytesReturned = sizeof(DWORD);
  422. *(LPDWORD)OutBuffer = 0;
  423. status = ERROR_SUCCESS;
  424. }
  425. break;
  426. case CLUSCTL_NETWORK_GET_FLAGS:
  427. status = NmpNetworkGetFlags(
  428. Network,
  429. networkKey,
  430. OutBuffer,
  431. OutBufferSize,
  432. BytesReturned,
  433. Required
  434. );
  435. break;
  436. case CLUSCTL_NETWORK_ENUM_PRIVATE_PROPERTIES:
  437. status = NmpNetworkEnumPrivateProperties(
  438. Network,
  439. networkKey,
  440. OutBuffer,
  441. OutBufferSize,
  442. BytesReturned,
  443. Required
  444. );
  445. break;
  446. default:
  447. status = ERROR_INVALID_FUNCTION;
  448. break;
  449. }
  450. DmCloseKey( networkKey );
  451. return(status);
  452. } // NmpNetworkControl
  453. DWORD
  454. NmpNetworkEnumCommonProperties(
  455. OUT PVOID OutBuffer,
  456. IN DWORD OutBufferSize,
  457. OUT LPDWORD BytesReturned,
  458. OUT LPDWORD Required
  459. )
  460. /*++
  461. Routine Description:
  462. Enumerates the common property names for a given network.
  463. Arguments:
  464. OutBuffer - Supplies the output buffer.
  465. OutBufferSize - Supplies the size of the output buffer.
  466. BytesReturned - The number of bytes returned in OutBuffer.
  467. Required - The required number of bytes if OutBuffer is too small.
  468. Return Value:
  469. ERROR_SUCCESS if successful.
  470. A Win32 error code on failure.
  471. --*/
  472. {
  473. DWORD status;
  474. //
  475. // Get the common properties.
  476. //
  477. status = ClRtlEnumProperties( NmpNetworkCommonProperties,
  478. OutBuffer,
  479. OutBufferSize,
  480. BytesReturned,
  481. Required );
  482. return(status);
  483. } // NmpNetworkEnumCommonProperties
  484. DWORD
  485. NmpNetworkGetCommonProperties(
  486. IN PNM_NETWORK Network,
  487. IN BOOL ReadOnly,
  488. IN HDMKEY RegistryKey,
  489. OUT PVOID OutBuffer,
  490. IN DWORD OutBufferSize,
  491. OUT LPDWORD BytesReturned,
  492. OUT LPDWORD Required
  493. )
  494. /*++
  495. Routine Description:
  496. Gets the common properties for a given network.
  497. Arguments:
  498. Network - Supplies the network.
  499. ReadOnly - TRUE if the read-only properties should be read. FALSE otherwise.
  500. RegistryKey - Supplies the registry key for this network.
  501. OutBuffer - Supplies the output buffer.
  502. OutBufferSize - Supplies the size of the output buffer.
  503. BytesReturned - The number of bytes returned in OutBuffer.
  504. Required - The required number of bytes if OutBuffer is too small.
  505. Return Value:
  506. ERROR_SUCCESS if successful.
  507. A Win32 error code on failure.
  508. --*/
  509. {
  510. DWORD status;
  511. NM_NETWORK_INFO networkInfo;
  512. PRESUTIL_PROPERTY_ITEM propertyTable;
  513. DWORD outBufferSize = OutBufferSize;
  514. //
  515. // Fetch the properties from the object
  516. //
  517. ZeroMemory(&networkInfo, sizeof(networkInfo));
  518. NmpAcquireLock();
  519. status = NmpGetNetworkObjectInfo(Network, &networkInfo);
  520. NmpReleaseLock();
  521. if (status == ERROR_SUCCESS) {
  522. if ( ReadOnly ) {
  523. propertyTable = NmpNetworkROCommonProperties;
  524. }
  525. else {
  526. propertyTable = NmpNetworkCommonProperties;
  527. }
  528. status = ClRtlPropertyListFromParameterBlock(
  529. propertyTable,
  530. OutBuffer,
  531. &outBufferSize,
  532. (LPBYTE) &networkInfo,
  533. BytesReturned,
  534. Required
  535. );
  536. ClNetFreeNetworkInfo(&networkInfo);
  537. }
  538. return(status);
  539. } // NmpNetworkGetCommonProperties
  540. DWORD
  541. NmpNetworkValidateCommonProperties(
  542. IN PNM_NETWORK Network,
  543. IN PVOID InBuffer,
  544. IN DWORD InBufferSize,
  545. OUT PNM_NETWORK_INFO NetworkInfo OPTIONAL
  546. )
  547. /*++
  548. Routine Description:
  549. Validates the common properties for a given network.
  550. Arguments:
  551. Network - Supplies the network object.
  552. InBuffer - Supplies the input buffer.
  553. InBufferSize - Supplies the size of the input buffer.
  554. NetworkInfo - On output, contains a pointer to a network
  555. information structure with the updates applied.
  556. Return Value:
  557. ERROR_SUCCESS if successful.
  558. A Win32 error code on failure.
  559. Notes:
  560. Called with the NmpLock held.
  561. --*/
  562. {
  563. DWORD status;
  564. NM_NETWORK_INFO infoBuffer;
  565. PNM_NETWORK_INFO networkInfo;
  566. LPCWSTR networkId = OmObjectId(Network);
  567. //
  568. // Check if there is input data.
  569. //
  570. if ( (InBuffer == NULL) ||
  571. (InBufferSize < sizeof(DWORD)) ) {
  572. return(ERROR_INVALID_DATA);
  573. }
  574. if (NetworkInfo != NULL) {
  575. networkInfo = NetworkInfo;
  576. }
  577. else {
  578. networkInfo = &infoBuffer;
  579. }
  580. ZeroMemory(networkInfo, sizeof(NM_NETWORK_INFO));
  581. //
  582. // Get a copy of the current network parameters.
  583. //
  584. status = NmpGetNetworkObjectInfo(Network, networkInfo);
  585. if ( status != ERROR_SUCCESS ) {
  586. goto error_exit;
  587. }
  588. //
  589. // Validate the property list and update the parameter block.
  590. //
  591. status = ClRtlVerifyPropertyTable(
  592. NmpNetworkCommonProperties,
  593. NULL, // Reserved
  594. FALSE, // Don't allow unknowns
  595. InBuffer,
  596. InBufferSize,
  597. (LPBYTE) networkInfo
  598. );
  599. if ( status != ERROR_SUCCESS ) {
  600. ClRtlLogPrint( LOG_CRITICAL,
  601. "[NM] ValidateCommonProperties, error in verify routine.\n"
  602. );
  603. goto error_exit;
  604. }
  605. CL_ASSERT(networkInfo->Role <= ClusterNetworkRoleInternalAndClient);
  606. //
  607. // If the role changed, ensure that the change is legal for this cluster.
  608. //
  609. if (Network->Role != ((CLUSTER_NETWORK_ROLE) networkInfo->Role)) {
  610. status = NmpValidateNetworkRoleChange(
  611. Network,
  612. networkInfo->Role
  613. );
  614. if (status != ERROR_SUCCESS) {
  615. goto error_exit;
  616. }
  617. }
  618. //
  619. // The change is valid.
  620. //
  621. CL_ASSERT(status == ERROR_SUCCESS);
  622. error_exit:
  623. if ((status != ERROR_SUCCESS) || (networkInfo == &infoBuffer)) {
  624. ClNetFreeNetworkInfo(networkInfo);
  625. }
  626. return(status);
  627. } // NmpNetworkValidateCommonProperties
  628. DWORD
  629. NmpNetworkSetCommonProperties(
  630. IN PNM_NETWORK Network,
  631. IN HDMKEY RegistryKey,
  632. IN PVOID InBuffer,
  633. IN DWORD InBufferSize
  634. )
  635. /*++
  636. Routine Description:
  637. Sets the common properties for a given network.
  638. Arguments:
  639. Network - Supplies the network object.
  640. InBuffer - Supplies the input buffer.
  641. InBufferSize - Supplies the size of the input buffer.
  642. Return Value:
  643. ERROR_SUCCESS if successful.
  644. A Win32 error code on failure.
  645. --*/
  646. {
  647. DWORD status;
  648. LPCWSTR networkId = OmObjectId(Network);
  649. ClRtlLogPrint(LOG_NOISE,
  650. "[NM] Setting common properties for network %1!ws!.\n",
  651. networkId
  652. );
  653. //
  654. // Issue a global update
  655. //
  656. status = GumSendUpdateEx(
  657. GumUpdateMembership,
  658. NmUpdateSetNetworkCommonProperties,
  659. 3,
  660. NM_WCSLEN(networkId),
  661. networkId,
  662. InBufferSize,
  663. InBuffer,
  664. sizeof(InBufferSize),
  665. &InBufferSize
  666. );
  667. if (status != ERROR_SUCCESS) {
  668. ClRtlLogPrint(LOG_CRITICAL,
  669. "[NM] Global update to set common properties for network %1!ws! failed, status %2!u!.\n",
  670. networkId,
  671. status
  672. );
  673. }
  674. return(status);
  675. } // NmpNetworkSetCommonProperties
  676. DWORD
  677. NmpNetworkEnumPrivateProperties(
  678. IN PNM_NETWORK Network,
  679. IN HDMKEY RegistryKey,
  680. OUT PVOID OutBuffer,
  681. IN DWORD OutBufferSize,
  682. OUT LPDWORD BytesReturned,
  683. OUT LPDWORD Required
  684. )
  685. /*++
  686. Routine Description:
  687. Enumerates the private property names for a given network.
  688. Arguments:
  689. Network - Supplies the network object.
  690. RegistryKey - Registry key for the network.
  691. OutBuffer - Supplies the output buffer.
  692. OutBufferSize - Supplies the size of the output buffer.
  693. BytesReturned - The number of bytes returned in OutBuffer.
  694. Required - The required number of bytes if OutBuffer is too small.
  695. Return Value:
  696. ERROR_SUCCESS if successful.
  697. A Win32 error code on failure.
  698. --*/
  699. {
  700. DWORD status;
  701. HDMKEY parametersKey;
  702. DWORD totalBufferSize = 0;
  703. *BytesReturned = 0;
  704. *Required = 0;
  705. //
  706. // Clear the output buffer
  707. //
  708. ZeroMemory( OutBuffer, OutBufferSize );
  709. //
  710. // Open the cluster network parameters key.
  711. //
  712. parametersKey = DmOpenKey( RegistryKey,
  713. CLUSREG_KEYNAME_PARAMETERS,
  714. MAXIMUM_ALLOWED );
  715. if ( parametersKey == NULL ) {
  716. status = GetLastError();
  717. if ( status == ERROR_FILE_NOT_FOUND ) {
  718. status = ERROR_SUCCESS;
  719. }
  720. return(status);
  721. }
  722. //
  723. // Enum private properties for the network.
  724. //
  725. status = ClRtlEnumPrivateProperties( parametersKey,
  726. &NmpClusterRegApis,
  727. OutBuffer,
  728. OutBufferSize,
  729. BytesReturned,
  730. Required );
  731. DmCloseKey( parametersKey );
  732. return(status);
  733. } // NmpNetworkEnumPrivateProperties
  734. DWORD
  735. NmpNetworkGetPrivateProperties(
  736. IN PNM_NETWORK Network,
  737. IN HDMKEY RegistryKey,
  738. OUT PVOID OutBuffer,
  739. IN DWORD OutBufferSize,
  740. OUT LPDWORD BytesReturned,
  741. OUT LPDWORD Required
  742. )
  743. /*++
  744. Routine Description:
  745. Gets the private properties for a given network.
  746. Arguments:
  747. Network - Supplies the network object.
  748. OutBuffer - Supplies the output buffer.
  749. OutBufferSize - Supplies the size of the output buffer.
  750. BytesReturned - The number of bytes returned in OutBuffer.
  751. Required - The required number of bytes if OutBuffer is too small.
  752. Return Value:
  753. ERROR_SUCCESS if successful.
  754. A Win32 error code on failure.
  755. --*/
  756. {
  757. DWORD status;
  758. HDMKEY parametersKey;
  759. DWORD totalBufferSize = 0;
  760. *BytesReturned = 0;
  761. *Required = 0;
  762. //
  763. // Clear the output buffer
  764. //
  765. ZeroMemory( OutBuffer, OutBufferSize );
  766. //
  767. // Open the cluster network parameters key.
  768. //
  769. parametersKey = DmOpenKey( RegistryKey,
  770. CLUSREG_KEYNAME_PARAMETERS,
  771. MAXIMUM_ALLOWED );
  772. if ( parametersKey == NULL ) {
  773. status = GetLastError();
  774. if ( status == ERROR_FILE_NOT_FOUND ) {
  775. //
  776. // If we don't have a parameters key, then return an
  777. // item count of 0 and an endmark.
  778. //
  779. totalBufferSize = sizeof(DWORD) + sizeof(CLUSPROP_SYNTAX);
  780. if ( OutBufferSize < totalBufferSize ) {
  781. *Required = totalBufferSize;
  782. status = ERROR_MORE_DATA;
  783. } else {
  784. // This is somewhat redundant since we zero the
  785. // buffer above, but it's here for clarity.
  786. CLUSPROP_BUFFER_HELPER buf;
  787. buf.pb = OutBuffer;
  788. buf.pList->nPropertyCount = 0;
  789. buf.pdw++;
  790. buf.pSyntax->dw = CLUSPROP_SYNTAX_ENDMARK;
  791. *BytesReturned = totalBufferSize;
  792. status = ERROR_SUCCESS;
  793. }
  794. }
  795. return(status);
  796. }
  797. //
  798. // Get private properties for the network.
  799. //
  800. status = ClRtlGetPrivateProperties( parametersKey,
  801. &NmpClusterRegApis,
  802. OutBuffer,
  803. OutBufferSize,
  804. BytesReturned,
  805. Required );
  806. DmCloseKey( parametersKey );
  807. return(status);
  808. } // NmpNetworkGetPrivateProperties
  809. DWORD
  810. NmpNetworkValidatePrivateProperties(
  811. IN PNM_NETWORK Network,
  812. IN HDMKEY RegistryKey,
  813. IN PVOID InBuffer,
  814. IN DWORD InBufferSize
  815. )
  816. /*++
  817. Routine Description:
  818. Validates the private properties for a given network.
  819. Arguments:
  820. Network - Supplies the network object.
  821. RegistryKey - Registry key for the network.
  822. InBuffer - Supplies the input buffer.
  823. InBufferSize - Supplies the size of the input buffer.
  824. Return Value:
  825. ERROR_SUCCESS if successful.
  826. A Win32 error code on failure.
  827. --*/
  828. {
  829. DWORD status;
  830. //
  831. // Validate the property list.
  832. //
  833. status = ClRtlVerifyPrivatePropertyList( InBuffer,
  834. InBufferSize );
  835. return(status);
  836. } // NmpNetworkValidatePrivateProperties
  837. DWORD
  838. NmpNetworkSetPrivateProperties(
  839. IN PNM_NETWORK Network,
  840. IN HDMKEY RegistryKey,
  841. IN PVOID InBuffer,
  842. IN DWORD InBufferSize
  843. )
  844. /*++
  845. Routine Description:
  846. Sets the private properties for a given network.
  847. Arguments:
  848. Network - Supplies the network object.
  849. RegistryKey - Registry key for the network.
  850. InBuffer - Supplies the input buffer.
  851. InBufferSize - Supplies the size of the input buffer.
  852. Return Value:
  853. ERROR_SUCCESS if successful.
  854. A Win32 error code on failure.
  855. --*/
  856. {
  857. DWORD status;
  858. HDMKEY parametersKey;
  859. DWORD disposition;
  860. BOOLEAN setProperties = TRUE;
  861. //
  862. // Validate the property list.
  863. //
  864. status = ClRtlVerifyPrivatePropertyList( InBuffer,
  865. InBufferSize );
  866. if ( status == ERROR_SUCCESS ) {
  867. //
  868. // Validate any multicast parameters being set.
  869. //
  870. status = NmpMulticastValidatePrivateProperties(
  871. Network,
  872. RegistryKey,
  873. InBuffer,
  874. InBufferSize
  875. );
  876. if (status == ERROR_SUCCESS) {
  877. //
  878. // Open the cluster network\xx\parameters key
  879. //
  880. parametersKey = DmOpenKey( RegistryKey,
  881. CLUSREG_KEYNAME_PARAMETERS,
  882. MAXIMUM_ALLOWED );
  883. if ( parametersKey == NULL ) {
  884. status = GetLastError();
  885. if ( status == ERROR_FILE_NOT_FOUND ) {
  886. //
  887. // Try to create the parameters key.
  888. //
  889. parametersKey = DmCreateKey( RegistryKey,
  890. CLUSREG_KEYNAME_PARAMETERS,
  891. 0,
  892. KEY_READ | KEY_WRITE,
  893. NULL,
  894. &disposition );
  895. if ( parametersKey == NULL ) {
  896. status = GetLastError();
  897. return(status);
  898. }
  899. }
  900. }
  901. NmpMulticastManualConfigChange(
  902. Network,
  903. RegistryKey,
  904. parametersKey,
  905. InBuffer,
  906. InBufferSize,
  907. &setProperties
  908. );
  909. if (setProperties) {
  910. status = ClRtlSetPrivatePropertyList(
  911. NULL, // IN HANDLE hXsaction
  912. parametersKey,
  913. &NmpClusterRegApis,
  914. InBuffer,
  915. InBufferSize
  916. );
  917. }
  918. DmCloseKey( parametersKey );
  919. }
  920. }
  921. return(status);
  922. } // NmpNetworkSetPrivateProperties
  923. DWORD
  924. NmpNetworkGetFlags(
  925. IN PNM_NETWORK Network,
  926. IN HDMKEY RegistryKey,
  927. OUT PVOID OutBuffer,
  928. IN DWORD OutBufferSize,
  929. OUT LPDWORD BytesReturned,
  930. OUT LPDWORD Required
  931. )
  932. /*++
  933. Routine Description:
  934. Gets the flags for a given network.
  935. Arguments:
  936. Network - Supplies the network.
  937. RegistryKey - Registry key for the network.
  938. OutBuffer - Supplies the output buffer.
  939. OutBufferSize - Supplies the size of the output buffer.
  940. BytesReturned - The number of bytes returned in OutBuffer.
  941. Required - The required number of bytes if OutBuffer is too small.
  942. Return Value:
  943. ERROR_SUCCESS if successful.
  944. A Win32 error code on failure.
  945. --*/
  946. {
  947. DWORD status;
  948. *BytesReturned = 0;
  949. if ( OutBufferSize < sizeof(DWORD) ) {
  950. *Required = sizeof(DWORD);
  951. if ( OutBuffer == NULL ) {
  952. status = ERROR_SUCCESS;
  953. } else {
  954. status = ERROR_MORE_DATA;
  955. }
  956. } else {
  957. DWORD valueType;
  958. //
  959. // Read the Flags value for the network.
  960. //
  961. *BytesReturned = OutBufferSize;
  962. status = DmQueryValue( RegistryKey,
  963. CLUSREG_NAME_FLAGS,
  964. &valueType,
  965. OutBuffer,
  966. BytesReturned );
  967. if ( status == ERROR_FILE_NOT_FOUND ) {
  968. *BytesReturned = sizeof(DWORD);
  969. *(LPDWORD)OutBuffer = 0;
  970. status = ERROR_SUCCESS;
  971. }
  972. }
  973. return(status);
  974. } // NmpNetworkGetFlags