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

tseum.c File Reference

#include <stdio.h>
#include <string.h>
#include <nt.h>
#include <ntrtl.h>
#include "sep.h"
#include "ttoken.c"

Go to the source code of this file.

Functions

VOID RtlDumpAcl (IN PACL Acl)
 main (int argc, char *argv[], char *envp[])
VOID SeMain ()
BOOLEAN TestCreateAcl ()
BOOLEAN TestQueryInformationAcl ()
BOOLEAN TestSetInformationAcl ()
BOOLEAN TestAddAce ()
BOOLEAN TestDeleteAce ()
BOOLEAN TestGetAce ()
BOOLEAN TestAccessCheck ()
BOOLEAN TestGenerateMessage ()


Function Documentation

main int  argc,
char *  argv[],
char *  envp[]
 

Definition at line 39 of file tseum.c.

References DbgPrint, NTSTATUS(), NtTerminateProcess(), NULL, SeMain(), Status, and VOID().

00044 { 00045 HANDLE CurrentProcessHandle; 00046 NTSTATUS Status; 00047 ULONG i; 00048 VOID SeMain(); 00049 00050 CurrentProcessHandle = NtCurrentProcess(); 00051 Status = STATUS_SUCCESS; 00052 00053 DbgPrint( "Entering User Mode Test Program\n" ); 00054 00055 DbgPrint( "argc: %ld\n", argc ); 00056 if (argv != NULL) { 00057 for (i=0; i<argc; i++) { 00058 DbgPrint( "argv[ %ld ]: %s\n", i, argv[ i ] ); 00059 } 00060 } 00061 00062 if (envp != NULL) { 00063 i = 0; 00064 while (*envp) { 00065 DbgPrint( "envp[ %02ld ]: %s\n", i++, *envp++ ); 00066 } 00067 } 00068 00069 SeMain(); 00070 00071 DbgPrint( "Exiting User Mode Test Program with Status = %lx\n", Status ); 00072 00073 NtTerminateProcess( CurrentProcessHandle, Status ); 00074 }

VOID RtlDumpAcl IN PACL  Acl  ) 
 

Referenced by main(), and TestSeAclRtl().

VOID SeMain  ) 
 

Definition at line 78 of file tseum.c.

References DbgPrint, TestAccessCheck(), TestAddAce(), TestCreateAcl(), TestDeleteAce(), TestGenerateMessage(), TestGetAce(), TestQueryInformationAcl(), and TestSetInformationAcl().

Referenced by main().

00080 { 00081 BOOLEAN TestCreateAcl(); 00082 BOOLEAN TestQueryInformationAcl(); 00083 BOOLEAN TestSetInformationAcl(); 00084 BOOLEAN TestAddAce(); 00085 BOOLEAN TestDeleteAce(); 00086 BOOLEAN TestGetAce(); 00087 00088 BOOLEAN TestAccessCheck(); 00089 BOOLEAN TestGenerateMessage(); 00090 00091 DbgPrint("Starting User Mode Security Test\n"); 00092 00093 if (!TestCreateAcl()) { 00094 DbgPrint("TestCreateAcl Error\n"); 00095 return; 00096 } 00097 if (!TestQueryInformationAcl()) { 00098 DbgPrint("TestCreateAcl Error\n"); 00099 return; 00100 } 00101 if (!TestSetInformationAcl()) { 00102 DbgPrint("TestCreateAcl Error\n"); 00103 return; 00104 } 00105 if (!TestAddAce()) { 00106 DbgPrint("TestCreateAcl Error\n"); 00107 return; 00108 } 00109 if (!TestDeleteAce()) { 00110 DbgPrint("TestCreateAcl Error\n"); 00111 return; 00112 } 00113 if (!TestGetAce()) { 00114 DbgPrint("TestCreateAcl Error\n"); 00115 return; 00116 } 00117 00118 if (!TestAccessCheck()) { 00119 DbgPrint("TestCreateAcl Error\n"); 00120 return; 00121 } 00122 if (!TestGenerateMessage()) { 00123 DbgPrint("TestCreateAcl Error\n"); 00124 return; 00125 } 00126 00127 DbgPrint("Ending User Mode Security Test\n"); 00128 00129 return; 00130 }

BOOLEAN TestAccessCheck  ) 
 

