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.

1413 lines
37 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ApiGroup.c
  5. Abstract:
  6. This module contains individual API handlers for the NetGroup APIs.
  7. SUPPORTED : NetGroupAdd, NetGroupAddUser, NetGroupDel, NetGroupDelUser,
  8. NetGroupEnum, NetGroupGetInfo, NetGroupGetUsers,
  9. NetGroupSetInfo, NetGroupSetUsers.
  10. Author:
  11. Shanku Niyogi (w-shanku) 13-Mar-1991
  12. Revision History:
  13. --*/
  14. //
  15. // Group APIs are UNICODE only.
  16. //
  17. #ifndef UNICODE
  18. #define UNICODE
  19. #endif
  20. #include "xactsrvp.h"
  21. //
  22. // Declaration of descriptor strings.
  23. //
  24. STATIC const LPDESC Desc16_group_info_0 = REM16_group_info_0;
  25. STATIC const LPDESC Desc32_group_info_0 = REM32_group_info_0;
  26. STATIC const LPDESC Desc16_group_info_1 = REM16_group_info_1;
  27. STATIC const LPDESC Desc32_group_info_1 = REM32_group_info_1;
  28. STATIC const LPDESC Desc16_group_info_1_setinfo = REM16_group_info_1_setinfo;
  29. STATIC const LPDESC Desc32_group_info_1_setinfo = REM32_group_info_1_setinfo;
  30. STATIC const LPDESC Desc16_group_users_info_0 = REM16_group_users_info_0;
  31. STATIC const LPDESC Desc32_group_users_info_0 = REM32_group_users_info_0;
  32. STATIC const LPDESC Desc16_group_users_info_0_set
  33. = REM16_group_users_info_0_set;
  34. STATIC const LPDESC Desc32_group_users_info_0_set
  35. = REM32_group_users_info_0_set;
  36. NTSTATUS
  37. XsNetGroupAdd (
  38. API_HANDLER_PARAMETERS
  39. )
  40. /*++
  41. Routine Description:
  42. This routine handles a call to NetGroupAdd.
  43. Arguments:
  44. API_HANDLER_PARAMETERS - information about the API call. See
  45. XsTypes.h for details.
  46. Return Value:
  47. NTSTATUS - STATUS_SUCCESS or reason for failure.
  48. --*/
  49. {
  50. NET_API_STATUS status;
  51. PXS_NET_GROUP_ADD parameters = Parameters;
  52. LPVOID buffer = NULL; // Native parameters
  53. LPBYTE stringLocation = NULL; // Conversion variables
  54. DWORD bytesRequired = 0;
  55. DWORD bufferSize;
  56. LPDESC nativeStructureDesc;
  57. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  58. IF_DEBUG(GROUP) {
  59. NetpKdPrint(( "XsNetGroupAdd: header at %lx, params at %lx, "
  60. "level %ld\n",
  61. Header, parameters, SmbGetUshort( &parameters->Level ) ));
  62. }
  63. try {
  64. //
  65. // Use the requested level to determine the format of the destination
  66. // 32-bit structure.
  67. //
  68. switch ( SmbGetUshort( &parameters->Level ) ) {
  69. case 0:
  70. StructureDesc = Desc16_group_info_0;
  71. nativeStructureDesc = Desc32_group_info_0;
  72. break;
  73. case 1:
  74. StructureDesc = Desc16_group_info_1;
  75. nativeStructureDesc = Desc32_group_info_1;
  76. break;
  77. default:
  78. Header->Status = ERROR_INVALID_LEVEL;
  79. goto cleanup;
  80. }
  81. //
  82. // Figure out if there is enough room in the buffer for all the
  83. // data required. If not, return NERR_BufTooSmall.
  84. //
  85. if ( !XsCheckBufferSize(
  86. SmbGetUshort( &parameters->BufLen ),
  87. StructureDesc,
  88. FALSE // not in native format
  89. )) {
  90. IF_DEBUG(ERRORS) {
  91. NetpKdPrint(( "XsNetGroupAdd: Buffer too small.\n" ));
  92. }
  93. Header->Status = NERR_BufTooSmall;
  94. goto cleanup;
  95. }
  96. //
  97. // Find out how big a buffer we need to allocate to hold the native
  98. // 32-bit version of the input data structure.
  99. //
  100. bufferSize = XsBytesForConvertedStructure(
  101. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  102. StructureDesc,
  103. nativeStructureDesc,
  104. RapToNative,
  105. TRUE
  106. );
  107. //
  108. // Allocate enough memory to hold the converted native buffer.
  109. //
  110. buffer = NetpMemoryAllocate( bufferSize );
  111. if ( buffer == NULL ) {
  112. IF_DEBUG(ERRORS) {
  113. NetpKdPrint(( "XsNetGroupAdd: failed to create buffer" ));
  114. }
  115. Header->Status = NERR_NoRoom;
  116. goto cleanup;
  117. }
  118. IF_DEBUG(GROUP) {
  119. NetpKdPrint(( "XsNetGroupAdd: buffer of %ld bytes at %lx\n",
  120. bufferSize, buffer ));
  121. }
  122. //
  123. // Convert the buffer from 16-bit to 32-bit.
  124. //
  125. stringLocation = (LPBYTE)buffer + bufferSize;
  126. bytesRequired = 0;
  127. status = RapConvertSingleEntry(
  128. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  129. StructureDesc,
  130. TRUE,
  131. buffer,
  132. buffer,
  133. nativeStructureDesc,
  134. FALSE,
  135. &stringLocation,
  136. &bytesRequired,
  137. Response,
  138. RapToNative
  139. );
  140. if ( status != NERR_Success ) {
  141. IF_DEBUG(ERRORS) {
  142. NetpKdPrint(( "XsNetGroupAdd: RapConvertSingleEntry failed: "
  143. "%X\n", status ));
  144. }
  145. Header->Status = NERR_InternalError;
  146. goto cleanup;
  147. }
  148. //
  149. // Make the local call.
  150. //
  151. status = NetGroupAdd(
  152. NULL,
  153. (DWORD)SmbGetUshort( &parameters->Level ),
  154. buffer,
  155. NULL
  156. );
  157. if ( !XsApiSuccess( status )) {
  158. IF_DEBUG(ERRORS) {
  159. NetpKdPrint(( "XsNetGroupAdd: NetGroupAdd failed: %X\n", status ));
  160. }
  161. Header->Status = (WORD)status;
  162. goto cleanup;
  163. }
  164. //
  165. // There is no real return information for this API.
  166. //
  167. cleanup:
  168. ;
  169. } except( EXCEPTION_EXECUTE_HANDLER ) {
  170. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  171. }
  172. NetpMemoryFree( buffer );
  173. return STATUS_SUCCESS;
  174. } // XsNetGroupAdd
  175. NTSTATUS
  176. XsNetGroupAddUser (
  177. API_HANDLER_PARAMETERS
  178. )
  179. /*++
  180. Routine Description:
  181. This routine handles a call to NetGroupAddUser.
  182. Arguments:
  183. API_HANDLER_PARAMETERS - information about the API call. See
  184. XsTypes.h for details.
  185. Return Value:
  186. NTSTATUS - STATUS_SUCCESS or reason for failure.
  187. --*/
  188. {
  189. NET_API_STATUS status;
  190. PXS_NET_GROUP_ADD_USER parameters = Parameters;
  191. LPTSTR nativeGroupName = NULL; // Native parameters
  192. LPTSTR nativeUserName = NULL;
  193. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  194. try {
  195. //
  196. // Translate parameters, check for errors.
  197. //
  198. XsConvertTextParameter(
  199. nativeGroupName,
  200. (LPSTR)XsSmbGetPointer( &parameters->GroupName )
  201. );
  202. XsConvertTextParameter(
  203. nativeUserName,
  204. (LPSTR)XsSmbGetPointer( &parameters->UserName )
  205. );
  206. //
  207. // Make the local call.
  208. //
  209. status = NetGroupAddUser(
  210. NULL,
  211. nativeGroupName,
  212. nativeUserName
  213. );
  214. if ( !XsApiSuccess( status )) {
  215. IF_DEBUG(ERRORS) {
  216. NetpKdPrint(( "XsNetGroupAddUser: NetGroupAddUser failed: %X\n",
  217. status ));
  218. }
  219. }
  220. cleanup:
  221. ;
  222. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  223. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  224. }
  225. NetpMemoryFree( nativeGroupName );
  226. NetpMemoryFree( nativeUserName );
  227. //
  228. // Nothing to return.
  229. //
  230. Header->Status = (WORD)status;
  231. return STATUS_SUCCESS;
  232. } // XsNetGroupAddUser
  233. NTSTATUS
  234. XsNetGroupDel (
  235. API_HANDLER_PARAMETERS
  236. )
  237. /*++
  238. Routine Description:
  239. This routine handles a call to NetGroupDel.
  240. Arguments:
  241. API_HANDLER_PARAMETERS - information about the API call. See
  242. XsTypes.h for details.
  243. Return Value:
  244. NTSTATUS - STATUS_SUCCESS or reason for failure.
  245. --*/
  246. {
  247. NET_API_STATUS status;
  248. PXS_NET_GROUP_DEL parameters = Parameters;
  249. LPTSTR nativeGroupName = NULL; // Native parameters
  250. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  251. IF_DEBUG(GROUP) {
  252. NetpKdPrint(( "XsNetGroupDel: header at %lx, params at %lx, name %s\n",
  253. Header, parameters,
  254. SmbGetUlong( &parameters->GroupName )));
  255. }
  256. try {
  257. //
  258. // Translate parameters, check for errors.
  259. //
  260. XsConvertTextParameter(
  261. nativeGroupName,
  262. (LPSTR)XsSmbGetPointer( &parameters->GroupName )
  263. );
  264. //
  265. // Make the local call.
  266. //
  267. status = NetGroupDel(
  268. NULL,
  269. nativeGroupName
  270. );
  271. if ( !XsApiSuccess( status )) {
  272. IF_DEBUG(ERRORS) {
  273. NetpKdPrint(( "XsNetGroupDel: NetGroupDel failed: %X\n", status ));
  274. }
  275. }
  276. cleanup:
  277. ;
  278. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  279. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  280. }
  281. NetpMemoryFree( nativeGroupName );
  282. //
  283. // Nothing to return.
  284. //
  285. Header->Status = (WORD)status;
  286. return STATUS_SUCCESS;
  287. } // XsNetGroupDel
  288. NTSTATUS
  289. XsNetGroupDelUser (
  290. API_HANDLER_PARAMETERS
  291. )
  292. /*++
  293. Routine Description:
  294. This routine handles a call to NetGroupDelUser.
  295. Arguments:
  296. API_HANDLER_PARAMETERS - information about the API call. See
  297. XsTypes.h for details.
  298. Return Value:
  299. NTSTATUS - STATUS_SUCCESS or reason for failure.
  300. --*/
  301. {
  302. NET_API_STATUS status;
  303. PXS_NET_GROUP_DEL_USER parameters = Parameters;
  304. LPTSTR nativeGroupName = NULL; // Native parameters
  305. LPTSTR nativeUserName = NULL;
  306. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  307. try {
  308. //
  309. // Translate parameters, check for errors.
  310. //
  311. XsConvertTextParameter(
  312. nativeGroupName,
  313. (LPSTR)XsSmbGetPointer( &parameters->GroupName )
  314. );
  315. XsConvertTextParameter(
  316. nativeUserName,
  317. (LPSTR)XsSmbGetPointer( &parameters->UserName )
  318. );
  319. //
  320. // Make the local call.
  321. //
  322. status = NetGroupDelUser(
  323. NULL,
  324. nativeGroupName,
  325. nativeUserName
  326. );
  327. if ( !XsApiSuccess( status )) {
  328. IF_DEBUG(ERRORS) {
  329. NetpKdPrint(( "XsNetGroupDelUser: NetGroupDelUser failed: %X\n",
  330. status ));
  331. }
  332. }
  333. cleanup:
  334. ;
  335. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  336. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  337. }
  338. NetpMemoryFree( nativeGroupName );
  339. NetpMemoryFree( nativeUserName );
  340. //
  341. // Nothing to return.
  342. //
  343. Header->Status = (WORD)status;
  344. return STATUS_SUCCESS;
  345. } // XsNetGroupDelUser
  346. NTSTATUS
  347. XsNetGroupEnum (
  348. API_HANDLER_PARAMETERS
  349. )
  350. /*++
  351. Routine Description:
  352. This routine handles a call to NetGroupEnum.
  353. Arguments:
  354. API_HANDLER_PARAMETERS - information about the API call. See
  355. XsTypes.h for details.
  356. Return Value:
  357. NTSTATUS - STATUS_SUCCESS or reason for failure.
  358. --*/
  359. {
  360. NET_API_STATUS status;
  361. PXS_NET_GROUP_ENUM parameters = Parameters;
  362. LPVOID outBuffer= NULL; // Native parameters
  363. DWORD entriesRead;
  364. DWORD totalEntries;
  365. DWORD entriesFilled = 0; // Conversion variables
  366. DWORD bytesRequired = 0;
  367. LPDESC nativeStructureDesc;
  368. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  369. IF_DEBUG(GROUP) {
  370. NetpKdPrint(( "XsNetGroupEnum: header at %lx, params at %lx, "
  371. "level %ld, buf size %ld\n",
  372. Header, parameters, SmbGetUshort( &parameters->Level ),
  373. SmbGetUshort( &parameters->BufLen )));
  374. }
  375. try {
  376. //
  377. // Check for errors.
  378. //
  379. if ( XsWordParamOutOfRange( parameters->Level, 0, 1 )) {
  380. Header->Status = ERROR_INVALID_LEVEL;
  381. goto cleanup;
  382. }
  383. //
  384. // Make the local call.
  385. //
  386. status = NetGroupEnum(
  387. NULL,
  388. (DWORD)SmbGetUshort( &parameters->Level ),
  389. (LPBYTE *)&outBuffer,
  390. XsNativeBufferSize( SmbGetUshort( &parameters->BufLen )),
  391. &entriesRead,
  392. &totalEntries,
  393. NULL
  394. );
  395. if ( !XsApiSuccess( status )) {
  396. IF_DEBUG(API_ERRORS) {
  397. NetpKdPrint(( "XsNetGroupEnum: NetGroupEnum failed: %X\n",
  398. status ));
  399. }
  400. Header->Status = (WORD)status;
  401. goto cleanup;
  402. }
  403. IF_DEBUG(GROUP) {
  404. NetpKdPrint(( "XsNetGroupEnum: received %ld entries at %lx\n",
  405. entriesRead, outBuffer ));
  406. }
  407. //
  408. // Use the requested level to determine the format of the
  409. // data structure.
  410. //
  411. switch ( SmbGetUshort( &parameters->Level ) ) {
  412. case 0:
  413. nativeStructureDesc = Desc32_group_info_0;
  414. StructureDesc = Desc16_group_info_0;
  415. break;
  416. case 1:
  417. nativeStructureDesc = Desc32_group_info_1;
  418. StructureDesc = Desc16_group_info_1;
  419. break;
  420. }
  421. //
  422. // Do the actual conversion from the 32-bit structures to 16-bit
  423. // structures.
  424. //
  425. XsFillEnumBuffer(
  426. outBuffer,
  427. entriesRead,
  428. nativeStructureDesc,
  429. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  430. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  431. SmbGetUshort( &parameters->BufLen ),
  432. StructureDesc,
  433. NULL, // verify function
  434. &bytesRequired,
  435. &entriesFilled,
  436. NULL
  437. );
  438. IF_DEBUG(GROUP) {
  439. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR,"
  440. " Entries %ld of %ld\n",
  441. outBuffer, SmbGetUlong( &parameters->Buffer ),
  442. bytesRequired, entriesFilled, totalEntries ));
  443. }
  444. //
  445. // If all the entries could not be filled, return ERROR_MORE_DATA,
  446. // and return the buffer as is. Otherwise, the data needs to be
  447. // packed so that we don't send too much useless data.
  448. //
  449. if ( entriesFilled < totalEntries ) {
  450. Header->Status = ERROR_MORE_DATA;
  451. } else {
  452. Header->Converter = XsPackReturnData(
  453. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  454. SmbGetUshort( &parameters->BufLen ),
  455. StructureDesc,
  456. entriesFilled
  457. );
  458. }
  459. //
  460. // Set up the response parameters.
  461. //
  462. SmbPutUshort( &parameters->EntriesRead, (WORD)entriesFilled );
  463. SmbPutUshort( &parameters->TotalAvail, (WORD)totalEntries );
  464. cleanup:
  465. ;
  466. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  467. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  468. }
  469. NetApiBufferFree( outBuffer );
  470. //
  471. // Determine return buffer size.
  472. //
  473. XsSetDataCount(
  474. &parameters->BufLen,
  475. StructureDesc,
  476. Header->Converter,
  477. entriesFilled,
  478. Header->Status
  479. );
  480. return STATUS_SUCCESS;
  481. } // XsNetGroupEnum
  482. NTSTATUS
  483. XsNetGroupGetInfo (
  484. API_HANDLER_PARAMETERS
  485. )
  486. /*++
  487. Routine Description:
  488. This routine handles a call to NetGroupGetInfo.
  489. Arguments:
  490. API_HANDLER_PARAMETERS - information about the API call. See
  491. XsTypes.h for details.
  492. Return Value:
  493. NTSTATUS - STATUS_SUCCESS or reason for failure.
  494. --*/
  495. {
  496. NET_API_STATUS status;
  497. PXS_NET_GROUP_GET_INFO parameters = Parameters;
  498. LPTSTR nativeGroupName = NULL; // Native parameters
  499. LPVOID outBuffer = NULL;
  500. LPBYTE stringLocation = NULL; // Conversion variables
  501. DWORD bytesRequired = 0;
  502. LPDESC nativeStructureDesc;
  503. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  504. IF_DEBUG(GROUP) {
  505. NetpKdPrint(( "XsNetGroupGetInfo: header at %lx, "
  506. "params at %lx, level %ld\n",
  507. Header, parameters, SmbGetUshort( &parameters->Level ) ));
  508. }
  509. try {
  510. //
  511. // Translate parameters, check for errors.
  512. //
  513. if ( XsWordParamOutOfRange( parameters->Level, 0, 1 )) {
  514. Header->Status = ERROR_INVALID_LEVEL;
  515. goto cleanup;
  516. }
  517. XsConvertTextParameter(
  518. nativeGroupName,
  519. (LPSTR)XsSmbGetPointer( &parameters->GroupName )
  520. );
  521. //
  522. // Make the local call.
  523. //
  524. status = NetGroupGetInfo(
  525. NULL,
  526. nativeGroupName,
  527. (DWORD)SmbGetUshort( &parameters->Level ),
  528. (LPBYTE *)&outBuffer
  529. );
  530. if ( !XsApiSuccess( status )) {
  531. IF_DEBUG(API_ERRORS) {
  532. NetpKdPrint(( "XsNetGroupGetInfo: NetGroupGetInfo failed: "
  533. "%X\n", status ));
  534. }
  535. Header->Status = (WORD)status;
  536. goto cleanup;
  537. }
  538. //
  539. // Use the requested level to determine the format of the
  540. // data structure.
  541. //
  542. switch ( SmbGetUshort( &parameters->Level ) ) {
  543. case 0:
  544. nativeStructureDesc = Desc32_group_info_0;
  545. StructureDesc = Desc16_group_info_0;
  546. break;
  547. case 1:
  548. nativeStructureDesc = Desc32_group_info_1;
  549. StructureDesc = Desc16_group_info_1;
  550. break;
  551. }
  552. //
  553. // Convert the structure returned by the 32-bit call to a 16-bit
  554. // structure. The last possible location for variable data is
  555. // calculated from buffer location and length.
  556. //
  557. stringLocation = (LPBYTE)( XsSmbGetPointer( &parameters->Buffer )
  558. + SmbGetUshort( &parameters->BufLen ) );
  559. status = RapConvertSingleEntry(
  560. outBuffer,
  561. nativeStructureDesc,
  562. FALSE,
  563. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  564. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  565. StructureDesc,
  566. TRUE,
  567. &stringLocation,
  568. &bytesRequired,
  569. Response,
  570. NativeToRap
  571. );
  572. if ( status != NERR_Success ) {
  573. IF_DEBUG(ERRORS) {
  574. NetpKdPrint(( "XsNetGroupGetInfo: RapConvertSingleEntry failed: "
  575. "%X\n", status ));
  576. }
  577. Header->Status = NERR_InternalError;
  578. goto cleanup;
  579. }
  580. IF_DEBUG(GROUP) {
  581. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR\n",
  582. outBuffer, SmbGetUlong( &parameters->Buffer ),
  583. bytesRequired ));
  584. }
  585. //
  586. // Determine return code based on the size of the buffer.
  587. //
  588. if ( !XsCheckBufferSize(
  589. SmbGetUshort( &parameters->BufLen ),
  590. StructureDesc,
  591. FALSE // not in native format
  592. )) {
  593. IF_DEBUG(ERRORS) {
  594. NetpKdPrint(( "XsNetGroupGetInfo: Buffer too small %ld s.b. %ld.\n",
  595. SmbGetUshort( &parameters->BufLen ),
  596. RapStructureSize(
  597. StructureDesc,
  598. Response,
  599. FALSE ) ));
  600. }
  601. Header->Status = NERR_BufTooSmall;
  602. } else if ( bytesRequired > (DWORD)SmbGetUshort( &parameters-> BufLen )) {
  603. IF_DEBUG(ERRORS) {
  604. NetpKdPrint(( "NetGroupGetInfo: More data available.\n" ));
  605. }
  606. Header->Status = ERROR_MORE_DATA;
  607. } else {
  608. //
  609. // Pack the response data.
  610. //
  611. Header->Converter = XsPackReturnData(
  612. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  613. SmbGetUshort( &parameters->BufLen ),
  614. StructureDesc,
  615. 1
  616. );
  617. }
  618. //
  619. // Set up the response parameters.
  620. //
  621. SmbPutUshort( &parameters->TotalAvail, (WORD)bytesRequired );
  622. cleanup:
  623. ;
  624. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  625. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  626. }
  627. NetApiBufferFree( outBuffer );
  628. NetpMemoryFree( nativeGroupName );
  629. //
  630. // Determine return buffer size.
  631. //
  632. XsSetDataCount(
  633. &parameters->BufLen,
  634. StructureDesc,
  635. Header->Converter,
  636. 1,
  637. Header->Status
  638. );
  639. return STATUS_SUCCESS;
  640. } // XsNetGroupGetInfo
  641. NTSTATUS
  642. XsNetGroupGetUsers (
  643. API_HANDLER_PARAMETERS
  644. )
  645. /*++
  646. Routine Description:
  647. This routine handles a call to NetGroupGetUsers.
  648. Arguments:
  649. API_HANDLER_PARAMETERS - information about the API call. See
  650. XsTypes.h for details.
  651. Return Value:
  652. NTSTATUS - STATUS_SUCCESS or reason for failure.
  653. --*/
  654. {
  655. NET_API_STATUS status;
  656. PXS_NET_GROUP_GET_USERS parameters = Parameters;
  657. LPTSTR nativeGroupName = NULL; // Native parameters
  658. LPVOID outBuffer= NULL;
  659. DWORD entriesRead;
  660. DWORD totalEntries;
  661. DWORD entriesFilled = 0; // Conversion variables
  662. DWORD bytesRequired = 0;
  663. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  664. IF_DEBUG(GROUP) {
  665. NetpKdPrint(( "XsNetGroupGetUsers: header at %lx, params at %lx, "
  666. "level %ld, buf size %ld\n",
  667. Header, parameters, SmbGetUshort( &parameters->Level ),
  668. SmbGetUshort( &parameters->BufLen )));
  669. }
  670. try {
  671. //
  672. // Translate parameters, check for errors.
  673. //
  674. if ( SmbGetUshort( &parameters->Level ) != 0 ) {
  675. Header->Status = ERROR_INVALID_LEVEL;
  676. goto cleanup;
  677. }
  678. XsConvertTextParameter(
  679. nativeGroupName,
  680. (LPSTR)XsSmbGetPointer( &parameters->GroupName )
  681. );
  682. //
  683. // Make the local call.
  684. //
  685. status = NetGroupGetUsers(
  686. NULL,
  687. nativeGroupName,
  688. (DWORD)SmbGetUshort( &parameters->Level ),
  689. (LPBYTE *)&outBuffer,
  690. XsNativeBufferSize( SmbGetUshort( &parameters->BufLen )),
  691. &entriesRead,
  692. &totalEntries,
  693. NULL
  694. );
  695. if ( !XsApiSuccess( status )) {
  696. IF_DEBUG(API_ERRORS) {
  697. NetpKdPrint(( "XsNetGroupGetUsers: NetGroupGetUsers failed: %X\n",
  698. status ));
  699. }
  700. Header->Status = (WORD)status;
  701. goto cleanup;
  702. }
  703. IF_DEBUG(GROUP) {
  704. NetpKdPrint(( "XsNetGroupGetUsers: received %ld entries at %lx\n",
  705. entriesRead, outBuffer ));
  706. }
  707. //
  708. // Do the conversion from 32- to 16-bit data.
  709. //
  710. XsFillEnumBuffer(
  711. outBuffer,
  712. entriesRead,
  713. Desc32_group_users_info_0,
  714. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  715. (LPVOID)XsSmbGetPointer( &parameters->Buffer ),
  716. SmbGetUshort( &parameters->BufLen ),
  717. Desc16_group_users_info_0,
  718. NULL, // verify function
  719. &bytesRequired,
  720. &entriesFilled,
  721. NULL
  722. );
  723. IF_DEBUG(GROUP) {
  724. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR,"
  725. " Entries %ld of %ld\n",
  726. outBuffer, SmbGetUlong( &parameters->Buffer ),
  727. bytesRequired, entriesFilled, totalEntries ));
  728. }
  729. //
  730. // If there is no room for one fixed structure, return NERR_BufTooSmall.
  731. // If all the entries could not be filled, return ERROR_MORE_DATA,
  732. // and return the buffer as is. GROUP_USERS_INFO_0 structures don't
  733. // need to be packed, because they have no variable data.
  734. //
  735. if ( !XsCheckBufferSize(
  736. SmbGetUshort( &parameters->BufLen ),
  737. Desc16_group_users_info_0,
  738. FALSE // not in native format
  739. )) {
  740. Header->Status = NERR_BufTooSmall;
  741. } else if ( entriesFilled < totalEntries ) {
  742. Header->Status = ERROR_MORE_DATA;
  743. }
  744. //
  745. // Set up the response parameters.
  746. //
  747. SmbPutUshort( &parameters->EntriesRead, (WORD)entriesFilled );
  748. SmbPutUshort( &parameters->TotalAvail, (WORD)totalEntries );
  749. cleanup:
  750. ;
  751. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  752. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  753. }
  754. NetApiBufferFree( outBuffer );
  755. NetpMemoryFree( nativeGroupName );
  756. //
  757. // Determine return buffer size.
  758. //
  759. XsSetDataCount(
  760. &parameters->BufLen,
  761. Desc16_group_users_info_0,
  762. Header->Converter,
  763. entriesFilled,
  764. Header->Status
  765. );
  766. return STATUS_SUCCESS;
  767. } // XsNetGroupGetUsers
  768. NTSTATUS
  769. XsNetGroupSetInfo (
  770. API_HANDLER_PARAMETERS
  771. )
  772. /*++
  773. Routine Description:
  774. This routine handles a call to NetGroupSetInfo.
  775. Arguments:
  776. API_HANDLER_PARAMETERS - information about the API call. See
  777. XsTypes.h for details.
  778. Return Value:
  779. NTSTATUS - STATUS_SUCCESS or reason for failure.
  780. --*/
  781. {
  782. NET_API_STATUS status;
  783. PXS_NET_GROUP_SET_INFO parameters = Parameters;
  784. LPTSTR nativeGroupName = NULL; // Native parameters
  785. LPVOID buffer = NULL;
  786. WORD fieldIndex; // Conversion variables
  787. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  788. try {
  789. //
  790. // Translate parameters, check for errors.
  791. //
  792. if ( SmbGetUshort( &parameters->Level ) != 1 ) {
  793. Header->Status = ERROR_INVALID_LEVEL;
  794. goto cleanup;
  795. }
  796. XsConvertTextParameter(
  797. nativeGroupName,
  798. (LPSTR)XsSmbGetPointer( &parameters->GroupName )
  799. );
  800. //
  801. // Translate parmnum to a field number.
  802. //
  803. fieldIndex = SmbGetUshort( &parameters->ParmNum );
  804. fieldIndex = ( fieldIndex == PARMNUM_ALL ) ?
  805. PARMNUM_ALL : fieldIndex + 1;
  806. status = XsConvertSetInfoBuffer(
  807. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  808. SmbGetUshort( &parameters->BufLen ),
  809. fieldIndex,
  810. TRUE,
  811. TRUE,
  812. Desc16_group_info_1,
  813. Desc32_group_info_1,
  814. Desc16_group_info_1_setinfo,
  815. Desc32_group_info_1_setinfo,
  816. (LPBYTE *)&buffer,
  817. NULL
  818. );
  819. if ( status != NERR_Success ) {
  820. IF_DEBUG(ERRORS) {
  821. NetpKdPrint(( "XsNetGroupSetInfo: Problem with conversion: %X\n",
  822. status ));
  823. }
  824. Header->Status = (WORD)status;
  825. goto cleanup;
  826. }
  827. //
  828. // Do the actual local call.
  829. //
  830. status = NetGroupSetInfo(
  831. NULL,
  832. nativeGroupName,
  833. XsLevelFromParmNum( SmbGetUshort( &parameters->Level ),
  834. SmbGetUshort( &parameters->ParmNum )),
  835. buffer,
  836. NULL
  837. );
  838. if ( !XsApiSuccess( status )) {
  839. IF_DEBUG(ERRORS) {
  840. NetpKdPrint(( "XsNetGroupSetInfo: NetGroupSetInfo failed: %X\n",
  841. status ));
  842. }
  843. Header->Status = (WORD)status;
  844. goto cleanup;
  845. }
  846. //
  847. // No return information for this API.
  848. //
  849. cleanup:
  850. ;
  851. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  852. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  853. }
  854. //
  855. // If there is a native 32-bit buffer, free it.
  856. //
  857. NetpMemoryFree( buffer );
  858. NetpMemoryFree( nativeGroupName );
  859. return STATUS_SUCCESS;
  860. } // XsNetGroupSetInfo
  861. NTSTATUS
  862. XsNetGroupSetUsers (
  863. API_HANDLER_PARAMETERS
  864. )
  865. /*++
  866. Routine Description:
  867. This routine handles a call to NetGroupSetUsers.
  868. Arguments:
  869. API_HANDLER_PARAMETERS - information about the API call. See
  870. XsTypes.h for details.
  871. Return Value:
  872. NTSTATUS - STATUS_SUCCESS or reason for failure.
  873. --*/
  874. {
  875. NET_API_STATUS status;
  876. PXS_NET_GROUP_SET_USERS parameters = Parameters;
  877. LPTSTR nativeGroupName = NULL; // Native parameters
  878. LPBYTE actualBuffer = NULL;
  879. DWORD userCount;
  880. LPBYTE stringLocation = NULL; // Conversion variables
  881. LPVOID buffer = NULL;
  882. DWORD bytesRequired = 0;
  883. LPDESC longDescriptor = NULL;
  884. LPDESC longNativeDescriptor = NULL;
  885. DWORD bufferSize;
  886. DWORD i;
  887. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  888. IF_DEBUG(GROUP) {
  889. NetpKdPrint(( "XsNetGroupSetUsers: header at %lx, params at %lx,"
  890. "level %ld\n",
  891. Header, parameters, SmbGetUshort( &parameters->Level ) ));
  892. }
  893. try {
  894. //
  895. // Translate parameters, check for errors.
  896. //
  897. if ( SmbGetUshort( &parameters->Level ) != 0 ) {
  898. Header->Status = ERROR_INVALID_LEVEL;
  899. goto cleanup;
  900. }
  901. StructureDesc = Desc16_group_users_info_0_set;
  902. AuxStructureDesc = Desc16_group_users_info_0;
  903. XsConvertTextParameter(
  904. nativeGroupName,
  905. (LPSTR)XsSmbGetPointer( &parameters->GroupName )
  906. );
  907. //
  908. // Use the count of group_users_info_0 structures to form a long
  909. // descriptor string which can be used to do all the conversion
  910. // in one pass.
  911. //
  912. userCount = (DWORD)SmbGetUshort( &parameters->Entries );
  913. longDescriptor = NetpMemoryAllocate(
  914. strlen( StructureDesc )
  915. + strlen( AuxStructureDesc ) * userCount
  916. + 1 );
  917. longNativeDescriptor = NetpMemoryAllocate(
  918. strlen( Desc32_group_users_info_0_set )
  919. + strlen( Desc32_group_users_info_0 ) * userCount
  920. + 1 );
  921. if (( longDescriptor == NULL ) || ( longNativeDescriptor == NULL )) {
  922. IF_DEBUG(ERRORS) {
  923. NetpKdPrint(( "XsNetGroupSetUsers: failed to allocate memory" ));
  924. }
  925. Header->Status = NERR_NoRoom;
  926. goto cleanup;
  927. }
  928. strcpy( longDescriptor, StructureDesc );
  929. strcpy( longNativeDescriptor, Desc32_group_users_info_0_set );
  930. for ( i = 0; i < userCount; i++ ) {
  931. strcat( longDescriptor, AuxStructureDesc );
  932. strcat( longNativeDescriptor, Desc32_group_users_info_0 );
  933. }
  934. //
  935. // Figure out if there is enough room in the buffer for all this
  936. // data. If not, return NERR_BufTooSmall.
  937. //
  938. if ( !XsCheckBufferSize(
  939. SmbGetUshort( &parameters->BufLen ),
  940. longDescriptor,
  941. FALSE // not in native format
  942. )) {
  943. IF_DEBUG(ERRORS) {
  944. NetpKdPrint(( "XsNetGroupSetUsers: Buffer too small.\n" ));
  945. }
  946. Header->Status = NERR_BufTooSmall;
  947. goto cleanup;
  948. }
  949. //
  950. // Find out how big a buffer we need to allocate to hold the native
  951. // 32-bit version of the input data structure.
  952. //
  953. bufferSize = XsBytesForConvertedStructure(
  954. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  955. longDescriptor,
  956. longNativeDescriptor,
  957. RapToNative,
  958. TRUE
  959. );
  960. //
  961. // Allocate enough memory to hold the converted native buffer.
  962. //
  963. buffer = NetpMemoryAllocate( bufferSize );
  964. if ( buffer == NULL ) {
  965. IF_DEBUG(ERRORS) {
  966. NetpKdPrint(( "XsNetGroupSetUsers: failed to create buffer" ));
  967. }
  968. Header->Status = NERR_NoRoom;
  969. goto cleanup;
  970. }
  971. IF_DEBUG(GROUP) {
  972. NetpKdPrint(( "XsNetGroupSetUsers: buffer of %ld bytes at %lx\n",
  973. bufferSize, buffer ));
  974. }
  975. //
  976. // Convert the buffer from 16-bit to 32-bit.
  977. //
  978. stringLocation = (LPBYTE)buffer + bufferSize;
  979. bytesRequired = 0;
  980. status = RapConvertSingleEntry(
  981. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  982. longDescriptor,
  983. TRUE,
  984. buffer,
  985. buffer,
  986. longNativeDescriptor,
  987. FALSE,
  988. &stringLocation,
  989. &bytesRequired,
  990. Response,
  991. RapToNative
  992. );
  993. if ( status != NERR_Success ) {
  994. IF_DEBUG(ERRORS) {
  995. NetpKdPrint(( "XsNetGroupSetUsers: RapConvertSingleEntry failed: "
  996. "%X\n", status ));
  997. }
  998. Header->Status = NERR_InternalError;
  999. goto cleanup;
  1000. }
  1001. //
  1002. // Check if we got all the entries. If not, we'll quit.
  1003. //
  1004. if ( RapAuxDataCount( buffer, Desc32_group_users_info_0_set, Both, TRUE )
  1005. != userCount ) {
  1006. Header->Status = NERR_BufTooSmall;
  1007. goto cleanup;
  1008. }
  1009. //
  1010. // If there are no entries, there's no data. Otherwise, the data comes
  1011. // after an initial header structure.
  1012. //
  1013. if ( userCount > 0 ) {
  1014. actualBuffer = (LPBYTE)buffer + RapStructureSize(
  1015. Desc32_group_users_info_0_set,
  1016. Both,
  1017. TRUE
  1018. );
  1019. } else {
  1020. actualBuffer = NULL;
  1021. }
  1022. //
  1023. // Make the local call.
  1024. //
  1025. status = NetGroupSetUsers(
  1026. NULL,
  1027. nativeGroupName,
  1028. (DWORD)SmbGetUshort( &parameters->Level ),
  1029. actualBuffer,
  1030. userCount
  1031. );
  1032. if ( !XsApiSuccess( status )) {
  1033. IF_DEBUG(ERRORS) {
  1034. NetpKdPrint(( "XsNetGroupSetUsers: NetGroupSetUsers failed: %X\n",
  1035. status ));
  1036. }
  1037. Header->Status = (WORD)status;
  1038. goto cleanup;
  1039. }
  1040. //
  1041. // There is no real return information for this API.
  1042. //
  1043. cleanup:
  1044. ;
  1045. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  1046. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  1047. }
  1048. NetpMemoryFree( nativeGroupName );
  1049. NetpMemoryFree( buffer );
  1050. NetpMemoryFree( longDescriptor );
  1051. NetpMemoryFree( longNativeDescriptor );
  1052. return STATUS_SUCCESS;
  1053. } // XsNetGroupSetUsers