Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1435 lines
33 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. ncpstub.c
  5. Abstract:
  6. Contains NCP Server APIs.
  7. Author:
  8. Yi-Hsin Sung (yihsins) 11-Sept-1993
  9. Andy Herron (andyhe)
  10. Revision History:
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <rpc.h>
  15. #include <ncpsvc.h>
  16. #include <nwstruct.h>
  17. DWORD NwpMapRpcError(
  18. IN DWORD RpcError
  19. );
  20. DWORD
  21. FpnwApiBufferFree(
  22. IN LPVOID pBuffer
  23. )
  24. /*++
  25. Routine Description:
  26. This API frees the memory allocated by all enumeration and getinfo APIs.
  27. Arguments:
  28. pBuffer - A pointer to an API information buffer previously returned
  29. on an API call.
  30. Return Value:
  31. Error.
  32. --*/
  33. {
  34. if ( pBuffer == NULL )
  35. return NO_ERROR;
  36. MIDL_user_free( pBuffer );
  37. return NO_ERROR;
  38. }
  39. DWORD
  40. NwApiBufferFree(
  41. IN LPVOID pBuffer
  42. )
  43. { return(FpnwApiBufferFree( pBuffer ));
  44. }
  45. DWORD
  46. FpnwServerGetInfo(
  47. IN LPWSTR pServerName OPTIONAL,
  48. IN DWORD dwLevel,
  49. OUT LPBYTE *ppServerInfo
  50. )
  51. /*++
  52. Routine Description:
  53. This API returns the information about the given server.
  54. Arguments:
  55. pServerName - A pointer to a UNICODE string containing the name of the
  56. remote server on which the function is to execute. A NULL pointer
  57. or string specifies the local machine.
  58. dwLevel - Reserved for the level of the server structure requested, use
  59. 1 for now.
  60. ppServerInfo - Place to store a pointer pointing to the returned
  61. NWSERVERINFO structure.
  62. Return Value:
  63. Error.
  64. --*/
  65. {
  66. DWORD err;
  67. if ( dwLevel != 1 )
  68. return ERROR_INVALID_LEVEL;
  69. if ( ppServerInfo == NULL )
  70. return ERROR_INVALID_PARAMETER;
  71. RpcTryExcept
  72. {
  73. err = NwrServerGetInfo( pServerName,
  74. dwLevel,
  75. (PFPNWSERVERINFO *) ppServerInfo );
  76. }
  77. RpcExcept(1)
  78. {
  79. err = NwpMapRpcError( RpcExceptionCode() );
  80. }
  81. RpcEndExcept
  82. return err;
  83. }
  84. DWORD
  85. NwServerGetInfo(
  86. IN LPWSTR pServerName OPTIONAL,
  87. IN DWORD dwLevel,
  88. OUT PNWSERVERINFO *ppServerInfo
  89. )
  90. { return(FpnwServerGetInfo( pServerName,
  91. dwLevel,
  92. (LPBYTE *) ppServerInfo));
  93. }
  94. DWORD
  95. FpnwServerSetInfo(
  96. IN LPWSTR pServerName OPTIONAL,
  97. IN DWORD dwLevel,
  98. IN LPBYTE pServerInfo
  99. )
  100. /*++
  101. Routine Description:
  102. This API sets the information about the given server.
  103. Arguments:
  104. pServerName - A pointer to a UNICODE string containing the name of the
  105. remote server on which the function is to execute. A NULL pointer
  106. or string specifies the local machine.
  107. dwLevel - Reserved for the level of the server structure contained in
  108. pServerInfo, use 1 for now.
  109. pServerInfo - Points to a NWSERVERINFO structure which contains the server
  110. properties to set to.
  111. Return Value:
  112. Error.
  113. --*/
  114. {
  115. DWORD err;
  116. if ( dwLevel != 1 )
  117. return ERROR_INVALID_LEVEL;
  118. if ( pServerInfo == NULL )
  119. return ERROR_INVALID_PARAMETER;
  120. RpcTryExcept
  121. {
  122. err = NwrServerSetInfo( pServerName,
  123. dwLevel,
  124. (PNWSERVERINFO) pServerInfo );
  125. }
  126. RpcExcept(1)
  127. {
  128. err = NwpMapRpcError( RpcExceptionCode() );
  129. }
  130. RpcEndExcept
  131. return err;
  132. }
  133. DWORD
  134. NwServerSetInfo(
  135. IN LPWSTR pServerName OPTIONAL,
  136. IN DWORD dwLevel,
  137. IN PNWSERVERINFO pServerInfo
  138. )
  139. { return( FpnwServerSetInfo( pServerName,
  140. dwLevel,
  141. (LPBYTE) pServerInfo ));
  142. }
  143. DWORD
  144. FpnwVolumeAdd(
  145. IN LPWSTR pServerName OPTIONAL,
  146. IN DWORD dwLevel,
  147. IN LPBYTE pVolumeInfo
  148. )
  149. /*++
  150. Routine Description:
  151. This API adds a volume to the given server.
  152. Arguments:
  153. pServerName - A pointer to a UNICODE string containing the name of the
  154. remote server on which the function is to execute. A NULL pointer
  155. or string specifies the local machine.
  156. dwLevel - Reserved for the level of the volume structure contained in
  157. pVolumeInfo, use 1 & 2 for now.
  158. pVolumeInfo - Points to a NWVOLUMEINFO structure which contains the
  159. information about the volume to be added, i.e. the volume name, path,
  160. type, user limit and description. dwCurrentUses will be ignored.
  161. Return Value:
  162. Error.
  163. --*/
  164. {
  165. DWORD err;
  166. ULONG SDLength = 0;
  167. ULONG oldSDLength;
  168. PSECURITY_DESCRIPTOR fileSecurityDescriptor = NULL;
  169. PSECURITY_DESCRIPTOR oldFileSecurityDescriptor = NULL;
  170. PFPNWVOLUMEINFO_2 volInfo = (PFPNWVOLUMEINFO_2) pVolumeInfo;
  171. if ( dwLevel != 1 && dwLevel != 2 )
  172. return ERROR_INVALID_LEVEL;
  173. if ( pVolumeInfo == NULL )
  174. return ERROR_INVALID_PARAMETER;
  175. RpcTryExcept
  176. {
  177. if ( dwLevel == 2 ) {
  178. //
  179. // Save this. We need to restore this later.
  180. //
  181. oldFileSecurityDescriptor = volInfo->FileSecurityDescriptor;
  182. oldSDLength = volInfo->dwFileSecurityDescriptorLength;
  183. if ( oldFileSecurityDescriptor != NULL ) {
  184. if ( !RtlValidSecurityDescriptor( oldFileSecurityDescriptor ) ) {
  185. return ERROR_INVALID_PARAMETER;
  186. }
  187. //
  188. // Make a self relative security descriptor for use in the
  189. // RPC call..
  190. //
  191. err = RtlMakeSelfRelativeSD(
  192. oldFileSecurityDescriptor,
  193. NULL,
  194. &SDLength
  195. );
  196. if (err != STATUS_BUFFER_TOO_SMALL) {
  197. return(ERROR_INVALID_PARAMETER);
  198. } else {
  199. fileSecurityDescriptor = MIDL_user_allocate( SDLength );
  200. if ( fileSecurityDescriptor == NULL) {
  201. return ERROR_NOT_ENOUGH_MEMORY;
  202. } else {
  203. //
  204. // make an appropriate self-relative security descriptor
  205. //
  206. err = RtlMakeSelfRelativeSD(
  207. oldFileSecurityDescriptor,
  208. (PSECURITY_DESCRIPTOR) fileSecurityDescriptor,
  209. &SDLength
  210. );
  211. if ( !NT_SUCCESS(err) ) {
  212. MIDL_user_free( fileSecurityDescriptor );
  213. return(ERROR_INVALID_PARAMETER);
  214. }
  215. volInfo->FileSecurityDescriptor = fileSecurityDescriptor;
  216. volInfo->dwFileSecurityDescriptorLength = SDLength;
  217. }
  218. }
  219. } else {
  220. volInfo->dwFileSecurityDescriptorLength = 0;
  221. }
  222. }
  223. err = NwrVolumeAdd( pServerName,
  224. dwLevel,
  225. (LPVOLUME_INFO) pVolumeInfo );
  226. if ( fileSecurityDescriptor != NULL ) {
  227. //
  228. // restore old values
  229. //
  230. volInfo->dwFileSecurityDescriptorLength = oldSDLength;
  231. volInfo->FileSecurityDescriptor = oldFileSecurityDescriptor;
  232. MIDL_user_free( fileSecurityDescriptor );
  233. }
  234. }
  235. RpcExcept(1)
  236. {
  237. err = NwpMapRpcError( RpcExceptionCode() );
  238. }
  239. RpcEndExcept
  240. return err;
  241. }
  242. DWORD
  243. NwVolumeAdd(
  244. IN LPWSTR pServerName OPTIONAL,
  245. IN DWORD dwLevel,
  246. IN PNWVOLUMEINFO pVolumeInfo
  247. )
  248. { return( FpnwVolumeAdd( pServerName, dwLevel, (LPBYTE) pVolumeInfo ));
  249. }
  250. DWORD
  251. FpnwVolumeDel(
  252. IN LPWSTR pServerName OPTIONAL,
  253. IN LPWSTR pVolumeName
  254. )
  255. /*++
  256. Routine Description:
  257. This API deletes a volume from the given server.
  258. Arguments:
  259. pServerName - A pointer to a UNICODE string containing the name of the
  260. remote server on which the function is to execute. A NULL pointer
  261. or string specifies the local machine.
  262. pVolumeName - Specifies teh volume name that is to be deleted.
  263. Return Value:
  264. Error.
  265. --*/
  266. {
  267. DWORD err;
  268. if ( (pVolumeName == NULL) || (pVolumeName[0] == 0 ))
  269. return ERROR_INVALID_PARAMETER;
  270. RpcTryExcept
  271. {
  272. err = NwrVolumeDel( pServerName,
  273. pVolumeName );
  274. }
  275. RpcExcept(1)
  276. {
  277. err = NwpMapRpcError( RpcExceptionCode() );
  278. }
  279. RpcEndExcept
  280. return err;
  281. }
  282. DWORD
  283. NwVolumeDel(
  284. IN LPWSTR pServerName OPTIONAL,
  285. IN LPWSTR pVolumeName
  286. )
  287. { return( FpnwVolumeDel( pServerName, pVolumeName ));
  288. }
  289. DWORD
  290. FpnwVolumeEnum(
  291. IN LPWSTR pServerName OPTIONAL,
  292. IN DWORD dwLevel,
  293. OUT LPBYTE *ppVolumeInfo,
  294. OUT PDWORD pEntriesRead,
  295. IN OUT PDWORD resumeHandle OPTIONAL
  296. )
  297. /*++
  298. Routine Description:
  299. This enumerates all volumes on the given server.
  300. Arguments:
  301. pServerName - A pointer to a UNICODE string containing the name of the
  302. remote server on which the function is to execute. A NULL pointer
  303. or string specifies the local machine.
  304. dwLevel - Reserved for the level of the volume structure contained in
  305. *ppVolumeInfo, use 1 for now.
  306. ppVolumeInfo - On return, this will point to an array of NWVOLUMEINFO
  307. structures, one for each volume on the server.
  308. pEntriesRead - On return, this will specify the number of volumes returned
  309. resumeHandle - On return, a resume handle is stored in the DWORD pointed
  310. to by resumeHandle, and is used to continue an existing server search.
  311. The handle should be zero on the first call and left unchanged for
  312. subsequent calls. If the resumeHandle is NULL, then no resume
  313. handle is stored.
  314. Return Value:
  315. Error.
  316. --*/
  317. {
  318. DWORD err;
  319. FPNWVOLUMEINFO_CONTAINER NwVolumeInfoContainer;
  320. if ( dwLevel != 1 )
  321. return ERROR_INVALID_LEVEL;
  322. if ( ppVolumeInfo == NULL || pEntriesRead == NULL )
  323. return ERROR_INVALID_PARAMETER;
  324. NwVolumeInfoContainer.Buffer = NULL;
  325. RpcTryExcept
  326. {
  327. err = NwrVolumeEnum( pServerName,
  328. dwLevel,
  329. &NwVolumeInfoContainer,
  330. resumeHandle );
  331. *ppVolumeInfo = (LPBYTE) NwVolumeInfoContainer.Buffer;
  332. if ( NwVolumeInfoContainer.Buffer != NULL ) {
  333. *pEntriesRead = NwVolumeInfoContainer.EntriesRead;
  334. } else {
  335. *pEntriesRead = 0;
  336. }
  337. }
  338. RpcExcept(1)
  339. {
  340. err = NwpMapRpcError( RpcExceptionCode() );
  341. }
  342. RpcEndExcept
  343. return err;
  344. }
  345. DWORD
  346. NwVolumeEnum(
  347. IN LPWSTR pServerName OPTIONAL,
  348. IN DWORD dwLevel,
  349. OUT PNWVOLUMEINFO *ppVolumeInfo,
  350. OUT PDWORD pEntriesRead,
  351. IN OUT PDWORD resumeHandle OPTIONAL
  352. )
  353. { return(FpnwVolumeEnum( pServerName,
  354. dwLevel,
  355. (LPBYTE *)ppVolumeInfo,
  356. pEntriesRead,
  357. resumeHandle ));
  358. }
  359. DWORD
  360. FpnwVolumeGetInfo(
  361. IN LPWSTR pServerName OPTIONAL,
  362. IN LPWSTR pVolumeName,
  363. IN DWORD dwLevel,
  364. OUT LPBYTE *ppVolumeInfo
  365. )
  366. /*++
  367. Routine Description:
  368. This querys the information about the given volume on the given server.
  369. Arguments:
  370. pServerName - A pointer to a UNICODE string containing the name of the
  371. remote server on which the function is to execute. A NULL pointer
  372. or string specifies the local machine.
  373. pVolumeName - A pointer to a UNICODE string containing the name of the
  374. volume we want to get information on.
  375. dwLevel - Reserved for the level of the volume structure contained in
  376. *ppVolumeInfo, use 1 for now.
  377. ppVolumeInfo - On return, this will point to a NWVOLUMEINFO structure
  378. which contains information on the given volume on the given server.
  379. Return Value:
  380. Error.
  381. --*/
  382. {
  383. DWORD err;
  384. if ( dwLevel != 1 && dwLevel != 2 ) {
  385. return ERROR_INVALID_LEVEL;
  386. }
  387. if ((pVolumeName == NULL) ||
  388. (pVolumeName[0] == 0 ) ||
  389. (ppVolumeInfo == NULL) ) {
  390. return ERROR_INVALID_PARAMETER;
  391. }
  392. *ppVolumeInfo = NULL ;
  393. RpcTryExcept
  394. {
  395. err = NwrVolumeGetInfo( pServerName,
  396. pVolumeName,
  397. dwLevel,
  398. (LPVOLUME_INFO *) ppVolumeInfo );
  399. }
  400. RpcExcept(1)
  401. {
  402. err = NwpMapRpcError( RpcExceptionCode() );
  403. }
  404. RpcEndExcept
  405. return err;
  406. }
  407. DWORD
  408. NwVolumeGetInfo(
  409. IN LPWSTR pServerName OPTIONAL,
  410. IN LPWSTR pVolumeName,
  411. IN DWORD dwLevel,
  412. OUT PNWVOLUMEINFO *ppVolumeInfo
  413. )
  414. { return(FpnwVolumeGetInfo( pServerName,
  415. pVolumeName,
  416. dwLevel,
  417. (LPBYTE *)ppVolumeInfo ));
  418. }
  419. DWORD
  420. FpnwVolumeSetInfo(
  421. IN LPWSTR pServerName OPTIONAL,
  422. IN LPWSTR pVolumeName,
  423. IN DWORD dwLevel,
  424. IN LPBYTE pVolumeInfo
  425. )
  426. /*++
  427. Routine Description:
  428. This sets the information about the given volume on the given server.
  429. Arguments:
  430. pServerName - A pointer to a UNICODE string containing the name of the
  431. remote server on which the function is to execute. A NULL pointer
  432. or string specifies the local machine.
  433. pVolumeName - A pointer to a UNICODE string containing the name of the
  434. volume we want to set information on.
  435. dwLevel - Reserved for the level of the volume structure contained in
  436. pVolumeInfo, use 1 for now.
  437. pVolumeInfo - Points to a NWVOLUMEINFO structure which contains
  438. information on the given volume to set to. Only dwMaxUses can be
  439. set. All the other fields in this structure will be ignored.
  440. Return Value:
  441. Error.
  442. --*/
  443. {
  444. DWORD err;
  445. ULONG SDLength = 0;
  446. ULONG oldSDLength;
  447. PFPNWVOLUMEINFO_2 volInfo = (PFPNWVOLUMEINFO_2) pVolumeInfo;
  448. PSECURITY_DESCRIPTOR fileSecurityDescriptor = NULL;
  449. PSECURITY_DESCRIPTOR oldFileSecurityDescriptor = NULL;
  450. if ( dwLevel != 1 && dwLevel != 2 )
  451. return ERROR_INVALID_LEVEL;
  452. if ( ((pVolumeName == NULL) ||
  453. ( pVolumeName[0] == 0 )) ||
  454. ( pVolumeInfo == NULL )
  455. ) {
  456. return ERROR_INVALID_PARAMETER;
  457. }
  458. RpcTryExcept
  459. {
  460. if ( dwLevel == 2 ) {
  461. //
  462. // Save this. We need to restore this later.
  463. //
  464. oldFileSecurityDescriptor = volInfo->FileSecurityDescriptor;
  465. oldSDLength = volInfo->dwFileSecurityDescriptorLength;
  466. if ( oldFileSecurityDescriptor != NULL ) {
  467. if ( !RtlValidSecurityDescriptor( oldFileSecurityDescriptor ) ) {
  468. return ERROR_INVALID_PARAMETER;
  469. }
  470. //
  471. // Make a self relative security descriptor for use in the
  472. // RPC call..
  473. //
  474. err = RtlMakeSelfRelativeSD(
  475. oldFileSecurityDescriptor,
  476. NULL,
  477. &SDLength
  478. );
  479. if (err != STATUS_BUFFER_TOO_SMALL) {
  480. return(ERROR_INVALID_PARAMETER);
  481. } else {
  482. fileSecurityDescriptor = MIDL_user_allocate( SDLength );
  483. if ( fileSecurityDescriptor == NULL) {
  484. return ERROR_NOT_ENOUGH_MEMORY;
  485. } else {
  486. //
  487. // make an appropriate self-relative security descriptor
  488. //
  489. err = RtlMakeSelfRelativeSD(
  490. oldFileSecurityDescriptor,
  491. (PSECURITY_DESCRIPTOR) fileSecurityDescriptor,
  492. &SDLength
  493. );
  494. if ( !NT_SUCCESS(err) ) {
  495. MIDL_user_free( fileSecurityDescriptor );
  496. return(ERROR_INVALID_PARAMETER);
  497. }
  498. volInfo->FileSecurityDescriptor = fileSecurityDescriptor;
  499. volInfo->dwFileSecurityDescriptorLength = SDLength;
  500. }
  501. }
  502. } else {
  503. volInfo->dwFileSecurityDescriptorLength = 0;
  504. }
  505. }
  506. err = NwrVolumeSetInfo( pServerName,
  507. pVolumeName,
  508. dwLevel,
  509. (LPVOLUME_INFO) pVolumeInfo );
  510. if ( fileSecurityDescriptor != NULL ) {
  511. //
  512. // restore old values
  513. //
  514. volInfo->dwFileSecurityDescriptorLength = oldSDLength;
  515. volInfo->FileSecurityDescriptor = oldFileSecurityDescriptor;
  516. MIDL_user_free( fileSecurityDescriptor );
  517. }
  518. }
  519. RpcExcept(1)
  520. {
  521. err = NwpMapRpcError( RpcExceptionCode() );
  522. }
  523. RpcEndExcept
  524. return err;
  525. }
  526. DWORD
  527. NwVolumeSetInfo(
  528. IN LPWSTR pServerName OPTIONAL,
  529. IN LPWSTR pVolumeName,
  530. IN DWORD dwLevel,
  531. IN PNWVOLUMEINFO pVolumeInfo
  532. )
  533. { return( FpnwVolumeSetInfo( pServerName,
  534. pVolumeName,
  535. dwLevel,
  536. (LPBYTE) pVolumeInfo ));
  537. }
  538. DWORD
  539. FpnwConnectionEnum(
  540. IN LPWSTR pServerName OPTIONAL,
  541. IN DWORD dwLevel,
  542. OUT LPBYTE *ppConnectionInfo,
  543. OUT PDWORD pEntriesRead,
  544. IN OUT PDWORD resumeHandle OPTIONAL
  545. )
  546. /*++
  547. Routine Description:
  548. This enumerates all connections on the given server.
  549. Arguments:
  550. pServerName - A pointer to a UNICODE string containing the name of the
  551. remote server on which the function is to execute. A NULL pointer
  552. or string specifies the local machine.
  553. dwLevel - Reserved for the level of the volume structure contained in
  554. *ppConnectionInfo, use 1 for now.
  555. ppConnectionInfo - On return, this will point to an array of
  556. NWCONNECTIONINFO structures, one for each volume on the server.
  557. pEntriesRead - On return, this will specify the number of current
  558. connecitons.
  559. resumeHandle - On return, a resume handle is stored in the DWORD pointed
  560. to by resumeHandle, and is used to continue an existing server search.
  561. The handle should be zero on the first call and left unchanged for
  562. subsequent calls. If the resumeHandle is NULL, then no resume
  563. handle is stored.
  564. Return Value:
  565. Error.
  566. --*/
  567. {
  568. DWORD err;
  569. FPNWCONNECTIONINFO_CONTAINER NwConnectionInfoContainer;
  570. if ( dwLevel != 1 )
  571. return ERROR_INVALID_LEVEL;
  572. if (( ppConnectionInfo == NULL ) || ( pEntriesRead == NULL ))
  573. return ERROR_INVALID_PARAMETER;
  574. NwConnectionInfoContainer.Buffer = NULL;
  575. RpcTryExcept
  576. {
  577. err = NwrConnectionEnum( pServerName,
  578. dwLevel,
  579. &NwConnectionInfoContainer,
  580. resumeHandle );
  581. *ppConnectionInfo = (LPBYTE) NwConnectionInfoContainer.Buffer;
  582. if ( NwConnectionInfoContainer.Buffer != NULL ) {
  583. *pEntriesRead = NwConnectionInfoContainer.EntriesRead;
  584. } else {
  585. *pEntriesRead = 0;
  586. }
  587. }
  588. RpcExcept(1)
  589. {
  590. err = NwpMapRpcError( RpcExceptionCode() );
  591. }
  592. RpcEndExcept
  593. return err;
  594. }
  595. DWORD
  596. NwConnectionEnum(
  597. IN LPWSTR pServerName OPTIONAL,
  598. IN DWORD dwLevel,
  599. OUT PNWCONNECTIONINFO *ppConnectionInfo,
  600. OUT PDWORD pEntriesRead,
  601. IN OUT PDWORD resumeHandle OPTIONAL
  602. )
  603. { return(FpnwConnectionEnum( pServerName,
  604. dwLevel,
  605. (LPBYTE *) ppConnectionInfo,
  606. pEntriesRead,
  607. resumeHandle ));
  608. }
  609. DWORD
  610. FpnwConnectionDel(
  611. IN LPWSTR pServerName OPTIONAL,
  612. IN DWORD dwConnectionId
  613. )
  614. /*++
  615. Routine Description:
  616. This delete the connection with the given connection id on the given server.
  617. Arguments:
  618. pServerName - A pointer to a UNICODE string containing the name of the
  619. remote server on which the function is to execute. A NULL pointer
  620. or string specifies the local machine.
  621. dwConnectionId - The identification number of the connection to tear down.
  622. Return Value:
  623. Error.
  624. --*/
  625. {
  626. DWORD err;
  627. RpcTryExcept
  628. {
  629. err = NwrConnectionDel( pServerName,
  630. dwConnectionId );
  631. }
  632. RpcExcept(1)
  633. {
  634. err = NwpMapRpcError( RpcExceptionCode() );
  635. }
  636. RpcEndExcept
  637. return err;
  638. }
  639. DWORD
  640. NwConnectionDel(
  641. IN LPWSTR pServerName OPTIONAL,
  642. IN DWORD dwConnectionId
  643. )
  644. { return( FpnwConnectionDel( pServerName, dwConnectionId ));
  645. }
  646. DWORD
  647. FpnwVolumeConnEnum(
  648. IN LPWSTR pServerName OPTIONAL,
  649. IN DWORD dwLevel,
  650. IN LPWSTR pVolumeName OPTIONAL,
  651. IN DWORD dwConnectionId,
  652. OUT LPBYTE *ppVolumeConnInfo,
  653. OUT PDWORD pEntriesRead,
  654. IN OUT PDWORD resumeHandle OPTIONAL
  655. )
  656. /*++
  657. Routine Description:
  658. This enumerates all connections to a volume or list all volumes used by
  659. a particular connection on the given server.
  660. Arguments:
  661. pServerName - A pointer to a UNICODE string containing the name of the
  662. remote server on which the function is to execute. A NULL pointer
  663. or string specifies the local machine.
  664. dwLevel - Reserved for the level of the volume structure contained in
  665. *ppVolumeConnInfo, use 1 for now.
  666. pVolumeName - Specifies the volume name which we want to get all opened
  667. resources. This must be NULL if dwConnectionId is not 0.
  668. dwConnectionId - Specifies the connection id on which we want to get all
  669. opened resources. This must be 0 if pVolumeName is not NULL.
  670. ppVolumeConnInfo - On return, this will point to an array of
  671. NWVOLUMECONNINFO structures.
  672. pEntriesRead - On return, this will specify the number of NWVOLUMECONNINFO
  673. returned.
  674. resumeHandle - On return, a resume handle is stored in the DWORD pointed
  675. to by resumeHandle, and is used to continue an existing server search.
  676. The handle should be zero on the first call and left unchanged for
  677. subsequent calls. If the resumeHandle is NULL, then no resume
  678. handle is stored.
  679. Return Value:
  680. Error.
  681. --*/
  682. {
  683. DWORD err;
  684. FPNWVOLUMECONNINFO_CONTAINER NwVolumeConnInfoContainer;
  685. if ( dwLevel != 1 )
  686. return ERROR_INVALID_LEVEL;
  687. if ( ( dwConnectionId == 0 )
  688. && (( pVolumeName == NULL ) || ( *pVolumeName == 0 ))
  689. )
  690. {
  691. return ERROR_INVALID_PARAMETER;
  692. }
  693. if ( ( dwConnectionId != 0 )
  694. && (( pVolumeName != NULL) && ( *pVolumeName != 0 ))
  695. )
  696. {
  697. return ERROR_INVALID_PARAMETER;
  698. }
  699. if (( ppVolumeConnInfo == NULL ) || ( pEntriesRead == NULL ))
  700. return ERROR_INVALID_PARAMETER;
  701. NwVolumeConnInfoContainer.Buffer = NULL;
  702. RpcTryExcept
  703. {
  704. err = NwrVolumeConnEnum( pServerName,
  705. dwLevel,
  706. pVolumeName,
  707. dwConnectionId,
  708. &NwVolumeConnInfoContainer,
  709. resumeHandle );
  710. *ppVolumeConnInfo = (LPBYTE) NwVolumeConnInfoContainer.Buffer;
  711. if ( NwVolumeConnInfoContainer.Buffer != NULL ) {
  712. *pEntriesRead = NwVolumeConnInfoContainer.EntriesRead;
  713. } else {
  714. *pEntriesRead = 0;
  715. }
  716. }
  717. RpcExcept(1)
  718. {
  719. err = NwpMapRpcError( RpcExceptionCode() );
  720. }
  721. RpcEndExcept
  722. return err;
  723. }
  724. DWORD
  725. NwVolumeConnEnum(
  726. IN LPWSTR pServerName OPTIONAL,
  727. IN DWORD dwLevel,
  728. IN LPWSTR pVolumeName OPTIONAL,
  729. IN DWORD dwConnectionId,
  730. OUT PNWVOLUMECONNINFO *ppVolumeConnInfo,
  731. OUT PDWORD pEntriesRead,
  732. IN OUT PDWORD resumeHandle OPTIONAL
  733. )
  734. { return( FpnwVolumeConnEnum( pServerName,
  735. dwLevel,
  736. pVolumeName,
  737. dwConnectionId,
  738. (LPBYTE *) ppVolumeConnInfo,
  739. pEntriesRead,
  740. resumeHandle ));
  741. }
  742. DWORD
  743. FpnwFileEnum(
  744. IN LPWSTR pServerName OPTIONAL,
  745. IN DWORD dwLevel,
  746. IN LPWSTR pPathName OPTIONAL,
  747. OUT LPBYTE *ppFileInfo,
  748. OUT PDWORD pEntriesRead,
  749. IN OUT PDWORD resumeHandle OPTIONAL
  750. )
  751. /*++
  752. Routine Description:
  753. This enumerates files opened on the server.
  754. Arguments:
  755. pServerName - A pointer to a UNICODE string containing the name of the
  756. remote server on which the function is to execute. A NULL pointer
  757. or string specifies the local machine.
  758. dwLevel - Reserved for the level of the volume structure contained in
  759. *ppFileInfo, use 1 for now.
  760. pPathName - If this is not NULL, this means that we want to filter
  761. on the path. We only want entries with this path, i.e., all users that
  762. currently opened the file. If this is NULL, then all files that are
  763. opened are returned along with the user information.
  764. ppFileInfo - On return, this will point to an array of NWFILEINFO structures
  765. pEntriesRead - On return, this will specify the number of NWFILEINFO
  766. returned.
  767. resumeHandle - On return, a resume handle is stored in the DWORD pointed
  768. to by resumeHandle, and is used to continue an existing server search.
  769. The handle should be zero on the first call and left unchanged for
  770. subsequent calls. If the resumeHandle is NULL, then no resume
  771. handle is stored.
  772. Return Value:
  773. Error.
  774. --*/
  775. {
  776. DWORD err;
  777. FPNWFILEINFO_CONTAINER NwFileInfoContainer;
  778. if ( dwLevel != 1 )
  779. return ERROR_INVALID_LEVEL;
  780. if (( ppFileInfo == NULL ) || ( pEntriesRead == NULL ))
  781. return ERROR_INVALID_PARAMETER;
  782. NwFileInfoContainer.Buffer = NULL;
  783. RpcTryExcept
  784. {
  785. err = NwrFileEnum( pServerName,
  786. dwLevel,
  787. pPathName,
  788. &NwFileInfoContainer,
  789. resumeHandle );
  790. *ppFileInfo = (LPBYTE) NwFileInfoContainer.Buffer;
  791. if ( NwFileInfoContainer.Buffer != NULL ) {
  792. *pEntriesRead = NwFileInfoContainer.EntriesRead;
  793. } else {
  794. *pEntriesRead = 0;
  795. }
  796. }
  797. RpcExcept(1)
  798. {
  799. err = NwpMapRpcError( RpcExceptionCode() );
  800. }
  801. RpcEndExcept
  802. return err;
  803. }
  804. DWORD
  805. NwFileEnum(
  806. IN LPWSTR pServerName OPTIONAL,
  807. IN DWORD dwLevel,
  808. IN LPWSTR pPathName OPTIONAL,
  809. OUT PNWFILEINFO *ppFileInfo,
  810. OUT PDWORD pEntriesRead,
  811. IN OUT PDWORD resumeHandle OPTIONAL
  812. )
  813. { return(FpnwFileEnum( pServerName,
  814. dwLevel,
  815. pPathName,
  816. (LPBYTE *) ppFileInfo,
  817. pEntriesRead,
  818. resumeHandle ));
  819. }
  820. DWORD
  821. FpnwFileClose(
  822. IN LPWSTR pServerName OPTIONAL,
  823. IN DWORD dwFileId
  824. )
  825. /*++
  826. Routine Description:
  827. This closes the file with the given identification number.
  828. Arguments:
  829. pServerName - A pointer to a UNICODE string containing the name of the
  830. remote server on which the function is to execute. A NULL pointer
  831. or string specifies the local machine.
  832. dwFileId - The identification number of the file to close.
  833. Return Value:
  834. Error.
  835. --*/
  836. {
  837. DWORD err;
  838. RpcTryExcept
  839. {
  840. err = NwrFileClose( pServerName,
  841. dwFileId );
  842. }
  843. RpcExcept(1)
  844. {
  845. err = NwpMapRpcError( RpcExceptionCode() );
  846. }
  847. RpcEndExcept
  848. return err;
  849. }
  850. DWORD
  851. NwFileClose(
  852. IN LPWSTR pServerName OPTIONAL,
  853. IN DWORD dwFileId
  854. )
  855. { return(FpnwFileClose( pServerName, dwFileId ));
  856. }
  857. DWORD
  858. FpnwMessageBufferSend(
  859. IN LPWSTR pServerName OPTIONAL,
  860. IN DWORD dwConnectionId,
  861. IN DWORD fConsoleBroadcast,
  862. IN LPBYTE pbBuffer,
  863. IN DWORD cbBuffer
  864. )
  865. /*++
  866. Routine Description:
  867. This sends the message to the given connection id.
  868. Arguments:
  869. pServerName - A pointer to a UNICODE string containing the name of the
  870. remote server on which the function is to execute. A NULL pointer
  871. or string specifies the local machine.
  872. dwConnectionId - The id of the connection to send message to.
  873. fConsoleBroadcast - If this is TRUE, that means use console broadcast. If
  874. FALSE, use user broadcast.
  875. pbBuffer - Points to the message buffer to be sent.
  876. cbBuffer - The size of the pbBuffer in bytes.
  877. Return Value:
  878. Error.
  879. --*/
  880. {
  881. DWORD err;
  882. if (( pbBuffer == NULL ) || ( cbBuffer == 0 ))
  883. return ERROR_INVALID_PARAMETER;
  884. RpcTryExcept
  885. {
  886. err = NwrMessageBufferSend( pServerName,
  887. dwConnectionId,
  888. fConsoleBroadcast,
  889. pbBuffer,
  890. cbBuffer );
  891. }
  892. RpcExcept(1)
  893. {
  894. err = NwpMapRpcError( RpcExceptionCode() );
  895. }
  896. RpcEndExcept
  897. return err;
  898. }
  899. DWORD
  900. NwMessageBufferSend(
  901. IN LPWSTR pServerName OPTIONAL,
  902. IN DWORD dwConnectionId,
  903. IN DWORD fConsoleBroadcast,
  904. IN LPBYTE pbBuffer,
  905. IN DWORD cbBuffer
  906. )
  907. { return( FpnwMessageBufferSend( pServerName,
  908. dwConnectionId,
  909. fConsoleBroadcast,
  910. pbBuffer,
  911. cbBuffer ));
  912. }
  913. DWORD
  914. FpnwSetDefaultQueue(
  915. IN LPWSTR pServerName OPTIONAL,
  916. IN LPWSTR pQueueName
  917. )
  918. /*++
  919. Routine Description:
  920. This sets the default queue on the server.
  921. Arguments:
  922. pServerName - A pointer to a UNICODE string containing the name of the
  923. remote server on which the function is to execute. A NULL pointer
  924. or string specifies the local machine.
  925. pQueueName - The name of the queue that will become the default
  926. Return Value:
  927. Error.
  928. --*/
  929. {
  930. DWORD err;
  931. if (( pQueueName == NULL ) || ( *pQueueName == 0 ))
  932. return ERROR_INVALID_PARAMETER;
  933. RpcTryExcept
  934. {
  935. err = NwrSetDefaultQueue( pServerName,
  936. pQueueName );
  937. }
  938. RpcExcept(1)
  939. {
  940. err = NwpMapRpcError( RpcExceptionCode() );
  941. }
  942. RpcEndExcept
  943. return err;
  944. }
  945. DWORD
  946. NwSetDefaultQueue(
  947. IN LPWSTR pServerName OPTIONAL,
  948. IN LPWSTR pQueueName
  949. )
  950. { return(FpnwSetDefaultQueue( pServerName, pQueueName ));
  951. }
  952. DWORD
  953. FpnwAddPServer(
  954. IN LPWSTR pServerName OPTIONAL,
  955. IN LPWSTR pPServerName
  956. )
  957. /*++
  958. Routine Description:
  959. This adds a pserver.
  960. Arguments:
  961. pServerName - A pointer to a UNICODE string containing the name of the
  962. remote server on which the function is to execute. A NULL pointer
  963. or string specifies the local machine.
  964. pPServerName - The name of the PServer.
  965. Return Value:
  966. Error.
  967. --*/
  968. {
  969. DWORD err;
  970. if (( pPServerName == NULL ) || ( *pPServerName == 0 ))
  971. return ERROR_INVALID_PARAMETER;
  972. RpcTryExcept
  973. {
  974. err = NwrAddPServer( pServerName,
  975. pPServerName );
  976. }
  977. RpcExcept(1)
  978. {
  979. err = NwpMapRpcError( RpcExceptionCode() );
  980. }
  981. RpcEndExcept
  982. return err;
  983. }
  984. DWORD
  985. NwAddPServer(
  986. IN LPWSTR pServerName OPTIONAL,
  987. IN LPWSTR pPServerName
  988. )
  989. { return( FpnwAddPServer( pServerName, pPServerName ));
  990. }
  991. DWORD
  992. FpnwRemovePServer(
  993. IN LPWSTR pServerName OPTIONAL,
  994. IN LPWSTR pPServerName
  995. )
  996. /*++
  997. Routine Description:
  998. This removes a pserver.
  999. Arguments:
  1000. pServerName - A pointer to a UNICODE string containing the name of the
  1001. remote server on which the function is to execute. A NULL pointer
  1002. or string specifies the local machine.
  1003. pPServerName - The name of the PServer.
  1004. Return Value:
  1005. Error.
  1006. --*/
  1007. {
  1008. DWORD err;
  1009. if (( pPServerName == NULL ) || ( *pPServerName == 0 ))
  1010. return ERROR_INVALID_PARAMETER;
  1011. RpcTryExcept
  1012. {
  1013. err = NwrRemovePServer( pServerName,
  1014. pPServerName );
  1015. }
  1016. RpcExcept(1)
  1017. {
  1018. err = NwpMapRpcError( RpcExceptionCode() );
  1019. }
  1020. RpcEndExcept
  1021. return err;
  1022. }
  1023. DWORD
  1024. NwRemovePServer(
  1025. IN LPWSTR pServerName OPTIONAL,
  1026. IN LPWSTR pPServerName
  1027. )
  1028. { return( FpnwRemovePServer( pServerName, pPServerName ));
  1029. }
  1030. DWORD NwpMapRpcError(
  1031. IN DWORD RpcError
  1032. )
  1033. /*++
  1034. Routine Description:
  1035. This routine maps the RPC error into a more meaningful windows
  1036. error for the caller.
  1037. Arguments:
  1038. RpcError - Supplies the exception error raised by RPC
  1039. Return Value:
  1040. Returns the mapped error.
  1041. --*/
  1042. {
  1043. switch (RpcError)
  1044. {
  1045. case RPC_S_INVALID_BINDING:
  1046. case RPC_X_SS_IN_NULL_CONTEXT:
  1047. case RPC_X_SS_CONTEXT_DAMAGED:
  1048. case RPC_X_SS_HANDLES_MISMATCH:
  1049. case ERROR_INVALID_HANDLE:
  1050. return ERROR_INVALID_HANDLE;
  1051. case RPC_X_NULL_REF_POINTER:
  1052. return ERROR_INVALID_PARAMETER;
  1053. case STATUS_ACCESS_VIOLATION:
  1054. return ERROR_INVALID_ADDRESS;
  1055. default:
  1056. return RpcError;
  1057. }
  1058. }
  1059. // ncpstub.c eof.