Definition at line 502 of file tseum.c.

References DbgPrint, FALSE, Fred, NT_SUCCESS, NtAccessCheck(), NTSTATUS(), NULL, Status, Token, and TRUE.

00503 { 00504 UCHAR AclBuffer[1024]; 00505 SECURITY_DESCRIPTOR SecurityDescriptor; 00506 PACL Acl; 00507 00508 UCHAR TokenBuffer[512]; 00509 PACCESS_TOKEN Token; 00510 00511 NTSTATUS Status; 00512 00513 Acl = (PACL)AclBuffer; 00514 BuildAcl( Fred, Acl, 1024 ); 00515 00516 Token = (PACCESS_TOKEN)TokenBuffer; 00517 BuildToken( Fred, Token ); 00518 00519 DiscretionarySecurityDescriptor( &SecurityDescriptor, Acl ); 00520 00521 // 00522 // Test should be successful based on aces 00523 // 00524 00525 if (!NT_SUCCESS(Status = NtAccessCheck( &SecurityDescriptor, 00526 Token, 00527 0x00000001, 00528 NULL ))) { 00529 DbgPrint("NtAccessCheck Error should allow access : %8lx\n", Status); 00530 return FALSE; 00531 } 00532 00533 // 00534 // Test should be successful based on owner 00535 // 00536 00537 if (!NT_SUCCESS(Status = NtAccessCheck( &SecurityDescriptor, 00538 Token, 00539 READ_CONTROL, 00540 &FredGuid ))) { 00541 DbgPrint("NtAccessCheck Error should allow owner : %8lx\n", Status); 00542 return FALSE; 00543 } 00544 00545 // 00546 // Test should be unsuccessful based on aces 00547 // 00548 00549 if (NT_SUCCESS(Status = NtAccessCheck( &SecurityDescriptor, 00550 Token, 00551 0x0000000f, 00552 &FredGuid ))) { 00553 DbgPrint("NtAccessCheck Error shouldn't allow access : %8lx\n", Status); 00554 return FALSE; 00555 } 00556 00557 // 00558 // Test should be unsuccessful based on non owner 00559 // 00560 00561 if (NT_SUCCESS(Status = NtAccessCheck( &SecurityDescriptor, 00562 Token, 00563 READ_CONTROL, 00564 &BarneyGuid ))) { 00565 DbgPrint("NtAccessCheck Error shouldn't allow non owner access : %8lx\n", Status); 00566 return FALSE; 00567 } 00568 00569 return TRUE; 00570 }

BOOLEAN TestAddAce  ) 
 

Definition at line 282 of file tseum.c.

References DbgPrint, FALSE, _STANDARD_ACE::Header, _STANDARD_ACE::Mask, NT_SUCCESS, NTSTATUS(), RtlAddAce(), RtlCreateAcl(), STANDARD_ACE, Status, and TRUE.

Referenced by SeMain().

