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

ctlnpqos.c

Go to the documentation of this file.
00001 00003 // // 00004 // Global Definitions // 00005 // // 00007 00008 #define DevPrint 00009 //#define DevPrint DbgPrint 00010 00011 #define Error(N,S) { DbgPrint(#N); DbgPrint(" Error %08lx\n", S); } 00012 00013 #define Delay(SECONDS) { \ 00014 LARGE_INTEGER Time; \ 00015 Time.QuadPart = -10 * 1000 * 1000, ((LONGLONG)SECONDS); \ 00016 NtDelayExecution(TRUE,(PLARGE_INTEGER)&Time); \ 00017 } 00018 00019 00021 // // 00022 // Global Variables // 00023 // // 00025 00026 NTSTATUS Status; 00027 OBJECT_ATTRIBUTES ObjectAttributes; 00028 STRING EventName; 00029 UNICODE_STRING UnicodeEventName; 00030 HANDLE EventHandle; 00031 STRING PortName; 00032 UNICODE_STRING UnicodePortName; 00033 STRING RelativePortName; 00034 UNICODE_STRING UnicodeRelativePortName; 00035 HANDLE EarPort; 00036 HANDLE TalkPort; 00037 SECURITY_QUALITY_OF_SERVICE SecurityQos; 00038 ULONG RequestCount; 00039 HANDLE ClientToken; 00040 TOKEN_STATISTICS ClientTokenStatistics; 00041 ULONG IgnoreLength; 00042 00043 HANDLE SepServerThread; 00044 00045 00046 00047 00049 // // 00050 // Test Routine Definitions // 00051 // // 00053 BOOLEAN 00054 SepClientTestStatic(VOID); 00055 00056 BOOLEAN 00057 SepClientTestDynamic(VOID); 00058 00059 BOOLEAN 00060 SepClientTestEffectiveOnly( 00061 BOOLEAN StaticTest 00062 ); 00063 00064 BOOLEAN 00065 SepClientTestNotEffectiveOnly( 00066 BOOLEAN StaticTest 00067 ); 00068 00069 BOOLEAN 00070 SepClientTestAnonymous( 00071 BOOLEAN StaticTest, 00072 BOOLEAN EffectiveOnly 00073 ); 00074 00075 BOOLEAN 00076 SepClientTestIdentification( 00077 BOOLEAN StaticTest, 00078 BOOLEAN EffectiveOnly 00079 ); 00080 00081 BOOLEAN 00082 SepClientTestImpersonation( 00083 BOOLEAN StaticTest, 00084 BOOLEAN EffectiveOnly 00085 ); 00086 00087 VOID 00088 SepClientConnect( 00089 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, 00090 SECURITY_CONTEXT_TRACKING_MODE TrackingMode, 00091 BOOLEAN EffectiveOnly 00092 ); 00093 00094 VOID 00095 SepClientMakeRemoteCall( VOID ); 00096 00097 VOID 00098 SepClientDropConnection( VOID ); 00099 00100 BOOLEAN 00101 SepClientTest(VOID); 00102 00103 NTSTATUS 00104 SepClientInitialize( 00105 ); 00106 00107 00108 00109 00110 00111 00112 BOOLEAN 00113 SepServerTestStatic(VOID); 00114 00115 BOOLEAN 00116 SepServerTestDynamic(VOID); 00117 00118 BOOLEAN 00119 SepServerTestEffectiveOnly( 00120 BOOLEAN StaticTest 00121 ); 00122 00123 BOOLEAN 00124 SepServerTestNotEffectiveOnly( 00125 BOOLEAN StaticTest 00126 ); 00127 00128 BOOLEAN 00129 SepServerTestAnonymous( 00130 BOOLEAN StaticTest, 00131 BOOLEAN EffectiveOnly 00132 ); 00133 00134 BOOLEAN 00135 SepServerTestIdentification( 00136 BOOLEAN StaticTest, 00137 BOOLEAN EffectiveOnly 00138 ); 00139 00140 BOOLEAN 00141 SepServerTestImpersonation( 00142 BOOLEAN StaticTest, 00143 BOOLEAN EffectiveOnly 00144 ); 00145 00146 VOID 00147 SepServerWaitForNextConnect( VOID ); 00148 00149 VOID 00150 SepServerGetNextMessage( VOID ); 00151 00152 VOID 00153 SepServerCompleteMessage( VOID ); 00154 00155 VOID 00156 SepServerDropConnection( VOID ); 00157 00158 00159 00160 BOOLEAN 00161 SepServerTest(VOID); 00162 00163 NTSTATUS 00164 SepServerInitialize( 00165 ); 00166 00167 VOID 00168 SepServerSpawnClientProcess(VOID); 00169 00170 00171 00172 00173 VOID 00174 SepWritePipe( PSZ String ); 00175 00176 VOID 00177 SepReadPipe(VOID); 00178 00179 VOID 00180 SepTransceivePipe( PSZ String ); 00181 00182 00183 00184 00185 HANDLE 00186 SepServerCreatePipe(VOID); 00187 00188 VOID 00189 SepServerListenPipe(VOID); 00190 00191 VOID 00192 SepServerImpersonatePipe(VOID); 00193 00194 VOID 00195 SepServerDisconnectPipe(VOID); 00196 00197 00198 00199 00200 HANDLE 00201 SepClientOpenPipe( VOID ); 00202 00203 00204 00205 00206 BOOLEAN 00207 CtLnpQos (VOID); 00208 00209 00211 // // 00212 // Client-Side Test Routines // 00213 // // 00215 00216 00217 VOID 00218 SepClientConnect( 00219 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, 00220 SECURITY_CONTEXT_TRACKING_MODE TrackingMode, 00221 BOOLEAN EffectiveOnly 00222 ) 00223 00224 { 00225 00226 SecurityQos.ImpersonationLevel = ImpersonationLevel; 00227 SecurityQos.ContextTrackingMode = TrackingMode; 00228 SecurityQos.EffectiveOnly = EffectiveOnly; 00229 00230 DevPrint("\nClient: "); 00231 TalkPort = SepClientOpenPipe(); 00232 00233 return; 00234 } 00235 00236 00237 VOID 00238 SepClientMakeRemoteCall( VOID ) 00239 00240 { 00241 00242 DevPrint("\nClient: "); 00243 SepTransceivePipe( "Make Client Call\n" ); 00244 00245 RequestCount += 1; 00246 00247 return; 00248 } 00249 00250 00251 VOID 00252 SepClientDropConnection( VOID ) 00253 00254 { 00255 00256 Status = NtClose( TalkPort ); SEASSERT_SUCCESS(Status); 00257 00258 return; 00259 00260 } 00261 00262 00263 BOOLEAN 00264 SepClientTestStatic(VOID) 00265 00266 { 00267 00268 BOOLEAN CompletionStatus; 00269 00270 // 00271 // Static Context Tracking ... Suite 00272 // 00273 00274 CompletionStatus = SepClientTestEffectiveOnly( TRUE ); 00275 00276 00277 if (CompletionStatus == TRUE) { 00278 00279 CompletionStatus = SepClientTestNotEffectiveOnly( TRUE ); 00280 } 00281 00282 return CompletionStatus; 00283 00284 } 00285 00286 00287 BOOLEAN 00288 SepClientTestDynamic(VOID) 00289 00290 { 00291 BOOLEAN CompletionStatus; 00292 00293 // 00294 // Dynamic Context Tracking ... Suite 00295 // 00296 00297 CompletionStatus = SepClientTestEffectiveOnly( FALSE ); 00298 00299 00300 if (CompletionStatus == TRUE) { 00301 00302 CompletionStatus = SepClientTestNotEffectiveOnly( FALSE ); 00303 } 00304 00305 return CompletionStatus; 00306 00307 } 00308 00309 00310 BOOLEAN 00311 SepClientTestEffectiveOnly( 00312 BOOLEAN StaticTest 00313 ) 00314 00315 00316 { 00317 00318 BOOLEAN CompletionStatus; 00319 00320 // 00321 // Effective Only ... Test 00322 // 00323 00324 CompletionStatus = SepClientTestAnonymous( StaticTest, TRUE ); 00325 if (CompletionStatus == TRUE) { 00326 CompletionStatus = SepClientTestIdentification( StaticTest, TRUE ); 00327 } 00328 if (CompletionStatus == TRUE) { 00329 CompletionStatus = SepClientTestImpersonation( StaticTest, TRUE ); 00330 } 00331 00332 return CompletionStatus; 00333 00334 } 00335 00336 00337 BOOLEAN 00338 SepClientTestNotEffectiveOnly( 00339 BOOLEAN StaticTest 00340 ) 00341 00342 { 00343 BOOLEAN CompletionStatus; 00344 00345 // 00346 // Not Effective Only ... Test 00347 // 00348 00349 CompletionStatus = SepClientTestAnonymous( StaticTest, FALSE ); 00350 if (CompletionStatus == TRUE) { 00351 CompletionStatus = SepClientTestIdentification( StaticTest, FALSE ); 00352 } 00353 if (CompletionStatus == TRUE) { 00354 CompletionStatus = SepClientTestImpersonation( StaticTest, FALSE ); 00355 } 00356 00357 return CompletionStatus; 00358 00359 } 00360 00361 00362 BOOLEAN 00363 SepClientTestAnonymous( 00364 BOOLEAN StaticTest, 00365 BOOLEAN EffectiveOnly 00366 ) 00367 00368 { 00369 00371 // // 00372 // Anonymous Use Test // 00373 // // 00375 00376 SECURITY_CONTEXT_TRACKING_MODE TrackingMode; 00377 00378 if (StaticTest) { 00379 TrackingMode = SECURITY_STATIC_TRACKING; 00380 } else { 00381 TrackingMode = SECURITY_DYNAMIC_TRACKING; 00382 } 00383 00384 if (!StaticTest) { 00385 // 00386 // No action for dynamic test 00387 // 00388 return TRUE; 00389 } 00390 00391 // 00392 // Anonymous Use ... Test 00393 // 00394 00395 00396 SepClientConnect( 00397 SecurityAnonymous, 00398 TrackingMode, 00399 EffectiveOnly 00400 ); 00401 00402 SepClientMakeRemoteCall(); 00403 00404 SepClientDropConnection(); 00405 00406 00407 return TRUE; 00408 } 00409 00410 00411 BOOLEAN 00412 SepClientTestIdentification( 00413 BOOLEAN StaticTest, 00414 BOOLEAN EffectiveOnly 00415 ) 00416 00417 { 00418 00420 // // 00421 // Identification Use Test // 00422 // // 00424 00425 SECURITY_CONTEXT_TRACKING_MODE TrackingMode; 00426 00427 if (StaticTest) { 00428 TrackingMode = SECURITY_STATIC_TRACKING; 00429 } else { 00430 TrackingMode = SECURITY_DYNAMIC_TRACKING; 00431 } 00432 00433 // 00434 // Identification Use ... Test 00435 // 00436 00437 00438 SepClientConnect( 00439 SecurityIdentification, 00440 TrackingMode, 00441 EffectiveOnly 00442 ); 00443 00444 SepClientMakeRemoteCall(); 00445 00446 SepClientDropConnection(); 00447 00448 00449 return TRUE; 00450 00451 } 00452 00453 00454 BOOLEAN 00455 SepClientTestImpersonation( 00456 BOOLEAN StaticTest, 00457 BOOLEAN EffectiveOnly 00458 ) 00459 00460 { 00461 00463 // // 00464 // Impersonation Use Test // 00465 // // 00467 00468 SECURITY_CONTEXT_TRACKING_MODE TrackingMode; 00469 00470 if (StaticTest) { 00471 TrackingMode = SECURITY_STATIC_TRACKING; 00472 } else { 00473 TrackingMode = SECURITY_DYNAMIC_TRACKING; 00474 } 00475 00476 00477 // 00478 // Impersonation Use ... Test 00479 // 00480 00481 00482 SepClientConnect( 00483 SecurityImpersonation, 00484 TrackingMode, 00485 EffectiveOnly 00486 ); 00487 00488 SepClientMakeRemoteCall(); 00489 00490 SepClientDropConnection(); 00491 00492 00493 00494 return TRUE; 00495 00496 } 00497 00498 00499 00500 00501 BOOLEAN 00502 SepClientTest(VOID) 00503 // 00504 // Tests: 00505 // 00506 // Static Context Tracking Tests 00507 // Effective Only 00508 // Anonymous 00509 // Identification 00510 // Impersonation 00511 // Not Effective Only 00512 // Anonymous 00513 // Identification 00514 // Impersonation 00515 // 00516 // Dynamic Context Tracking Tests 00517 // Effective Only 00518 // Identification 00519 // Impersonation 00520 // Not Effective Only 00521 // Identification 00522 // Impersonation 00523 // 00524 { 00525 00526 BOOLEAN CompletionStatus; 00527 00528 00529 00530 00531 // 00532 // Run the static test suite... 00533 // 00534 00535 CompletionStatus = SepClientTestStatic(); 00536 00537 // 00538 // Run the dynamic test suite... 00539 // 00540 00541 if (CompletionStatus == TRUE) { 00542 CompletionStatus = SepClientTestDynamic(); 00543 } 00544 00545 DbgPrint("Se: Client Test Complete.\n"); 00546 00547 00548 return CompletionStatus; 00549 } 00550 00551 00552 NTSTATUS 00553 SepClientInitialize( 00554 ) 00555 00556 { 00557 00558 00559 00560 DbgPrint("Se: Client Initializing ...\n"); 00561 00562 00563 RequestCount = 0; 00564 00565 00566 // 00567 // Signal the named event to start the test 00568 // 00569 00570 DbgPrint("Se: Client Starting Test ...\n"); 00571 Status = NtSetEvent( EventHandle, NULL ); SEASSERT_SUCCESS(Status); 00572 00573 Status = NtClose( EventHandle ); SEASSERT_SUCCESS(Status); 00574 00575 00576 return STATUS_SUCCESS; 00577 } 00578 00579 00581 // // 00582 // Server-Side Test Routines // 00583 // // 00585 00586 00587 VOID 00588 SepServerWaitForNextConnect( VOID ) 00589 { 00590 00591 DevPrint("\nServer: "); 00592 SepServerListenPipe(); 00593 00594 Status = NtDuplicateObject( 00595 NtCurrentProcess(), // SourceProcessHandle 00596 EarPort, // SourceHandle 00597 NtCurrentProcess(), // TargetProcessHandle 00598 &TalkPort, // TargetHandle 00599 0, // DesiredAccess (over-ridden by option) 00600 0, // HandleAttributes 00601 DUPLICATE_SAME_ACCESS // Options 00602 ); 00603 ASSERT(NT_SUCCESS(Status)); 00604 00605 00606 return; 00607 00608 } 00609 00610 VOID 00611 SepServerGetNextMessage( VOID ) 00612 00613 { 00614 00615 00616 00617 DevPrint("\nServer: "); 00618 SepReadPipe(); 00619 00620 RequestCount += 1; 00621 00622 return; 00623 } 00624 00625 VOID 00626 SepServerCompleteMessage( VOID ) 00627 00628 { 00629 00630 DevPrint("\nServer: "); 00631 SepWritePipe("Return From Server\n"); 00632 return; 00633 } 00634 00635 VOID 00636 SepServerImpersonateClient( VOID ) 00637 00638 { 00639 00640 DevPrint("\nServer: "); 00641 SepServerImpersonatePipe( ); 00642 00643 } 00644 00645 00646 VOID 00647 SepServerRevertToSelf( VOID ) 00648 00649 { 00650 NTSTATUS TmpStatus; 00651 HANDLE NullHandle; 00652 00653 NullHandle = NULL; 00654 TmpStatus = NtSetInformationThread( 00655 SepServerThread, 00656 ThreadImpersonationToken, 00657 (PVOID)&NullHandle, 00658 (ULONG)sizeof(HANDLE) 00659 ); SEASSERT_SUCCESS(TmpStatus); 00660 00661 } 00662 00663 00664 VOID 00665 SepServerDropConnection( VOID ) 00666 00667 { 00668 DevPrint("\nServer: "); 00669 SepServerDisconnectPipe(); 00670 00671 return; 00672 } 00673 00674 BOOLEAN 00675 SepServerTestStatic(VOID) 00676 00677 { 00678 BOOLEAN CompletionStatus; 00679 00680 DbgPrint("Se: Static Context Tracking ... Suite\n"); 00681 00682 CompletionStatus = SepServerTestEffectiveOnly( TRUE ); 00683 00684 00685 if (CompletionStatus == TRUE) { 00686 00687 CompletionStatus = SepServerTestNotEffectiveOnly( TRUE ); 00688 } 00689 00690 return CompletionStatus; 00691 00692 } 00693 00694 00695 BOOLEAN 00696 SepServerTestDynamic(VOID) 00697 00698 { 00699 BOOLEAN CompletionStatus; 00700 00701 DbgPrint("Se: Dynamic Context Tracking ... Suite\n"); 00702 00703 CompletionStatus = SepServerTestEffectiveOnly( FALSE ); 00704 00705 00706 if (CompletionStatus == TRUE) { 00707 00708 CompletionStatus = SepServerTestNotEffectiveOnly( FALSE ); 00709 } 00710 00711 return CompletionStatus; 00712 00713 } 00714 00715 00716 BOOLEAN 00717 SepServerTestEffectiveOnly( 00718 BOOLEAN StaticTest 00719 ) 00720 00721 { 00722 00723 BOOLEAN CompletionStatus; 00724 00725 DbgPrint("Se: Effective Only ... Test\n"); 00726 00727 CompletionStatus = SepServerTestAnonymous( StaticTest, TRUE ); 00728 if (CompletionStatus == TRUE) { 00729 CompletionStatus = SepServerTestIdentification( StaticTest, TRUE ); 00730 } 00731 if (CompletionStatus == TRUE) { 00732 CompletionStatus = SepServerTestImpersonation( StaticTest, TRUE ); 00733 } 00734 00735 return CompletionStatus; 00736 00737 } 00738 00739 00740 BOOLEAN 00741 SepServerTestNotEffectiveOnly( 00742 BOOLEAN StaticTest 00743 ) 00744 00745 { 00746 00747 BOOLEAN CompletionStatus; 00748 00749 DbgPrint("Se: Not Effective Only ... Test\n"); 00750 00751 CompletionStatus = SepServerTestAnonymous( StaticTest, FALSE ); 00752 if (CompletionStatus == TRUE) { 00753 CompletionStatus = SepServerTestIdentification( StaticTest, FALSE ); 00754 } 00755 if (CompletionStatus == TRUE) { 00756 CompletionStatus = SepServerTestImpersonation( StaticTest, FALSE ); 00757 } 00758 00759 return CompletionStatus; 00760 00761 } 00762 00763 00764 BOOLEAN 00765 SepServerTestAnonymous( 00766 BOOLEAN StaticTest, 00767 BOOLEAN EffectiveOnly 00768 ) 00769 00770 { 00771 BOOLEAN CompletionStatus = TRUE; 00772 00774 // // 00775 // Anonymous Use Test // 00776 // // 00778 00779 00780 if (!StaticTest) { 00781 // 00782 // No action for dynamic test 00783 // 00784 00785 return TRUE; 00786 } 00787 00788 DbgPrint("Se: Anonymous Use ... "); 00789 00790 SepServerWaitForNextConnect(); 00791 00792 SepServerGetNextMessage(); 00793 00794 00795 SepServerImpersonateClient(); 00796 Status = NtOpenThreadToken( 00797 SepServerThread, 00798 TOKEN_ALL_ACCESS, 00799 TRUE, 00800 &ClientToken 00801 ); 00802 SepServerRevertToSelf(); 00803 if (Status == STATUS_CANT_OPEN_ANONYMOUS) { 00804 00805 DbgPrint(" Succeeded\n"); 00806 00807 } else { 00808 DbgPrint("* ! FAILED (srvr) ! *\n"); 00809 DbgPrint("Status is: 0x%lx \n", Status ); 00810 CompletionStatus = FALSE; 00811 } 00812 00813 00814 SepServerCompleteMessage(); 00815 00816 SepServerDropConnection(); 00817 00818 // 00819 // Appease the compiler Gods.. 00820 // 00821 00822 if (EffectiveOnly) {;} 00823 00824 00825 return CompletionStatus; 00826 00827 } 00828 00829 00830 BOOLEAN 00831 SepServerTestIdentification( 00832 BOOLEAN StaticTest, 00833 BOOLEAN EffectiveOnly 00834 ) 00835 00836 { 00837 00838 BOOLEAN CompletionStatus = TRUE; 00840 // // 00841 // Identification Use Test // 00842 // // 00844 00845 DbgPrint("Se: Identification Use ... "); 00846 00847 SepServerWaitForNextConnect(); 00848 00849 SepServerGetNextMessage(); 00850 00851 SepServerImpersonateClient(); 00852 Status = NtOpenThreadToken( 00853 SepServerThread, 00854 TOKEN_ALL_ACCESS, 00855 TRUE, 00856 &ClientToken 00857 ); SEASSERT_SUCCESS(Status); 00858 SepServerRevertToSelf(); 00859 Status = NtQueryInformationToken( 00860 ClientToken, 00861 TokenStatistics, 00862 &ClientTokenStatistics, 00863 (ULONG)sizeof(TOKEN_STATISTICS), 00864 &IgnoreLength 00865 ); SEASSERT_SUCCESS(Status); 00866 00867 if ( (ClientTokenStatistics.TokenType == TokenImpersonation) && 00868 (ClientTokenStatistics.ImpersonationLevel == SecurityIdentification) 00869 ) { 00870 DbgPrint(" Succeeded\n"); 00871 00872 } else { 00873 DbgPrint("* ! FAILED (srvr) ! *\n"); 00874 CompletionStatus = FALSE; 00875 } 00876 00877 00878 SepServerCompleteMessage(); 00879 00880 SepServerDropConnection(); 00881 00882 // 00883 // Appease the compiler Gods.. 00884 // 00885 if (StaticTest) {;} 00886 if (EffectiveOnly) {;} 00887 00888 return CompletionStatus; 00889 } 00890 00891 00892 BOOLEAN 00893 SepServerTestImpersonation( 00894 BOOLEAN StaticTest, 00895 BOOLEAN EffectiveOnly 00896 ) 00897 00898 { 00899 BOOLEAN CompletionStatus = TRUE; 00900 00902 // // 00903 // Impersonation Use Test // 00904 // // 00906 00907 DbgPrint("Se: Impersonation Use ... "); 00908 00909 00910 SepServerWaitForNextConnect(); 00911 00912 SepServerGetNextMessage(); 00913 00914 00915 00916 SepServerImpersonateClient(); 00917 Status = NtOpenThreadToken( 00918 SepServerThread, 00919 TOKEN_ALL_ACCESS, 00920 TRUE, 00921 &ClientToken 00922 ); SEASSERT_SUCCESS(Status); 00923 SepServerRevertToSelf(); 00924 Status = NtQueryInformationToken( 00925 ClientToken, 00926 TokenStatistics, 00927 &ClientTokenStatistics, 00928 (ULONG)sizeof(TOKEN_STATISTICS), 00929 &IgnoreLength 00930 ); SEASSERT_SUCCESS(Status); 00931 00932 if ( (ClientTokenStatistics.TokenType == TokenImpersonation) && 00933 (ClientTokenStatistics.ImpersonationLevel == SecurityImpersonation) 00934 ) { 00935 DbgPrint(" Succeeded\n"); 00936 00937 } else { 00938 DbgPrint("* ! FAILED (srvr) ! *\n"); 00939 CompletionStatus = FALSE; 00940 } 00941 00942 00943 00944 00945 SepServerCompleteMessage(); 00946 00947 SepServerDropConnection(); 00948 00949 // 00950 // Appease the compiler gods 00951 // 00952 if (StaticTest) {;} 00953 if (EffectiveOnly) {;} 00954 00955 return CompletionStatus; 00956 } 00957 00958 00959 BOOLEAN 00960 SepServerTest(VOID) 00961 // 00962 // Tests: 00963 // 00964 // Static Context Tracking Tests 00965 // Effective Only 00966 // Anonymous 00967 // Identification 00968 // Impersonation 00969 // Not Effective Only 00970 // Anonymous 00971 // Identification 00972 // Impersonation 00973 // 00974 // Dynamic Context Tracking Tests 00975 // Effective Only 00976 // Identification 00977 // Impersonation 00978 // Not Effective Only 00979 // Identification 00980 // Impersonation 00981 // 00982 { 00983 00984 BOOLEAN CompletionStatus; 00985 00986 00987 DbgPrint("Se: Server Starting Test ...\n"); 00988 00989 // 00990 // Run the static test suite... 00991 // 00992 00993 CompletionStatus = SepServerTestStatic(); 00994 00995 // 00996 // Run the dynamic test suite... 00997 // 00998 00999 if (CompletionStatus == TRUE) { 01000 CompletionStatus = SepServerTestDynamic(); 01001 } 01002 01003 DbgPrint("Se: Server Test Complete.\n"); 01004 01005 // 01006 // Print test results 01007 // 01008 01009 DbgPrint("\n"); 01010 DbgPrint("\n"); 01011 DbgPrint("**********************\n"); 01012 DbgPrint("** **\n"); 01013 01014 if (CompletionStatus == TRUE) { 01015 DbgPrint("** Test Succeeded **\n"); 01016 } else { 01017 DbgPrint("** Test Failed !! **\n"); 01018 } 01019 01020 DbgPrint("** **\n"); 01021 DbgPrint("**********************\n"); 01022 01023 return CompletionStatus; 01024 01025 } 01026 01027 NTSTATUS 01028 SepServerInitialize( 01029 ) 01030 01031 { 01032 01033 OBJECT_ATTRIBUTES ThreadAttributes; 01034 PTEB CurrentTeb; 01035 01036 01037 DbgPrint("Se: Server Initializing ...\n"); 01038 01039 // 01040 // Initialize global variables 01041 // 01042 01043 RequestCount = 0; 01044 01045 // 01046 // Get a handle to our thread to so that we can access our thread 01047 // even when impersonating an anonymous client (which we can't do 01048 // using NtCurrentThread()). 01049 // 01050 01051 CurrentTeb = NtCurrentTeb(); 01052 InitializeObjectAttributes(&ThreadAttributes, NULL, 0, NULL, NULL); 01053 Status = NtOpenThread( 01054 &SepServerThread, // TargetHandle 01055 THREAD_ALL_ACCESS, // DesiredAccess 01056 &ThreadAttributes, // ObjectAttributes 01057 &CurrentTeb->ClientId // ClientId 01058 ); 01059 ASSERT( NT_SUCCESS(Status) ); 01060 01061 01062 // 01063 // Create the server's port 01064 // 01065 01066 EarPort = SepServerCreatePipe(); 01067 01068 01069 01070 // 01071 // Spawn a copy of ourselves... 01072 // 01073 01074 DbgPrint("Se: Server Spawning client process ...\n"); 01075 SepServerSpawnClientProcess(); 01076 01077 01078 DbgPrint("Se: Server waiting for start of test signal ...\n"); 01079 01080 Status = NtWaitForSingleObject( 01081 EventHandle, 01082 TRUE, 01083 NULL 01084 ); SEASSERT_SUCCESS(Status); 01085 01086 Status = NtClose( EventHandle ); SEASSERT_SUCCESS(Status); 01087 01088 01089 return STATUS_SUCCESS; 01090 } 01091 01092 VOID 01093 SepServerSpawnClientProcess(VOID) 01094 01095 { 01096 01097 RTL_USER_PROCESS_INFORMATION ProcessInformation; 01098 STRING ProgramName; 01099 UNICODE_STRING UnicodeProgramName; 01100 STRING ImagePathName; 01101 UNICODE_STRING UnicodeImagePathName; 01102 PRTL_USER_PROCESS_PARAMETERS ProcessParameters; 01103 01104 RtlInitString( &ProgramName, "\\SystemRoot\\Bin\\utlnpqos.exe" ); 01105 Status = RtlAnsiStringToUnicodeString( 01106 &UnicodeProgramName, 01107 &ProgramName, 01108 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01109 RtlInitString( &ImagePathName, "utlnpqos.exe"); 01110 Status = RtlAnsiStringToUnicodeString( 01111 &UnicodeImagePathName, 01112 &ImagePathName, 01113 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01114 01115 01116 Status = RtlCreateProcessParameters( 01117 &ProcessParameters, 01118 &ImagePathName, // FIX, FIX &UnicodeImagePathName, (when converted to unicode) 01119 NULL, 01120 NULL, 01121 NULL, 01122 NULL, 01123 NULL, 01124 NULL, 01125 NULL, 01126 NULL 01127 ); 01128 01129 SEASSERT_SUCCESS(Status); 01130 RtlFreeUnicodeString( &UnicodeImagePathName ); 01131 01132 01133 Status = RtlCreateUserProcess( 01134 &ProgramName, // FIX, FIX &UnicodeProgramName (when converted to unicode) 01135 ProcessParameters, // ProcessParameters 01136 NULL, // ProcessSecurityDescriptor 01137 NULL, // ThreadSecurityDescriptor 01138 NtCurrentProcess(), // ParentProcess 01139 FALSE, // InheritHandles 01140 NULL, // DebugPort 01141 NULL, // ExceptionPort 01142 &ProcessInformation // ProcessInformation 01143 ); SEASSERT_SUCCESS(Status); 01144 RtlFreeUnicodeString( &UnicodeProgramName ); 01145 01146 Status = NtResumeThread( 01147 ProcessInformation.Thread, 01148 NULL 01149 ); SEASSERT_SUCCESS(Status); 01150 01151 RtlDestroyProcessParameters( ProcessParameters ); 01152 01153 } 01154 01155 01156 01157 01159 // // 01160 // Main Program Entry Routine // 01161 // // 01163 01164 BOOLEAN 01165 CtLnpQos (VOID) 01166 { 01167 01168 BOOLEAN Result = TRUE; 01169 01170 RtlInitString( &PortName, "\\Device\\NamedPipe\\TestLnpQosServerPort" ); 01171 Status = RtlAnsiStringToUnicodeString( 01172 &UnicodePortName, 01173 &PortName, 01174 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01175 01176 RtlInitString( &RelativePortName, "TestLnpQosServerPort" ); 01177 Status = RtlAnsiStringToUnicodeString( 01178 &UnicodeRelativePortName, 01179 &RelativePortName, 01180 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01181 01182 01183 // 01184 // Determine whether we are the client or server side of the test. 01185 // This is done by creating or opening a named event object. If the 01186 // event does not yet exist, then we are the client, and must create 01187 // the server process. Otherwise, we are the server and the client 01188 // is waiting for us to signal the event. 01189 // 01190 01191 RtlInitString( &EventName, "\\TestLnpQosEvent" ); 01192 Status = RtlAnsiStringToUnicodeString( 01193 &UnicodeEventName, 01194 &EventName, 01195 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01196 01197 InitializeObjectAttributes( 01198 &ObjectAttributes, 01199 &UnicodeEventName, 01200 OBJ_OPENIF, 01201 NULL, 01202 NULL 01203 ); 01204 Status = NtCreateEvent( 01205 &EventHandle, 01206 EVENT_ALL_ACCESS, 01207 &ObjectAttributes, 01208 SynchronizationEvent, 01209 FALSE 01210 ); 01211 RtlFreeUnicodeString( &UnicodeEventName ); 01212 01213 if (Status == STATUS_OBJECT_NAME_EXISTS) { 01214 01215 // 01216 // Server is already running, therefore, this process gets to be 01217 // the client. 01218 // 01219 01220 Status = SepClientInitialize(); SEASSERT_SUCCESS(Status); 01221 Result = SepClientTest(); 01222 01223 } else { 01224 01225 SEASSERT_SUCCESS(Status); 01226 01227 // 01228 // Event wasn't yet there, so we must be the server. 01229 // 01230 01231 DbgPrint("Se: Starting Local Named Pipe Impersonation Test.\n"); 01232 01233 Status = SepServerInitialize(); SEASSERT_SUCCESS(Status); 01234 Result = SepServerTest(); 01235 01236 DbgPrint("Se: End Test.\n"); 01237 01238 } 01239 01240 01241 01242 Status = NtTerminateThread( NtCurrentThread(), STATUS_SUCCESS); 01243 SEASSERT_SUCCESS(Status); 01244 01245 return Result; 01246 01247 } 01248 01249 01251 // // 01252 // Named Pipe Common Operations // 01253 // // 01255 01256 01257 VOID 01258 SepReadPipe( 01259 ) 01260 { 01261 IO_STATUS_BLOCK Iosb; 01262 UCHAR Buffer[512]; 01263 01264 DevPrint("ReadPipe...\n", 0); 01265 01266 if (!NT_SUCCESS(Status = NtReadFile( TalkPort, 01267 (HANDLE)NULL, 01268 (PIO_APC_ROUTINE)NULL, 01269 (PVOID)NULL, 01270 &Iosb, 01271 Buffer, 01272 512, 01273 (PLARGE_INTEGER)NULL, 01274 (PULONG) NULL ))) { 01275 Error( NtReadFile, Status ); 01276 } 01277 01278 if (!NT_SUCCESS(Status = NtWaitForSingleObject( TalkPort, TRUE, NULL ))) { 01279 01280 Error( NtWaitForSingleObject, Status ); 01281 } 01282 01283 if (!NT_SUCCESS(Iosb.Status)) { 01284 01285 Error( NtReadFileFinalStatus, Iosb.Status ); 01286 } 01287 01288 return; 01289 } 01290 01291 01292 VOID 01293 SepWritePipe( 01294 PSZ String 01295 ) 01296 { 01297 NTSTATUS Status; 01298 IO_STATUS_BLOCK Iosb; 01299 01300 01301 DevPrint("WritePipe...\n", 0); 01302 01303 if (!NT_SUCCESS(Status = NtWriteFile( TalkPort, 01304 (HANDLE)NULL, 01305 (PIO_APC_ROUTINE)NULL, 01306 (PVOID)NULL, 01307 &Iosb, 01308 String, 01309 strlen( String ), 01310 (PLARGE_INTEGER)NULL, 01311 (PULONG)NULL ))) { 01312 Error( NtWriteFile, Status ); 01313 } 01314 01315 if (!NT_SUCCESS(Status = NtWaitForSingleObject( TalkPort, TRUE, NULL ))) { 01316 01317 Error( NtWaitForSingleObject, Status ); 01318 } 01319 01320 if (!NT_SUCCESS(Iosb.Status)) { 01321 01322 Error( NtWriteFileFinalStatus, Iosb.Status ); 01323 } 01324 01325 return; 01326 } 01327 01328 01329 VOID 01330 SepTransceivePipe( 01331 PSZ String 01332 ) 01333 { 01334 NTSTATUS Status; 01335 IO_STATUS_BLOCK Iosb; 01336 UCHAR Buffer[512]; 01337 01338 01339 DevPrint("TransceivePipe...\n", 0); 01340 01341 if (!NT_SUCCESS(Status = NtFsControlFile( 01342 TalkPort, 01343 NULL, // Event 01344 NULL, // ApcRoutine 01345 NULL, // ApcContext 01346 &Iosb, 01347 FSCTL_PIPE_TRANSCEIVE, 01348 String, 01349 strlen( String ), 01350 Buffer, 01351 511 01352 ))) { 01353 Error( NtTransceiveFile, Status ); 01354 } 01355 01356 if (!NT_SUCCESS(Status = NtWaitForSingleObject( TalkPort, TRUE, NULL ))) { 01357 01358 Error( NtWaitForSingleObject, Status ); 01359 } 01360 01361 if (!NT_SUCCESS(Iosb.Status)) { 01362 01363 Error( NtTransceiveFileFinalStatus, Iosb.Status ); 01364 } 01365 01366 return; 01367 } 01368 01369 01371 // // 01372 // Named Pipe Server Operations // 01373 // // 01375 01376 HANDLE 01377 SepServerCreatePipe( 01378 VOID 01379 ) 01380 { 01381 HANDLE PipeHandle; 01382 NTSTATUS Status; 01383 IO_STATUS_BLOCK Iosb; 01384 LARGE_INTEGER Timeout; 01385 READ_MODE Mode; 01386 ULONG Share; 01387 NAMED_PIPE_CONFIGURATION Config = FILE_PIPE_FULL_DUPLEX; 01388 NAMED_PIPE_TYPE PipeType = FILE_PIPE_MESSAGE_TYPE; 01389 COMPLETION_MODE CompletionMode = FILE_PIPE_QUEUE_OPERATION; 01390 ULONG MaximumInstances = 4; 01391 01392 01393 // 01394 // Set the default timeout to 60 seconds, and initalize the attributes 01395 // 01396 01397 Timeout.QuadPart = -10 * 1000 * 1000 * 60; 01398 01399 InitializeObjectAttributes( 01400 &ObjectAttributes, 01401 &UnicodePortName, 01402 OBJ_CASE_INSENSITIVE, 01403 NULL, 01404 NULL 01405 ); 01406 01407 // 01408 // Calculate the readmode and share access 01409 // 01410 01411 Mode = (PipeType == FILE_PIPE_MESSAGE_TYPE ? FILE_PIPE_MESSAGE_MODE : 01412 FILE_PIPE_BYTE_STREAM_MODE); 01413 01414 Share = (Config == FILE_PIPE_INBOUND ? FILE_SHARE_WRITE : 01415 (Config == FILE_PIPE_OUTBOUND ? FILE_SHARE_READ : 01416 FILE_SHARE_READ | FILE_SHARE_WRITE)); 01417 01418 if (!NT_SUCCESS(Status = NtCreateNamedPipeFile( 01419 &PipeHandle, 01420 GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 01421 &ObjectAttributes, 01422 &Iosb, 01423 Share, 01424 FILE_CREATE, 01425 0, 01426 PipeType, 01427 Mode, 01428 CompletionMode, 01429 MaximumInstances, 01430 1024, 01431 1024, 01432 (PLARGE_INTEGER)&Timeout ))) { 01433 01434 Error( CreatePipe, Status ); 01435 } 01436 RtlFreeUnicodeString( &UnicodePortName ); 01437 01438 return PipeHandle; 01439 } 01440 01441 01442 VOID 01443 SepServerListenPipe( 01444 ) 01445 { 01446 NTSTATUS Status; 01447 IO_STATUS_BLOCK Iosb; 01448 01449 DevPrint("ListenPipe...\n", 0); 01450 01451 if (!NT_SUCCESS(Status = NtFsControlFile( 01452 EarPort, 01453 NULL, // Event 01454 NULL, // ApcRoutine 01455 NULL, // ApcContext 01456 &Iosb, 01457 FSCTL_PIPE_LISTEN, 01458 NULL, // InputBuffer 01459 0, // InputBufferLength, 01460 NULL, // OutputBuffer 01461 0 // OutputBufferLength 01462 ))) { 01463 01464 Error( ListenPipe, Status ); 01465 } 01466 if (!NT_SUCCESS(Status = NtWaitForSingleObject( EarPort, TRUE, NULL ))) { 01467 01468 Error( NtWaitForSingleObject, Status ); 01469 } 01470 01471 if (!NT_SUCCESS(Iosb.Status)) { 01472 01473 Error( ListenPipeFinalStatus, Iosb.Status ); 01474 } 01475 01476 01477 return; 01478 } 01479 01480 01481 VOID 01482 SepServerImpersonatePipe( 01483 ) 01484 { 01485 NTSTATUS Status; 01486 IO_STATUS_BLOCK Iosb; 01487 01488 DevPrint("ImpersonatePipe...\n", 0); 01489 01490 if (!NT_SUCCESS(Status = NtFsControlFile( 01491 TalkPort, 01492 NULL, // Event 01493 NULL, // ApcRoutine 01494 NULL, // ApcContext 01495 &Iosb, 01496 FSCTL_PIPE_IMPERSONATE, 01497 NULL, // InputBuffer 01498 0, // InputBufferLength, 01499 NULL, // OutputBuffer 01500 0 // OutputBufferLength 01501 ))) { 01502 01503 Error( ImpersonatePipe, Status ); 01504 } 01505 if (!NT_SUCCESS(Status = NtWaitForSingleObject( TalkPort, TRUE, NULL ))) { 01506 01507 Error( NtWaitForSingleObject, Status ); 01508 } 01509 01510 if (!NT_SUCCESS(Iosb.Status)) { 01511 01512 Error( ImpersonatePipeFinalStatus, Iosb.Status ); 01513 } 01514 01515 return; 01516 } 01517 01518 01519 VOID 01520 SepServerDisconnectPipe( 01521 ) 01522 { 01523 NTSTATUS Status; 01524 IO_STATUS_BLOCK Iosb; 01525 01526 DevPrint("DisconnectPipe...\n", 0); 01527 DevPrint(" (Flush)...\n", 0); 01528 01529 if (!NT_SUCCESS(Status = NtFlushBuffersFile( 01530 TalkPort, 01531 &Iosb 01532 ))) { 01533 Error( DisconnectPipe, Status ); 01534 } 01535 01536 if (!NT_SUCCESS(Iosb.Status)) { 01537 01538 Error( FlushPipeFinalStatus, Iosb.Status ); 01539 } 01540 01541 01542 DevPrint(" (Close Talk Port)...\n", 0); 01543 Status = NtClose( TalkPort ); SEASSERT_SUCCESS(Status); 01544 01545 DevPrint(" (Disconnect)...\n", 0); 01546 if (!NT_SUCCESS(Status = NtFsControlFile( 01547 EarPort, 01548 NULL, // Event 01549 NULL, // ApcRoutine 01550 NULL, // ApcContext 01551 &Iosb, 01552 FSCTL_PIPE_DISCONNECT, 01553 NULL, // InputBuffer 01554 0, // InputBufferLength, 01555 NULL, // OutputBuffer 01556 0 // OutputBufferLength 01557 ))) { 01558 01559 Error( DisconnectPipe, Status ); 01560 } 01561 if (!NT_SUCCESS(Status = NtWaitForSingleObject( EarPort, TRUE, NULL ))) { 01562 01563 Error( NtWaitForSingleObject, Status ); 01564 } 01565 01566 if (!NT_SUCCESS(Iosb.Status)) { 01567 01568 Error( DisconnectPipeFinalStatus, Iosb.Status ); 01569 } 01570 01571 return; 01572 } 01573 01574 01576 // // 01577 // Named Pipe Client Operations // 01578 // // 01580 01581 HANDLE 01582 SepClientOpenPipe( 01583 VOID 01584 ) 01585 { 01586 HANDLE PipeHandle, NpfsHandle; 01587 NTSTATUS Status; 01588 IO_STATUS_BLOCK Iosb; 01589 ULONG Share; 01590 STRING Npfs; 01591 UNICODE_STRING UnicodeNpfs; 01592 PFILE_PIPE_WAIT_FOR_BUFFER WaitPipe; 01593 ULONG WaitPipeLength; 01594 NAMED_PIPE_CONFIGURATION Config = FILE_PIPE_FULL_DUPLEX; 01595 READ_MODE ReadMode = FILE_PIPE_MESSAGE_MODE; 01596 COMPLETION_MODE CompletionMode = FILE_PIPE_QUEUE_OPERATION; 01597 01598 01599 //#ifdef NOT_YET_WORKING 01600 // 01601 // Wait for the server's pipe to reach a listen state... 01602 // 01603 01604 RtlInitString( &Npfs, "\\Device\\NamedPipe\\"); 01605 Status = RtlAnsiStringToUnicodeString( 01606 &UnicodeNpfs, 01607 &Npfs, 01608 TRUE ); SEASSERT_SUCCESS( NT_SUCCESS(Status) ); 01609 01610 InitializeObjectAttributes( 01611 &ObjectAttributes, 01612 &UnicodeNpfs, 01613 OBJ_CASE_INSENSITIVE, 01614 NULL, 01615 NULL); 01616 01617 if (!NT_SUCCESS(Status = NtOpenFile( 01618 &NpfsHandle, 01619 GENERIC_READ | SYNCHRONIZE, 01620 &ObjectAttributes, 01621 &Iosb, 01622 FILE_SHARE_READ, 01623 0 ))) { 01624 01625 Error( OpenNpfs, Status ); 01626 } 01627 RtlFreeUnicodeString( &UnicodeNpfs ); 01628 01629 WaitPipeLength = 01630 FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[0]) + 01631 RelativePortName.MaximumLength; //UNICODEFIX UnicodeRelativePortName.MaximumLength; 01632 WaitPipe = RtlAllocateHeap(RtlProcessHeap(), 0, WaitPipeLength); 01633 WaitPipe->TimeoutSpecified = FALSE; 01634 01635 WaitPipe->NameLength = RelativePortName.Length; //UNICODEFIX UnicodeRelativePortName.Length; 01636 strcpy(WaitPipe->Name, RelativePortName.Buffer); //UNICODEFIX UnicodePortName.Buffer; 01637 01638 if (!NT_SUCCESS(Status = NtFsControlFile( 01639 NpfsHandle, 01640 NULL, // Event 01641 NULL, // ApcRoutine 01642 NULL, // ApcContext 01643 &Iosb, 01644 FSCTL_PIPE_WAIT, 01645 WaitPipe, // Buffer for data to the FS 01646 WaitPipeLength, 01647 NULL, // OutputBuffer 01648 0 // OutputBufferLength 01649 ))) { 01650 01651 Error( ClientWaitPipe, Status ); 01652 } 01653 if (Status == STATUS_PENDING) { 01654 if (!NT_SUCCESS(Status = NtWaitForSingleObject( NpfsHandle, TRUE, NULL ))) { 01655 01656 Error( NtWaitForSingleObject, Status ); 01657 } 01658 } 01659 01660 if (!NT_SUCCESS(Iosb.Status)) { 01661 01662 Error( ClientWaitPipeFinalStatus, Iosb.Status ); 01663 } 01664 01665 Status = NtClose( NpfsHandle ); 01666 ASSERT(NT_SUCCESS(Status)); 01667 //#endif // NOT_YET_WORKING 01668 // Delay(1); 01669 01670 01671 // 01672 // Initialize the attributes 01673 // 01674 01675 InitializeObjectAttributes( 01676 &ObjectAttributes, 01677 &UnicodePortName, 01678 OBJ_CASE_INSENSITIVE, 01679 NULL, 01680 NULL 01681 ); 01682 ObjectAttributes.SecurityQualityOfService = (PVOID)(&SecurityQos); 01683 01684 // 01685 // Calculate the share access 01686 // 01687 01688 Share = (Config == FILE_PIPE_INBOUND ? FILE_SHARE_WRITE : 01689 (Config == FILE_PIPE_OUTBOUND ? FILE_SHARE_READ : 01690 FILE_SHARE_READ | FILE_SHARE_WRITE)); 01691 01692 01693 01694 // 01695 // And now open it... 01696 // 01697 01698 if (!NT_SUCCESS(Status = NtOpenFile( 01699 &PipeHandle, 01700 GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 01701 &ObjectAttributes, 01702 &Iosb, 01703 Share, 01704 0 ))) { 01705 01706 Error( OpenPipe, Status ); 01707 } 01708 01709 if ((ReadMode != FILE_PIPE_BYTE_STREAM_MODE) || 01710 (CompletionMode != FILE_PIPE_QUEUE_OPERATION)) { 01711 01712 FILE_PIPE_INFORMATION Buffer; 01713 01714 Buffer.ReadMode = ReadMode; 01715 Buffer.CompletionMode = CompletionMode; 01716 01717 if (!NT_SUCCESS(Status = NtSetInformationFile( 01718 PipeHandle, 01719 &Iosb, 01720 &Buffer, 01721 sizeof(FILE_PIPE_INFORMATION), 01722 FilePipeInformation ))) { 01723 01724 Error( NtSetInformationFile, Status ); 01725 } 01726 } 01727 01728 return PipeHandle; 01729 }

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