Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

ctlpcqos.c

Go to the documentation of this file.
00001 00003 // // 00004 // Global Definitions // 00005 // // 00007 00008 00009 00010 00012 // // 00013 // Global Variables // 00014 // // 00016 00017 NTSTATUS Status; 00018 OBJECT_ATTRIBUTES ObjectAttributes; 00019 STRING EventName; 00020 UNICODE_STRING UnicodeEventName; 00021 HANDLE EventHandle; 00022 UNICODE_STRING PortName; 00023 HANDLE EarPort; 00024 HANDLE TalkPort; 00025 PORT_MESSAGE RequestMessage; 00026 SECURITY_QUALITY_OF_SERVICE SecurityQos; 00027 ULONG RequestCount; 00028 HANDLE ClientToken; 00029 TOKEN_STATISTICS ClientTokenStatistics; 00030 ULONG IgnoreLength; 00031 00032 HANDLE SepServerThread; 00033 00034 00035 00036 00038 // // 00039 // Test Routine Definitions // 00040 // // 00042 BOOLEAN 00043 SepClientTestStatic(VOID); 00044 00045 BOOLEAN 00046 SepClientTestDynamic(VOID); 00047 00048 BOOLEAN 00049 SepClientTestEffectiveOnly( 00050 BOOLEAN StaticTest 00051 ); 00052 00053 BOOLEAN 00054 SepClientTestNotEffectiveOnly( 00055 BOOLEAN StaticTest 00056 ); 00057 00058 BOOLEAN 00059 SepClientTestAnonymous( 00060 BOOLEAN StaticTest, 00061 BOOLEAN EffectiveOnly 00062 ); 00063 00064 BOOLEAN 00065 SepClientTestIdentification( 00066 BOOLEAN StaticTest, 00067 BOOLEAN EffectiveOnly 00068 ); 00069 00070 BOOLEAN 00071 SepClientTestImpersonation( 00072 BOOLEAN StaticTest, 00073 BOOLEAN EffectiveOnly 00074 ); 00075 00076 VOID 00077 SepClientConnect( 00078 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, 00079 SECURITY_CONTEXT_TRACKING_MODE TrackingMode, 00080 BOOLEAN EffectiveOnly 00081 ); 00082 00083 VOID 00084 SepClientMakeRemoteCall( VOID ); 00085 00086 VOID 00087 SepClientDropConnection( VOID ); 00088 00089 BOOLEAN 00090 SepClientTest(VOID); 00091 00092 NTSTATUS 00093 SepClientInitialize( 00094 ); 00095 00096 00097 00098 00099 00100 00101 BOOLEAN 00102 SepServerTestStatic(VOID); 00103 00104 BOOLEAN 00105 SepServerTestDynamic(VOID); 00106 00107 BOOLEAN 00108 SepServerTestEffectiveOnly( 00109 BOOLEAN StaticTest 00110 ); 00111 00112 BOOLEAN 00113 SepServerTestNotEffectiveOnly( 00114 BOOLEAN StaticTest 00115 ); 00116 00117 BOOLEAN 00118 SepServerTestAnonymous( 00119 BOOLEAN StaticTest, 00120 BOOLEAN EffectiveOnly 00121 ); 00122 00123 BOOLEAN 00124 SepServerTestIdentification( 00125 BOOLEAN StaticTest, 00126 BOOLEAN EffectiveOnly 00127 ); 00128 00129 BOOLEAN 00130 SepServerTestImpersonation( 00131 BOOLEAN StaticTest, 00132 BOOLEAN EffectiveOnly 00133 ); 00134 00135 VOID 00136 SepServerWaitForNextConnect( VOID ); 00137 00138 VOID 00139 SepServerGetNextMessage( VOID ); 00140 00141 VOID 00142 SepServerCompleteMessage( VOID ); 00143 00144 VOID 00145 SepServerDropConnection( VOID ); 00146 00147 00148 00149 BOOLEAN 00150 SepServerTest(VOID); 00151 00152 NTSTATUS 00153 SepServerInitialize( 00154 ); 00155 00156 VOID 00157 SepServerSpawnClientProcess(VOID); 00158 00159 00160 00161 00162 BOOLEAN 00163 CtLpcQos (VOID); 00164 00165 00167 // // 00168 // Client-Side Test Routines // 00169 // // 00171 00172 00173 VOID 00174 SepClientConnect( 00175 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, 00176 SECURITY_CONTEXT_TRACKING_MODE TrackingMode, 00177 BOOLEAN EffectiveOnly 00178 ) 00179 00180 { 00181 00182 SecurityQos.ImpersonationLevel = ImpersonationLevel; 00183 SecurityQos.ContextTrackingMode = TrackingMode; 00184 SecurityQos.EffectiveOnly = EffectiveOnly; 00185 00186 Status = NtConnectPort( 00187 &TalkPort, 00188 &PortName, 00189 &SecurityQos, 00190 0L, 00191 NULL, 00192 NULL, 00193 NULL, 00194 NULL, 00195 NULL 00196 ); SEASSERT_SUCCESS(Status); 00197 00198 return; 00199 } 00200 00201 00202 VOID 00203 SepClientMakeRemoteCall( VOID ) 00204 00205 { 00206 PORT_MESSAGE ReplyMessage; 00207 00208 Status = NtRequestWaitReplyPort( 00209 TalkPort, 00210 &RequestMessage, 00211 &ReplyMessage 00212 ); 00213 00214 RequestCount += 1; 00215 00216 return; 00217 } 00218 00219 00220 VOID 00221 SepClientDropConnection( VOID ) 00222 00223 { 00224 00225 Status = NtClose( TalkPort ); SEASSERT_SUCCESS(Status); 00226 00227 return; 00228 00229 } 00230 00231 00232 BOOLEAN 00233 SepClientTestStatic(VOID) 00234 00235 { 00236 00237 BOOLEAN CompletionStatus; 00238 00239 // 00240 // Static Context Tracking ... Suite 00241 // 00242 00243 CompletionStatus = SepClientTestEffectiveOnly( TRUE ); 00244 00245 00246 if (CompletionStatus == TRUE) { 00247 00248 CompletionStatus = SepClientTestNotEffectiveOnly( TRUE ); 00249 } 00250 00251 return CompletionStatus; 00252 00253 } 00254 00255 00256 BOOLEAN 00257 SepClientTestDynamic(VOID) 00258 00259 { 00260 BOOLEAN CompletionStatus; 00261 00262 // 00263 // Dynamic Context Tracking ... Suite 00264 // 00265 00266 CompletionStatus = SepClientTestEffectiveOnly( FALSE ); 00267 00268 00269 if (CompletionStatus == TRUE) { 00270 00271 CompletionStatus = SepClientTestNotEffectiveOnly( FALSE ); 00272 } 00273 00274 return CompletionStatus; 00275 00276 } 00277 00278 00279 BOOLEAN 00280 SepClientTestEffectiveOnly( 00281 BOOLEAN StaticTest 00282 ) 00283 00284 00285 { 00286 00287 BOOLEAN CompletionStatus; 00288 00289 // 00290 // Effective Only ... Test 00291 // 00292 00293 CompletionStatus = SepClientTestAnonymous( StaticTest, TRUE ); 00294 if (CompletionStatus == TRUE) { 00295 CompletionStatus = SepClientTestIdentification( StaticTest, TRUE ); 00296 } 00297 if (CompletionStatus == TRUE) { 00298 CompletionStatus = SepClientTestImpersonation( StaticTest, TRUE ); 00299 } 00300 00301 return CompletionStatus; 00302 00303 } 00304 00305 00306 BOOLEAN 00307 SepClientTestNotEffectiveOnly( 00308 BOOLEAN StaticTest 00309 ) 00310 00311 { 00312 BOOLEAN CompletionStatus; 00313 00314 // 00315 // Not Effective Only ... Test 00316 // 00317 00318 CompletionStatus = SepClientTestAnonymous( StaticTest, FALSE ); 00319 if (CompletionStatus == TRUE) { 00320 CompletionStatus = SepClientTestIdentification( StaticTest, FALSE ); 00321 } 00322 if (CompletionStatus == TRUE) { 00323 CompletionStatus = SepClientTestImpersonation( StaticTest, FALSE ); 00324 } 00325 00326 return CompletionStatus; 00327 00328 } 00329 00330 00331 BOOLEAN 00332 SepClientTestAnonymous( 00333 BOOLEAN StaticTest, 00334 BOOLEAN EffectiveOnly 00335 ) 00336 00337 { 00338 00340 // // 00341 // Anonymous Use Test // 00342 // // 00344 00345 SECURITY_CONTEXT_TRACKING_MODE TrackingMode; 00346 00347 if (StaticTest) { 00348 TrackingMode = SECURITY_STATIC_TRACKING; 00349 } else { 00350 TrackingMode = SECURITY_DYNAMIC_TRACKING; 00351 } 00352 00353 if (!StaticTest) { 00354 // 00355 // No action for dynamic test 00356 // 00357 return TRUE; 00358 } 00359 00360 // 00361 // Anonymous Use ... Test 00362 // 00363 00364 00365 SepClientConnect( 00366 SecurityAnonymous, 00367 TrackingMode, 00368 EffectiveOnly 00369 ); 00370 00371 SepClientMakeRemoteCall(); 00372 00373 SepClientDropConnection(); 00374 00375 00376 return TRUE; 00377 } 00378 00379 00380 BOOLEAN 00381 SepClientTestIdentification( 00382 BOOLEAN StaticTest, 00383 BOOLEAN EffectiveOnly 00384 ) 00385 00386 { 00387 00389 // // 00390 // Identification Use Test // 00391 // // 00393 00394 SECURITY_CONTEXT_TRACKING_MODE TrackingMode; 00395 00396 if (StaticTest) { 00397 TrackingMode = SECURITY_STATIC_TRACKING; 00398 } else { 00399 TrackingMode = SECURITY_DYNAMIC_TRACKING; 00400 } 00401 00402 // 00403 // Identification Use ... Test 00404 // 00405 00406 00407 SepClientConnect( 00408 SecurityIdentification, 00409 TrackingMode, 00410 EffectiveOnly 00411 ); 00412 00413 SepClientMakeRemoteCall(); 00414 00415 SepClientDropConnection(); 00416 00417 00418 return TRUE; 00419 00420 } 00421 00422 00423 BOOLEAN 00424 SepClientTestImpersonation( 00425 BOOLEAN StaticTest, 00426 BOOLEAN EffectiveOnly 00427 ) 00428 00429 { 00430 00432 // // 00433 // Impersonation Use Test // 00434 // // 00436 00437 SECURITY_CONTEXT_TRACKING_MODE TrackingMode; 00438 00439 if (StaticTest) { 00440 TrackingMode = SECURITY_STATIC_TRACKING; 00441 } else { 00442 TrackingMode = SECURITY_DYNAMIC_TRACKING; 00443 } 00444 00445 00446 // 00447 // Impersonation Use ... Test 00448 // 00449 00450 00451 SepClientConnect( 00452 SecurityImpersonation, 00453 TrackingMode, 00454 EffectiveOnly 00455 ); 00456 00457 SepClientMakeRemoteCall(); 00458 00459 SepClientDropConnection(); 00460 00461 00462 00463 return TRUE; 00464 00465 } 00466 00467 00468 00469 00470 BOOLEAN 00471 SepClientTest(VOID) 00472 // 00473 // Tests: 00474 // 00475 // Static Context Tracking Tests 00476 // Effective Only 00477 // Anonymous 00478 // Identification 00479 // Impersonation 00480 // Not Effective Only 00481 // Anonymous 00482 // Identification 00483 // Impersonation 00484 // 00485 // Dynamic Context Tracking Tests 00486 // Effective Only 00487 // Identification 00488 // Impersonation 00489 // Not Effective Only 00490 // Identification 00491 // Impersonation 00492 // 00493 { 00494 00495 BOOLEAN CompletionStatus; 00496 00497 00498 00499 00500 // 00501 // Run the static test suite... 00502 // 00503 00504 CompletionStatus = SepClientTestStatic(); 00505 00506 // 00507 // Run the dynamic test suite... 00508 // 00509 00510 if (CompletionStatus == TRUE) { 00511 CompletionStatus = SepClientTestDynamic(); 00512 } 00513 00514 DbgPrint("Se: Client Test Complete.\n"); 00515 00516 00517 return CompletionStatus; 00518 } 00519 00520 00521 NTSTATUS 00522 SepClientInitialize( 00523 ) 00524 00525 { 00526 00527 00528 00529 DbgPrint("Se: Client Initializing ...\n"); 00530 00531 // 00532 // Initialize global variables 00533 // 00534 00535 RequestMessage.u1.s1.DataLength = 0; 00536 RequestMessage.u1.s1.TotalLength = (CSHORT)sizeof(PORT_MESSAGE); 00537 RequestMessage.u2.ZeroInit = 0; 00538 00539 RequestCount = 0; 00540 00541 00542 // 00543 // Signal the named event to start the test 00544 // 00545 00546 DbgPrint("Se: Client Starting Test ...\n"); 00547 Status = NtSetEvent( EventHandle, NULL ); SEASSERT_SUCCESS(Status); 00548 00549 Status = NtClose( EventHandle ); SEASSERT_SUCCESS(Status); 00550 00551 00552 return STATUS_SUCCESS; 00553 } 00554 00555 00557 // // 00558 // Server-Side Test Routines // 00559 // // 00561 00562 00563 VOID 00564 SepServerWaitForNextConnect( VOID ) 00565 { 00566 00567 CONNECTION_REQUEST ConnectionRequest; 00568 00569 ConnectionRequest.Length = (ULONG)sizeof(CONNECTION_REQUEST); 00570 00571 // 00572 // Wait for the client to connect to the port 00573 // 00574 00575 Status = NtListenPort( 00576 EarPort, 00577 &ConnectionRequest, 00578 NULL, 00579 0L 00580 ); SEASSERT_SUCCESS(Status); 00581 00582 Status = NtAcceptConnectPort( 00583 &TalkPort, 00584 NULL, 00585 &ConnectionRequest, 00586 TRUE, 00587 NULL, 00588 NULL, 00589 NULL, 00590 0L 00591 ); SEASSERT_SUCCESS(Status); 00592 00593 Status = NtCompleteConnectPort( TalkPort ); SEASSERT_SUCCESS(Status); 00594 00595 return; 00596 00597 } 00598 00599 VOID 00600 SepServerGetNextMessage( VOID ) 00601 00602 { 00603 00604 // 00605 // Wait for the next message to come in... 00606 // 00607 00608 Status = NtReplyWaitReceivePort( 00609 EarPort, 00610 NULL, 00611 NULL, 00612 &RequestMessage 00613 ); SEASSERT_SUCCESS(Status); 00614 00615 RequestCount += 1; 00616 00617 return; 00618 } 00619 00620 VOID 00621 SepServerCompleteMessage( VOID ) 00622 00623 { 00624 PORT_MESSAGE ReplyMessage; 00625 00626 ReplyMessage.u1.s1.DataLength = 0; 00627 ReplyMessage.u1.s1.TotalLength = (CSHORT)sizeof(PORT_MESSAGE); 00628 ReplyMessage.u2.ZeroInit = 0; 00629 ReplyMessage.ClientId = RequestMessage.ClientId; 00630 ReplyMessage.MessageId = RequestMessage.MessageId; 00631 00632 // 00633 // Send the response message 00634 // 00635 00636 Status = NtReplyPort( 00637 EarPort, 00638 &ReplyMessage 00639 ); SEASSERT_SUCCESS(Status); 00640 00641 return; 00642 } 00643 00644 VOID 00645 SepServerImpersonateClient( VOID ) 00646 00647 { 00648 00649 Status = NtImpersonateClientOfPort( 00650 TalkPort, 00651 &RequestMessage 00652 ); SEASSERT_SUCCESS(Status); 00653 00654 } 00655 00656 00657 VOID 00658 SepServerRevertToSelf( VOID ) 00659 00660 { 00661 NTSTATUS TmpStatus; 00662 HANDLE NullHandle; 00663 00664 NullHandle = NULL; 00665 TmpStatus = NtSetInformationThread( 00666 SepServerThread, 00667 ThreadImpersonationToken, 00668 (PVOID)&NullHandle, 00669 (ULONG)sizeof(HANDLE) 00670 ); SEASSERT_SUCCESS(TmpStatus); 00671 00672 } 00673 00674 00675 VOID 00676 SepServerDropConnection( VOID ) 00677 00678 { 00679 Status = NtClose( TalkPort ); SEASSERT_SUCCESS(Status); 00680 00681 return; 00682 } 00683 00684 BOOLEAN 00685 SepServerTestStatic(VOID) 00686 00687 { 00688 BOOLEAN CompletionStatus; 00689 00690 DbgPrint("Se: Static Context Tracking ... Suite\n"); 00691 00692 CompletionStatus = SepServerTestEffectiveOnly( TRUE ); 00693 00694 00695 if (CompletionStatus == TRUE) { 00696 00697 CompletionStatus = SepServerTestNotEffectiveOnly( TRUE ); 00698 } 00699 00700 return CompletionStatus; 00701 00702 } 00703 00704 00705 BOOLEAN 00706 SepServerTestDynamic(VOID) 00707 00708 { 00709 BOOLEAN CompletionStatus; 00710 00711 DbgPrint("Se: Dynamic Context Tracking ... Suite\n"); 00712 00713 CompletionStatus = SepServerTestEffectiveOnly( FALSE ); 00714 00715 00716 if (CompletionStatus == TRUE) { 00717 00718 CompletionStatus = SepServerTestNotEffectiveOnly( FALSE ); 00719 } 00720 00721 return CompletionStatus; 00722 00723 } 00724 00725 00726 BOOLEAN 00727 SepServerTestEffectiveOnly( 00728 BOOLEAN StaticTest 00729 ) 00730 00731 { 00732 00733 BOOLEAN CompletionStatus; 00734 00735 DbgPrint("Se: Effective Only ... Test\n"); 00736 00737 CompletionStatus = SepServerTestAnonymous( StaticTest, TRUE ); 00738 if (CompletionStatus == TRUE) { 00739 CompletionStatus = SepServerTestIdentification( StaticTest, TRUE ); 00740 } 00741 if (CompletionStatus == TRUE) { 00742 CompletionStatus = SepServerTestImpersonation( StaticTest, TRUE ); 00743 } 00744 00745 return CompletionStatus; 00746 00747 } 00748 00749 00750 BOOLEAN 00751 SepServerTestNotEffectiveOnly( 00752 BOOLEAN StaticTest 00753 ) 00754 00755 { 00756 00757 BOOLEAN CompletionStatus; 00758 00759 DbgPrint("Se: Not Effective Only ... Test\n"); 00760 00761 CompletionStatus = SepServerTestAnonymous( StaticTest, FALSE ); 00762 if (CompletionStatus == TRUE) { 00763 CompletionStatus = SepServerTestIdentification( StaticTest, FALSE ); 00764 } 00765 if (CompletionStatus == TRUE) { 00766 CompletionStatus = SepServerTestImpersonation( StaticTest, FALSE ); 00767 } 00768 00769 return CompletionStatus; 00770 00771 } 00772 00773 00774 BOOLEAN 00775 SepServerTestAnonymous( 00776 BOOLEAN StaticTest, 00777 BOOLEAN EffectiveOnly 00778 ) 00779 00780 { 00781 BOOLEAN CompletionStatus = TRUE; 00782 00784 // // 00785 // Anonymous Use Test // 00786 // // 00788 00789 00790 if (!StaticTest) { 00791 // 00792 // No action for dynamic test 00793 // 00794 00795 return TRUE; 00796 } 00797 00798 DbgPrint("Se: Anonymous Use ... "); 00799 00800 SepServerWaitForNextConnect(); 00801 00802 SepServerGetNextMessage(); 00803 00804 00805 SepServerImpersonateClient(); 00806 Status = NtOpenThreadToken( 00807 SepServerThread, 00808 TOKEN_ALL_ACCESS, 00809 TRUE, 00810 &ClientToken 00811 ); 00812 SepServerRevertToSelf(); 00813 if (Status == STATUS_CANT_OPEN_ANONYMOUS) { 00814 00815 DbgPrint(" Succeeded\n"); 00816 00817 } else { 00818 DbgPrint("* ! FAILED (srvr) ! *\n"); 00819 DbgPrint("Status is: 0x%lx \n", Status ); 00820 CompletionStatus = FALSE; 00821 } 00822 00823 00824 SepServerCompleteMessage(); 00825 00826 SepServerDropConnection(); 00827 00828 // 00829 // Appease the compiler Gods.. 00830 // 00831 00832 if (EffectiveOnly) {;} 00833 00834 00835 return CompletionStatus; 00836 00837 } 00838 00839 00840 BOOLEAN 00841 SepServerTestIdentification( 00842 BOOLEAN StaticTest, 00843 BOOLEAN EffectiveOnly 00844 ) 00845 00846 { 00847 00848 BOOLEAN CompletionStatus = TRUE; 00850 // // 00851 // Identification Use Test // 00852 // // 00854 00855 DbgPrint("Se: Identification Use ... "); 00856 00857 SepServerWaitForNextConnect(); 00858 00859 SepServerGetNextMessage(); 00860 00861 SepServerImpersonateClient(); 00862 Status = NtOpenThreadToken( 00863 SepServerThread, 00864 TOKEN_ALL_ACCESS, 00865 TRUE, 00866 &ClientToken 00867 ); SEASSERT_SUCCESS(Status); 00868 SepServerRevertToSelf(); 00869 Status = NtQueryInformationToken( 00870 ClientToken, 00871 TokenStatistics, 00872 &ClientTokenStatistics, 00873 (ULONG)sizeof(TOKEN_STATISTICS), 00874 &IgnoreLength 00875 ); SEASSERT_SUCCESS(Status); 00876 00877 if ( (ClientTokenStatistics.TokenType == TokenImpersonation) && 00878 (ClientTokenStatistics.ImpersonationLevel == SecurityIdentification) 00879 ) { 00880 DbgPrint(" Succeeded\n"); 00881 00882 } else { 00883 DbgPrint("* ! FAILED (srvr) ! *\n"); 00884 CompletionStatus = FALSE; 00885 } 00886 00887 00888 SepServerCompleteMessage(); 00889 00890 SepServerDropConnection(); 00891 00892 // 00893 // Appease the compiler Gods.. 00894 // 00895 if (StaticTest) {;} 00896 if (EffectiveOnly) {;} 00897 00898 return CompletionStatus; 00899 } 00900 00901 00902 BOOLEAN 00903 SepServerTestImpersonation( 00904 BOOLEAN StaticTest, 00905 BOOLEAN EffectiveOnly 00906 ) 00907 00908 { 00909 BOOLEAN CompletionStatus = TRUE; 00910 00912 // // 00913 // Impersonation Use Test // 00914 // // 00916 00917 DbgPrint("Se: Impersonation Use ... "); 00918 00919 00920 SepServerWaitForNextConnect(); 00921 00922 SepServerGetNextMessage(); 00923 00924 00925 00926 SepServerImpersonateClient(); 00927 Status = NtOpenThreadToken( 00928 SepServerThread, 00929 TOKEN_ALL_ACCESS, 00930 TRUE, 00931 &ClientToken 00932 ); SEASSERT_SUCCESS(Status); 00933 SepServerRevertToSelf(); 00934 Status = NtQueryInformationToken( 00935 ClientToken, 00936 TokenStatistics, 00937 &ClientTokenStatistics, 00938 (ULONG)sizeof(TOKEN_STATISTICS), 00939 &IgnoreLength 00940 ); SEASSERT_SUCCESS(Status); 00941 00942 if ( (ClientTokenStatistics.TokenType == TokenImpersonation) && 00943 (ClientTokenStatistics.ImpersonationLevel == SecurityImpersonation) 00944 ) { 00945 DbgPrint(" Succeeded\n"); 00946 00947 } else { 00948 DbgPrint("* ! FAILED (srvr) ! *\n"); 00949 CompletionStatus = FALSE; 00950 } 00951 00952 00953 00954 00955 SepServerCompleteMessage(); 00956 00957 SepServerDropConnection(); 00958 00959 // 00960 // Appease the compiler gods 00961 // 00962 if (StaticTest) {;} 00963 if (EffectiveOnly) {;} 00964 00965 return CompletionStatus; 00966 } 00967 00968 00969 BOOLEAN 00970 SepServerTest(VOID) 00971 // 00972 // Tests: 00973 // 00974 // Static Context Tracking Tests 00975 // Effective Only 00976 // Anonymous 00977 // Identification 00978 // Impersonation 00979 // Not Effective Only 00980 // Anonymous 00981 // Identification 00982 // Impersonation 00983 // 00984 // Dynamic Context Tracking Tests 00985 // Effective Only 00986 // Identification 00987 // Impersonation 00988 // Not Effective Only 00989 // Identification 00990 // Impersonation 00991 // 00992 { 00993 00994 BOOLEAN CompletionStatus; 00995 00996 00997 DbgPrint("Se: Server Starting Test ...\n"); 00998 00999 // 01000 // Run the static test suite... 01001 // 01002 01003 CompletionStatus = SepServerTestStatic(); 01004 01005 // 01006 // Run the dynamic test suite... 01007 // 01008 01009 if (CompletionStatus == TRUE) { 01010 CompletionStatus = SepServerTestDynamic(); 01011 } 01012 01013 DbgPrint("Se: Server Test Complete.\n"); 01014 01015 // 01016 // Print test results 01017 // 01018 01019 DbgPrint("\n"); 01020 DbgPrint("\n"); 01021 DbgPrint("**********************\n"); 01022 DbgPrint("** **\n"); 01023 01024 if (CompletionStatus == TRUE) { 01025 DbgPrint("** Test Succeeded **\n"); 01026 } else { 01027 DbgPrint("** Test Failed !! **\n"); 01028 } 01029 01030 DbgPrint("** **\n"); 01031 DbgPrint("**********************\n"); 01032 01033 return CompletionStatus; 01034 01035 } 01036 01037 NTSTATUS 01038 SepServerInitialize( 01039 ) 01040 01041 { 01042 01043 NTSTATUS Status; 01044 OBJECT_ATTRIBUTES ThreadAttributes; 01045 PTEB CurrentTeb; 01046 01047 01048 DbgPrint("Se: Server Initializing ...\n"); 01049 01050 // 01051 // Initialize global variables 01052 // 01053 01054 RequestCount = 0; 01055 01056 // 01057 // Get a handle to our thread to so that we can access our thread 01058 // even when impersonating an anonymous client (which we can't do 01059 // using NtCurrentThread()). 01060 // 01061 01062 CurrentTeb = NtCurrentTeb(); 01063 InitializeObjectAttributes(&ThreadAttributes, NULL, 0, NULL, NULL); 01064 Status = NtOpenThread( 01065 &SepServerThread, // TargetHandle 01066 THREAD_ALL_ACCESS, // DesiredAccess 01067 &ThreadAttributes, // ObjectAttributes 01068 &CurrentTeb->ClientId // ClientId 01069 ); 01070 ASSERT( NT_SUCCESS(Status) ); 01071 01072 01073 // 01074 // Create the server's port 01075 // 01076 01077 InitializeObjectAttributes( 01078 &ObjectAttributes, 01079 &PortName, 01080 0, 01081 NULL, 01082 NULL ); 01083 01084 Status = NtCreatePort( 01085 &EarPort, 01086 &ObjectAttributes, 01087 0, 01088 4, 01089 4 * 256 01090 ); SEASSERT_SUCCESS(Status); 01091 01092 01093 01094 // 01095 // Spawn a copy of ourselves... 01096 // 01097 01098 DbgPrint("Se: Server Spawning client process ...\n"); 01099 SepServerSpawnClientProcess(); 01100 01101 01102 DbgPrint("Se: Server waiting for start of test signal ...\n"); 01103 01104 Status = NtWaitForSingleObject( 01105 EventHandle, 01106 TRUE, 01107 NULL 01108 ); SEASSERT_SUCCESS(Status); 01109 01110 Status = NtClose( EventHandle ); SEASSERT_SUCCESS(Status); 01111 01112 01113 return STATUS_SUCCESS; 01114 } 01115 01116 VOID 01117 SepServerSpawnClientProcess(VOID) 01118 01119 { 01120 01121 01122 RTL_USER_PROCESS_INFORMATION ProcessInformation; 01123 STRING ImagePathName, ProgramName; 01124 UNICODE_STRING UnicodeImagePathName, UnicodeProgramName; 01125 PRTL_USER_PROCESS_PARAMETERS ProcessParameters; 01126 01127 RtlInitString( &ProgramName, "\\SystemRoot\\Bin\\utlpcqos.exe" ); 01128 Status = RtlAnsiStringToUnicodeString( 01129 &UnicodeProgramName, 01130 &ProgramName, 01131 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01132 RtlInitString( &ImagePathName, "utlpcqos.exe"); 01133 Status = RtlAnsiStringToUnicodeString( 01134 &UnicodeImagePathName, 01135 &ImagePathName, 01136 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01137 01138 Status = RtlCreateProcessParameters( 01139 &ProcessParameters, 01140 &ImagePathName, //UNICODEFIX &UnicodeImagePathName, 01141 NULL, 01142 NULL, 01143 NULL, 01144 NULL, 01145 NULL, 01146 NULL, 01147 NULL, 01148 NULL 01149 ); 01150 01151 SEASSERT_SUCCESS(Status); 01152 01153 01154 Status = RtlCreateUserProcess( 01155 &ProgramName, // UNICODEFIX &UnicodeProgramName, 01156 ProcessParameters, // ProcessParameters 01157 NULL, // ProcessSecurityDescriptor 01158 NULL, // ThreadSecurityDescriptor 01159 NtCurrentProcess(), // ParentProcess 01160 FALSE, // InheritHandles 01161 NULL, // DebugPort 01162 NULL, // ExceptionPort 01163 &ProcessInformation // ProcessInformation 01164 ); SEASSERT_SUCCESS(Status); 01165 01166 Status = NtResumeThread( 01167 ProcessInformation.Thread, 01168 NULL 01169 ); SEASSERT_SUCCESS(Status); 01170 01171 RtlDestroyProcessParameters( ProcessParameters ); 01172 RtlFreeUnicodeString( &UnicodeProgramName ); 01173 RtlFreeUnicodeString( &UnicodeImagePathName ); 01174 01175 } 01176 01177 01178 01179 01181 // // 01182 // Main Program Entry Routine // 01183 // // 01185 01186 BOOLEAN 01187 CtLpcQos (VOID) 01188 { 01189 01190 BOOLEAN Result = TRUE; 01191 01192 RtlInitUnicodeString( &PortName, L"\\TestLpcQosServerPort" ); 01193 01194 // 01195 // Determine whether we are the client or server side of the test. 01196 // This is done by creating or opening a named event object. If the 01197 // event does not yet exist, then we are the client, and must create 01198 // the server process. Otherwise, we are the server and the client 01199 // is waiting for us to signal the event. 01200 // 01201 01202 RtlInitString( &EventName, "\\TestLpcQosEvent" ); 01203 Status = RtlAnsiStringToUnicodeString( 01204 &UnicodeEventName, 01205 &EventName, 01206 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01207 InitializeObjectAttributes( 01208 &ObjectAttributes, 01209 &UnicodeEventName, 01210 OBJ_OPENIF, 01211 NULL, 01212 NULL 01213 ); 01214 Status = NtCreateEvent( 01215 &EventHandle, 01216 EVENT_ALL_ACCESS, 01217 &ObjectAttributes, 01218 SynchronizationEvent, 01219 FALSE 01220 ); 01221 01222 if (Status == STATUS_OBJECT_NAME_EXISTS) { 01223 01224 // 01225 // Server is already running, therefore, this process gets to be 01226 // the client. 01227 // 01228 01229 Status = SepClientInitialize(); SEASSERT_SUCCESS(Status); 01230 Result = SepClientTest(); 01231 01232 } else { 01233 01234 SEASSERT_SUCCESS(Status); 01235 01236 // 01237 // Event wasn't yet there, so we must be the server. 01238 // 01239 01240 DbgPrint("Se: Starting LPC Impersonation Test.\n"); 01241 01242 Status = SepServerInitialize(); SEASSERT_SUCCESS(Status); 01243 Result = SepServerTest(); 01244 01245 DbgPrint("Se: End Test.\n"); 01246 01247 } 01248 01249 01250 01251 Status = NtTerminateThread( NtCurrentThread(), STATUS_SUCCESS); 01252 SEASSERT_SUCCESS(Status); 01253 01254 return Result; 01255 01256 }

Generated on Sat May 15 19:39:37 2004 for test by doxygen 1.3.7