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.

1012 lines
35 KiB

  1. /*++
  2. Copyright (C) 1993 Microsoft Corporation
  3. Module Name:
  4. NWAPI32.C
  5. Abstract:
  6. This module contains several useful functions. Mostly wrappers.
  7. Author:
  8. Chuck Y. Chan (ChuckC) 06-Mar-1995
  9. Revision History:
  10. --*/
  11. #include "procs.h"
  12. //
  13. // Define structure for internal use. Our handle passed back from attach to
  14. // file server will be pointer to this. We keep server string around for
  15. // discnnecting from the server on logout. The structure is freed on detach.
  16. // Callers should not use this structure but treat pointer as opaque handle.
  17. //
  18. typedef struct _NWC_SERVER_INFO {
  19. HANDLE hConn ;
  20. UNICODE_STRING ServerString ;
  21. } NWC_SERVER_INFO, *PNWC_SERVER_INFO ;
  22. //
  23. // forward declare
  24. //
  25. #ifndef WIN95
  26. extern NTSTATUS
  27. NwAttachToServer(
  28. IN LPWSTR ServerName,
  29. OUT LPHANDLE phandleServer
  30. ) ;
  31. extern NTSTATUS
  32. NwDetachFromServer(
  33. IN HANDLE handleServer
  34. ) ;
  35. #endif
  36. extern DWORD
  37. CancelAllConnections(
  38. LPWSTR pszServer
  39. ) ;
  40. extern DWORD
  41. szToWide(
  42. LPWSTR lpszW,
  43. LPCSTR lpszC,
  44. INT nSize
  45. );
  46. NTSTATUS
  47. NWPAttachToFileServerW(
  48. const WCHAR *pszServerName,
  49. NWLOCAL_SCOPE ScopeFlag,
  50. NWCONN_HANDLE *phNewConn
  51. )
  52. {
  53. NTSTATUS NtStatus;
  54. LPWSTR lpwszServerName; // Pointer to buffer for WIDE servername
  55. int nSize;
  56. PNWC_SERVER_INFO pServerInfo = NULL;
  57. UNREFERENCED_PARAMETER(ScopeFlag) ;
  58. //
  59. // check parameters and init return result to be null.
  60. //
  61. if (!pszServerName || !phNewConn)
  62. return STATUS_INVALID_PARAMETER;
  63. *phNewConn = NULL ;
  64. //
  65. // Allocate a buffer to store the file server name
  66. //
  67. nSize = wcslen(pszServerName)+3 ;
  68. if(!(lpwszServerName = (LPWSTR) LocalAlloc(
  69. LPTR,
  70. nSize * sizeof(WCHAR) )))
  71. {
  72. NtStatus = STATUS_NO_MEMORY;
  73. goto ExitPoint ;
  74. }
  75. wcscpy( lpwszServerName, L"\\\\" );
  76. wcscat( lpwszServerName, pszServerName );
  77. //
  78. // Allocate a buffer for the server info (handle + name pointer). Also
  79. // init the unicode string.
  80. //
  81. if( !(pServerInfo = (PNWC_SERVER_INFO) LocalAlloc(
  82. LPTR,
  83. sizeof(NWC_SERVER_INFO))) )
  84. {
  85. NtStatus = STATUS_NO_MEMORY;
  86. goto ExitPoint ;
  87. }
  88. RtlInitUnicodeString(&pServerInfo->ServerString, lpwszServerName) ;
  89. //
  90. // Call createfile to get a handle for the redirector calls
  91. //
  92. NtStatus = NwAttachToServer( lpwszServerName, &pServerInfo->hConn );
  93. ExitPoint:
  94. //
  95. // Free the memory allocated above before exiting
  96. //
  97. if ( !NT_SUCCESS( NtStatus))
  98. {
  99. if (lpwszServerName)
  100. (void) LocalFree( (HLOCAL) lpwszServerName );
  101. if (pServerInfo)
  102. (void) LocalFree( (HLOCAL) pServerInfo );
  103. }
  104. else
  105. *phNewConn = (HANDLE) pServerInfo ;
  106. return( NtStatus );
  107. }
  108. NTSTATUS
  109. NWPDetachFromFileServer(
  110. NWCONN_HANDLE hConn
  111. )
  112. {
  113. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  114. (void) NwDetachFromServer( pServerInfo->hConn );
  115. (void) LocalFree (pServerInfo->ServerString.Buffer) ;
  116. //
  117. // catch any body that still trirs to use this puppy...
  118. //
  119. pServerInfo->ServerString.Buffer = NULL ;
  120. pServerInfo->hConn = NULL ;
  121. (void) LocalFree (pServerInfo) ;
  122. return STATUS_SUCCESS;
  123. }
  124. NTSTATUS
  125. NWPGetFileServerVersionInfo(
  126. NWCONN_HANDLE hConn,
  127. VERSION_INFO *lpVerInfo
  128. )
  129. {
  130. NTSTATUS NtStatus ;
  131. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  132. NtStatus = NwlibMakeNcp(
  133. pServerInfo->hConn, // Connection Handle
  134. FSCTL_NWR_NCP_E3H, // Bindery function
  135. 3, // Max request packet size
  136. 130, // Max response packet size
  137. "b|r", // Format string
  138. // === REQUEST ================================
  139. 0x11, // b Get File Server Information
  140. // === REPLY ==================================
  141. lpVerInfo, // r File Version Structure
  142. sizeof(VERSION_INFO)
  143. );
  144. // Convert HI-LO words to LO-HI
  145. // ===========================================================
  146. lpVerInfo->ConnsSupported = wSWAP( lpVerInfo->ConnsSupported );
  147. lpVerInfo->connsInUse = wSWAP( lpVerInfo->connsInUse );
  148. lpVerInfo->maxVolumes = wSWAP( lpVerInfo->maxVolumes );
  149. lpVerInfo->PeakConns = wSWAP( lpVerInfo->PeakConns );
  150. return NtStatus;
  151. }
  152. NTSTATUS
  153. NWPGetObjectName(
  154. NWCONN_HANDLE hConn,
  155. NWOBJ_ID dwObjectID,
  156. char *pszObjName,
  157. NWOBJ_TYPE *pwObjType )
  158. {
  159. NWOBJ_ID dwRetID;
  160. NTSTATUS NtStatus ;
  161. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  162. NtStatus = NwlibMakeNcp(
  163. pServerInfo->hConn, // Connection Handle
  164. FSCTL_NWR_NCP_E3H, // Bindery function
  165. 7, // Max request packet size
  166. 56, // Max response packet size
  167. "br|rrr", // Format string
  168. // === REQUEST ================================
  169. 0x36, // b Get Bindery Object Name
  170. &dwObjectID,DW_SIZE, // r Object ID HI-LO
  171. // === REPLY ==================================
  172. &dwRetID,DW_SIZE, // r Object ID HI-LO
  173. pwObjType,W_SIZE, // r Object Type
  174. pszObjName,48 // r Object Name
  175. );
  176. return NtStatus;
  177. }
  178. DWORD
  179. NWPLoginToFileServerW(
  180. NWCONN_HANDLE hConn,
  181. LPWSTR pszUserNameW,
  182. NWOBJ_TYPE wObjType,
  183. LPWSTR pszPasswordW
  184. )
  185. {
  186. NETRESOURCEW NetResource;
  187. DWORD dwRes;
  188. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  189. //
  190. // validate parameters
  191. //
  192. if (!hConn || !pszUserNameW || !pszPasswordW)
  193. return ERROR_INVALID_PARAMETER;
  194. NetResource.dwScope = 0 ;
  195. NetResource.dwUsage = 0 ;
  196. NetResource.dwType = RESOURCETYPE_ANY;
  197. NetResource.lpLocalName = NULL;
  198. NetResource.lpRemoteName = (LPWSTR) pServerInfo->ServerString.Buffer;
  199. NetResource.lpComment = NULL;
  200. NetResource.lpProvider = NULL ;
  201. //
  202. // make the connection
  203. //
  204. dwRes=NPAddConnection ( &NetResource,
  205. pszPasswordW,
  206. pszUserNameW );
  207. if( NO_ERROR != dwRes )
  208. dwRes = GetLastError();
  209. return( dwRes );
  210. }
  211. DWORD
  212. NWPLogoutFromFileServer(
  213. NWCONN_HANDLE hConn
  214. )
  215. {
  216. DWORD dwRes;
  217. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  218. //
  219. // now cancel the any connection to \\servername.
  220. //
  221. dwRes = NPCancelConnection( pServerInfo->ServerString.Buffer, TRUE );
  222. if ( NO_ERROR != dwRes )
  223. dwRes = GetLastError();
  224. return dwRes;
  225. }
  226. NTSTATUS
  227. NWPReadPropertyValue(
  228. NWCONN_HANDLE hConn,
  229. const char *pszObjName,
  230. NWOBJ_TYPE wObjType,
  231. char *pszPropName,
  232. unsigned char ucSegment,
  233. char *pValue,
  234. NWFLAGS *pucMoreFlag,
  235. NWFLAGS *pucPropFlag
  236. )
  237. {
  238. NTSTATUS NtStatus ;
  239. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  240. NtStatus = NwlibMakeNcp(
  241. pServerInfo->hConn, // Connection Handle
  242. FSCTL_NWR_NCP_E3H, // Bindery function
  243. 70, // Max request packet size
  244. 132, // Max response packet size
  245. "brpbp|rbb", // Format string
  246. // === REQUEST ================================
  247. 0x3D, // b Read Property Value
  248. &wObjType,W_SIZE, // r Object Type HI-LO
  249. pszObjName, // p Object Name
  250. ucSegment, // b Segment Number
  251. pszPropName, // p Property Name
  252. // === REPLY ==================================
  253. pValue,128, // r Property value
  254. pucMoreFlag, // b More Flag
  255. pucPropFlag // b Prop Flag
  256. );
  257. return NtStatus;
  258. }
  259. NTSTATUS
  260. NWPScanObject(
  261. NWCONN_HANDLE hConn,
  262. const char *pszSearchName,
  263. NWOBJ_TYPE wObjSearchType,
  264. NWOBJ_ID *pdwObjectID,
  265. char *pszObjectName,
  266. NWOBJ_TYPE *pwObjType,
  267. NWFLAGS *pucHasProperties,
  268. NWFLAGS *pucObjectFlags,
  269. NWFLAGS *pucObjSecurity
  270. )
  271. {
  272. NTSTATUS NtStatus ;
  273. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  274. NtStatus = NwlibMakeNcp(
  275. pServerInfo->hConn, // Connection Handle
  276. FSCTL_NWR_NCP_E3H, // Bindery function
  277. 57, // Max request packet size
  278. 59, // Max response packet size
  279. "brrp|rrrbbb", // Format string
  280. // === REQUEST ================================
  281. 0x37, // b Scan bindery object
  282. pdwObjectID,DW_SIZE, // r 0xffffffff to start or last returned ID when enumerating HI-LO
  283. &wObjSearchType,W_SIZE, // r Use OT_??? Defines HI-LO
  284. pszSearchName, // p Search Name. (use "*") for all
  285. // === REPLY ==================================
  286. pdwObjectID,DW_SIZE, // r Returned ID HI-LO
  287. pwObjType,W_SIZE, // r rObject Type HI-LO
  288. pszObjectName,48, // r Found Name
  289. pucObjectFlags, // b Object Flag
  290. pucObjSecurity, // b Object Security
  291. pucHasProperties // b Has Properties
  292. );
  293. return NtStatus;
  294. }
  295. NTSTATUS
  296. NWPScanProperty(
  297. NWCONN_HANDLE hConn,
  298. const char *pszObjectName,
  299. NWOBJ_TYPE wObjType,
  300. char *pszSearchName,
  301. NWOBJ_ID *pdwSequence,
  302. char *pszPropName,
  303. NWFLAGS *pucPropFlags,
  304. NWFLAGS *pucPropSecurity,
  305. NWFLAGS *pucHasValue,
  306. NWFLAGS *pucMore
  307. )
  308. {
  309. NTSTATUS NtStatus ;
  310. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  311. NtStatus = NwlibMakeNcp(
  312. pServerInfo->hConn, // Connection Handle
  313. FSCTL_NWR_NCP_E3H, // Bindery function
  314. 73, // Max request packet size
  315. 26, // Max response packet size
  316. "brprp|rbbrbb", // Format string
  317. // === REQUEST ================================
  318. 0x3C, // b Scan Prop function
  319. &wObjType,W_SIZE, // r Type of Object
  320. pszObjectName, // p Object Name
  321. pdwSequence,DW_SIZE, // r Sequence HI-LO
  322. pszSearchName, // p Property Name to Search for
  323. // === REPLY ==================================
  324. pszPropName,16, // r Returned Property Name
  325. pucPropFlags, // b Property Flags
  326. pucPropSecurity, // b Property Security
  327. pdwSequence,DW_SIZE, // r Sequence HI-LO
  328. pucHasValue, // b Property Has value
  329. pucMore // b More Properties
  330. );
  331. return NtStatus;
  332. }
  333. NTSTATUS
  334. NWPDeleteObject(
  335. NWCONN_HANDLE hConn,
  336. const char *pszObjectName,
  337. NWOBJ_TYPE wObjType
  338. )
  339. {
  340. NTSTATUS NtStatus ;
  341. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  342. NtStatus = NwlibMakeNcp(
  343. pServerInfo->hConn, // Connection Handle
  344. FSCTL_NWR_NCP_E3H, // Bindery function
  345. 54, // Max request packet size
  346. 2, // Max response packet size
  347. "brp|", // Format string
  348. // === REQUEST ================================
  349. 0x33, // b Scan Prop function
  350. &wObjType,W_SIZE, // r Type of Object
  351. pszObjectName // p Object Name
  352. // === REPLY ==================================
  353. );
  354. return NtStatus;
  355. }
  356. NTSTATUS
  357. NWPCreateObject(
  358. NWCONN_HANDLE hConn,
  359. const char *pszObjectName,
  360. NWOBJ_TYPE wObjType,
  361. NWFLAGS ucObjectFlags,
  362. NWFLAGS ucObjSecurity
  363. )
  364. {
  365. NTSTATUS NtStatus ;
  366. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  367. NtStatus = NwlibMakeNcp(
  368. pServerInfo->hConn, // Connection Handle
  369. FSCTL_NWR_NCP_E3H, // Bindery function
  370. 56, // Max request packet size
  371. 2, // Max response packet size
  372. "bbbrp|", // Format string
  373. // === REQUEST ================================
  374. 0x32, // b Scan Prop function
  375. ucObjectFlags, // b Object flags
  376. ucObjSecurity, // b Object security
  377. &wObjType,W_SIZE, // r Type of Object
  378. pszObjectName // p Object Name
  379. // === REPLY ==================================
  380. );
  381. return NtStatus;
  382. }
  383. NTSTATUS
  384. NWPCreateProperty(
  385. NWCONN_HANDLE hConn,
  386. const char *pszObjectName,
  387. NWOBJ_TYPE wObjType,
  388. const char *pszPropertyName,
  389. NWFLAGS ucObjectFlags,
  390. NWFLAGS ucObjSecurity
  391. )
  392. {
  393. NTSTATUS NtStatus ;
  394. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  395. NtStatus = NwlibMakeNcp(
  396. pServerInfo->hConn, // Connection Handle
  397. FSCTL_NWR_NCP_E3H, // Bindery function
  398. 73, // Max request packet size
  399. 2, // Max response packet size
  400. "brpbbp|", // Format string
  401. // === REQUEST ================================
  402. 0x39, // b Create Prop function
  403. &wObjType,W_SIZE, // r Type of Object
  404. pszObjectName, // p Object Name
  405. ucObjectFlags, // b Object flags
  406. ucObjSecurity, // b Object security
  407. pszPropertyName // p Property Name
  408. // === REPLY ==================================
  409. );
  410. return NtStatus;
  411. }
  412. NTSTATUS
  413. NWPDeleteProperty(
  414. NWCONN_HANDLE hConn,
  415. const char *pszObjectName,
  416. NWOBJ_TYPE wObjType,
  417. const char *pszPropertyName
  418. )
  419. {
  420. NTSTATUS NtStatus ;
  421. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  422. NtStatus = NwlibMakeNcp(
  423. pServerInfo->hConn, // Connection Handle
  424. FSCTL_NWR_NCP_E3H, // Bindery function
  425. 73, // Max request packet size
  426. 2, // Max response packet size
  427. "brpp|", // Format string
  428. // === REQUEST ================================
  429. 0x3A, // b Delete Prop function
  430. &wObjType,W_SIZE, // r Type of Object
  431. pszObjectName, // p Object Name
  432. pszPropertyName // p Property Name
  433. // === REPLY ==================================
  434. );
  435. return NtStatus;
  436. }
  437. NTSTATUS
  438. NWPWritePropertyValue(
  439. NWCONN_HANDLE hConn,
  440. const char *pszObjectName,
  441. NWOBJ_TYPE wObjType,
  442. const char *pszPropertyName,
  443. NWSEGMENT_NUM segmentNumber,
  444. NWSEGMENT_DATA *segmentData,
  445. NWFLAGS moreSegments
  446. )
  447. {
  448. NTSTATUS NtStatus ;
  449. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  450. NtStatus = NwlibMakeNcp(
  451. pServerInfo->hConn, // Connection Handle
  452. FSCTL_NWR_NCP_E3H, // Bindery function
  453. 201, // Max request packet size
  454. 2, // Max response packet size
  455. "brpbbpr|", // Format string
  456. // === REQUEST ================================
  457. 0x3E, // b Write Prop function
  458. &wObjType,W_SIZE, // r Type of Object
  459. pszObjectName, // p Object Name
  460. segmentNumber, // b Segment Number
  461. moreSegments, // b Segment remaining
  462. pszPropertyName, // p Property Name
  463. segmentData, 128 // r Property Value Data
  464. // === REPLY ==================================
  465. );
  466. return NtStatus;
  467. }
  468. NTSTATUS
  469. NWPChangeObjectPasswordEncrypted(
  470. NWCONN_HANDLE hConn,
  471. const char *pszObjectName,
  472. NWOBJ_TYPE wObjType,
  473. BYTE *validationKey,
  474. BYTE *newKeyedPassword
  475. )
  476. {
  477. NTSTATUS NtStatus ;
  478. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  479. NtStatus = NwlibMakeNcp(
  480. pServerInfo->hConn, // Connection Handle
  481. FSCTL_NWR_NCP_E3H, // Bindery function
  482. strlen( pszObjectName) + 32, // Max request packet size
  483. 2, // Max response packet size
  484. "brrpr|", // Format string
  485. // === REQUEST ================================
  486. 0x4B, // b Write Prop function
  487. validationKey, 8, // r Key
  488. &wObjType,W_SIZE, // r Type of Object
  489. pszObjectName, // p Object Name
  490. newKeyedPassword, 17 // r New Keyed Password
  491. // === REPLY ==================================
  492. );
  493. return NtStatus;
  494. }
  495. NTSTATUS
  496. NWPGetObjectID(
  497. NWCONN_HANDLE hConn,
  498. const char *pszObjectName,
  499. NWOBJ_TYPE wObjType,
  500. NWOBJ_ID *objectID
  501. )
  502. {
  503. NTSTATUS NtStatus ;
  504. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  505. NtStatus = NwlibMakeNcp(
  506. pServerInfo->hConn, // Connection Handle
  507. FSCTL_NWR_NCP_E3H, // Bindery function
  508. 54, // Max request packet size
  509. 56, // Max response packet size
  510. "brp|d", // Format string
  511. // === REQUEST ================================
  512. 0x35, // b Get Obj ID
  513. &wObjType,W_SIZE, // r Type of Object
  514. pszObjectName, // p Object Name
  515. // === REPLY ==================================
  516. objectID // d Object ID
  517. );
  518. *objectID = dwSWAP( *objectID );
  519. return NtStatus;
  520. }
  521. NTSTATUS
  522. NWPRenameBinderyObject(
  523. NWCONN_HANDLE hConn,
  524. const char *pszObjectName,
  525. const char *pszNewObjectName,
  526. NWOBJ_TYPE wObjType
  527. )
  528. {
  529. NTSTATUS NtStatus;
  530. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  531. NtStatus = NwlibMakeNcp(
  532. pServerInfo->hConn, // Connection Handle
  533. FSCTL_NWR_NCP_E3H, // Bindery function
  534. 105, // Max request packet size
  535. 2, // Max response packet size
  536. "brpp", // Format string
  537. // === REQUEST ================================
  538. 0x34, // b Rename bindery object
  539. &wObjType,W_SIZE, // r Type of Object
  540. pszObjectName, // p Object Name
  541. pszNewObjectName // p New Object Name
  542. // === REPLY ==================================
  543. );
  544. return NtStatus;
  545. }
  546. NTSTATUS
  547. NWPAddObjectToSet(
  548. NWCONN_HANDLE hConn,
  549. const char *pszObjectName,
  550. NWOBJ_TYPE wObjType,
  551. const char *pszPropertyName,
  552. const char *pszMemberName,
  553. NWOBJ_TYPE memberType
  554. )
  555. {
  556. NTSTATUS NtStatus ;
  557. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  558. NtStatus = NwlibMakeNcp(
  559. pServerInfo->hConn, // Connection Handle
  560. FSCTL_NWR_NCP_E3H, // Bindery function
  561. 122, // Max request packet size
  562. 2, // Max response packet size
  563. "brpprp|", // Format string
  564. // === REQUEST ================================
  565. 0x41, // b Add obj to set
  566. &wObjType,W_SIZE, // r Type of Object
  567. pszObjectName, // p Object Name
  568. pszPropertyName, // p Property Name
  569. &memberType, W_SIZE, // r Member type
  570. pszMemberName // p Member Name
  571. // === REPLY ==================================
  572. );
  573. return NtStatus;
  574. }
  575. NTSTATUS
  576. NWPDeleteObjectFromSet(
  577. NWCONN_HANDLE hConn,
  578. const char *pszObjectName,
  579. NWOBJ_TYPE wObjType,
  580. const char *pszPropertyName,
  581. const char *pszMemberName,
  582. NWOBJ_TYPE memberType
  583. )
  584. {
  585. NTSTATUS NtStatus ;
  586. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  587. NtStatus = NwlibMakeNcp(
  588. pServerInfo->hConn, // Connection Handle
  589. FSCTL_NWR_NCP_E3H, // Bindery function
  590. 122, // Max request packet size
  591. 2, // Max response packet size
  592. "brpprp|", // Format string
  593. // === REQUEST ================================
  594. 0x42, // b Del object from set
  595. &wObjType,W_SIZE, // r Type of Object
  596. pszObjectName, // p Object Name
  597. pszPropertyName, // p Property Name
  598. &memberType, W_SIZE, // r Member type
  599. pszMemberName // p Member Name
  600. // === REPLY ==================================
  601. );
  602. return NtStatus;
  603. }
  604. NTSTATUS
  605. NWPGetChallengeKey(
  606. NWCONN_HANDLE hConn,
  607. UCHAR *challengeKey
  608. )
  609. {
  610. NTSTATUS NtStatus ;
  611. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  612. NtStatus = NwlibMakeNcp(
  613. pServerInfo->hConn, // Connection Handle
  614. FSCTL_NWR_NCP_E3H, // Bindery function
  615. 3, // Max request packet size
  616. 10, // Max response packet size
  617. "b|r", // Format string
  618. // === REQUEST ================================
  619. 0x17, // b Get Challenge
  620. // === REPLY ==================================
  621. challengeKey, 8
  622. );
  623. return NtStatus;
  624. }
  625. NTSTATUS
  626. NWPCreateDirectory(
  627. NWCONN_HANDLE hConn,
  628. NWDIR_HANDLE dirHandle,
  629. const char *pszPath,
  630. NWACCESS_RIGHTS accessMask
  631. )
  632. {
  633. NTSTATUS NtStatus ;
  634. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  635. NtStatus = NwlibMakeNcp(
  636. pServerInfo->hConn, // Connection Handle
  637. FSCTL_NWR_NCP_E2H, // Bindery function
  638. 261, // Max request packet size
  639. 2, // Max response packet size
  640. "bbbp|", // Format string
  641. // === REQUEST ================================
  642. 0xA, // b Create Directory
  643. dirHandle, // b Directory Handle
  644. accessMask, // b Access Mask
  645. pszPath // p Property Name
  646. // === REPLY ==================================
  647. );
  648. return NtStatus;
  649. }
  650. NTSTATUS
  651. NWPAddTrustee(
  652. NWCONN_HANDLE hConn,
  653. NWDIR_HANDLE dirHandle,
  654. const char *pszPath,
  655. NWOBJ_ID dwTrusteeID,
  656. NWRIGHTS_MASK rightsMask
  657. )
  658. {
  659. NTSTATUS NtStatus ;
  660. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  661. NtStatus = NwlibMakeNcp(
  662. pServerInfo->hConn, // Connection Handle
  663. FSCTL_NWR_NCP_E2H, // Directory function
  664. 266, // Max request packet size
  665. 2, // Max response packet size
  666. "bbrrp|", // Format string
  667. // === REQUEST ================================
  668. 0x27, // b Add trustee to directory
  669. dirHandle, // b Directory handle
  670. &dwTrusteeID,DW_SIZE, // r Object ID to assigned to directory
  671. &rightsMask,W_SIZE, // r User rights for directory
  672. pszPath // p Directory (if dirHandle = 0 then vol:directory)
  673. );
  674. return NtStatus;
  675. }
  676. NTSTATUS
  677. NWPScanForTrustees(
  678. NWCONN_HANDLE hConn,
  679. NWDIR_HANDLE dirHandle,
  680. char *pszsearchDirPath,
  681. NWSEQUENCE *pucsequenceNumber,
  682. BYTE *numberOfEntries,
  683. TRUSTEE_INFO *ti
  684. )
  685. {
  686. ULONG i;
  687. DWORD oid[20];
  688. WORD or[20];
  689. NTSTATUS NtStatus ;
  690. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  691. NtStatus = NwlibMakeNcp(
  692. pServerInfo->hConn, // Connection Handle
  693. FSCTL_NWR_NCP_E2H, // Bindery function
  694. 261, // Max request packet size
  695. 121, // Max response packet size
  696. "bbbp|brr", // Format string
  697. // === REQUEST ================================
  698. 0x26, // b Scan For Trustees
  699. dirHandle, // b Directory Handle
  700. *pucsequenceNumber, // b Sequence Number
  701. pszsearchDirPath, // p Search Dir Path
  702. // === REPLY ==================================
  703. numberOfEntries,
  704. &oid[0],DW_SIZE*20, // r trustee object ID
  705. &or[0], W_SIZE*20 // b Trustee rights mask
  706. );
  707. for(i = 0; i < 20; i++) {
  708. ti[i].objectID = oid[i];
  709. ti[i].objectRights = or[i];
  710. }
  711. (*pucsequenceNumber)++;
  712. return NtStatus ;
  713. } // NWScanForTrustees
  714. NTSTATUS
  715. NWPScanDirectoryForTrustees2(
  716. NWCONN_HANDLE hConn,
  717. NWDIR_HANDLE dirHandle,
  718. char *pszsearchDirPath,
  719. NWSEQUENCE *pucsequenceNumber,
  720. char *pszdirName,
  721. NWDATE_TIME *dirDateTime,
  722. NWOBJ_ID *ownerID,
  723. TRUSTEE_INFO *ti
  724. )
  725. {
  726. ULONG i;
  727. DWORD oid[5];
  728. BYTE or[5];
  729. NTSTATUS NtStatus ;
  730. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  731. memset(oid, 0, sizeof(oid));
  732. memset(or, 0, sizeof(or));
  733. NtStatus = NwlibMakeNcp(
  734. pServerInfo->hConn, // Connection Handle
  735. FSCTL_NWR_NCP_E2H, // Bindery function
  736. 261, // Max request packet size
  737. 49, // Max response packet size
  738. "bbbp|rrrrr", // Format string
  739. // === REQUEST ================================
  740. 0x0C, // b Scan Directory function
  741. dirHandle, // b Directory Handle
  742. *pucsequenceNumber, // b Sequence Number
  743. pszsearchDirPath, // p Search Dir Path
  744. // === REPLY ==================================
  745. pszdirName,16, // r Returned Directory Name
  746. dirDateTime,DW_SIZE, // r Date and Time
  747. ownerID,DW_SIZE, // r Owner ID
  748. &oid[0],DW_SIZE*5, // r trustee object ID
  749. &or[0], 5 // b Trustee rights mask
  750. );
  751. for(i = 0; i < 5; i++) {
  752. ti[i].objectID = oid[i];
  753. ti[i].objectRights = (WORD) or[i];
  754. }
  755. (*pucsequenceNumber)++;
  756. return NtStatus ;
  757. } // NWScanDirectoryForTrustees2
  758. NTSTATUS
  759. NWPGetBinderyAccessLevel(
  760. NWCONN_HANDLE hConn,
  761. NWFLAGS *accessLevel,
  762. NWOBJ_ID *objectID
  763. )
  764. {
  765. NTSTATUS NtStatus ;
  766. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  767. NtStatus = NwlibMakeNcp(
  768. pServerInfo->hConn, // Connection Handle
  769. FSCTL_NWR_NCP_E3H, // Bindery function
  770. 3, // Max request packet size
  771. 7, // Max response packet size
  772. "b|br", // Format string
  773. // === REQUEST ================================
  774. 0x46, // b Get Bindery Access Level
  775. // === REPLY ==================================
  776. accessLevel,
  777. objectID,DW_SIZE
  778. );
  779. return NtStatus ;
  780. } // NWGetBinderyAccessLevel
  781. NTSTATUS
  782. NWPGetFileServerDescription(
  783. NWCONN_HANDLE hConn,
  784. char *pszCompany,
  785. char *pszVersion,
  786. char *pszRevision
  787. )
  788. {
  789. NTSTATUS NtStatus ;
  790. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  791. NtStatus = NwlibMakeNcp(
  792. pServerInfo->hConn, // Connection Handle
  793. FSCTL_NWR_NCP_E3H, // Bindery function
  794. 3, // Max request packet size
  795. 514, // Max response packet size
  796. "b|ccc", // Format string
  797. // === REQUEST ================================
  798. 0xC9, // b Get File Server Information
  799. // === REPLY ==================================
  800. pszCompany, // c Company
  801. pszVersion, // c Version
  802. pszRevision // c Description
  803. );
  804. return NtStatus;
  805. }
  806. NTSTATUS
  807. NWPGetVolumeNumber(
  808. NWCONN_HANDLE hConn,
  809. char *pszVolume,
  810. NWVOL_NUM *VolumeNumber
  811. )
  812. {
  813. NTSTATUS NtStatus ;
  814. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  815. NtStatus = NwlibMakeNcp(
  816. pServerInfo->hConn, // Connection Handle
  817. FSCTL_NWR_NCP_E2H, // Bindery function
  818. 20, // Max request packet size
  819. 3, // Max response packet size
  820. "bp|b", // Format string
  821. // === REQUEST ================================
  822. 0x05, // b Get Volume Number
  823. pszVolume, // p volume name
  824. // === REPLY ==================================
  825. VolumeNumber // b Description
  826. );
  827. return NtStatus;
  828. }
  829. NTSTATUS
  830. NWPGetVolumeUsage(
  831. NWCONN_HANDLE hConn,
  832. NWVOL_NUM VolumeNumber,
  833. DWORD *TotalBlocks,
  834. DWORD *FreeBlocks,
  835. DWORD *PurgeableBlocks,
  836. DWORD *NotYetPurgeableBlocks,
  837. DWORD *TotalDirectoryEntries,
  838. DWORD *AvailableDirectoryEntries,
  839. BYTE *SectorsPerBlock
  840. )
  841. {
  842. NTSTATUS NtStatus ;
  843. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  844. NtStatus = NwlibMakeNcp(
  845. pServerInfo->hConn, // Connection Handle
  846. FSCTL_NWR_NCP_E2H, // Bindery function
  847. 4, // Max request packet size
  848. 46, // Max response packet size
  849. "bb|dddddd==b", // Format string
  850. // === REQUEST ================================
  851. 0x2C, // b Get Volume Number
  852. VolumeNumber, // p volume number
  853. // === REPLY ==================================
  854. TotalBlocks,
  855. FreeBlocks,
  856. PurgeableBlocks,
  857. NotYetPurgeableBlocks,
  858. TotalDirectoryEntries,
  859. AvailableDirectoryEntries,
  860. SectorsPerBlock
  861. );
  862. *TotalBlocks = dwSWAP( *TotalBlocks );
  863. *FreeBlocks = dwSWAP( *FreeBlocks );
  864. *PurgeableBlocks = dwSWAP( *PurgeableBlocks );
  865. *NotYetPurgeableBlocks = dwSWAP( *NotYetPurgeableBlocks );
  866. *TotalDirectoryEntries = dwSWAP( *TotalDirectoryEntries );
  867. *AvailableDirectoryEntries = dwSWAP( *AvailableDirectoryEntries );
  868. return NtStatus;
  869. }