Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1256 lines
27 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // Global Definitions //
  4. // //
  5. //////////////////////////////////////////////////////////////////////////////
  6. //////////////////////////////////////////////////////////////////////////////
  7. // //
  8. // Global Variables //
  9. // //
  10. //////////////////////////////////////////////////////////////////////////////
  11. NTSTATUS Status;
  12. OBJECT_ATTRIBUTES ObjectAttributes;
  13. STRING EventName;
  14. UNICODE_STRING UnicodeEventName;
  15. HANDLE EventHandle;
  16. UNICODE_STRING PortName;
  17. HANDLE EarPort;
  18. HANDLE TalkPort;
  19. PORT_MESSAGE RequestMessage;
  20. SECURITY_QUALITY_OF_SERVICE SecurityQos;
  21. ULONG RequestCount;
  22. HANDLE ClientToken;
  23. TOKEN_STATISTICS ClientTokenStatistics;
  24. ULONG IgnoreLength;
  25. HANDLE SepServerThread;
  26. //////////////////////////////////////////////////////////////////////////////
  27. // //
  28. // Test Routine Definitions //
  29. // //
  30. //////////////////////////////////////////////////////////////////////////////
  31. BOOLEAN
  32. SepClientTestStatic(VOID);
  33. BOOLEAN
  34. SepClientTestDynamic(VOID);
  35. BOOLEAN
  36. SepClientTestEffectiveOnly(
  37. BOOLEAN StaticTest
  38. );
  39. BOOLEAN
  40. SepClientTestNotEffectiveOnly(
  41. BOOLEAN StaticTest
  42. );
  43. BOOLEAN
  44. SepClientTestAnonymous(
  45. BOOLEAN StaticTest,
  46. BOOLEAN EffectiveOnly
  47. );
  48. BOOLEAN
  49. SepClientTestIdentification(
  50. BOOLEAN StaticTest,
  51. BOOLEAN EffectiveOnly
  52. );
  53. BOOLEAN
  54. SepClientTestImpersonation(
  55. BOOLEAN StaticTest,
  56. BOOLEAN EffectiveOnly
  57. );
  58. VOID
  59. SepClientConnect(
  60. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
  61. SECURITY_CONTEXT_TRACKING_MODE TrackingMode,
  62. BOOLEAN EffectiveOnly
  63. );
  64. VOID
  65. SepClientMakeRemoteCall( VOID );
  66. VOID
  67. SepClientDropConnection( VOID );
  68. BOOLEAN
  69. SepClientTest(VOID);
  70. NTSTATUS
  71. SepClientInitialize(
  72. );
  73. BOOLEAN
  74. SepServerTestStatic(VOID);
  75. BOOLEAN
  76. SepServerTestDynamic(VOID);
  77. BOOLEAN
  78. SepServerTestEffectiveOnly(
  79. BOOLEAN StaticTest
  80. );
  81. BOOLEAN
  82. SepServerTestNotEffectiveOnly(
  83. BOOLEAN StaticTest
  84. );
  85. BOOLEAN
  86. SepServerTestAnonymous(
  87. BOOLEAN StaticTest,
  88. BOOLEAN EffectiveOnly
  89. );
  90. BOOLEAN
  91. SepServerTestIdentification(
  92. BOOLEAN StaticTest,
  93. BOOLEAN EffectiveOnly
  94. );
  95. BOOLEAN
  96. SepServerTestImpersonation(
  97. BOOLEAN StaticTest,
  98. BOOLEAN EffectiveOnly
  99. );
  100. VOID
  101. SepServerWaitForNextConnect( VOID );
  102. VOID
  103. SepServerGetNextMessage( VOID );
  104. VOID
  105. SepServerCompleteMessage( VOID );
  106. VOID
  107. SepServerDropConnection( VOID );
  108. BOOLEAN
  109. SepServerTest(VOID);
  110. NTSTATUS
  111. SepServerInitialize(
  112. );
  113. VOID
  114. SepServerSpawnClientProcess(VOID);
  115. BOOLEAN
  116. CtLpcQos (VOID);
  117. //////////////////////////////////////////////////////////////////////////////
  118. // //
  119. // Client-Side Test Routines //
  120. // //
  121. //////////////////////////////////////////////////////////////////////////////
  122. VOID
  123. SepClientConnect(
  124. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
  125. SECURITY_CONTEXT_TRACKING_MODE TrackingMode,
  126. BOOLEAN EffectiveOnly
  127. )
  128. {
  129. SecurityQos.ImpersonationLevel = ImpersonationLevel;
  130. SecurityQos.ContextTrackingMode = TrackingMode;
  131. SecurityQos.EffectiveOnly = EffectiveOnly;
  132. Status = NtConnectPort(
  133. &TalkPort,
  134. &PortName,
  135. &SecurityQos,
  136. 0L,
  137. NULL,
  138. NULL,
  139. NULL,
  140. NULL,
  141. NULL
  142. ); SEASSERT_SUCCESS(Status);
  143. return;
  144. }
  145. VOID
  146. SepClientMakeRemoteCall( VOID )
  147. {
  148. PORT_MESSAGE ReplyMessage;
  149. Status = NtRequestWaitReplyPort(
  150. TalkPort,
  151. &RequestMessage,
  152. &ReplyMessage
  153. );
  154. RequestCount += 1;
  155. return;
  156. }
  157. VOID
  158. SepClientDropConnection( VOID )
  159. {
  160. Status = NtClose( TalkPort ); SEASSERT_SUCCESS(Status);
  161. return;
  162. }
  163. BOOLEAN
  164. SepClientTestStatic(VOID)
  165. {
  166. BOOLEAN CompletionStatus;
  167. //
  168. // Static Context Tracking ... Suite
  169. //
  170. CompletionStatus = SepClientTestEffectiveOnly( TRUE );
  171. if (CompletionStatus == TRUE) {
  172. CompletionStatus = SepClientTestNotEffectiveOnly( TRUE );
  173. }
  174. return CompletionStatus;
  175. }
  176. BOOLEAN
  177. SepClientTestDynamic(VOID)
  178. {
  179. BOOLEAN CompletionStatus;
  180. //
  181. // Dynamic Context Tracking ... Suite
  182. //
  183. CompletionStatus = SepClientTestEffectiveOnly( FALSE );
  184. if (CompletionStatus == TRUE) {
  185. CompletionStatus = SepClientTestNotEffectiveOnly( FALSE );
  186. }
  187. return CompletionStatus;
  188. }
  189. BOOLEAN
  190. SepClientTestEffectiveOnly(
  191. BOOLEAN StaticTest
  192. )
  193. {
  194. BOOLEAN CompletionStatus;
  195. //
  196. // Effective Only ... Test
  197. //
  198. CompletionStatus = SepClientTestAnonymous( StaticTest, TRUE );
  199. if (CompletionStatus == TRUE) {
  200. CompletionStatus = SepClientTestIdentification( StaticTest, TRUE );
  201. }
  202. if (CompletionStatus == TRUE) {
  203. CompletionStatus = SepClientTestImpersonation( StaticTest, TRUE );
  204. }
  205. return CompletionStatus;
  206. }
  207. BOOLEAN
  208. SepClientTestNotEffectiveOnly(
  209. BOOLEAN StaticTest
  210. )
  211. {
  212. BOOLEAN CompletionStatus;
  213. //
  214. // Not Effective Only ... Test
  215. //
  216. CompletionStatus = SepClientTestAnonymous( StaticTest, FALSE );
  217. if (CompletionStatus == TRUE) {
  218. CompletionStatus = SepClientTestIdentification( StaticTest, FALSE );
  219. }
  220. if (CompletionStatus == TRUE) {
  221. CompletionStatus = SepClientTestImpersonation( StaticTest, FALSE );
  222. }
  223. return CompletionStatus;
  224. }
  225. BOOLEAN
  226. SepClientTestAnonymous(
  227. BOOLEAN StaticTest,
  228. BOOLEAN EffectiveOnly
  229. )
  230. {
  231. //////////////////////////////////////////////////////////////////////////
  232. // //
  233. // Anonymous Use Test //
  234. // //
  235. //////////////////////////////////////////////////////////////////////////
  236. SECURITY_CONTEXT_TRACKING_MODE TrackingMode;
  237. if (StaticTest) {
  238. TrackingMode = SECURITY_STATIC_TRACKING;
  239. } else {
  240. TrackingMode = SECURITY_DYNAMIC_TRACKING;
  241. }
  242. if (!StaticTest) {
  243. //
  244. // No action for dynamic test
  245. //
  246. return TRUE;
  247. }
  248. //
  249. // Anonymous Use ... Test
  250. //
  251. SepClientConnect(
  252. SecurityAnonymous,
  253. TrackingMode,
  254. EffectiveOnly
  255. );
  256. SepClientMakeRemoteCall();
  257. SepClientDropConnection();
  258. return TRUE;
  259. }
  260. BOOLEAN
  261. SepClientTestIdentification(
  262. BOOLEAN StaticTest,
  263. BOOLEAN EffectiveOnly
  264. )
  265. {
  266. //////////////////////////////////////////////////////////////////////////
  267. // //
  268. // Identification Use Test //
  269. // //
  270. //////////////////////////////////////////////////////////////////////////
  271. SECURITY_CONTEXT_TRACKING_MODE TrackingMode;
  272. if (StaticTest) {
  273. TrackingMode = SECURITY_STATIC_TRACKING;
  274. } else {
  275. TrackingMode = SECURITY_DYNAMIC_TRACKING;
  276. }
  277. //
  278. // Identification Use ... Test
  279. //
  280. SepClientConnect(
  281. SecurityIdentification,
  282. TrackingMode,
  283. EffectiveOnly
  284. );
  285. SepClientMakeRemoteCall();
  286. SepClientDropConnection();
  287. return TRUE;
  288. }
  289. BOOLEAN
  290. SepClientTestImpersonation(
  291. BOOLEAN StaticTest,
  292. BOOLEAN EffectiveOnly
  293. )
  294. {
  295. //////////////////////////////////////////////////////////////////////////
  296. // //
  297. // Impersonation Use Test //
  298. // //
  299. //////////////////////////////////////////////////////////////////////////
  300. SECURITY_CONTEXT_TRACKING_MODE TrackingMode;
  301. if (StaticTest) {
  302. TrackingMode = SECURITY_STATIC_TRACKING;
  303. } else {
  304. TrackingMode = SECURITY_DYNAMIC_TRACKING;
  305. }
  306. //
  307. // Impersonation Use ... Test
  308. //
  309. SepClientConnect(
  310. SecurityImpersonation,
  311. TrackingMode,
  312. EffectiveOnly
  313. );
  314. SepClientMakeRemoteCall();
  315. SepClientDropConnection();
  316. return TRUE;
  317. }
  318. BOOLEAN
  319. SepClientTest(VOID)
  320. //
  321. // Tests:
  322. //
  323. // Static Context Tracking Tests
  324. // Effective Only
  325. // Anonymous
  326. // Identification
  327. // Impersonation
  328. // Not Effective Only
  329. // Anonymous
  330. // Identification
  331. // Impersonation
  332. //
  333. // Dynamic Context Tracking Tests
  334. // Effective Only
  335. // Identification
  336. // Impersonation
  337. // Not Effective Only
  338. // Identification
  339. // Impersonation
  340. //
  341. {
  342. BOOLEAN CompletionStatus;
  343. //
  344. // Run the static test suite...
  345. //
  346. CompletionStatus = SepClientTestStatic();
  347. //
  348. // Run the dynamic test suite...
  349. //
  350. if (CompletionStatus == TRUE) {
  351. CompletionStatus = SepClientTestDynamic();
  352. }
  353. DbgPrint("Se: Client Test Complete.\n");
  354. return CompletionStatus;
  355. }
  356. NTSTATUS
  357. SepClientInitialize(
  358. )
  359. {
  360. DbgPrint("Se: Client Initializing ...\n");
  361. //
  362. // Initialize global variables
  363. //
  364. RequestMessage.u1.s1.DataLength = 0;
  365. RequestMessage.u1.s1.TotalLength = (CSHORT)sizeof(PORT_MESSAGE);
  366. RequestMessage.u2.ZeroInit = 0;
  367. RequestCount = 0;
  368. //
  369. // Signal the named event to start the test
  370. //
  371. DbgPrint("Se: Client Starting Test ...\n");
  372. Status = NtSetEvent( EventHandle, NULL ); SEASSERT_SUCCESS(Status);
  373. Status = NtClose( EventHandle ); SEASSERT_SUCCESS(Status);
  374. return STATUS_SUCCESS;
  375. }
  376. //////////////////////////////////////////////////////////////////////////////
  377. // //
  378. // Server-Side Test Routines //
  379. // //
  380. //////////////////////////////////////////////////////////////////////////////
  381. VOID
  382. SepServerWaitForNextConnect( VOID )
  383. {
  384. CONNECTION_REQUEST ConnectionRequest;
  385. ConnectionRequest.Length = (ULONG)sizeof(CONNECTION_REQUEST);
  386. //
  387. // Wait for the client to connect to the port
  388. //
  389. Status = NtListenPort(
  390. EarPort,
  391. &ConnectionRequest,
  392. NULL,
  393. 0L
  394. ); SEASSERT_SUCCESS(Status);
  395. Status = NtAcceptConnectPort(
  396. &TalkPort,
  397. NULL,
  398. &ConnectionRequest,
  399. TRUE,
  400. NULL,
  401. NULL,
  402. NULL,
  403. 0L
  404. ); SEASSERT_SUCCESS(Status);
  405. Status = NtCompleteConnectPort( TalkPort ); SEASSERT_SUCCESS(Status);
  406. return;
  407. }
  408. VOID
  409. SepServerGetNextMessage( VOID )
  410. {
  411. //
  412. // Wait for the next message to come in...
  413. //
  414. Status = NtReplyWaitReceivePort(
  415. EarPort,
  416. NULL,
  417. NULL,
  418. &RequestMessage
  419. ); SEASSERT_SUCCESS(Status);
  420. RequestCount += 1;
  421. return;
  422. }
  423. VOID
  424. SepServerCompleteMessage( VOID )
  425. {
  426. PORT_MESSAGE ReplyMessage;
  427. ReplyMessage.u1.s1.DataLength = 0;
  428. ReplyMessage.u1.s1.TotalLength = (CSHORT)sizeof(PORT_MESSAGE);
  429. ReplyMessage.u2.ZeroInit = 0;
  430. ReplyMessage.ClientId = RequestMessage.ClientId;
  431. ReplyMessage.MessageId = RequestMessage.MessageId;
  432. //
  433. // Send the response message
  434. //
  435. Status = NtReplyPort(
  436. EarPort,
  437. &ReplyMessage
  438. ); SEASSERT_SUCCESS(Status);
  439. return;
  440. }
  441. VOID
  442. SepServerImpersonateClient( VOID )
  443. {
  444. Status = NtImpersonateClientOfPort(
  445. TalkPort,
  446. &RequestMessage
  447. ); SEASSERT_SUCCESS(Status);
  448. }
  449. VOID
  450. SepServerRevertToSelf( VOID )
  451. {
  452. NTSTATUS TmpStatus;
  453. HANDLE NullHandle;
  454. NullHandle = NULL;
  455. TmpStatus = NtSetInformationThread(
  456. SepServerThread,
  457. ThreadImpersonationToken,
  458. (PVOID)&NullHandle,
  459. (ULONG)sizeof(HANDLE)
  460. ); SEASSERT_SUCCESS(TmpStatus);
  461. }
  462. VOID
  463. SepServerDropConnection( VOID )
  464. {
  465. Status = NtClose( TalkPort ); SEASSERT_SUCCESS(Status);
  466. return;
  467. }
  468. BOOLEAN
  469. SepServerTestStatic(VOID)
  470. {
  471. BOOLEAN CompletionStatus;
  472. DbgPrint("Se: Static Context Tracking ... Suite\n");
  473. CompletionStatus = SepServerTestEffectiveOnly( TRUE );
  474. if (CompletionStatus == TRUE) {
  475. CompletionStatus = SepServerTestNotEffectiveOnly( TRUE );
  476. }
  477. return CompletionStatus;
  478. }
  479. BOOLEAN
  480. SepServerTestDynamic(VOID)
  481. {
  482. BOOLEAN CompletionStatus;
  483. DbgPrint("Se: Dynamic Context Tracking ... Suite\n");
  484. CompletionStatus = SepServerTestEffectiveOnly( FALSE );
  485. if (CompletionStatus == TRUE) {
  486. CompletionStatus = SepServerTestNotEffectiveOnly( FALSE );
  487. }
  488. return CompletionStatus;
  489. }
  490. BOOLEAN
  491. SepServerTestEffectiveOnly(
  492. BOOLEAN StaticTest
  493. )
  494. {
  495. BOOLEAN CompletionStatus;
  496. DbgPrint("Se: Effective Only ... Test\n");
  497. CompletionStatus = SepServerTestAnonymous( StaticTest, TRUE );
  498. if (CompletionStatus == TRUE) {
  499. CompletionStatus = SepServerTestIdentification( StaticTest, TRUE );
  500. }
  501. if (CompletionStatus == TRUE) {
  502. CompletionStatus = SepServerTestImpersonation( StaticTest, TRUE );
  503. }
  504. return CompletionStatus;
  505. }
  506. BOOLEAN
  507. SepServerTestNotEffectiveOnly(
  508. BOOLEAN StaticTest
  509. )
  510. {
  511. BOOLEAN CompletionStatus;
  512. DbgPrint("Se: Not Effective Only ... Test\n");
  513. CompletionStatus = SepServerTestAnonymous( StaticTest, FALSE );
  514. if (CompletionStatus == TRUE) {
  515. CompletionStatus = SepServerTestIdentification( StaticTest, FALSE );
  516. }
  517. if (CompletionStatus == TRUE) {
  518. CompletionStatus = SepServerTestImpersonation( StaticTest, FALSE );
  519. }
  520. return CompletionStatus;
  521. }
  522. BOOLEAN
  523. SepServerTestAnonymous(
  524. BOOLEAN StaticTest,
  525. BOOLEAN EffectiveOnly
  526. )
  527. {
  528. BOOLEAN CompletionStatus = TRUE;
  529. //////////////////////////////////////////////////////////////////////////
  530. // //
  531. // Anonymous Use Test //
  532. // //
  533. //////////////////////////////////////////////////////////////////////////
  534. if (!StaticTest) {
  535. //
  536. // No action for dynamic test
  537. //
  538. return TRUE;
  539. }
  540. DbgPrint("Se: Anonymous Use ... ");
  541. SepServerWaitForNextConnect();
  542. SepServerGetNextMessage();
  543. SepServerImpersonateClient();
  544. Status = NtOpenThreadToken(
  545. SepServerThread,
  546. TOKEN_ALL_ACCESS,
  547. TRUE,
  548. &ClientToken
  549. );
  550. SepServerRevertToSelf();
  551. if (Status == STATUS_CANT_OPEN_ANONYMOUS) {
  552. DbgPrint(" Succeeded\n");
  553. } else {
  554. DbgPrint("* ! FAILED (srvr) ! *\n");
  555. DbgPrint("Status is: 0x%lx \n", Status );
  556. CompletionStatus = FALSE;
  557. }
  558. SepServerCompleteMessage();
  559. SepServerDropConnection();
  560. //
  561. // Appease the compiler Gods..
  562. //
  563. if (EffectiveOnly) {;}
  564. return CompletionStatus;
  565. }
  566. BOOLEAN
  567. SepServerTestIdentification(
  568. BOOLEAN StaticTest,
  569. BOOLEAN EffectiveOnly
  570. )
  571. {
  572. BOOLEAN CompletionStatus = TRUE;
  573. //////////////////////////////////////////////////////////////////////////
  574. // //
  575. // Identification Use Test //
  576. // //
  577. //////////////////////////////////////////////////////////////////////////
  578. DbgPrint("Se: Identification Use ... ");
  579. SepServerWaitForNextConnect();
  580. SepServerGetNextMessage();
  581. SepServerImpersonateClient();
  582. Status = NtOpenThreadToken(
  583. SepServerThread,
  584. TOKEN_ALL_ACCESS,
  585. TRUE,
  586. &ClientToken
  587. ); SEASSERT_SUCCESS(Status);
  588. SepServerRevertToSelf();
  589. Status = NtQueryInformationToken(
  590. ClientToken,
  591. TokenStatistics,
  592. &ClientTokenStatistics,
  593. (ULONG)sizeof(TOKEN_STATISTICS),
  594. &IgnoreLength
  595. ); SEASSERT_SUCCESS(Status);
  596. if ( (ClientTokenStatistics.TokenType == TokenImpersonation) &&
  597. (ClientTokenStatistics.ImpersonationLevel == SecurityIdentification)
  598. ) {
  599. DbgPrint(" Succeeded\n");
  600. } else {
  601. DbgPrint("* ! FAILED (srvr) ! *\n");
  602. CompletionStatus = FALSE;
  603. }
  604. SepServerCompleteMessage();
  605. SepServerDropConnection();
  606. //
  607. // Appease the compiler Gods..
  608. //
  609. if (StaticTest) {;}
  610. if (EffectiveOnly) {;}
  611. return CompletionStatus;
  612. }
  613. BOOLEAN
  614. SepServerTestImpersonation(
  615. BOOLEAN StaticTest,
  616. BOOLEAN EffectiveOnly
  617. )
  618. {
  619. BOOLEAN CompletionStatus = TRUE;
  620. //////////////////////////////////////////////////////////////////////////
  621. // //
  622. // Impersonation Use Test //
  623. // //
  624. //////////////////////////////////////////////////////////////////////////
  625. DbgPrint("Se: Impersonation Use ... ");
  626. SepServerWaitForNextConnect();
  627. SepServerGetNextMessage();
  628. SepServerImpersonateClient();
  629. Status = NtOpenThreadToken(
  630. SepServerThread,
  631. TOKEN_ALL_ACCESS,
  632. TRUE,
  633. &ClientToken
  634. ); SEASSERT_SUCCESS(Status);
  635. SepServerRevertToSelf();
  636. Status = NtQueryInformationToken(
  637. ClientToken,
  638. TokenStatistics,
  639. &ClientTokenStatistics,
  640. (ULONG)sizeof(TOKEN_STATISTICS),
  641. &IgnoreLength
  642. ); SEASSERT_SUCCESS(Status);
  643. if ( (ClientTokenStatistics.TokenType == TokenImpersonation) &&
  644. (ClientTokenStatistics.ImpersonationLevel == SecurityImpersonation)
  645. ) {
  646. DbgPrint(" Succeeded\n");
  647. } else {
  648. DbgPrint("* ! FAILED (srvr) ! *\n");
  649. CompletionStatus = FALSE;
  650. }
  651. SepServerCompleteMessage();
  652. SepServerDropConnection();
  653. //
  654. // Appease the compiler gods
  655. //
  656. if (StaticTest) {;}
  657. if (EffectiveOnly) {;}
  658. return CompletionStatus;
  659. }
  660. BOOLEAN
  661. SepServerTest(VOID)
  662. //
  663. // Tests:
  664. //
  665. // Static Context Tracking Tests
  666. // Effective Only
  667. // Anonymous
  668. // Identification
  669. // Impersonation
  670. // Not Effective Only
  671. // Anonymous
  672. // Identification
  673. // Impersonation
  674. //
  675. // Dynamic Context Tracking Tests
  676. // Effective Only
  677. // Identification
  678. // Impersonation
  679. // Not Effective Only
  680. // Identification
  681. // Impersonation
  682. //
  683. {
  684. BOOLEAN CompletionStatus;
  685. DbgPrint("Se: Server Starting Test ...\n");
  686. //
  687. // Run the static test suite...
  688. //
  689. CompletionStatus = SepServerTestStatic();
  690. //
  691. // Run the dynamic test suite...
  692. //
  693. if (CompletionStatus == TRUE) {
  694. CompletionStatus = SepServerTestDynamic();
  695. }
  696. DbgPrint("Se: Server Test Complete.\n");
  697. //
  698. // Print test results
  699. //
  700. DbgPrint("\n");
  701. DbgPrint("\n");
  702. DbgPrint("**********************\n");
  703. DbgPrint("** **\n");
  704. if (CompletionStatus == TRUE) {
  705. DbgPrint("** Test Succeeded **\n");
  706. } else {
  707. DbgPrint("** Test Failed !! **\n");
  708. }
  709. DbgPrint("** **\n");
  710. DbgPrint("**********************\n");
  711. return CompletionStatus;
  712. }
  713. NTSTATUS
  714. SepServerInitialize(
  715. )
  716. {
  717. NTSTATUS Status;
  718. OBJECT_ATTRIBUTES ThreadAttributes;
  719. PTEB CurrentTeb;
  720. DbgPrint("Se: Server Initializing ...\n");
  721. //
  722. // Initialize global variables
  723. //
  724. RequestCount = 0;
  725. //
  726. // Get a handle to our thread to so that we can access our thread
  727. // even when impersonating an anonymous client (which we can't do
  728. // using NtCurrentThread()).
  729. //
  730. CurrentTeb = NtCurrentTeb();
  731. InitializeObjectAttributes(&ThreadAttributes, NULL, 0, NULL, NULL);
  732. Status = NtOpenThread(
  733. &SepServerThread, // TargetHandle
  734. THREAD_ALL_ACCESS, // DesiredAccess
  735. &ThreadAttributes, // ObjectAttributes
  736. &CurrentTeb->ClientId // ClientId
  737. );
  738. ASSERT( NT_SUCCESS(Status) );
  739. //
  740. // Create the server's port
  741. //
  742. InitializeObjectAttributes(
  743. &ObjectAttributes,
  744. &PortName,
  745. 0,
  746. NULL,
  747. NULL );
  748. Status = NtCreatePort(
  749. &EarPort,
  750. &ObjectAttributes,
  751. 0,
  752. 4,
  753. 4 * 256
  754. ); SEASSERT_SUCCESS(Status);
  755. //
  756. // Spawn a copy of ourselves...
  757. //
  758. DbgPrint("Se: Server Spawning client process ...\n");
  759. SepServerSpawnClientProcess();
  760. DbgPrint("Se: Server waiting for start of test signal ...\n");
  761. Status = NtWaitForSingleObject(
  762. EventHandle,
  763. TRUE,
  764. NULL
  765. ); SEASSERT_SUCCESS(Status);
  766. Status = NtClose( EventHandle ); SEASSERT_SUCCESS(Status);
  767. return STATUS_SUCCESS;
  768. }
  769. VOID
  770. SepServerSpawnClientProcess(VOID)
  771. {
  772. RTL_USER_PROCESS_INFORMATION ProcessInformation;
  773. STRING ImagePathName, ProgramName;
  774. UNICODE_STRING UnicodeImagePathName, UnicodeProgramName;
  775. PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
  776. RtlInitString( &ProgramName, "\\SystemRoot\\Bin\\utlpcqos.exe" );
  777. Status = RtlAnsiStringToUnicodeString(
  778. &UnicodeProgramName,
  779. &ProgramName,
  780. TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) );
  781. RtlInitString( &ImagePathName, "utlpcqos.exe");
  782. Status = RtlAnsiStringToUnicodeString(
  783. &UnicodeImagePathName,
  784. &ImagePathName,
  785. TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) );
  786. Status = RtlCreateProcessParameters(
  787. &ProcessParameters,
  788. &ImagePathName, //UNICODEFIX &UnicodeImagePathName,
  789. NULL,
  790. NULL,
  791. NULL,
  792. NULL,
  793. NULL,
  794. NULL,
  795. NULL,
  796. NULL
  797. );
  798. SEASSERT_SUCCESS(Status);
  799. Status = RtlCreateUserProcess(
  800. &ProgramName, // UNICODEFIX &UnicodeProgramName,
  801. ProcessParameters, // ProcessParameters
  802. NULL, // ProcessSecurityDescriptor
  803. NULL, // ThreadSecurityDescriptor
  804. NtCurrentProcess(), // ParentProcess
  805. FALSE, // InheritHandles
  806. NULL, // DebugPort
  807. NULL, // ExceptionPort
  808. &ProcessInformation // ProcessInformation
  809. ); SEASSERT_SUCCESS(Status);
  810. Status = NtResumeThread(
  811. ProcessInformation.Thread,
  812. NULL
  813. ); SEASSERT_SUCCESS(Status);
  814. RtlDestroyProcessParameters( ProcessParameters );
  815. RtlFreeUnicodeString( &UnicodeProgramName );
  816. RtlFreeUnicodeString( &UnicodeImagePathName );
  817. }
  818. //////////////////////////////////////////////////////////////////////////////
  819. // //
  820. // Main Program Entry Routine //
  821. // //
  822. //////////////////////////////////////////////////////////////////////////////
  823. BOOLEAN
  824. CtLpcQos (VOID)
  825. {
  826. BOOLEAN Result = TRUE;
  827. RtlInitUnicodeString( &PortName, L"\\TestLpcQosServerPort" );
  828. //
  829. // Determine whether we are the client or server side of the test.
  830. // This is done by creating or opening a named event object. If the
  831. // event does not yet exist, then we are the client, and must create
  832. // the server process. Otherwise, we are the server and the client
  833. // is waiting for us to signal the event.
  834. //
  835. RtlInitString( &EventName, "\\TestLpcQosEvent" );
  836. Status = RtlAnsiStringToUnicodeString(
  837. &UnicodeEventName,
  838. &EventName,
  839. TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) );
  840. InitializeObjectAttributes(
  841. &ObjectAttributes,
  842. &UnicodeEventName,
  843. OBJ_OPENIF,
  844. NULL,
  845. NULL
  846. );
  847. Status = NtCreateEvent(
  848. &EventHandle,
  849. EVENT_ALL_ACCESS,
  850. &ObjectAttributes,
  851. SynchronizationEvent,
  852. FALSE
  853. );
  854. if (Status == STATUS_OBJECT_NAME_EXISTS) {
  855. //
  856. // Server is already running, therefore, this process gets to be
  857. // the client.
  858. //
  859. Status = SepClientInitialize(); SEASSERT_SUCCESS(Status);
  860. Result = SepClientTest();
  861. } else {
  862. SEASSERT_SUCCESS(Status);
  863. //
  864. // Event wasn't yet there, so we must be the server.
  865. //
  866. DbgPrint("Se: Starting LPC Impersonation Test.\n");
  867. Status = SepServerInitialize(); SEASSERT_SUCCESS(Status);
  868. Result = SepServerTest();
  869. DbgPrint("Se: End Test.\n");
  870. }
  871. Status = NtTerminateThread( NtCurrentThread(), STATUS_SUCCESS);
  872. SEASSERT_SUCCESS(Status);
  873. return Result;
  874. }