00283 { 00284 UCHAR AclBuffer[512]; 00285 PACL Acl; 00286 00287 STANDARD_ACE AceList[2]; 00288 00289 NTSTATUS Status; 00290 00291 Acl = (PACL)AclBuffer; 00292 00293 // 00294 // Create a good large acl 00295 // 00296 00297 if (!NT_SUCCESS(Status = RtlCreateAcl( Acl, 512, 1))) { 00298 DbgPrint("RtlCreateAcl Error large Acl : %8lx\n", Status); 00299 return FALSE; 00300 } 00301 00302 // 00303 // test add ace to add two aces to an empty acl 00304 // 00305 00306 AceList[0].Header.AceType = ACCESS_ALLOWED_ACE_TYPE; 00307 AceList[0].Header.AceSize = sizeof(STANDARD_ACE); 00308 AceList[0].Header.InheritFlags = 0; 00309 AceList[0].Header.AceFlags = 0; 00310 AceList[0].Mask = 0x22222222; 00311 CopyGuid(&AceList[0].Guid, &FredGuid); 00312 00313 AceList[1].Header.AceType = ACCESS_ALLOWED_ACE_TYPE; 00314 AceList[1].Header.AceSize = sizeof(STANDARD_ACE); 00315 AceList[1].Header.InheritFlags = 0; 00316 AceList[1].Header.AceFlags = 0; 00317 AceList[1].Mask = 0x44444444; 00318 CopyGuid(&AceList[1].Guid, &WilmaGuid); 00319 00320 if (!NT_SUCCESS(Status = RtlAddAce( Acl, 00321 1, 00322 0, 00323 AceList, 00324 2*sizeof(STANDARD_ACE)))) { 00325 DbgPrint("RtlAddAce to empty acl Error : %8lx\n", Status); 00326 return FALSE; 00327 } 00328 00329 // RtlDumpAcl(Acl); 00330 00331 // 00332 // test add ace to add one to the beginning of an acl 00333 // 00334 00335 AceList[0].Header.AceType = SYSTEM_AUDIT_ACE_TYPE; 00336 AceList[0].Header.AceSize = sizeof(STANDARD_ACE); 00337 AceList[0].Header.InheritFlags = 0; 00338 AceList[0].Header.AceFlags = 0; 00339 AceList[0].Mask = 0x11111111; 00340 CopyGuid(&AceList[0].Guid, &PebblesGuid); 00341 00342 if (!NT_SUCCESS(Status = RtlAddAce( Acl, 00343 1, 00344 0, 00345 AceList, 00346 sizeof(STANDARD_ACE)))) { 00347 DbgPrint("RtlAddAce to beginning of acl Error : %8lx\n", Status); 00348 return FALSE; 00349 } 00350 00351 // RtlDumpAcl(Acl); 00352 00353 // 00354 // test add ace to add one to the middle of an acl 00355 // 00356 00357 AceList[0].Header.AceType = ACCESS_DENIED_ACE_TYPE; 00358 AceList[0].Header.AceSize = sizeof(STANDARD_ACE); 00359 AceList[0].Header.InheritFlags = 0; 00360 AceList[0].Header.AceFlags = 0; 00361 AceList[0].Mask = 0x33333333; 00362 CopyGuid(&AceList[0].Guid, &DinoGuid); 00363 00364 if (!NT_SUCCESS(Status = RtlAddAce( Acl, 00365 1, 00366 2, 00367 AceList, 00368 sizeof(STANDARD_ACE)))) { 00369 DbgPrint("RtlAddAce to middle of acl Error : %8lx\n", Status); 00370 return FALSE; 00371 } 00372 00373 // RtlDumpAcl(Acl); 00374 00375 // 00376 // test add ace to add one to the end of an acl 00377 // 00378 00379 AceList[0].Header.AceType = ACCESS_DENIED_ACE_TYPE; 00380 AceList[0].Header.AceSize = sizeof(STANDARD_ACE); 00381 AceList[0].Header.InheritFlags = 0; 00382 AceList[0].Header.AceFlags = 0; 00383 AceList[0].Mask = 0x55555555; 00384 CopyGuid(&AceList[0].Guid, &FlintstoneGuid); 00385 00386 if (!NT_SUCCESS(Status = RtlAddAce( Acl, 00387 1, 00388 MAXULONG, 00389 AceList, 00390 sizeof(STANDARD_ACE)))) { 00391 DbgPrint("RtlAddAce to end of an acl Error : %8lx\n", Status); 00392 return FALSE; 00393 } 00394 00395 // RtlDumpAcl(Acl); 00396 00397 return TRUE; 00398 }

BOOLEAN TestCreateAcl  ) 
 

Definition at line 134 of file tseum.c.

References Buffer, DbgPrint, FALSE, NT_SUCCESS, NTSTATUS(), RtlCreateAcl(), Status, and TRUE.

Referenced by SeMain().

00135 { 00136 UCHAR Buffer[512]; 00137 PACL Acl; 00138 00139 NTSTATUS Status; 00140 00141 Acl = (PACL)Buffer; 00142 00143 // 00144 // Create a good large acl 00145 // 00146 00147 if (!NT_SUCCESS(Status = RtlCreateAcl( Acl, 512, 1))) { 00148 DbgPrint("RtlCreateAcl Error large Acl : %8lx\n", Status); 00149 return FALSE; 00150 } 00151 00152 // 00153 // Create a good small acl 00154 // 00155 00156 if (!NT_SUCCESS(Status = RtlCreateAcl( Acl, sizeof(ACL), 1))) { 00157 DbgPrint("RtlCreateAcl Error small Acl : %8lx\n", Status); 00158 return FALSE; 00159 } 00160 00161 // 00162 // Create a too small acl 00163 // 00164 00165 if (NT_SUCCESS(Status = RtlCreateAcl( Acl, sizeof(ACL) - 1, 1))) { 00166 DbgPrint("RtlCreateAcl Error too small Acl : %8lx\n", Status); 00167 return FALSE; 00168 } 00169 00170 // 00171 // Create a bad version acl 00172 // 00173 00174 if (NT_SUCCESS(Status = RtlCreateAcl( Acl, 512, 2))) { 00175 DbgPrint("RtlCreateAcl Error bad version : %8lx\n", Status); 00176 return FALSE; 00177 } 00178 00179 return TRUE; 00180 }

BOOLEAN TestDeleteAce  ) 
 

