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.

1486 lines
49 KiB

  1. /*++
  2. Copyright (C) 1993 Microsoft Corporation
  3. Module Name:
  4. NWAPI32.C
  5. Abstract:
  6. This module contains the NetWare(R) SDK support to routines
  7. into the NetWare redirector
  8. Author:
  9. Chris Sandys (a-chrisa) 09-Sep-1993
  10. Revision History:
  11. Chuck Y. Chan (chuckc) 02/06/94 Moved to NWCS. Make it more NT like.
  12. Chuck Y. Chan (chuckc) 02/27/94 Clear out old code.
  13. Make logout work.
  14. Check for error in many places.
  15. Dont hard code strings.
  16. Remove non compatible parameters.
  17. Lotsa other cleanup.
  18. Tommy R. Evans (tommye) 04/21/00 Added two routines:
  19. NwNdsObjectHandleToConnHandle()
  20. NwNdsConnHandleFree()
  21. --*/
  22. #include "procs.h"
  23. #include "nwapi32.h"
  24. #include <nds32.h>
  25. #include <stdio.h>
  26. //
  27. // Define structure for internal use. Our handle passed back from attach to
  28. // file server will be pointer to this. We keep server string around for
  29. // discnnecting from the server on logout. The structure is freed on detach.
  30. // Callers should not use this structure but treat pointer as opaque handle.
  31. //
  32. typedef struct _NWC_SERVER_INFO {
  33. HANDLE hConn ;
  34. UNICODE_STRING ServerString ;
  35. } NWC_SERVER_INFO, *PNWC_SERVER_INFO ;
  36. //
  37. // define define categories of errors
  38. //
  39. typedef enum _NCP_CLASS {
  40. NcpClassConnect,
  41. NcpClassBindery,
  42. NcpClassDir
  43. } NCP_CLASS ;
  44. //
  45. // define error mapping structure
  46. //
  47. typedef struct _NTSTATUS_TO_NCP {
  48. NTSTATUS NtStatus ;
  49. NWCCODE NcpCode ;
  50. } NTSTATUS_TO_NCP, *LPNTSTATUS_TO_NCP ;
  51. //
  52. // Error mappings for directory errors
  53. //
  54. NTSTATUS_TO_NCP MapNcpDirErrors[] =
  55. {
  56. {STATUS_NO_SUCH_DEVICE, VOLUME_DOES_NOT_EXIST},
  57. {STATUS_INVALID_HANDLE, BAD_DIRECTORY_HANDLE},
  58. {STATUS_OBJECT_PATH_NOT_FOUND, INVALID_PATH},
  59. {STATUS_UNSUCCESSFUL, INVALID_PATH},
  60. {STATUS_NO_MORE_ENTRIES, NO_SUCH_OBJECT},
  61. {STATUS_ACCESS_DENIED, NO_OBJECT_READ_PRIVILEGE},
  62. {STATUS_INSUFF_SERVER_RESOURCES, SERVER_OUT_OF_MEMORY},
  63. { 0, 0 }
  64. } ;
  65. //
  66. // Error mappings for connect errors
  67. //
  68. NTSTATUS_TO_NCP MapNcpConnectErrors[] =
  69. {
  70. {STATUS_UNSUCCESSFUL, INVALID_CONNECTION},
  71. {STATUS_ACCESS_DENIED, NO_OBJECT_READ_PRIVILEGE},
  72. {STATUS_NO_MORE_ENTRIES, UNKNOWN_FILE_SERVER},
  73. {STATUS_INSUFF_SERVER_RESOURCES, SERVER_OUT_OF_MEMORY},
  74. { 0, 0 }
  75. } ;
  76. //
  77. // Error mappings for bindery errors
  78. //
  79. NTSTATUS_TO_NCP MapNcpBinderyErrors[] =
  80. {
  81. {STATUS_ACCESS_DENIED, NO_OBJECT_READ_PRIVILEGE},
  82. {STATUS_NO_MORE_ENTRIES, UNKNOWN_FILE_SERVER},
  83. {STATUS_NO_MORE_ENTRIES, NO_SUCH_OBJECT},
  84. {STATUS_INVALID_PARAMETER, NO_SUCH_PROPERTY},
  85. {STATUS_UNSUCCESSFUL, INVALID_CONNECTION},
  86. {STATUS_INSUFF_SERVER_RESOURCES, SERVER_OUT_OF_MEMORY},
  87. {STATUS_NO_SUCH_DEVICE, VOLUME_DOES_NOT_EXIST},
  88. {STATUS_INVALID_HANDLE, BAD_DIRECTORY_HANDLE},
  89. {STATUS_OBJECT_PATH_NOT_FOUND, INVALID_PATH},
  90. // {0xC0010001, INVALID_CONNECTION},
  91. // {0xC0010096, SERVER_OUT_OF_MEMORY},
  92. // {0xC0010098, VOLUME_DOES_NOT_EXIST},
  93. // {0xC001009B, BAD_DIRECTORY_HANDLE},
  94. // {0xC001009C, INVALID_PATH},
  95. // {0xC00100FB, NO_SUCH_PROPERTY},
  96. // {0xC00100FC, NO_SUCH_OBJECT},
  97. { 0, 0 }
  98. } ;
  99. //
  100. // Forwards
  101. //
  102. DWORD
  103. CancelAllConnections(
  104. LPWSTR pszServer
  105. );
  106. NWCCODE
  107. MapNtStatus(
  108. const NTSTATUS ntstatus,
  109. const NCP_CLASS ncpclass
  110. );
  111. DWORD
  112. SetWin32ErrorFromNtStatus(
  113. NTSTATUS NtStatus
  114. ) ;
  115. DWORD
  116. szToWide(
  117. LPWSTR lpszW,
  118. LPCSTR lpszC,
  119. INT nSize
  120. );
  121. //
  122. // Static functions used internally
  123. //
  124. LPSTR
  125. NwDupStringA(
  126. const LPSTR lpszA,
  127. WORD length
  128. )
  129. {
  130. LPSTR lpRet;
  131. //
  132. // Allocate memory
  133. //
  134. lpRet = LocalAlloc( LMEM_FIXED|LMEM_ZEROINIT , length );
  135. if(lpRet == NULL) return(NULL);
  136. //
  137. // Dupulicate string
  138. //
  139. memcpy( (LPVOID)lpRet, (LPVOID)lpszA, length );
  140. return(lpRet);
  141. }
  142. VOID
  143. MapSpecialJapaneseChars(
  144. LPSTR lpszA,
  145. WORD length
  146. )
  147. {
  148. LCID lcid;
  149. //
  150. // Netware Japanese version The following character is replaced with another one
  151. // if the string is for File Name only when sendding from Client to Server.
  152. //
  153. // any char, even DBCS trailByte.
  154. //
  155. // SJIS+0xBF -> 0x10
  156. // SJIS+0xAE -> 0x11
  157. // SJIS+0xAA -> 0x12
  158. //
  159. // DBCS TrailByte only.
  160. //
  161. // SJIS+0x5C -> 0x13
  162. //
  163. // Get system locale and language ID in Kernel mode in order to
  164. // distinguish the currently running system.
  165. NtQueryDefaultLocale( TRUE, &lcid );
  166. if (! (PRIMARYLANGID(lcid) == LANG_JAPANESE ||
  167. PRIMARYLANGID(lcid) == LANG_KOREAN ||
  168. PRIMARYLANGID(lcid) == LANG_CHINESE) ) {
  169. return;
  170. }
  171. if(lpszA == NULL)
  172. return;
  173. while( length ) {
  174. if( IsDBCSLeadByte(*lpszA) && (length >= 2) ) {
  175. // Adding length>=2 ensure the Lead Byte is followed by
  176. // a trail byte , Fix bug #102729
  177. //
  178. // This is a DBCS character, check trailbyte is 0x5C or not.
  179. //
  180. lpszA++;
  181. length--;
  182. if( *lpszA == 0x5C ) {
  183. *lpszA = (UCHAR)0x13;
  184. }
  185. }
  186. switch( (UCHAR) *lpszA ) {
  187. case 0xBF :
  188. *lpszA = (UCHAR)0x10;
  189. break;
  190. case 0xAE :
  191. *lpszA = (UCHAR)0x11;
  192. break;
  193. case 0xAA :
  194. *lpszA = (UCHAR)0x12;
  195. break;
  196. }
  197. //
  198. // next char
  199. //
  200. lpszA++;
  201. length--;
  202. }
  203. }
  204. VOID
  205. UnmapSpecialJapaneseChars(
  206. LPSTR lpszA,
  207. WORD length
  208. )
  209. {
  210. LCID lcid;
  211. //
  212. // Get system locale and language ID in Kernel mode in order to
  213. // distinguish the currently running system.
  214. //
  215. NtQueryDefaultLocale( TRUE, &lcid );
  216. if (! (PRIMARYLANGID(lcid) == LANG_JAPANESE ||
  217. PRIMARYLANGID(lcid) == LANG_KOREAN ||
  218. PRIMARYLANGID(lcid) == LANG_CHINESE) ) {
  219. return;
  220. }
  221. if (lpszA == NULL)
  222. return;
  223. while( length ) {
  224. if( IsDBCSLeadByte(*lpszA) && (length >= 2) ) {
  225. // Adding length>=2 ensure the Lead Byte is followed by
  226. // a trail byte , Fix bug #102729
  227. //
  228. // This is a DBCS character, check trailbyte is 0x5C or not.
  229. //
  230. lpszA++;
  231. length--;
  232. if( *lpszA == 0x13 ) {
  233. *lpszA = (UCHAR)0x5C;
  234. }
  235. }
  236. switch( (UCHAR) *lpszA ) {
  237. case 0x10 :
  238. *lpszA = (UCHAR)0xBF;
  239. break;
  240. case 0x11 :
  241. *lpszA = (UCHAR)0xAE;
  242. break;
  243. case 0x12 :
  244. *lpszA = (UCHAR)0xAA;
  245. break;
  246. }
  247. //
  248. // next char
  249. //
  250. lpszA++;
  251. length--;
  252. }
  253. }
  254. DWORD
  255. szToWide(
  256. LPWSTR lpszW,
  257. LPCSTR lpszC,
  258. INT nSize
  259. )
  260. {
  261. if (!MultiByteToWideChar(CP_ACP,
  262. MB_PRECOMPOSED,
  263. lpszC,
  264. -1,
  265. lpszW,
  266. nSize))
  267. {
  268. return (GetLastError()) ;
  269. }
  270. return NO_ERROR ;
  271. }
  272. NWCCODE
  273. MapNtStatus(
  274. const NTSTATUS ntstatus,
  275. const NCP_CLASS ncpclass
  276. )
  277. {
  278. LPNTSTATUS_TO_NCP pErrorMap ;
  279. if (ntstatus == STATUS_SUCCESS)
  280. return SUCCESSFUL ;
  281. switch ( ncpclass ) {
  282. case NcpClassBindery:
  283. pErrorMap = MapNcpBinderyErrors ;
  284. break ;
  285. case NcpClassDir:
  286. pErrorMap = MapNcpDirErrors ;
  287. break ;
  288. case NcpClassConnect:
  289. pErrorMap = MapNcpConnectErrors ;
  290. break ;
  291. default:
  292. return 0xFFFF ;
  293. }
  294. while (pErrorMap->NtStatus)
  295. {
  296. if (pErrorMap->NtStatus == ntstatus)
  297. return (pErrorMap->NcpCode) ;
  298. pErrorMap++ ;
  299. }
  300. return 0xFFFF ;
  301. }
  302. DWORD
  303. SetWin32ErrorFromNtStatus(
  304. NTSTATUS NtStatus
  305. )
  306. {
  307. DWORD Status ;
  308. if (NtStatus & 0xC0010000) { // netware specific
  309. Status = ERROR_EXTENDED_ERROR ;
  310. } else if (NtStatus == NWRDR_PASSWORD_HAS_EXPIRED) {
  311. Status = 0 ; // note this is not an error (the operation suceeded!)
  312. } else {
  313. Status = RtlNtStatusToDosError(NtStatus) ;
  314. }
  315. SetLastError(Status) ;
  316. return Status ;
  317. }
  318. //
  319. // FormatString - Supplies an ANSI string which describes how to
  320. // convert from the input arguments into NCP request fields, and
  321. // from the NCP response fields into the output arguments.
  322. //
  323. // Field types, request/response:
  324. //
  325. // 'b' byte ( byte / byte* )
  326. // 'w' hi-lo word ( word / word* )
  327. // 'd' hi-lo dword ( dword / dword* )
  328. // '-' zero/skip byte ( void )
  329. // '=' zero/skip word ( void )
  330. // ._. zero/skip string ( word )
  331. // 'p' pstring ( char* )
  332. // 'P' DBCS pstring ( char* )
  333. // 'c' cstring ( char* )
  334. // 'C' cstring followed skip word ( char*, word )
  335. // 'r' raw bytes ( byte*, word )
  336. // 'R' DBCS raw bytes ( byte*, word )
  337. // 'u' p unicode string ( UNICODE_STRING * )
  338. // 'U' p uppercase string( UNICODE_STRING * )
  339. // 'W' word n followed by an array of word[n] ( word, word* )
  340. //
  341. //
  342. //
  343. //
  344. // Standard NCP Function Block
  345. //
  346. //
  347. // NWCCODE NWAPI DLLEXPORT
  348. // NW***(
  349. // NWCONN_HANDLE hConn,
  350. // )
  351. // {
  352. // NWCCODE NcpCode;
  353. // NTSTATUS NtStatus;
  354. //
  355. // NtStatus = NwlibMakeNcp(
  356. // hConn, // Connection Handle
  357. // FSCTL_NWR_NCP_E3H, // Bindery function
  358. // , // Max request packet size
  359. // , // Max response packet size
  360. // "b|", // Format string
  361. // // === REQUEST ================================
  362. // 0x, // b Function
  363. // // === REPLY ==================================
  364. // );
  365. //
  366. // return MapNtStatus( NtStatus, NcpClassXXX );
  367. // }
  368. //
  369. //
  370. NWCCODE NWAPI DLLEXPORT
  371. NWAddTrusteeToDirectory(
  372. NWCONN_HANDLE hConn,
  373. NWDIR_HANDLE dirHandle,
  374. const char NWFAR *pszPath,
  375. NWOBJ_ID dwTrusteeID,
  376. NWACCESS_RIGHTS rightsMask
  377. )
  378. {
  379. unsigned short reply;
  380. NTSTATUS NtStatus ;
  381. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  382. NtStatus = NwlibMakeNcp(
  383. pServerInfo->hConn, // Connection Handle
  384. FSCTL_NWR_NCP_E2H, // Directory function
  385. 265, // Max request packet size
  386. 2, // Max response packet size
  387. "bbrbP|", // Format string
  388. // === REQUEST ================================
  389. 0x0d, // b Add trustee to directory
  390. dirHandle, // b 0xffffffff to start or last returned ID when enumerating HI-LO
  391. &dwTrusteeID,DW_SIZE, // r Object ID to assigned to directory
  392. rightsMask, // b User rights for directory
  393. pszPath, // P Directory (if dirHandle = 0 then vol:directory)
  394. // === REPLY ==================================
  395. &reply // Not used
  396. );
  397. (void) SetWin32ErrorFromNtStatus( NtStatus );
  398. return MapNtStatus( NtStatus, NcpClassDir );
  399. }
  400. NWCCODE NWAPI DLLEXPORT
  401. NWAllocPermanentDirectoryHandle(
  402. NWCONN_HANDLE hConn,
  403. NWDIR_HANDLE dirHandle,
  404. char NWFAR *pszDirPath,
  405. NWDIR_HANDLE NWFAR *pbNewDirHandle,
  406. NWACCESS_RIGHTS NWFAR *pbRightsMask
  407. )
  408. {
  409. NTSTATUS NtStatus ;
  410. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  411. NtStatus = NwlibMakeNcp(
  412. pServerInfo->hConn, // Connection Handle
  413. FSCTL_NWR_NCP_E2H, // E2 Function function
  414. 261, // Max request packet size
  415. 4, // Max response packet size
  416. "bbbP|bb", // Format string
  417. // === REQUEST ================================
  418. 0x12, // b Function Alloc Perm Dir
  419. dirHandle, // b 0 for new
  420. 0, // b Drive Letter
  421. pszDirPath, // P Volume Name (SYS: or SYS:\PUBLIC)
  422. // === REPLY ==================================
  423. pbNewDirHandle, // b Dir Handle
  424. pbRightsMask // b Rights
  425. );
  426. (void) SetWin32ErrorFromNtStatus( NtStatus );
  427. return MapNtStatus( NtStatus, NcpClassDir );
  428. }
  429. NWCCODE NWAPI DLLEXPORT
  430. NWAllocTemporaryDirectoryHandle(
  431. NWCONN_HANDLE hConn,
  432. NWDIR_HANDLE dirHandle,
  433. char NWFAR *pszDirPath,
  434. NWDIR_HANDLE NWFAR *pbNewDirHandle,
  435. NWACCESS_RIGHTS NWFAR *pbRightsMask
  436. )
  437. {
  438. NTSTATUS NtStatus ;
  439. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  440. NtStatus = NwlibMakeNcp(
  441. pServerInfo->hConn, // Connection Handle
  442. FSCTL_NWR_NCP_E2H, // E2 Function function
  443. 261, // Max request packet size
  444. 4, // Max response packet size
  445. "bbbP|bb", // Format string
  446. // === REQUEST ================================
  447. 0x13, // b Function Alloc Temp Dir
  448. dirHandle, // b 0 for new
  449. 0, // b Drive Letter
  450. pszDirPath, // P Volume Name (SYS: or SYS:\PUBLIC)
  451. // === REPLY ==================================
  452. pbNewDirHandle, // b Dir Handle
  453. pbRightsMask // b Rights
  454. );
  455. (void) SetWin32ErrorFromNtStatus( NtStatus );
  456. return MapNtStatus( NtStatus, NcpClassDir );
  457. }
  458. NWCCODE NWAPI DLLEXPORT
  459. NWCheckConsolePrivileges(
  460. NWCONN_HANDLE hConn
  461. )
  462. {
  463. WORD wDummy;
  464. NTSTATUS NtStatus ;
  465. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  466. NtStatus = NwlibMakeNcp(
  467. pServerInfo->hConn, // Connection Handle
  468. FSCTL_NWR_NCP_E3H, // Bindery function
  469. 3, // Max request packet size
  470. 2, // Max response packet size
  471. "b|r", // Format string
  472. // === REQUEST ================================
  473. 0xC8, // b Get Console Privilges
  474. // === REPLY ==================================
  475. &wDummy,W_SIZE // r Dummy Response
  476. );
  477. (void) SetWin32ErrorFromNtStatus( NtStatus );
  478. return MapNtStatus( NtStatus, NcpClassBindery );
  479. }
  480. NWCCODE NWAPI DLLEXPORT
  481. NWDeallocateDirectoryHandle(
  482. NWCONN_HANDLE hConn,
  483. NWDIR_HANDLE dirHandle
  484. )
  485. {
  486. WORD wDummy;
  487. NTSTATUS NtStatus ;
  488. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  489. NtStatus = NwlibMakeNcp(
  490. pServerInfo->hConn, // Connection Handle
  491. FSCTL_NWR_NCP_E2H, // E2 Function function
  492. 4, // Max request packet size
  493. 2, // Max response packet size
  494. "bb|w", // Format string
  495. // === REQUEST ================================
  496. 0x14, // b Function Dealloc Dir Hand
  497. dirHandle, // b 0 for new
  498. // === REPLY ==================================
  499. &wDummy
  500. );
  501. (void) SetWin32ErrorFromNtStatus( NtStatus );
  502. return MapNtStatus( NtStatus, NcpClassDir );
  503. }
  504. NWCCODE NWAPI DLLEXPORT
  505. NWGetFileServerVersionInfo(
  506. NWCONN_HANDLE hConn,
  507. VERSION_INFO NWFAR *lpVerInfo
  508. )
  509. {
  510. NTSTATUS NtStatus ;
  511. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  512. NtStatus = NwlibMakeNcp(
  513. pServerInfo->hConn, // Connection Handle
  514. FSCTL_NWR_NCP_E3H, // Bindery function
  515. 3, // Max request packet size
  516. 130, // Max response packet size
  517. "b|r", // Format string
  518. // === REQUEST ================================
  519. 0x11, // b Get File Server Information
  520. // === REPLY ==================================
  521. lpVerInfo, // r File Version Structure
  522. sizeof(VERSION_INFO)
  523. );
  524. // Convert HI-LO words to LO-HI
  525. // ===========================================================
  526. lpVerInfo->ConnsSupported = wSWAP( lpVerInfo->ConnsSupported );
  527. lpVerInfo->connsInUse = wSWAP( lpVerInfo->connsInUse );
  528. lpVerInfo->maxVolumes = wSWAP( lpVerInfo->maxVolumes );
  529. lpVerInfo->PeakConns = wSWAP( lpVerInfo->PeakConns );
  530. (void) SetWin32ErrorFromNtStatus( NtStatus );
  531. return MapNtStatus( NtStatus, NcpClassBindery );
  532. }
  533. NWCCODE NWAPI DLLEXPORT
  534. NWGetInternetAddress(
  535. NWCONN_HANDLE hConn,
  536. NWCONN_NUM nConnNum,
  537. NWNET_ADDR NWFAR *pIntAddr
  538. )
  539. {
  540. NTSTATUS NtStatus ;
  541. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  542. NtStatus = NwlibMakeNcp(
  543. pServerInfo->hConn, // Connection Handle
  544. FSCTL_NWR_NCP_E3H, // Bindery function
  545. 4, // Max request packet size
  546. 14, // Max response packet size
  547. "bb|r", // Format string
  548. // === REQUEST ================================
  549. 0x13, // b Get Internet Address
  550. nConnNum, // b Connection Number
  551. // === REPLY ==================================
  552. pIntAddr,12 // r File Version Structure
  553. );
  554. (void) SetWin32ErrorFromNtStatus( NtStatus );
  555. return MapNtStatus( NtStatus, NcpClassBindery );
  556. }
  557. NWCCODE NWAPI DLLEXPORT
  558. NWGetObjectName(
  559. NWCONN_HANDLE hConn,
  560. NWOBJ_ID dwObjectID,
  561. char NWFAR *pszObjName,
  562. NWOBJ_TYPE NWFAR *pwObjType )
  563. {
  564. NWOBJ_ID dwRetID;
  565. NTSTATUS NtStatus ;
  566. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  567. NtStatus = NwlibMakeNcp(
  568. pServerInfo->hConn, // Connection Handle
  569. FSCTL_NWR_NCP_E3H, // Bindery function
  570. 7, // Max request packet size
  571. 56, // Max response packet size
  572. "br|rrR", // Format string
  573. // === REQUEST ================================
  574. 0x36, // b Get Bindery Object Name
  575. &dwObjectID,DW_SIZE, // r Object ID HI-LO
  576. // === REPLY ==================================
  577. &dwRetID,DW_SIZE, // r Object ID HI-LO
  578. pwObjType,W_SIZE, // r Object Type
  579. pszObjName,48 // R Object Name
  580. );
  581. (void) SetWin32ErrorFromNtStatus( NtStatus );
  582. return MapNtStatus( NtStatus, NcpClassBindery );
  583. }
  584. // This function not supported (E3 E9)
  585. NWCCODE NWAPI DLLEXPORT
  586. NWGetVolumeInfoWithNumber(
  587. NWCONN_HANDLE hConn,
  588. NWVOL_NUM nVolNum,
  589. char NWFAR *pszVolName,
  590. NWNUMBER NWFAR *pwTotalBlocks,
  591. NWNUMBER NWFAR *pwSectors,
  592. NWNUMBER NWFAR *pwAvailBlocks,
  593. NWNUMBER NWFAR *pwTotalDir,
  594. NWNUMBER NWFAR *pwAvailDir,
  595. NWVOL_FLAGS NWFAR *pfVolRemovable
  596. )
  597. {
  598. WORD wTime; // w Elapsed Time
  599. BYTE bVoln; // b Vol Num
  600. BYTE bDriven; // b Drive Num
  601. WORD wStartBlock; // w Starting Block
  602. WORD wMaxUsedDir; // w Actual Max Used Directory Entries
  603. BYTE bVolHashed; // b Volume is hashed
  604. BYTE bVolCached; // b Volume is Cached
  605. BYTE bVolMounted; // b Volume is mounted
  606. NTSTATUS NtStatus ;
  607. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  608. NtStatus = NwlibMakeNcp(
  609. pServerInfo->hConn, // Connection Handle
  610. FSCTL_NWR_NCP_E3H, // Bindery function
  611. 4, // Max request packet size
  612. 42, // Max response packet size
  613. "bb|wbbwwwwwwwbbbbr", // Format string
  614. // === REQUEST ================================
  615. 0xe9, // b Get Volume Information
  616. nVolNum, // b Volume Number (0 to Max Vol)
  617. // === REPLY ==================================
  618. &wTime, // w Elapsed Time
  619. &bVoln, // b Vol Num
  620. &bDriven, // b Drive Num
  621. pwSectors, // w Sectors per block
  622. &wStartBlock, // w Starting Block
  623. pwTotalBlocks, // w Total Blocks
  624. pwAvailBlocks, // w Available Blocks (free)
  625. pwTotalDir, // w Total Dir Slots
  626. pwAvailDir, // w Available Directory Slots
  627. &wMaxUsedDir, // w Actual Max Used Directory Entries
  628. &bVolHashed, // b Volume is hashed
  629. &bVolCached, // b Volume is Cached
  630. pfVolRemovable, // b Volume is removable
  631. &bVolMounted, // b Volume is mounted
  632. pszVolName,16 // r Volume Name
  633. );
  634. (void) SetWin32ErrorFromNtStatus( NtStatus );
  635. return MapNtStatus( NtStatus, NcpClassBindery );
  636. }
  637. NWCCODE NWAPI DLLEXPORT
  638. NWGetVolumeInfoWithHandle(
  639. NWCONN_HANDLE hConn,
  640. NWDIR_HANDLE nDirHand,
  641. char NWFAR *pszVolName,
  642. NWNUMBER NWFAR *pwTotalBlocks,
  643. NWNUMBER NWFAR *pwSectors,
  644. NWNUMBER NWFAR *pwAvailBlocks,
  645. NWNUMBER NWFAR *pwTotalDir,
  646. NWNUMBER NWFAR *pwAvailDir,
  647. NWVOL_FLAGS NWFAR *pfVolRemovable
  648. )
  649. {
  650. NTSTATUS NtStatus ;
  651. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  652. NtStatus = NwlibMakeNcp(
  653. pServerInfo->hConn, // Connection Handle
  654. FSCTL_NWR_NCP_E2H, // Bindery function
  655. 4, // Max request packet size
  656. 30, // Max response packet size
  657. "bb|wwwwwrb", // Format string
  658. // === REQUEST ================================
  659. 0x15, // b Get Volume Information
  660. nDirHand, // b Dir Handle
  661. // === REPLY ==================================
  662. pwSectors, // w Sectors per block
  663. pwTotalBlocks, // w Total Blocks
  664. pwAvailBlocks, // w Available Blocks (free)
  665. pwTotalDir, // w Total Dir Slots
  666. pwAvailDir, // w Available Directory Slots
  667. pszVolName,16, // r Volume Name
  668. pfVolRemovable // b Volume is removable
  669. );
  670. (void) SetWin32ErrorFromNtStatus( NtStatus );
  671. return MapNtStatus( NtStatus, NcpClassDir );
  672. }
  673. NWCCODE NWAPI DLLEXPORT
  674. NWGetVolumeName(
  675. NWCONN_HANDLE hConn,
  676. NWVOL_NUM bVolNum,
  677. char NWFAR *pszVolName
  678. )
  679. {
  680. NTSTATUS NtStatus ;
  681. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  682. NtStatus = NwlibMakeNcp(
  683. pServerInfo->hConn, // Connection Handle
  684. FSCTL_NWR_NCP_E2H, // Directory Services
  685. 4, // Max request packet size
  686. 19, // Max response packet size
  687. "bb|p", // Format string
  688. // === REQUEST ================================
  689. 0x06, // Get Volume Name
  690. bVolNum, // Volume Number
  691. // === REPLY ==================================
  692. pszVolName // Return Volume name
  693. );
  694. (void) SetWin32ErrorFromNtStatus( NtStatus );
  695. return MapNtStatus( NtStatus, NcpClassDir );
  696. }
  697. NWCCODE NWAPI DLLEXPORT
  698. NWIsObjectInSet(
  699. NWCONN_HANDLE hConn,
  700. const char NWFAR *lpszObjectName,
  701. NWOBJ_TYPE wObjType,
  702. const char NWFAR *lpszPropertyName,
  703. const char NWFAR *lpszMemberName,
  704. NWOBJ_TYPE wMemberType
  705. )
  706. {
  707. NTSTATUS NtStatus ;
  708. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  709. WORD Dummy;
  710. NtStatus = NwlibMakeNcp(
  711. pServerInfo->hConn, // Connection Handle
  712. FSCTL_NWR_NCP_E3H, // Bindery function
  713. 122, // Max request packet size
  714. 2, // Max response packet size
  715. "brPPrP|", // Format string
  716. // === REQUEST ================================
  717. 0x43, // b Read Property Value
  718. &wObjType,W_SIZE, // r OT_??? HI-LO
  719. lpszObjectName, // P Object Name
  720. lpszPropertyName, // P Prop Name
  721. &wMemberType,W_SIZE, // r Member Type
  722. lpszMemberName, // P Member Name
  723. // === REPLY ==================================
  724. &Dummy,W_SIZE
  725. );
  726. (void) SetWin32ErrorFromNtStatus( NtStatus );
  727. return MapNtStatus( NtStatus, NcpClassBindery );
  728. } // NWIsObjectInSet
  729. NWCCODE NWAPI DLLEXPORT
  730. NWLoginToFileServer(
  731. NWCONN_HANDLE hConn,
  732. const char NWFAR *pszUserName,
  733. NWOBJ_TYPE wObType,
  734. const char NWFAR *pszPassword
  735. )
  736. {
  737. NETRESOURCEW NetResource;
  738. DWORD dwRes, dwSize;
  739. NWCCODE nwRes;
  740. LPWSTR pszUserNameW = NULL,
  741. pszPasswordW = NULL;
  742. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  743. //
  744. // validate parameters
  745. //
  746. if (!hConn || !pszUserName || !pszPassword)
  747. return INVALID_CONNECTION ;
  748. //
  749. // allocate memory for unicode strings and convert ANSI input
  750. // to Unicode.
  751. //
  752. dwSize = strlen(pszUserName)+1 ;
  753. if (!(pszUserNameW = (LPWSTR)LocalAlloc(
  754. LPTR,
  755. dwSize * sizeof(WCHAR))))
  756. {
  757. nwRes = REQUESTER_ERROR ;
  758. goto ExitPoint ;
  759. }
  760. if (szToWide( pszUserNameW, pszUserName, dwSize ) != NO_ERROR)
  761. {
  762. nwRes = REQUESTER_ERROR ;
  763. goto ExitPoint ;
  764. }
  765. dwSize = strlen(pszPassword)+1 ;
  766. if (!(pszPasswordW = (LPWSTR)LocalAlloc(
  767. LPTR,
  768. dwSize * sizeof(WCHAR))))
  769. {
  770. nwRes = REQUESTER_ERROR ;
  771. goto ExitPoint ;
  772. }
  773. if (szToWide( pszPasswordW, pszPassword, dwSize ) != NO_ERROR)
  774. {
  775. nwRes = REQUESTER_ERROR ;
  776. goto ExitPoint ;
  777. }
  778. NetResource.dwScope = 0 ;
  779. NetResource.dwUsage = 0 ;
  780. NetResource.dwType = RESOURCETYPE_ANY;
  781. NetResource.lpLocalName = NULL;
  782. NetResource.lpRemoteName = (LPWSTR) pServerInfo->ServerString.Buffer;
  783. NetResource.lpComment = NULL;
  784. NetResource.lpProvider = NULL ;
  785. //
  786. // make the connection
  787. //
  788. dwRes=NPAddConnection ( &NetResource,
  789. pszPasswordW,
  790. pszUserNameW );
  791. if( NO_ERROR != dwRes ) {
  792. dwRes = GetLastError();
  793. switch( dwRes ) {
  794. case ERROR_SESSION_CREDENTIAL_CONFLICT:
  795. nwRes = SUCCESSFUL;
  796. break;
  797. case ERROR_ALREADY_ASSIGNED:
  798. nwRes = ALREADY_ATTACHED;
  799. break;
  800. case ERROR_ACCESS_DENIED:
  801. case ERROR_BAD_DEV_TYPE:
  802. case ERROR_BAD_DEVICE:
  803. case ERROR_BAD_NET_NAME:
  804. case ERROR_BAD_PROFILE:
  805. case ERROR_CANNOT_OPEN_PROFILE:
  806. case ERROR_DEVICE_ALREADY_REMEMBERED:
  807. case ERROR_EXTENDED_ERROR:
  808. case ERROR_INVALID_PASSWORD:
  809. case ERROR_NO_NET_OR_BAD_PATH:
  810. case ERROR_NO_NETWORK:
  811. nwRes = INVALID_CONNECTION;
  812. break;
  813. default:
  814. nwRes = INVALID_CONNECTION;
  815. break;
  816. }
  817. } else {
  818. nwRes = SUCCESSFUL;
  819. }
  820. ExitPoint:
  821. if (pszUserNameW)
  822. (void) LocalFree((HLOCAL) pszUserNameW) ;
  823. if (pszPasswordW)
  824. (void) LocalFree((HLOCAL) pszPasswordW) ;
  825. return( nwRes );
  826. }
  827. NWCCODE NWAPI DLLEXPORT
  828. NWLogoutFromFileServer(
  829. NWCONN_HANDLE hConn
  830. )
  831. {
  832. DWORD dwRes;
  833. NWCCODE nwRes;
  834. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  835. //
  836. // cancel all explicit connections to that server
  837. //
  838. (void) CancelAllConnections ( pServerInfo->ServerString.Buffer );
  839. //
  840. // now cancel the any connection to \\servername.
  841. //
  842. dwRes=NPCancelConnection( pServerInfo->ServerString.Buffer, TRUE );
  843. if( NO_ERROR != dwRes ) {
  844. dwRes = GetLastError();
  845. switch( dwRes )
  846. {
  847. case ERROR_NOT_CONNECTED:
  848. case ERROR_INVALID_HANDLE:
  849. nwRes = SUCCESSFUL;
  850. break;
  851. case ERROR_BAD_PROFILE:
  852. case ERROR_CANNOT_OPEN_PROFILE:
  853. case ERROR_DEVICE_IN_USE:
  854. case ERROR_EXTENDED_ERROR:
  855. nwRes = INVALID_CONNECTION;
  856. break;
  857. default:
  858. nwRes = INVALID_CONNECTION;
  859. break;
  860. }
  861. } else {
  862. nwRes = SUCCESSFUL;
  863. }
  864. return( nwRes );
  865. }
  866. NWCCODE NWAPI DLLEXPORT
  867. NWReadPropertyValue(
  868. NWCONN_HANDLE hConn,
  869. const char NWFAR *pszObjName,
  870. NWOBJ_TYPE wObjType,
  871. char NWFAR *pszPropName,
  872. unsigned char ucSegment,
  873. char NWFAR *pValue,
  874. NWFLAGS NWFAR *pucMoreFlag,
  875. NWFLAGS NWFAR *pucPropFlag
  876. )
  877. {
  878. NTSTATUS NtStatus ;
  879. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  880. NtStatus = NwlibMakeNcp(
  881. pServerInfo->hConn, // Connection Handle
  882. FSCTL_NWR_NCP_E3H, // Bindery function
  883. 70, // Max request packet size
  884. 132, // Max response packet size
  885. "brPbP|rbb", // Format string
  886. // === REQUEST ================================
  887. 0x3D, // b Read Property Value
  888. &wObjType,W_SIZE, // r Object Type HI-LO
  889. pszObjName, // P Object Name
  890. ucSegment, // b Segment Number
  891. pszPropName, // P Property Name
  892. // === REPLY ==================================
  893. pValue,128, // r Property value
  894. pucMoreFlag, // b More Flag
  895. pucPropFlag // b Prop Flag
  896. );
  897. (void) SetWin32ErrorFromNtStatus( NtStatus );
  898. return MapNtStatus( NtStatus, NcpClassBindery );
  899. }
  900. NWCCODE NWAPI DLLEXPORT
  901. NWScanObject(
  902. NWCONN_HANDLE hConn,
  903. const char NWFAR *pszSearchName,
  904. NWOBJ_TYPE wObjSearchType,
  905. NWOBJ_ID NWFAR *pdwObjectID,
  906. char NWFAR *pszObjectName,
  907. NWOBJ_TYPE NWFAR *pwObjType,
  908. NWFLAGS NWFAR *pucHasProperties,
  909. NWFLAGS NWFAR *pucObjectFlags,
  910. NWFLAGS NWFAR *pucObjSecurity
  911. )
  912. {
  913. NTSTATUS NtStatus ;
  914. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  915. NtStatus = NwlibMakeNcp(
  916. pServerInfo->hConn, // Connection Handle
  917. FSCTL_NWR_NCP_E3H, // Bindery function
  918. 57, // Max request packet size
  919. 59, // Max response packet size
  920. "brrP|rrRbbb", // Format string
  921. // === REQUEST ================================
  922. 0x37, // b Scan bindery object
  923. pdwObjectID,DW_SIZE, // r 0xffffffff to start or last returned ID when enumerating HI-LO
  924. &wObjSearchType,W_SIZE, // r Use OT_??? Defines HI-LO
  925. pszSearchName, // P Search Name. (use "*") for all
  926. // === REPLY ==================================
  927. pdwObjectID,DW_SIZE, // r Returned ID HI-LO
  928. pwObjType,W_SIZE, // r rObject Type HI-LO
  929. pszObjectName,48, // R Found Name
  930. pucObjectFlags, // b Object Flag
  931. pucObjSecurity, // b Object Security
  932. pucHasProperties // b Has Properties
  933. );
  934. (void) SetWin32ErrorFromNtStatus( NtStatus );
  935. return MapNtStatus( NtStatus, NcpClassBindery );
  936. }
  937. NWCCODE NWAPI DLLEXPORT
  938. NWScanProperty(
  939. NWCONN_HANDLE hConn,
  940. const char NWFAR *pszObjectName,
  941. NWOBJ_TYPE wObjType,
  942. char NWFAR *pszSearchName,
  943. NWOBJ_ID NWFAR *pdwSequence,
  944. char NWFAR *pszPropName,
  945. NWFLAGS NWFAR *pucPropFlags,
  946. NWFLAGS NWFAR *pucPropSecurity,
  947. NWFLAGS NWFAR *pucHasValue,
  948. NWFLAGS NWFAR *pucMore
  949. )
  950. {
  951. NTSTATUS NtStatus ;
  952. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  953. NtStatus = NwlibMakeNcp(
  954. pServerInfo->hConn, // Connection Handle
  955. FSCTL_NWR_NCP_E3H, // Bindery function
  956. 73, // Max request packet size
  957. 26, // Max response packet size
  958. "brPrP|Rbbrbb", // Format string
  959. // === REQUEST ================================
  960. 0x3C, // b Scan Prop function
  961. &wObjType,W_SIZE, // r Type of Object
  962. pszObjectName, // P Object Name
  963. pdwSequence,DW_SIZE, // r Sequence HI-LO
  964. pszSearchName, // P Property Name to Search for
  965. // === REPLY ==================================
  966. pszPropName,16, // R Returned Property Name
  967. pucPropFlags, // b Property Flags
  968. pucPropSecurity, // b Property Security
  969. pdwSequence,DW_SIZE, // r Sequence HI-LO
  970. pucHasValue, // b Property Has value
  971. pucMore // b More Properties
  972. );
  973. (void) SetWin32ErrorFromNtStatus( NtStatus );
  974. return MapNtStatus( NtStatus, NcpClassBindery );
  975. }
  976. NWCCODE NWAPI DLLEXPORT
  977. NWGetFileServerDateAndTime(
  978. NWCONN_HANDLE hConn,
  979. BYTE NWFAR *year,
  980. BYTE NWFAR *month,
  981. BYTE NWFAR *day,
  982. BYTE NWFAR *hour,
  983. BYTE NWFAR *minute,
  984. BYTE NWFAR *second,
  985. BYTE NWFAR *dayofweek
  986. )
  987. {
  988. NTSTATUS NtStatus ;
  989. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  990. NtStatus = NwlibMakeNcp(
  991. pServerInfo->hConn, // Connection Handle
  992. FSCTL_NWR_NCP_E0H, // Server function
  993. 0, // Max request packet size
  994. 9, // Max response packet size
  995. "|bbbbbbb", // Format string
  996. // === REQUEST ================================
  997. // === REPLY ==================================
  998. year,
  999. month,
  1000. day,
  1001. hour,
  1002. minute,
  1003. second,
  1004. dayofweek
  1005. );
  1006. (void) SetWin32ErrorFromNtStatus( NtStatus );
  1007. return MapNtStatus( NtStatus, NcpClassConnect );
  1008. } // NWGetFileServerDateAndTime
  1009. //
  1010. // worker routines
  1011. //
  1012. #define NW_RDR_SERVER_PREFIX L"\\Device\\Nwrdr\\"
  1013. DWORD
  1014. CancelAllConnections(
  1015. LPWSTR pszServer
  1016. )
  1017. /*++
  1018. Routine Description:
  1019. This routine cancels all connections to a server
  1020. Arguments:
  1021. pszServer - the server we are disconnecting from
  1022. Return Value:
  1023. NO_ERROR or win32 error for failure.
  1024. --*/
  1025. {
  1026. DWORD status = ERROR_NO_NETWORK;
  1027. HANDLE EnumHandle = (HANDLE) NULL;
  1028. LPNETRESOURCE NetR = NULL;
  1029. DWORD BytesNeeded = 4096;
  1030. DWORD EntriesRead;
  1031. DWORD i;
  1032. //
  1033. // Retrieve the list of connections
  1034. //
  1035. status = NPOpenEnum(
  1036. RESOURCE_CONNECTED,
  1037. 0,
  1038. 0,
  1039. NULL,
  1040. &EnumHandle
  1041. );
  1042. if (status != NO_ERROR) {
  1043. EnumHandle = (HANDLE) NULL;
  1044. goto CleanExit;
  1045. }
  1046. //
  1047. // Allocate buffer to get connection list.
  1048. //
  1049. if ((NetR = (LPNETRESOURCE) LocalAlloc(
  1050. LPTR,
  1051. (UINT) BytesNeeded
  1052. )) == NULL) {
  1053. status = ERROR_NOT_ENOUGH_MEMORY;
  1054. goto CleanExit;
  1055. }
  1056. do {
  1057. EntriesRead = 0xFFFFFFFF; // Read as many as possible
  1058. status = NPEnumResource(
  1059. EnumHandle,
  1060. &EntriesRead,
  1061. (LPVOID) NetR,
  1062. &BytesNeeded
  1063. );
  1064. if (status == WN_SUCCESS)
  1065. {
  1066. LPNETRESOURCE TmpPtr = NetR;
  1067. for (i = 0; i < EntriesRead; i++, TmpPtr++)
  1068. {
  1069. LPWSTR pszTmp ;
  1070. //
  1071. // If it contains the server we are logging off from, we want
  1072. // to cancel it. First, lets extract the server name part.
  1073. //
  1074. pszTmp = TmpPtr->lpRemoteName ;
  1075. if (!pszTmp || !*pszTmp)
  1076. continue ;
  1077. if ((*pszTmp == L'\\') && (*(pszTmp+1) == L'\\'))
  1078. pszTmp += 2 ;
  1079. if (pszTmp = wcschr(pszTmp, L'\\'))
  1080. *pszTmp = 0 ;
  1081. if (_wcsicmp(TmpPtr->lpRemoteName, pszServer) == 0)
  1082. {
  1083. //
  1084. // Aha, it matches. Restore the '\' and nuke it with force.
  1085. // Ignore errors here.
  1086. //
  1087. if (pszTmp)
  1088. *pszTmp = L'\\' ;
  1089. if (TmpPtr->lpLocalName && *(TmpPtr->lpLocalName))
  1090. {
  1091. //
  1092. // if local name present, its a redirection.
  1093. //
  1094. (void) NPCancelConnection( TmpPtr->lpLocalName,TRUE );
  1095. }
  1096. else
  1097. {
  1098. //
  1099. // else cancel the deviceless use
  1100. //
  1101. (void) NPCancelConnection( TmpPtr->lpRemoteName,TRUE );
  1102. }
  1103. }
  1104. }
  1105. }
  1106. else if (status != WN_NO_MORE_ENTRIES) {
  1107. status = GetLastError();
  1108. if (status == WN_MORE_DATA) {
  1109. //
  1110. // Original buffer was too small. Free it and allocate
  1111. // the recommended size and then some to get as many
  1112. // entries as possible.
  1113. //
  1114. (void) LocalFree((HLOCAL) NetR);
  1115. if ((NetR = (LPNETRESOURCE) LocalAlloc(
  1116. LPTR,
  1117. (UINT) BytesNeeded
  1118. )) == NULL) {
  1119. status = ERROR_NOT_ENOUGH_MEMORY;
  1120. goto CleanExit;
  1121. }
  1122. }
  1123. else
  1124. {
  1125. //
  1126. // cant handle other errors. bag out.
  1127. //
  1128. goto CleanExit;
  1129. }
  1130. }
  1131. } while (status != WN_NO_MORE_ENTRIES);
  1132. if (status == WN_NO_MORE_ENTRIES)
  1133. {
  1134. status = NO_ERROR;
  1135. }
  1136. CleanExit:
  1137. if (EnumHandle != (HANDLE) NULL)
  1138. {
  1139. (void) NPCloseEnum(EnumHandle);
  1140. }
  1141. if (NetR != NULL)
  1142. {
  1143. (void) LocalFree((HLOCAL) NetR);
  1144. }
  1145. return status;
  1146. }
  1147. NWCCODE NWAPI DLLEXPORT
  1148. NWCreateQueue(
  1149. NWCONN_HANDLE hConn,
  1150. NWDIR_HANDLE dirHandle,
  1151. const char NWFAR *pszQueueName,
  1152. NWOBJ_TYPE wQueueType,
  1153. const char NWFAR *pszPathName,
  1154. NWOBJ_ID NWFAR *pdwQueueId
  1155. )
  1156. {
  1157. NTSTATUS NtStatus;
  1158. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  1159. NtStatus = NwlibMakeNcp(
  1160. pServerInfo->hConn, // Connection Handle
  1161. FSCTL_NWR_NCP_E3H, // Bindery function
  1162. 174, // Max request packet size
  1163. 6, // Max response packet size
  1164. "brPbP|r", // Format string
  1165. // === REQUEST ================================
  1166. 0x64, // b Create Queue
  1167. &wQueueType,W_SIZE, // r Queue Type HI-LO
  1168. pszQueueName, // P Queue Name
  1169. dirHandle, // b Directory Handle
  1170. pszPathName, // P Path name
  1171. // === REPLY ==================================
  1172. pdwQueueId,DW_SIZE // r Queue ID HI-LO
  1173. );
  1174. (void) SetWin32ErrorFromNtStatus(NtStatus);
  1175. return MapNtStatus( NtStatus, NcpClassBindery );
  1176. }
  1177. NWCCODE NWAPI DLLEXPORT
  1178. NWChangePropertySecurity(
  1179. NWCONN_HANDLE hConn,
  1180. const char NWFAR *pszObjName,
  1181. NWOBJ_TYPE wObjType,
  1182. const char NWFAR *pszPropertyName,
  1183. NWFLAGS ucObjSecurity
  1184. )
  1185. {
  1186. NTSTATUS NtStatus;
  1187. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  1188. NtStatus = NwlibMakeNcp (
  1189. pServerInfo->hConn, // Connection Handle
  1190. FSCTL_NWR_NCP_E3H, // Bindery function
  1191. 70, // Max request packet size
  1192. 2, // Max response packet size
  1193. "brPbP|", // Format string
  1194. // === REQUEST ================================
  1195. 0x3B, // b Change Property Security
  1196. &wObjType,W_SIZE, // r OT_??? HI-LO
  1197. pszObjName, // P Prop Name
  1198. ucObjSecurity, // b New Property security
  1199. pszPropertyName // P Property Name
  1200. // === REPLY ==================================
  1201. );
  1202. (void) SetWin32ErrorFromNtStatus( NtStatus );
  1203. return MapNtStatus( NtStatus, NcpClassBindery );
  1204. }
  1205. NWCCODE NWAPI DLLEXPORT
  1206. NWDestroyQueue(
  1207. NWCONN_HANDLE hConn,
  1208. NWOBJ_ID dwQueueId
  1209. )
  1210. {
  1211. NTSTATUS NtStatus;
  1212. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn ;
  1213. NtStatus = NwlibMakeNcp(
  1214. pServerInfo->hConn, // Connection Handle
  1215. FSCTL_NWR_NCP_E3H, // Bindery function
  1216. 7, // Max request packet size
  1217. 2, // Max response packet size
  1218. "bd|", // Format string
  1219. // === REQUEST ================================
  1220. 0x65, // b Destroy Queue
  1221. dwQueueId // d Queue ID
  1222. // === REPLY ==================================
  1223. );
  1224. (void) SetWin32ErrorFromNtStatus( NtStatus );
  1225. return MapNtStatus( NtStatus, NcpClassBindery );
  1226. }
  1227. //
  1228. // tommye MS 88021 / MCS
  1229. //
  1230. // Added the following two routines to allow the library user
  1231. // to obtain a NWCONN_HANDLE given a ObjectHandle, then free that
  1232. // handle.
  1233. //
  1234. NWCONN_HANDLE NWAPI DLLEXPORT
  1235. NwNdsObjectHandleToConnHandle(
  1236. IN HANDLE ObjectHandle)
  1237. {
  1238. PNWC_SERVER_INFO pServerInfo;
  1239. LPNDS_OBJECT_PRIV pObject = (LPNDS_OBJECT_PRIV)ObjectHandle;
  1240. /** Allocate the NWCONN_HANDLE to return **/
  1241. pServerInfo = (PNWC_SERVER_INFO)LocalAlloc(LPTR, sizeof(NWC_SERVER_INFO));
  1242. if (pServerInfo == NULL) {
  1243. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  1244. return NULL;
  1245. }
  1246. /** Fill it in **/
  1247. pServerInfo->hConn = pObject->NdsTree;
  1248. /**
  1249. Fill in the server name, even though NWLoginToFileServer and
  1250. NWLogoutFromFileServer are the only calls that use it now.
  1251. **/
  1252. RtlInitUnicodeString(
  1253. &pServerInfo->ServerString,
  1254. pObject->szContainerName);
  1255. /**
  1256. Return the pointer to the block, which is our form of NWCONN_HANDLE.
  1257. The caller is responsible for calling NwNdsConnHandlFree when done.
  1258. **/
  1259. return (NWCONN_HANDLE)pServerInfo;
  1260. }
  1261. VOID NWAPI DLLEXPORT
  1262. NwNdsConnHandleFree(
  1263. IN NWCONN_HANDLE hConn)
  1264. {
  1265. if (hConn) {
  1266. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)hConn;
  1267. /** Free the connection handle **/
  1268. LocalFree(pServerInfo);
  1269. }
  1270. /** All done **/
  1271. return;
  1272. }