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.

683 lines
17 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ApiMsg.c
  5. Abstract:
  6. This module contains individual API handlers for the NetMessage APIs.
  7. SUPPORTED - NetMessageBufferSend, NetMessageNameAdd, NetMessageNameDel,
  8. NetMessageNameEnum, NetMessageNameGetInfo.
  9. Author:
  10. Shanku Niyogi (w-shanku) 8-Mar-1991
  11. Revision History:
  12. --*/
  13. #include "XactSrvP.h"
  14. //
  15. // Declaration of descriptor strings.
  16. //
  17. STATIC const LPDESC Desc16_msg_info_0 = REM16_msg_info_0;
  18. STATIC const LPDESC Desc32_msg_info_0 = REM32_msg_info_0;
  19. STATIC const LPDESC Desc16_msg_info_1 = REM16_msg_info_1;
  20. STATIC const LPDESC Desc32_msg_info_1 = REM32_msg_info_1;
  21. NTSTATUS
  22. XsNetMessageBufferSend (
  23. API_HANDLER_PARAMETERS
  24. )
  25. /*++
  26. Routine Description:
  27. This routine handles a call to NetMessageBufferSend.
  28. Arguments:
  29. API_HANDLER_PARAMETERS - information about the API call. See
  30. XsTypes.h for details.
  31. Return Value:
  32. NTSTATUS - STATUS_SUCCESS or reason for failure.
  33. --*/
  34. {
  35. NET_API_STATUS status;
  36. PXS_NET_MESSAGE_BUFFER_SEND parameters = Parameters;
  37. LPTSTR nativeRecipient = NULL; // Native parameters
  38. LPBYTE nativeBuffer = NULL;
  39. DWORD nativeBufLen;
  40. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  41. IF_DEBUG(MESSAGE) {
  42. NetpKdPrint(( "XsNetMessageBufferSend: header at %lx, params at %lx, "
  43. "recipient %s\n",
  44. Header, parameters,
  45. SmbGetUlong( &parameters->Recipient )));
  46. }
  47. try {
  48. //
  49. // Translate parameters, check for errors.
  50. //
  51. XsConvertTextParameter(
  52. nativeRecipient,
  53. (LPSTR)XsSmbGetPointer( &parameters->Recipient )
  54. );
  55. //
  56. // NetMessageBufferSend has an ASCII data buffer. Convert this to
  57. // Unicode if necessary.
  58. //
  59. #ifdef UNICODE
  60. nativeBufLen = SmbGetUshort( &parameters->BufLen ) * sizeof(WCHAR);
  61. if (( nativeBuffer = NetpMemoryAllocate( nativeBufLen )) == NULL ) {
  62. status = NERR_NoRoom;
  63. goto cleanup;
  64. } else {
  65. XsCopyBufToTBuf(
  66. (LPBYTE)nativeBuffer,
  67. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  68. (DWORD)SmbGetUshort( &parameters->BufLen )
  69. );
  70. }
  71. #else
  72. nativeBuffer = (LPBYTE)SmbGetUlong( &parameters->Buffer );
  73. nativeBufLen = (DWORD)SmbGetUshort( &parameters->BufLen );
  74. #endif // def UNICODE
  75. status = NetMessageBufferSend(
  76. NULL,
  77. nativeRecipient,
  78. NULL,
  79. nativeBuffer,
  80. nativeBufLen
  81. );
  82. if ( !XsApiSuccess( status )) {
  83. IF_DEBUG(ERRORS) {
  84. NetpKdPrint(( "XsNetMessageBufferSend: NetMessageBufferSend "
  85. "failed: %X\n", status ));
  86. }
  87. }
  88. cleanup:
  89. ;
  90. } except( EXCEPTION_EXECUTE_HANDLER ) {
  91. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  92. }
  93. NetpMemoryFree( nativeRecipient );
  94. #ifdef UNICODE
  95. NetpMemoryFree( nativeBuffer );
  96. #endif // def UNICODE
  97. //
  98. // Nothing to return.
  99. //
  100. Header->Status = (WORD)status;
  101. return STATUS_SUCCESS;
  102. } // XsNetMessageBufferSend
  103. NTSTATUS
  104. XsNetMessageNameAdd (
  105. API_HANDLER_PARAMETERS
  106. )
  107. /*++
  108. Routine Description:
  109. This routine handles a call to NetMessageNameAdd.
  110. Arguments:
  111. API_HANDLER_PARAMETERS - information about the API call. See
  112. XsTypes.h for details.
  113. Return Value:
  114. NTSTATUS - STATUS_SUCCESS or reason for failure.
  115. --*/
  116. {
  117. NET_API_STATUS status;
  118. PXS_NET_MESSAGE_NAME_ADD parameters = Parameters;
  119. LPTSTR nativeMessageName = NULL; // Native parameters
  120. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  121. IF_DEBUG(MESSAGE) {
  122. NetpKdPrint(( "XsNetMessageNameDel: header at %lx, params at %lx, "
  123. "name %s\n",
  124. Header, parameters,
  125. SmbGetUlong( &parameters->MessageName )));
  126. }
  127. try {
  128. //
  129. // Translate parameters, check for errors.
  130. //
  131. XsConvertTextParameter(
  132. nativeMessageName,
  133. (LPSTR)XsSmbGetPointer( &parameters->MessageName )
  134. );
  135. //
  136. // NetMessageNameAdd has one useful parameter, MessageName, a string.
  137. // The other parameter, FwdAction, is ignored in NT, because forwarding
  138. // messages is not supported.
  139. //
  140. // Make the local call.
  141. //
  142. status = NetMessageNameAdd(
  143. NULL,
  144. nativeMessageName
  145. );
  146. if ( !XsApiSuccess( status )) {
  147. IF_DEBUG(ERRORS) {
  148. NetpKdPrint(( "XsNetMessageNameAdd: NetMessageNameAdd "
  149. "failed: %X\n", status ));
  150. }
  151. }
  152. cleanup:
  153. ;
  154. } except( EXCEPTION_EXECUTE_HANDLER ) {
  155. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  156. }
  157. NetpMemoryFree( nativeMessageName );
  158. //
  159. // Nothing to return.
  160. //
  161. Header->Status = (WORD)status;
  162. return STATUS_SUCCESS;
  163. } // XsNetMessageNameAdd
  164. NTSTATUS
  165. XsNetMessageNameDel (
  166. API_HANDLER_PARAMETERS
  167. )
  168. /*++
  169. Routine Description:
  170. This routine handles a call to NetMessageNameDel.
  171. Arguments:
  172. Transaction - a pointer to a transaction block containing information
  173. about the API to process.
  174. Return Value:
  175. NTSTATUS - STATUS_SUCCESS or reason for failure.
  176. --*/
  177. {
  178. NET_API_STATUS status;
  179. PXS_NET_MESSAGE_NAME_DEL parameters = Parameters;
  180. LPTSTR nativeMessageName = NULL; // Native parameters
  181. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  182. IF_DEBUG(MESSAGE) {
  183. NetpKdPrint(( "XsNetMessageNameDel: header at %lx, params at %lx, "
  184. "name %s\n",
  185. Header, parameters,
  186. SmbGetUlong( &parameters->MessageName )));
  187. }
  188. try {
  189. //
  190. // Translate parameters, check for errors.
  191. //
  192. XsConvertTextParameter(
  193. nativeMessageName,
  194. (LPSTR)XsSmbGetPointer( &parameters->MessageName )
  195. );
  196. //
  197. // NetMessageNameDel has only one useful parameter, MessageName, which is
  198. // a string. The other parameter, FwdAction, is ignored, because NT does
  199. // not support message forwarding.
  200. //
  201. // Make the local call.
  202. //
  203. status = NetMessageNameDel(
  204. NULL,
  205. nativeMessageName
  206. );
  207. if ( !XsApiSuccess( status )) {
  208. IF_DEBUG(ERRORS) {
  209. NetpKdPrint(( "XsNetMessageNameDel: NetMessageNameDel failed: "
  210. "%X\n", status ));
  211. }
  212. }
  213. cleanup:
  214. ;
  215. } except( EXCEPTION_EXECUTE_HANDLER ) {
  216. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  217. }
  218. NetpMemoryFree( nativeMessageName );
  219. //
  220. // Nothing to return.
  221. //
  222. Header->Status = (WORD)status;
  223. return STATUS_SUCCESS;
  224. } // XsNetMessageNameDel
  225. NTSTATUS
  226. XsNetMessageNameEnum (
  227. API_HANDLER_PARAMETERS
  228. )
  229. /*++
  230. Routine Description:
  231. This routine handles a call to NetMessageNameEnum.
  232. Arguments:
  233. API_HANDLER_PARAMETERS - information about the API call. See
  234. XsTypes.h for details.
  235. Return Value:
  236. NTSTATUS - STATUS_SUCCESS or reason for failure.
  237. --*/
  238. {
  239. NET_API_STATUS status;
  240. PXS_NET_MESSAGE_NAME_ENUM parameters = Parameters;
  241. LPVOID outBuffer = NULL; // Native parameters
  242. DWORD entriesRead;
  243. DWORD totalEntries;
  244. DWORD entriesFilled = 0; // Conversion variables
  245. DWORD bytesRequired = 0;
  246. LPDESC nativeStructureDesc;
  247. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  248. IF_DEBUG(MESSAGE) {
  249. NetpKdPrint(( "XsNetMessageNameEnum: header at %lx, params at %lx, "
  250. "level %ld, buf size %ld\n",
  251. Header, parameters, SmbGetUshort( &parameters->Level ),
  252. SmbGetUshort( &parameters->BufLen )));
  253. }
  254. try {
  255. //
  256. // Check for errors.
  257. //
  258. if ( XsWordParamOutOfRange( parameters->Level, 0, 1 )) {
  259. Header->Status = ERROR_INVALID_LEVEL;
  260. goto cleanup;
  261. }
  262. //
  263. // Get the actual information from the local 32-bit call.
  264. //
  265. status = NetMessageNameEnum(
  266. NULL,
  267. (DWORD)SmbGetUshort( &parameters->Level ),
  268. (LPBYTE *)&outBuffer,
  269. XsNativeBufferSize( SmbGetUshort( &parameters->BufLen )),
  270. &entriesRead,
  271. &totalEntries,
  272. NULL
  273. );
  274. if ( !XsApiSuccess( status )) {
  275. IF_DEBUG(API_ERRORS) {
  276. NetpKdPrint(( "XsNetMessageNameEnum: NetMessageNameEnum failed:"
  277. " %X\n", status ));
  278. }
  279. Header->Status = (WORD)status;
  280. goto cleanup;
  281. }
  282. IF_DEBUG(MESSAGE) {
  283. NetpKdPrint(( "XsNetMessageNameEnum: received %ld entries at %lx\n",
  284. entriesRead, outBuffer ));
  285. }
  286. //
  287. // Use the requested level to determine the format of the
  288. // data structure.
  289. //
  290. switch ( SmbGetUshort( &parameters->Level ) ) {
  291. case 0:
  292. nativeStructureDesc = Desc32_msg_info_0;
  293. StructureDesc = Desc16_msg_info_0;
  294. break;
  295. case 1:
  296. nativeStructureDesc = Desc32_msg_info_1;
  297. StructureDesc = Desc16_msg_info_1;
  298. break;
  299. }
  300. //
  301. // Do the actual conversion from the 32-bit structures to 16-bit
  302. // structures.
  303. //
  304. XsFillEnumBuffer(
  305. outBuffer,
  306. entriesRead,
  307. nativeStructureDesc,
  308. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  309. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  310. SmbGetUshort( &parameters->BufLen ),
  311. StructureDesc,
  312. NULL, // verify function
  313. &bytesRequired,
  314. &entriesFilled,
  315. NULL
  316. );
  317. IF_DEBUG(MESSAGE) {
  318. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR,"
  319. " Entries %ld of %ld\n",
  320. outBuffer, SmbGetUlong( &parameters->Buffer ),
  321. bytesRequired, entriesFilled, totalEntries ));
  322. }
  323. //
  324. // If all the entries could not be filled, return ERROR_MORE_DATA,
  325. // and return the buffer as is. MSG_INFO_x structures have no
  326. // data to pack.
  327. //
  328. if ( entriesFilled < totalEntries ) {
  329. Header->Status = ERROR_MORE_DATA;
  330. }
  331. //
  332. // Set up the response parameters.
  333. //
  334. SmbPutUshort( &parameters->EntriesRead, (WORD)entriesFilled );
  335. SmbPutUshort( &parameters->TotalAvail, (WORD)totalEntries );
  336. cleanup:
  337. ;
  338. } except( EXCEPTION_EXECUTE_HANDLER ) {
  339. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  340. }
  341. NetApiBufferFree( outBuffer );
  342. //
  343. // Determine return buffer size.
  344. //
  345. XsSetDataCount(
  346. &parameters->BufLen,
  347. StructureDesc,
  348. Header->Converter,
  349. entriesFilled,
  350. Header->Status
  351. );
  352. return STATUS_SUCCESS;
  353. } // XsNetMessageNameEnum
  354. NTSTATUS
  355. XsNetMessageNameGetInfo (
  356. API_HANDLER_PARAMETERS
  357. )
  358. /*++
  359. Routine Description:
  360. This routine handles a call to NetMessageNameGetInfo.
  361. Arguments:
  362. API_HANDLER_PARAMETERS - information about the API call. See
  363. XsTypes.h for details.
  364. Return Value:
  365. NTSTATUS - STATUS_SUCCESS or reason for failure.
  366. --*/
  367. {
  368. NET_API_STATUS status;
  369. PXS_NET_MESSAGE_NAME_GET_INFO parameters = Parameters;
  370. LPTSTR nativeMessageName = NULL; // Native parameters
  371. LPVOID outBuffer = NULL;
  372. DWORD bytesRequired = 0; // Conversion variables
  373. LPBYTE stringLocation = NULL;
  374. LPDESC nativeStructureDesc;
  375. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  376. IF_DEBUG(MESSAGE) {
  377. NetpKdPrint(( "XsNetMessageNameGetInfo: header at %lx, "
  378. "params at %lx, level %ld\n",
  379. Header, parameters, SmbGetUshort( &parameters->Level ) ));
  380. }
  381. try {
  382. //
  383. // Translate parameters, check for errors.
  384. //
  385. if ( XsWordParamOutOfRange( parameters->Level, 0, 1 )) {
  386. Header->Status = ERROR_INVALID_LEVEL;
  387. goto cleanup;
  388. }
  389. XsConvertTextParameter(
  390. nativeMessageName,
  391. (LPSTR)XsSmbGetPointer( &parameters->MessageName )
  392. );
  393. //
  394. // Do the actual local call.
  395. //
  396. status = NetMessageNameGetInfo(
  397. NULL,
  398. nativeMessageName,
  399. (DWORD)SmbGetUshort( &parameters->Level ),
  400. (LPBYTE *)&outBuffer
  401. );
  402. if ( !XsApiSuccess( status )) {
  403. IF_DEBUG(API_ERRORS) {
  404. NetpKdPrint(( "XsNetMessageNameGetInfo: "
  405. "NetMessageNameGetInfo failed: %X\n", status ));
  406. }
  407. Header->Status = (WORD)status;
  408. goto cleanup;
  409. }
  410. //
  411. // Use the requested level to determine the format of the
  412. // data structure.
  413. //
  414. switch ( SmbGetUshort( &parameters->Level ) ) {
  415. case 0:
  416. nativeStructureDesc = Desc32_msg_info_0;
  417. StructureDesc = Desc16_msg_info_0;
  418. break;
  419. case 1:
  420. nativeStructureDesc = Desc32_msg_info_1;
  421. StructureDesc = Desc16_msg_info_1;
  422. break;
  423. }
  424. //
  425. // Convert the structure returned by the 32-bit call to a 16-bit
  426. // structure. The last possible location for variable data is
  427. // calculated from buffer location and length.
  428. //
  429. stringLocation = (LPBYTE)( XsSmbGetPointer( &parameters->Buffer )
  430. + SmbGetUshort( &parameters->BufLen ) );
  431. status = RapConvertSingleEntry(
  432. outBuffer,
  433. nativeStructureDesc,
  434. FALSE,
  435. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  436. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  437. StructureDesc,
  438. TRUE,
  439. &stringLocation,
  440. &bytesRequired,
  441. Response,
  442. NativeToRap
  443. );
  444. if ( status != NERR_Success ) {
  445. IF_DEBUG(ERRORS) {
  446. NetpKdPrint(( "NetMessageNameGetInfo: "
  447. "RapConvertSingleEntry failed: %X\n", status ));
  448. }
  449. Header->Status = NERR_InternalError;
  450. goto cleanup;
  451. }
  452. IF_DEBUG(MESSAGE) {
  453. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR\n",
  454. outBuffer, SmbGetUlong( &parameters->Buffer ),
  455. bytesRequired ));
  456. }
  457. //
  458. // Determine return code based on the size of the buffer. msg_info_x
  459. // structures have no data to pack.
  460. //
  461. if ( !XsCheckBufferSize(
  462. SmbGetUshort( &parameters->BufLen ),
  463. StructureDesc,
  464. FALSE // not in native format
  465. )) {
  466. IF_DEBUG(ERRORS) {
  467. NetpKdPrint(( "XsNetMessageNameGetInfo: Buffer too small.\n" ));
  468. }
  469. Header->Status = NERR_BufTooSmall;
  470. }
  471. //
  472. // Set up the response parameters.
  473. //
  474. SmbPutUshort( &parameters->TotalAvail, (WORD)bytesRequired );
  475. cleanup:
  476. ;
  477. } except( EXCEPTION_EXECUTE_HANDLER ) {
  478. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  479. }
  480. NetApiBufferFree( outBuffer );
  481. NetpMemoryFree( nativeMessageName );
  482. //
  483. // Determine return buffer size.
  484. //
  485. XsSetDataCount(
  486. &parameters->BufLen,
  487. StructureDesc,
  488. Header->Converter,
  489. 1,
  490. Header->Status
  491. );
  492. return STATUS_SUCCESS;
  493. } // XsNetMessageNameGetInfo