Definition at line 402 of file tseum.c.

References Buffer, DbgPrint, FALSE, Fred, NT_SUCCESS, NTSTATUS(), RtlDeleteAce(), Status, and TRUE.

Referenced by SeMain().

00403 { 00404 UCHAR Buffer[512]; 00405 PACL Acl; 00406 00407 NTSTATUS Status; 00408 00409 Acl = (PACL)Buffer; 00410 00411 BuildAcl( Fred, Acl, 512 ); 00412 00413 // 00414 // test delete first ace 00415 // 00416 00417 if (!NT_SUCCESS(Status = RtlDeleteAce(Acl, 0))) { 00418 DbgPrint("RtlDeleteAce first ace Error : %8lx\n", Status); 00419 return FALSE; 00420 } 00421 00422 // RtlDumpAcl(Acl); 00423 00424 // 00425 // test delete middle ace 00426 // 00427 00428 if (!NT_SUCCESS(Status = RtlDeleteAce(Acl, 2))) { 00429 DbgPrint("RtlDeleteAce middle ace Error : %8lx\n", Status); 00430 return FALSE; 00431 } 00432 00433 // RtlDumpAcl(Acl); 00434 00435 // 00436 // test delete last ace 00437 // 00438 00439 if (!NT_SUCCESS(Status = RtlDeleteAce(Acl, 3))) { 00440 DbgPrint("RtlDeleteAce last ace Error : %8lx\n", Status); 00441 return FALSE; 00442 } 00443 00444 // RtlDumpAcl(Acl); 00445 00446 return TRUE; 00447 }

BOOLEAN TestGenerateMessage  ) 
 

Definition at line 574 of file tseum.c.

References TRUE.

00575 { 00576 return TRUE; 00577 }

BOOLEAN TestGetAce  ) 
 

Definition at line 451 of file tseum.c.

References Buffer, DbgPrint, FALSE, Fred, NT_SUCCESS, NTSTATUS(), RtlGetAce(), Status, and TRUE.

Referenced by SeMain().

00452 { 00453 UCHAR Buffer[512]; 00454 PACL Acl; 00455 00456 STANDARD_ACE Ace; 00457 00458 NTSTATUS Status; 00459 00460 Acl = (PACL)Buffer; 00461 00462 BuildAcl( Fred, Acl, 512 ); 00463 00464 // 00465 // Get first ace 00466 // 00467 00468 if (!NT_SUCCESS(Status = RtlGetAce(Acl, 0, (PVOID)&Ace))) { 00469 DbgPrint("RtlGetAce first ace error : %8lx\n", Status); 00470 return FALSE; 00471 } 00472 00473 // RtlDumpAcl(Acl); 00474 00475 // 00476 // Get middle ace 00477 // 00478 00479 if (!NT_SUCCESS(Status = RtlGetAce(Acl, 3, (PVOID)&Ace))) { 00480 DbgPrint("RtlGetAce middle ace error : %8lx\n", Status); 00481 return FALSE; 00482 } 00483 00484 // RtlDumpAcl(Acl); 00485 00486 // 00487 // Get last ace 00488 // 00489 00490 if (!NT_SUCCESS(Status = RtlGetAce(Acl, 5, (PVOID)&Ace))) { 00491 DbgPrint("RtlGetAce last ace error : %8lx\n", Status); 00492 return FALSE; 00493 } 00494 00495 // RtlDumpAcl(Acl); 00496 00497 return TRUE; 00498 }

BOOLEAN TestQueryInformationAcl  ) 
 

Definition at line 184 of file tseum.c.

