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.

618 lines
16 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ApiSess.c
  5. Abstract:
  6. This module contains individual API handlers for the NetSession APIs.
  7. SUPPORTED : NetSessionDel, NetSessionEnum, NetSessionGetInfo.
  8. Author:
  9. Shanku Niyogi (w-shanku) 5-Feb-1991
  10. Revision History:
  11. --*/
  12. #include "XactSrvP.h"
  13. //
  14. // Declaration of descriptor strings.
  15. //
  16. STATIC const LPDESC Desc16_session_info_0 = REM16_session_info_0;
  17. STATIC const LPDESC Desc32_session_info_0 = REM32_session_info_0;
  18. STATIC const LPDESC Desc16_session_info_1 = REM16_session_info_1;
  19. STATIC const LPDESC Desc32_session_info_1 = REM32_session_info_1;
  20. STATIC const LPDESC Desc16_session_info_2 = REM16_session_info_2;
  21. STATIC const LPDESC Desc32_session_info_2 = REM32_session_info_2;
  22. STATIC const LPDESC Desc16_session_info_10 = REM16_session_info_10;
  23. STATIC const LPDESC Desc32_session_info_10 = REM32_session_info_10;
  24. NTSTATUS
  25. XsNetSessionDel (
  26. API_HANDLER_PARAMETERS
  27. )
  28. /*++
  29. Routine Description:
  30. This routine handles a call to NetSessionDel.
  31. Arguments:
  32. API_HANDLER_PARAMETERS - information about the API call. See
  33. XsTypes.h for details.
  34. Return Value:
  35. NTSTATUS - STATUS_SUCCESS or reason for failure.
  36. --*/
  37. {
  38. NET_API_STATUS status;
  39. PXS_NET_SESSION_DEL parameters = Parameters;
  40. LPTSTR nativeClientName = NULL; // Native parameters
  41. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  42. IF_DEBUG(SESSION) {
  43. NetpKdPrint(( "XsNetSessionDel: header at %lx, params at %lx, "
  44. "device %s\n",
  45. Header, parameters,
  46. SmbGetUlong( &parameters->ClientName )));
  47. }
  48. try {
  49. //
  50. // Translate parameters, check for errors.
  51. //
  52. XsConvertTextParameter(
  53. nativeClientName,
  54. (LPSTR)XsSmbGetPointer( &parameters->ClientName )
  55. );
  56. //
  57. // Make the local call.
  58. //
  59. status = NetSessionDel(
  60. NULL,
  61. nativeClientName,
  62. NULL
  63. );
  64. if ( !XsApiSuccess( status )) {
  65. IF_DEBUG(ERRORS) {
  66. NetpKdPrint(( "XsNetSessionDel: NetSessionDel failed: %X\n",
  67. status ));
  68. }
  69. }
  70. cleanup:
  71. ;
  72. } except( EXCEPTION_EXECUTE_HANDLER ) {
  73. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  74. }
  75. NetpMemoryFree( nativeClientName );
  76. //
  77. // Nothing to return.
  78. //
  79. Header->Status = (WORD)status;
  80. return STATUS_SUCCESS;
  81. } // NetSessionDel
  82. NTSTATUS
  83. XsNetSessionEnum (
  84. API_HANDLER_PARAMETERS
  85. )
  86. /*++
  87. Routine Description:
  88. This routine handles a call to NetSessionEnum.
  89. Arguments:
  90. API_HANDLER_PARAMETERS - information about the API call. See
  91. XsTypes.h for details.
  92. Return Value:
  93. NTSTATUS - STATUS_SUCCESS or reason for failure.
  94. --*/
  95. {
  96. NET_API_STATUS status;
  97. PXS_NET_SESSION_ENUM parameters = Parameters;
  98. LPVOID outBuffer = NULL; // Native parameters
  99. DWORD entriesRead;
  100. DWORD totalEntries;
  101. DWORD entriesFilled = 0; // Conversion variables
  102. DWORD bytesRequired = 0;
  103. LPDESC nativeStructureDesc;
  104. PSESSION_16_INFO_1 struct1;
  105. PSESSION_16_INFO_2 struct2;
  106. DWORD i;
  107. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  108. IF_DEBUG(SESSION) {
  109. NetpKdPrint(( "XsNetSessionEnum: header at %lx, params at %lx, "
  110. "level %ld, buf size %ld\n",
  111. Header, parameters, SmbGetUshort( &parameters->Level ),
  112. SmbGetUshort( &parameters->BufLen )));
  113. }
  114. try {
  115. //
  116. // Check for errors.
  117. //
  118. if ( XsWordParamOutOfRange( parameters->Level, 0, 2 ) &&
  119. ( SmbGetUshort( &parameters->Level ) != 10 )) {
  120. Header->Status = ERROR_INVALID_LEVEL;
  121. goto cleanup;
  122. }
  123. //
  124. // Make the local call.
  125. //
  126. status = NetSessionEnum(
  127. NULL,
  128. NULL,
  129. NULL,
  130. (DWORD)SmbGetUshort( &parameters->Level ),
  131. (LPBYTE *)&outBuffer,
  132. XsNativeBufferSize( SmbGetUshort( &parameters->BufLen )),
  133. &entriesRead,
  134. &totalEntries,
  135. NULL
  136. );
  137. if ( !XsApiSuccess( status )) {
  138. IF_DEBUG(API_ERRORS) {
  139. NetpKdPrint(( "XsNetSessionEnum: NetSessionEnum failed: "
  140. "%X\n", status ));
  141. }
  142. Header->Status = (WORD)status;
  143. goto cleanup;
  144. }
  145. IF_DEBUG(SESSION) {
  146. NetpKdPrint(( "XsNetSessionEnum: received %ld entries at %lx\n",
  147. entriesRead, outBuffer ));
  148. }
  149. //
  150. // Use the requested level to determine the format of the
  151. // data structure.
  152. //
  153. switch ( SmbGetUshort( &parameters->Level ) ) {
  154. case 0:
  155. nativeStructureDesc = Desc32_session_info_0;
  156. StructureDesc = Desc16_session_info_0;
  157. break;
  158. case 1:
  159. nativeStructureDesc = Desc32_session_info_1;
  160. StructureDesc = Desc16_session_info_1;
  161. break;
  162. case 2:
  163. nativeStructureDesc = Desc32_session_info_2;
  164. StructureDesc = Desc16_session_info_2;
  165. break;
  166. case 10:
  167. nativeStructureDesc = Desc32_session_info_10;
  168. StructureDesc = Desc16_session_info_10;
  169. break;
  170. }
  171. //
  172. // Do the actual conversion from the 32-bit structures to 16-bit
  173. // structures.
  174. //
  175. XsFillEnumBuffer(
  176. outBuffer,
  177. entriesRead,
  178. nativeStructureDesc,
  179. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  180. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  181. SmbGetUshort( &parameters->BufLen ),
  182. StructureDesc,
  183. NULL, // verify function
  184. &bytesRequired,
  185. &entriesFilled,
  186. NULL
  187. );
  188. IF_DEBUG(SESSION) {
  189. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR,"
  190. " Entries %ld of %ld\n",
  191. outBuffer, SmbGetUlong( &parameters->Buffer ),
  192. bytesRequired, entriesFilled, totalEntries ));
  193. }
  194. //
  195. // Go through all the structures, and fill in the default data.
  196. //
  197. struct1 = (PSESSION_16_INFO_1)XsSmbGetPointer( &parameters->Buffer );
  198. struct2 = (PSESSION_16_INFO_2)struct1;
  199. switch ( SmbGetUshort( &parameters->Level )) {
  200. case 1:
  201. for ( i = 0; i < entriesFilled; i++, struct1++ ) {
  202. SmbPutUshort( &struct1->sesi1_num_conns, DEF16_ses_num_conns );
  203. SmbPutUshort( &struct1->sesi1_num_users, DEF16_ses_num_users );
  204. }
  205. break;
  206. case 2:
  207. for ( i = 0; i < entriesFilled; i++, struct2++ ) {
  208. SmbPutUshort( &struct2->sesi2_num_conns, DEF16_ses_num_conns );
  209. SmbPutUshort( &struct2->sesi2_num_users, DEF16_ses_num_users );
  210. }
  211. break;
  212. default:
  213. break;
  214. }
  215. //
  216. // If all the entries could not be filled, return ERROR_MORE_DATA,
  217. // and return the buffer as is. Otherwise, the data needs to be
  218. // packed so that we don't send too much useless data.
  219. //
  220. if ( entriesFilled < totalEntries ) {
  221. Header->Status = ERROR_MORE_DATA;
  222. } else {
  223. Header->Converter = XsPackReturnData(
  224. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  225. SmbGetUshort( &parameters->BufLen ),
  226. StructureDesc,
  227. entriesFilled
  228. );
  229. }
  230. //
  231. // Set up the response parameters.
  232. //
  233. SmbPutUshort( &parameters->EntriesRead, (WORD)entriesFilled );
  234. SmbPutUshort( &parameters->TotalAvail, (WORD)totalEntries );
  235. cleanup:
  236. ;
  237. } except( EXCEPTION_EXECUTE_HANDLER ) {
  238. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  239. }
  240. NetApiBufferFree( outBuffer );
  241. //
  242. // Determine return buffer size.
  243. //
  244. XsSetDataCount(
  245. &parameters->BufLen,
  246. StructureDesc,
  247. Header->Converter,
  248. entriesFilled,
  249. Header->Status
  250. );
  251. return STATUS_SUCCESS;
  252. } // NetSessionEnum
  253. NTSTATUS
  254. XsNetSessionGetInfo (
  255. API_HANDLER_PARAMETERS
  256. )
  257. /*++
  258. Routine Description:
  259. This routine handles a call to NetSessionGetInfo.
  260. Arguments:
  261. API_HANDLER_PARAMETERS - information about the API call. See
  262. XsTypes.h for details.
  263. Return Value:
  264. NTSTATUS - STATUS_SUCCESS or reason for failure.
  265. --*/
  266. {
  267. NET_API_STATUS status;
  268. PXS_NET_SESSION_GET_INFO parameters = Parameters;
  269. LPTSTR nativeClientName = NULL; // Native parameters
  270. LPVOID outBuffer = NULL;
  271. DWORD entriesRead;
  272. DWORD totalEntries;
  273. LPBYTE stringLocation = NULL; // Conversion variables
  274. DWORD bytesRequired = 0;
  275. LPDESC nativeStructureDesc;
  276. PSESSION_16_INFO_2 struct2;
  277. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  278. IF_DEBUG(SESSION) {
  279. NetpKdPrint(( "XsNetSessionGetInfo: header at %lx, "
  280. "params at %lx, level %ld\n",
  281. Header, parameters, SmbGetUshort( &parameters->Level ) ));
  282. }
  283. try {
  284. //
  285. // Translate parameters, check for errors.
  286. //
  287. if ( XsWordParamOutOfRange( parameters->Level, 0, 2 ) &&
  288. ( SmbGetUshort( &parameters->Level ) != 10 )) {
  289. Header->Status = ERROR_INVALID_LEVEL;
  290. goto cleanup;
  291. }
  292. XsConvertTextParameter(
  293. nativeClientName,
  294. (LPSTR)XsSmbGetPointer( &parameters->ClientName )
  295. );
  296. //
  297. // If this is a null client name, send the appropriate response.
  298. //
  299. if ( ( nativeClientName == NULL ) ||
  300. STRLEN( nativeClientName ) == 0 ) {
  301. Header->Status = NERR_ClientNameNotFound;
  302. goto cleanup;
  303. }
  304. //
  305. // Make the local call.
  306. //
  307. status = NetSessionEnum(
  308. NULL,
  309. nativeClientName,
  310. NULL,
  311. (DWORD)SmbGetUshort( &parameters->Level ),
  312. (LPBYTE *)&outBuffer,
  313. XsNativeBufferSize( SmbGetUshort( &parameters->BufLen )),
  314. &entriesRead,
  315. &totalEntries,
  316. NULL
  317. );
  318. if ( !XsApiSuccess( status )) {
  319. IF_DEBUG(API_ERRORS) {
  320. NetpKdPrint(( "XsNetSessionGetInfo: NetSessionEnum failed: "
  321. "%X\n", status ));
  322. }
  323. Header->Status = (WORD)status;
  324. goto cleanup;
  325. }
  326. IF_DEBUG(SESSION) {
  327. NetpKdPrint(( "XsNetSessionGetInfo: Received %ld entries\n",
  328. entriesRead ));
  329. }
  330. //
  331. // Use the requested level to determine the format of the 32-bit
  332. // structure we got back from NetSessionGetInfo. The format of the
  333. // 16-bit structure is stored in the transaction block, and we
  334. // got a pointer to it as a parameter.
  335. //
  336. switch ( SmbGetUshort( &parameters->Level ) ) {
  337. case 0:
  338. nativeStructureDesc = Desc32_session_info_0;
  339. StructureDesc = Desc16_session_info_0;
  340. break;
  341. case 1:
  342. nativeStructureDesc = Desc32_session_info_1;
  343. StructureDesc = Desc16_session_info_1;
  344. break;
  345. case 2:
  346. nativeStructureDesc = Desc32_session_info_2;
  347. StructureDesc = Desc16_session_info_2;
  348. break;
  349. case 10:
  350. nativeStructureDesc = Desc32_session_info_10;
  351. StructureDesc = Desc16_session_info_10;
  352. break;
  353. }
  354. //
  355. // Convert the structure returned by the 32-bit call to a 16-bit
  356. // structure. The last possible location for variable data is
  357. // calculated from buffer location and length.
  358. //
  359. stringLocation = (LPBYTE)( XsSmbGetPointer( &parameters->Buffer )
  360. + SmbGetUshort( &parameters->BufLen ) );
  361. status = RapConvertSingleEntry(
  362. outBuffer,
  363. nativeStructureDesc,
  364. FALSE,
  365. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  366. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  367. StructureDesc,
  368. TRUE,
  369. &stringLocation,
  370. &bytesRequired,
  371. Response,
  372. NativeToRap
  373. );
  374. if ( status != NERR_Success ) {
  375. IF_DEBUG(ERRORS) {
  376. NetpKdPrint(( "NetSessionGetInfo: RapConvertSingleEntry failed: "
  377. "%X\n", status ));
  378. }
  379. Header->Status = NERR_InternalError;
  380. goto cleanup;
  381. }
  382. IF_DEBUG(SESSION) {
  383. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR\n",
  384. outBuffer, SmbGetUlong( &parameters->Buffer ),
  385. bytesRequired ));
  386. }
  387. //
  388. // Determine return code based on the size of the buffer.
  389. //
  390. if ( !XsCheckBufferSize(
  391. SmbGetUshort( &parameters->BufLen ),
  392. StructureDesc,
  393. FALSE // not in native format
  394. )) {
  395. IF_DEBUG(ERRORS) {
  396. NetpKdPrint(( "XsNetSessionGetInfo: Buffer too small.\n" ));
  397. }
  398. Header->Status = NERR_BufTooSmall;
  399. } else {
  400. //
  401. // Fill in default data in the structure.
  402. //
  403. if (( SmbGetUshort( &parameters->Level ) == 1 ) ||
  404. SmbGetUshort( &parameters->Level ) == 2 ) {
  405. struct2 = (PSESSION_16_INFO_2)XsSmbGetPointer( &parameters->Buffer );
  406. SmbPutUshort( &struct2->sesi2_num_conns, DEF16_ses_num_conns );
  407. SmbPutUshort( &struct2->sesi2_num_users, (WORD)entriesRead );
  408. }
  409. if ( bytesRequired > (DWORD)SmbGetUshort( &parameters-> BufLen )) {
  410. IF_DEBUG(ERRORS) {
  411. NetpKdPrint(( "NetSessionGetInfo: More data available.\n" ));
  412. }
  413. Header->Status = ERROR_MORE_DATA;
  414. } else {
  415. //
  416. // Pack the response data.
  417. //
  418. Header->Converter = XsPackReturnData(
  419. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  420. SmbGetUshort( &parameters->BufLen ),
  421. StructureDesc,
  422. 1
  423. );
  424. }
  425. }
  426. //
  427. // Set up the response parameters.
  428. //
  429. SmbPutUshort( &parameters->TotalAvail, (WORD)bytesRequired );
  430. cleanup:
  431. ;
  432. } except( EXCEPTION_EXECUTE_HANDLER ) {
  433. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  434. }
  435. NetApiBufferFree( outBuffer );
  436. NetpMemoryFree( nativeClientName );
  437. //
  438. // Determine return buffer size.
  439. //
  440. XsSetDataCount(
  441. &parameters->BufLen,
  442. StructureDesc,
  443. Header->Converter,
  444. 1,
  445. Header->Status
  446. );
  447. return STATUS_SUCCESS;
  448. } // NetSessionGetInfo