References Buffer, DbgPrint, FALSE, Fred, NT_SUCCESS, NTSTATUS(), RtlQueryInformationAcl(), Status, and TRUE.

Referenced by SeMain().

00185 { 00186 UCHAR Buffer[512]; 00187 PACL Acl; 00188 ACL_REVISION_INFORMATION AclRevisionInfo; 00189 ACL_SIZE_INFORMATION AclSizeInfo; 00190 00191 NTSTATUS Status; 00192 00193 Acl = (PACL)Buffer; 00194 00195 BuildAcl( Fred, Acl, 512 ); 00196 00197 // 00198 // Query the revision information 00199 // 00200 00201 if (!NT_SUCCESS(Status = RtlQueryInformationAcl( Acl, 00202 (PVOID)&AclRevisionInfo, 00203 sizeof(ACL_REVISION_INFORMATION), 00204 AclRevisionInformation))) { 00205 DbgPrint("RtlQueryInformationAcl revision info error : %8lx\n", Status); 00206 return FALSE; 00207 } 00208 if (AclRevisionInfo.AclRevision != ACL_REVISION) { 00209 DbgPrint("RtlAclRevision Error\n"); 00210 return FALSE; 00211 } 00212 00213 // 00214 // Query size information 00215 // 00216 00217 if (!NT_SUCCESS(Status = RtlQueryInformationAcl( Acl, 00218 (PVOID)&AclSizeInfo, 00219 sizeof(ACL_SIZE_INFORMATION), 00220 AclSizeInformation))) { 00221 DbgPrint("RtlQueryInformationAcl size info Error : %8lx\n", Status); 00222 return FALSE; 00223 } 00224 if ((AclSizeInfo.AceCount != 6) || 00225 (AclSizeInfo.AclBytesInUse != (sizeof(ACL)+6*sizeof(STANDARD_ACE))) || 00226 (AclSizeInfo.AclBytesFree != 512 - AclSizeInfo.AclBytesInUse)) { 00227 DbgPrint("RtlAclSize Error\n"); 00228 DbgPrint("AclSizeInfo.AceCount = %8lx\n", AclSizeInfo.AceCount); 00229 DbgPrint("AclSizeInfo.AclBytesInUse = %8lx\n", AclSizeInfo.AclBytesInUse); 00230 DbgPrint("AclSizeInfo.AclBytesFree = %8lx\n", AclSizeInfo.AclBytesFree); 00231 return FALSE; 00232 } 00233 00234 return TRUE; 00235 }

BOOLEAN TestSetInformationAcl  ) 
 

Definition at line 239 of file tseum.c.

References Buffer, DbgPrint, FALSE, Fred, NT_SUCCESS, NTSTATUS(), RtlSetInformationAcl(), Status, and TRUE.

Referenced by SeMain().

00240 { 00241 UCHAR Buffer[512]; 00242 PACL Acl; 00243 ACL_REVISION_INFORMATION AclRevisionInfo; 00244 00245 NTSTATUS Status; 00246 00247 Acl = (PACL)Buffer; 00248 00249 BuildAcl( Fred, Acl, 512 ); 00250 00251 // 00252 // Set the revision information to the current revision level 00253 // 00254 00255 AclRevisionInfo.AclRevision = ACL_REVISION; 00256 if (!NT_SUCCESS(Status = RtlSetInformationAcl( Acl, 00257 (PVOID)&AclRevisionInfo, 00258 sizeof(ACL_REVISION_INFORMATION), 00259 AclRevisionInformation))) { 00260 DbgPrint("RtlSetInformationAcl revision info error : %8lx\n", Status); 00261 return FALSE; 00262 } 00263 00264 // 00265 // Set the revision information to something wrong 00266 // 00267 00268 AclRevisionInfo.AclRevision = ACL_REVISION+1; 00269 if (NT_SUCCESS(Status = RtlSetInformationAcl( Acl, 00270 (PVOID)&AclRevisionInfo, 00271 sizeof(ACL_REVISION_INFORMATION), 00272 AclRevisionInformation))) { 00273 DbgPrint("RtlSetInformationAcl revision to wrong info error : %8lx\n", Status); 00274 return FALSE; 00275 } 00276 00277 return TRUE; 00278 }


Generated on Sat May 15 19:45:49 2004 for test by doxygen 1.3.7