symport/e32/common/secure.cpp
changeset 1 0a7b44b10206
child 2 806186ab5e14
equal deleted inserted replaced
0:c55016431358 1:0a7b44b10206
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\common\secure.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #define __INCLUDE_ALL_SUPPORTED_CAPABILITIES__
       
    19 #include "common.h"
       
    20 #ifdef __KERNEL_MODE__
       
    21 #include <kernel.h>
       
    22 #include <kern_priv.h>
       
    23 #endif
       
    24 
       
    25 // Check that the layout of TSecurityInfo and SSecurityInfo are the same
       
    26 // because we use this assumption in the TSecurityInfo::Set methods
       
    27 __ASSERT_COMPILE(_FOFF(TSecurityInfo,iSecureId)==_FOFF(SSecurityInfo,iSecureId));
       
    28 __ASSERT_COMPILE(_FOFF(TSecurityInfo,iVendorId)==_FOFF(SSecurityInfo,iVendorId));
       
    29 __ASSERT_COMPILE(_FOFF(TSecurityInfo,iCaps)==_FOFF(SSecurityInfo,iCaps));
       
    30 
       
    31 #ifndef __TOOLS2__
       
    32 #ifdef __KERNEL_MODE__
       
    33 
       
    34 
       
    35 /**
       
    36 Construct a TSecurityInfo setting it to the security attributes of aProcess.
       
    37 @param aProcess A process.
       
    38 */
       
    39 EXPORT_C TSecurityInfo::TSecurityInfo(DProcess* aProcess)
       
    40 	{
       
    41 	memcpy(this, &aProcess->iS, sizeof(SSecurityInfo));
       
    42 	}
       
    43 
       
    44 /**
       
    45 Construct a TSecurityInfo setting it to the security attributes to those of the process
       
    46 owning the specified thread.
       
    47 @param aThread A thread.
       
    48 */
       
    49 EXPORT_C TSecurityInfo::TSecurityInfo(DThread* aThread)
       
    50 	{
       
    51 	memcpy(this, &aThread->iOwningProcess->iS, sizeof(SSecurityInfo));
       
    52 	}
       
    53 
       
    54 #else
       
    55 
       
    56 /**
       
    57 Construct a TSecurityInfo setting it to the security attributes of aProcess.
       
    58 @param aProcess A process.
       
    59 */
       
    60 EXPORT_C TSecurityInfo::TSecurityInfo(RProcess aProcess)
       
    61 	{
       
    62 	Exec::ProcessSecurityInfo(aProcess.Handle(),*(SSecurityInfo*)this);
       
    63 	}
       
    64 
       
    65 /**
       
    66 Construct a TSecurityInfo setting it to the security attributes to those of the process
       
    67 owning the specified thread.
       
    68 @param aThread A thread.
       
    69 */
       
    70 EXPORT_C TSecurityInfo::TSecurityInfo(RThread aThread)
       
    71 	{
       
    72 	Exec::ThreadSecurityInfo(aThread.Handle(),*(SSecurityInfo*)this);
       
    73 	}
       
    74 
       
    75 /**
       
    76 Construct a TSecurityInfo setting it to the security attributes of the process
       
    77 which sent the message aMsgPtr
       
    78 @param aMsgPtr a message
       
    79 */
       
    80 EXPORT_C TSecurityInfo::TSecurityInfo(RMessagePtr2 aMsgPtr)
       
    81 	{
       
    82 	Exec::MessageSecurityInfo(aMsgPtr.Handle(),*(SSecurityInfo*)this);
       
    83 	}
       
    84 
       
    85 TInt TSecurityInfo::Set(RSessionBase aSession)
       
    86 	{
       
    87 	return Exec::SessionSecurityInfo(aSession.Handle(),*(SSecurityInfo*)this);
       
    88 	}
       
    89 
       
    90 /**
       
    91 Sets this TSecurityInfo to the security attributes of this process' creator.
       
    92 */
       
    93 EXPORT_C void TSecurityInfo::SetToCreatorInfo()
       
    94 	{
       
    95 	Exec::CreatorSecurityInfo(*(SSecurityInfo*)this);
       
    96 	}
       
    97 
       
    98 #endif //__KERNEL_MODE__
       
    99 #endif // __TOOLS2__
       
   100 
       
   101 /**
       
   102 Construct a set consisting of two capabilities.
       
   103 @param aCapability1 The first capability.
       
   104 @param aCapability2 The second capability.
       
   105 */
       
   106 EXPORT_C TCapabilitySet::TCapabilitySet(TCapability aCapability1, TCapability aCapability2)
       
   107 	{
       
   108 	SetEmpty();
       
   109 	AddCapability(aCapability1);
       
   110 	AddCapability(aCapability2);
       
   111 	}
       
   112 
       
   113 /**
       
   114 Make this set empty. I.e. Containing no capabilities.
       
   115 */
       
   116 EXPORT_C void TCapabilitySet::SetEmpty()
       
   117 	{
       
   118 	memset(iCaps,0,sizeof(iCaps));
       
   119 	}
       
   120 
       
   121 
       
   122 /**
       
   123 Make this set consist of all capabilities supported by this OS version.
       
   124 */
       
   125 EXPORT_C void TCapabilitySet::SetAllSupported()
       
   126 	{
       
   127 	*(SCapabilitySet*)&iCaps=AllSupportedCapabilities;
       
   128 	}
       
   129 
       
   130 #ifndef __TOOLS2__
       
   131 #ifndef __KERNEL_MODE__
       
   132 // Documented in header file
       
   133 EXPORT_C void TCapabilitySet::SetDisabled()
       
   134 	{
       
   135 	Exec::DisabledCapabilities(*(SCapabilitySet*)this);
       
   136 	}
       
   137 #endif // __KERNEL_MODE__
       
   138 #endif // __TOOLS2__
       
   139 
       
   140 /**
       
   141 Add a single capability to the set.
       
   142 If the capability is not supported by this OS version then it is not added and
       
   143 the set is left unchanged.
       
   144 @see TCapabilitySet::SetAllSupported()
       
   145 @param aCapability Capability to add.
       
   146 */
       
   147 EXPORT_C void TCapabilitySet::AddCapability(TCapability aCapability)
       
   148 	{
       
   149 	if((TUint32)aCapability<(TUint32)ECapability_Limit)
       
   150 		{
       
   151 		TInt index = aCapability>>3;
       
   152 		TUint8 mask = (TUint8)(1<<(aCapability&7));
       
   153 		mask &= ((TUint8*)&AllSupportedCapabilities)[index];
       
   154 		((TUint8*)iCaps)[index] |= mask;
       
   155 		}
       
   156 	}
       
   157 
       
   158 /**
       
   159 Remove a single capability from the set, if it is present.
       
   160 @param aCapability Capability to remove.
       
   161 */
       
   162 EXPORT_C void TCapabilitySet::RemoveCapability(TCapability aCapability)
       
   163 	{
       
   164 	if((TUint32)aCapability<(TUint32)ECapability_Limit)
       
   165 		{
       
   166 		TInt index = aCapability>>3;
       
   167 		TUint8 mask = (TUint8)(1<<(aCapability&7));
       
   168 		((TUint8*)iCaps)[index] &= ~mask;
       
   169 		}
       
   170 	}
       
   171 
       
   172 /**
       
   173 Perform a union of this capability set with another.
       
   174 The result replaces the content of 'this'.
       
   175 @param aCapabilities A cpability set
       
   176 */
       
   177 EXPORT_C void TCapabilitySet::Union(const TCapabilitySet& aCapabilities)
       
   178 	{
       
   179 	for(TInt n = (ECapability_Limit-1)>>5; n>=0; n--)
       
   180 		iCaps[n] |= aCapabilities.iCaps[n];
       
   181 	}
       
   182 
       
   183 /**
       
   184 Perform an intersection of this capability set with another.
       
   185 The result replaces the content of 'this'.
       
   186 @param aCapabilities A capability set
       
   187 */
       
   188 EXPORT_C void TCapabilitySet::Intersection(const TCapabilitySet& aCapabilities)
       
   189 	{
       
   190 	for(TInt n = (ECapability_Limit-1)>>5; n>=0; n--)
       
   191 		iCaps[n] &= aCapabilities.iCaps[n];
       
   192 	}
       
   193 
       
   194 /**
       
   195 Remove a set of capabilities from this set.
       
   196 @param aCapabilities The set of capabilities to remove
       
   197 */
       
   198 EXPORT_C void TCapabilitySet::Remove(const TCapabilitySet& aCapabilities)
       
   199 	{
       
   200 	for(TInt n = (ECapability_Limit-1)>>5; n>=0; n--)
       
   201 		iCaps[n] &= ~aCapabilities.iCaps[n];
       
   202 	}
       
   203 
       
   204 /**
       
   205 Test if a single capability is present in the set.
       
   206 The capability ECapability_None is always treated as being present.
       
   207 @param aCapability The capability to test
       
   208 @return 1 if the capability is present, 0 if it is not.
       
   209 */
       
   210 EXPORT_C TBool TCapabilitySet::HasCapability(TCapability aCapability) const
       
   211 	{
       
   212 	if((TUint32)aCapability<(TUint32)ECapability_Limit)
       
   213 		return (((TUint8*)iCaps)[aCapability>>3]>>(aCapability&7))&1;
       
   214 	if(aCapability==ECapability_None)
       
   215 		return ETrue;
       
   216 	return EFalse;  // Handles illegal argument and ECapability_Denied
       
   217 	}
       
   218 
       
   219 /**
       
   220 Test if all the capabilities in a given set are present in this set
       
   221 @param aCapabilities The capability set to test
       
   222 @return A non-zero value if all the capabilities are present, zero otherwise.
       
   223 */
       
   224 EXPORT_C TBool TCapabilitySet::HasCapabilities(const TCapabilitySet& aCapabilities) const
       
   225 	{
       
   226 	TUint32 checkFail=0;
       
   227 	for(TInt n = (ECapability_Limit-1)>>5; n>=0; n--)
       
   228 		checkFail |= aCapabilities.iCaps[n]&~iCaps[n];
       
   229 	return checkFail?0:1;
       
   230 	}
       
   231 
       
   232 // Documented in header file
       
   233 TBool TCapabilitySet::NotEmpty() const
       
   234 	{
       
   235 	TUint32 notEmpty=0;
       
   236 	for(TInt n = (ECapability_Limit-1)>>5; n>=0; n--)
       
   237 		notEmpty |= iCaps[n];
       
   238 	return notEmpty;
       
   239 	}
       
   240 
       
   241 //ECapability_None is assumed to be -1 in the internals of TSecurityPolicy
       
   242 __ASSERT_COMPILE(ECapability_None == -1);
       
   243 
       
   244 /** Constructs a TSecurityPolicy to either always pass or always fail checks made
       
   245 against it, depending on the value of aType.
       
   246 @param aType Must be one of EAlwaysPass or EAlwaysFail
       
   247 @panic USER 191 if aType is not a valid value
       
   248 */
       
   249 EXPORT_C TSecurityPolicy::TSecurityPolicy(TSecPolicyType aType)
       
   250 	: iType((TUint8)aType), iSecureId(TUint32(ECapability_None))
       
   251 	{
       
   252 	//This constructor uses TSecPolicyType as public alias for the internal
       
   253 	//TType.  Thus EAlwaysFail must have the same value as ETypeFail (same with the
       
   254 	//pass case too).
       
   255 	__ASSERT_COMPILE(EAlwaysFail == (TSecPolicyType)ETypeFail);
       
   256 	__ASSERT_COMPILE(EAlwaysPass == (TSecPolicyType)ETypePass);
       
   257 
       
   258 	__ASSERT_ALWAYS(aType == EAlwaysFail || aType == EAlwaysPass, Panic(ETSecPolicyTypeInvalid));
       
   259 	iCaps[0] = (TUint8)ECapability_None;
       
   260 	iCaps[1] = (TUint8)ECapability_None;
       
   261 	iCaps[2] = (TUint8)ECapability_None;
       
   262 	}
       
   263 
       
   264 /** Construct a TSecurityPolicy object to check up to 3 capabilties.
       
   265 @param aCap1 The first capability to add to this policy
       
   266 @param aCap2 An optional second capability to add to this policy
       
   267 @param aCap3 An optional third capability to add to this policy
       
   268 @panic USER 189 If any of the supplied capabilities are not valid.
       
   269 */
       
   270 EXPORT_C TSecurityPolicy::TSecurityPolicy(TCapability aCap1, TCapability aCap2, TCapability aCap3)
       
   271 	//iSecureId=0xFFFFFFFF sets iExtraCaps[0-3] each to ECapability_None (==0xFF)
       
   272 	: iType(ETypeC3), iSecureId(TUint32(ECapability_None))
       
   273 	{
       
   274 	ConstructAndCheck3(aCap1, aCap2, aCap3);
       
   275 	}
       
   276 
       
   277 /** Construct a TSecurityPolicy object to check up to 7 capabilties.
       
   278 @param aCap1 The first capability to add to this policy
       
   279 @param aCap2 The second capability to add to this policy
       
   280 @param aCap3 The third capability to add to this policy
       
   281 @param aCap4 The fourth capability to add to this policy
       
   282 @param aCap5 An optional fifth capability to add to this policy
       
   283 @param aCap6 An optional sixth capability to add to this policy
       
   284 @param aCap7 An optional seventh capability to add to this policy
       
   285 @panic USER 189 If any of the supplied capabilities are not valid.
       
   286 */
       
   287 EXPORT_C TSecurityPolicy::TSecurityPolicy(TCapability aCap1, TCapability aCap2, 
       
   288 	TCapability aCap3, TCapability aCap4, TCapability aCap5, TCapability aCap6, TCapability aCap7)
       
   289 	: iType(ETypeC7)  
       
   290 	{
       
   291 	ConstructAndCheck3(aCap1, aCap2, aCap3);
       
   292 	__ASSERT_COMPILE(ECapability_None==-1); // Our argument check below assumes this
       
   293 	__ASSERT_ALWAYS(  (TUint)(aCap4+1)<=(TUint)ECapability_Limit
       
   294 					&&(TUint)(aCap5+1)<=(TUint)ECapability_Limit
       
   295 					&&(TUint)(aCap6+1)<=(TUint)ECapability_Limit
       
   296 					&&(TUint)(aCap7+1)<=(TUint)ECapability_Limit
       
   297 					,Panic(ECapabilityInvalid));
       
   298 	iExtraCaps[0] = (TUint8)aCap4;
       
   299 	iExtraCaps[1] = (TUint8)aCap5;
       
   300 	iExtraCaps[2] = (TUint8)aCap6;
       
   301 	iExtraCaps[3] = (TUint8)aCap7;
       
   302 	}
       
   303 
       
   304 /** Construct a TSecurityPolicy object to check a secure id and up to 3 capabilties.
       
   305 @param aSecureId The secure id to add to this policy
       
   306 @param aCap1 The first capability to add to this policy
       
   307 @param aCap2 The second capability to add to this policy
       
   308 @param aCap3 The third capability to add to this policy
       
   309 @panic USER 189 If any of the supplied capabilities are not valid.
       
   310 */
       
   311 EXPORT_C TSecurityPolicy::TSecurityPolicy(TSecureId aSecureId, 
       
   312 	TCapability aCap1, TCapability aCap2, TCapability aCap3)
       
   313 	: iType(ETypeS3), iSecureId(aSecureId)
       
   314 	{
       
   315 	ConstructAndCheck3(aCap1, aCap2, aCap3);
       
   316 	}
       
   317 
       
   318 /** Construct a TSecurityPolicy object to check a vendor id and up to 3 capabilties.
       
   319 @param aVendorId The vendor id to add to this policy
       
   320 @param aCap1 The first capability to add to this policy
       
   321 @param aCap2 The second capability to add to this policy
       
   322 @param aCap3 The third capability to add to this policy
       
   323 @panic USER 189 If any of the supplied capabilities are not valid.
       
   324 */
       
   325 EXPORT_C TSecurityPolicy::TSecurityPolicy(TVendorId aVendorId, 
       
   326 	TCapability aCap1, TCapability aCap2, TCapability aCap3)
       
   327 	: iType(ETypeV3), iVendorId(aVendorId)
       
   328 	{
       
   329 	ConstructAndCheck3(aCap1, aCap2, aCap3);
       
   330 	}
       
   331 
       
   332 /** Sets up iCaps[0-2] with supplied values and checks for their validity.
       
   333 @panic USER 189 If any of the supplied capabilities are invalid.
       
   334 */
       
   335 void TSecurityPolicy::ConstructAndCheck3(TCapability aCap1, TCapability aCap2, TCapability aCap3)
       
   336 	{
       
   337 	__ASSERT_COMPILE(ECapability_None==-1); // Our argument check below assumes this
       
   338 	__ASSERT_ALWAYS(  (TUint)(aCap1+1)<=(TUint)ECapability_Limit
       
   339 					&&(TUint)(aCap2+1)<=(TUint)ECapability_Limit
       
   340 					&&(TUint)(aCap3+1)<=(TUint)ECapability_Limit
       
   341 					,Panic(ECapabilityInvalid));
       
   342 	iCaps[0] = (TUint8)aCap1;
       
   343 	iCaps[1] = (TUint8)aCap2;
       
   344 	iCaps[2] = (TUint8)aCap3;
       
   345 	}
       
   346 
       
   347 /**
       
   348 Checks that this object is in a valid state
       
   349 @return A non-zero value if this object is valid, zero otherwise.
       
   350 @internalComponent
       
   351 */
       
   352 TBool TSecurityPolicy::Validate() const
       
   353 	{
       
   354 	switch(iType)
       
   355 		{
       
   356 		case ETypeFail:
       
   357 		case ETypePass:
       
   358 			if(iSecureId!=TUint32(ECapability_None))
       
   359 				return EFalse;
       
   360 			__ASSERT_COMPILE(TUint8(ECapability_None)==0xffu); // Test below assumes this...
       
   361 			if((iCaps[0]&iCaps[1]&iCaps[2])!=TUint8(ECapability_None)) // check caps 0 to 2 are each == ECapability_None
       
   362 				return EFalse;
       
   363 			return ETrue;
       
   364 
       
   365 		case ETypeC7:
       
   366 			return ETrue;
       
   367 
       
   368 		case ETypeC3:
       
   369 			if(iSecureId!=TUint32(ECapability_None))
       
   370 				return EFalse;
       
   371 			return ETrue;
       
   372 
       
   373 		case ETypeS3:
       
   374 		case ETypeV3:
       
   375 			return ETrue;
       
   376 
       
   377 		default:
       
   378 			return EFalse;
       
   379 		}
       
   380 	}
       
   381 
       
   382 /** Sets this TSecurityPolicy to a copy of the policy described by the
       
   383 supplied descriptor. Such a descriptor can be obtained from
       
   384 TSecurityPolicy::Package().
       
   385 @see TSecurityPolicy::Package()
       
   386 @param aDes A descriptor representing the state of another TSecurityPolicy.
       
   387 @return KErrNone, if successful, otherwise one of the other system-wide error
       
   388 codes.
       
   389 */
       
   390 EXPORT_C TInt TSecurityPolicy::Set(const TDesC8& aDes)
       
   391 	{
       
   392 	if(aDes.Size() == sizeof(TSecurityPolicy))
       
   393 		{
       
   394 		*this = *(TSecurityPolicy*)aDes.Ptr();
       
   395 		if(Validate())
       
   396 			return KErrNone;
       
   397 		}
       
   398 	// Set failed so set up the policy as an EAlwaysFail case.
       
   399 	iType = EAlwaysFail;
       
   400 	iCaps[0] = TUint8(ECapability_None);
       
   401 	iCaps[1] = TUint8(ECapability_None);
       
   402 	iCaps[2] = TUint8(ECapability_None);
       
   403 	iSecureId = TUint32(ECapability_None);
       
   404 	return KErrArgument;
       
   405 	}
       
   406 
       
   407 /** 
       
   408 Constructs a TPtrC8 wrapping the platform security attributes of this
       
   409 TSecurityPolicy.  Such a descriptor is suitable for passing across the
       
   410 client server boundary.
       
   411 
       
   412 The format of the descriptor is determined by the first byte which specifies 
       
   413 the type of this TSecurityPolicy.  The first byte is one of the constants
       
   414 specified in the enum TSecurityPolicy::TType.
       
   415 
       
   416 For TSecurityPolicy objects of types ETypeC3, ETypeS3, ETypePass or ETypeFail
       
   417 the descriptor will contain the following data in the order listed:
       
   418 @code
       
   419 	TUint8 iType; 		// set to ETypeC3, ETypeS3, ETypePass or ETypeFail
       
   420 	TUint8 iCaps[3];
       
   421 	TUint32 iSecureId;
       
   422 @endcode
       
   423 ETypeC3 descriptors will contain capabilities in iCaps but have iSecureId set
       
   424 to ECapability_None.  ETypeS3 are similar to ETypeC3 descriptors but will have
       
   425 iSecureId set to the secure ID value of the TSecurityPolicy object.
       
   426 ETypePass and ETypeFail objects will have values of all of the elements of iCaps
       
   427 and iSecureId set to ECapability_None.
       
   428 
       
   429 For TSecurityPolicy objects of type ETypeV3 the descriptor will contain the
       
   430 following data in the order listed:
       
   431 @code
       
   432 	TUint8 iType;		// set to ETypeV3
       
   433 	TUint8 iCaps[3];	// set to the values of 3 capabilities
       
   434 	TUint32 iVendorId;	// set to the value of the vendor ID of the TSecurityPolicy
       
   435 @endcode
       
   436 
       
   437 For TSecurityPolicy objects of type ETypeC7 the descriptor will contain the
       
   438 following data in the order listed:
       
   439 @code
       
   440 	TUint8 iType;			// set to ETypeC7
       
   441 	TUint8 iCaps[3];		// set to the values of 3 of the objects capabilities
       
   442 	TUint8 iExtraCaps[4];	// set to the values of 4 of the objects capabilities
       
   443 @endcode
       
   444 @see TSecurityPolicy::TType
       
   445 @see TSecurityPolicy::Set()
       
   446 @return A TPtrC8 wrapping the platform security attributes of this TSecurityPolicy.
       
   447 */
       
   448 EXPORT_C TPtrC8 TSecurityPolicy::Package() const
       
   449 	{
       
   450 	return TPtrC8((TUint8*)(this), sizeof(TSecurityPolicy));
       
   451 	}
       
   452 
       
   453 /** Checks this policy against the supplied SSecurityInfo.
       
   454 @param aSecInfo The SSecurityInfo object to check against this TSecurityPolicy.
       
   455 @param aMissing A SSecurityInfo object which this method fills with any capabilities or IDs
       
   456 				it finds to be missing. This is designed to help generating diagnostic messages.
       
   457 @return ETrue if all the requirements of this TSecurityPolicy are met, EFalse
       
   458 @panic USER 190 if aSecInfo is an invalid SSecurityInfo object
       
   459 otherwise.
       
   460 */
       
   461 TBool TSecurityPolicy::CheckPolicy(const SSecurityInfo& aSecInfo, SSecurityInfo& aMissing) const
       
   462 	{
       
   463 	TBool result = EFalse;
       
   464 	//It is thought to be by far the most common case to have 3 or less
       
   465 	//capabilities in a policy.  Hence we'll set this for all of them even
       
   466 	//though ETypePass doesn't need it.
       
   467 	aMissing.iSecureId = 0;
       
   468 	aMissing.iVendorId = 0;
       
   469 	__ASSERT_COMPILE(SCapabilitySet::ENCapW == 2);
       
   470 	aMissing.iCaps[0] = 0;
       
   471 	aMissing.iCaps[1] = 0;
       
   472 	aMissing.iCaps.AddCapability((TCapability)(iCaps[0]));
       
   473 	aMissing.iCaps.AddCapability((TCapability)(iCaps[1]));
       
   474 	aMissing.iCaps.AddCapability((TCapability)(iCaps[2]));
       
   475 	aMissing.iCaps.Remove(aSecInfo.iCaps);
       
   476 	switch(iType)
       
   477 		{
       
   478 		case ETypeFail:
       
   479 			//result already False;
       
   480 			break;
       
   481 		case ETypePass:
       
   482 			result = ETrue;	
       
   483 			break;
       
   484 		case ETypeC7:
       
   485 			aMissing.iCaps.AddCapability((TCapability)(iExtraCaps[0]));
       
   486 			aMissing.iCaps.AddCapability((TCapability)(iExtraCaps[1]));
       
   487 			aMissing.iCaps.AddCapability((TCapability)(iExtraCaps[2]));
       
   488 			aMissing.iCaps.AddCapability((TCapability)(iExtraCaps[3]));
       
   489 			aMissing.iCaps.Remove(aSecInfo.iCaps);
       
   490 			//It is intentional that there is no break statement here
       
   491 		case ETypeC3:
       
   492 			if(!aMissing.iCaps.NotEmpty())
       
   493 				{
       
   494 				result = ETrue;
       
   495 				}
       
   496 			break;
       
   497 		case ETypeS3:
       
   498 			if(!aMissing.iCaps.NotEmpty() && iSecureId == aSecInfo.iSecureId)
       
   499 				{
       
   500 				result = ETrue;
       
   501 				}
       
   502 			//This else if required to set the aMissing.iCaps secure id for diagnostics.
       
   503 			//Doesn't affect pass case.
       
   504 			else if(iSecureId != aSecInfo.iSecureId) 
       
   505 				{
       
   506 				aMissing.iSecureId = iSecureId;
       
   507 				}
       
   508 			break;
       
   509 		case ETypeV3:
       
   510 			if(!aMissing.iCaps.NotEmpty() && iVendorId == aSecInfo.iVendorId)
       
   511 				{
       
   512 				result = ETrue;
       
   513 				}
       
   514 			else if(iVendorId != aSecInfo.iVendorId)
       
   515 				{
       
   516 				aMissing.iVendorId = iVendorId;
       
   517 				}
       
   518 			break;
       
   519 		default:
       
   520 			Panic(ESecurityPolicyCorrupt);
       
   521 			break;
       
   522 		}
       
   523 	return result;
       
   524 	}
       
   525 
       
   526 #ifndef __TOOLS2__
       
   527 #ifndef __KERNEL_MODE__
       
   528 
       
   529 /** Checks this policy against the platform security attributes of aProcess.
       
   530 
       
   531 	When a check fails the action taken is determined by the system wide Platform Security
       
   532 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   533 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   534 	check failed.
       
   535 
       
   536 @param aProcess The RProcess object to check against this TSecurityPolicy.
       
   537 @param aDiagnostic A string that will be emitted along with any diagnostic message
       
   538 							that may be issued if the policy check fails.
       
   539 							This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro
       
   540 							which enables it to be easily removed from the system.
       
   541 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   542 platform security attributes of aProcess, EFalse otherwise.
       
   543 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   544 */
       
   545 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   546 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RProcess aProcess, const char* aDiagnostic) const
       
   547 	{
       
   548 	SSecurityInfo missing;
       
   549 	TSecurityInfo secInfo(aProcess);
       
   550 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   551 	if(!pass)
       
   552 		pass = PlatSec::PolicyCheckFail(aProcess.Handle(),missing,aDiagnostic)==KErrNone;
       
   553 	return pass;
       
   554 	}
       
   555 #else // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   556 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RProcess aProcess, const char* /*aDiagnostic*/) const
       
   557 	{
       
   558 	return DoCheckPolicy(aProcess);
       
   559 	}
       
   560 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   561 
       
   562 /** Checks this policy against the platform security attributes of aProcess.
       
   563 
       
   564 	When a check fails the action taken is determined by the system wide Platform Security
       
   565 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   566 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   567 	check failed.
       
   568 
       
   569 @param aProcess The RProcess object to check against this TSecurityPolicy.
       
   570 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   571 platform security attributes of aProcess, EFalse otherwise.
       
   572 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   573 */
       
   574 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RProcess aProcess) const
       
   575 	{
       
   576 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   577 	return DoCheckPolicy(aProcess, NULL);
       
   578 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   579 	SSecurityInfo missing;
       
   580 	TSecurityInfo secInfo(aProcess);
       
   581 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   582 	if(!pass)
       
   583 		pass = (PlatSec::EmitDiagnostic() == KErrNone);
       
   584 	return pass;
       
   585 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   586 	}
       
   587 
       
   588 /** Checks this policy against the platform security attributes of the process
       
   589 owning aThread.
       
   590 
       
   591 	When a check fails the action taken is determined by the system wide Platform Security
       
   592 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   593 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   594 	check failed.
       
   595 
       
   596 @param aThread The thread whose owning process' platform security attributes
       
   597 are to be checked against this TSecurityPolicy.
       
   598 @param aDiagnostic A string that will be emitted along with any diagnostic message
       
   599 							that may be issued if the policy check fails.
       
   600 							This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro
       
   601 							which enables it to be easily removed from the system.
       
   602 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   603 platform security parameters of the owning process of aThread, EFalse otherwise.
       
   604 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   605 */
       
   606 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   607 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RThread aThread, const char* aDiagnostic) const
       
   608 	{
       
   609 	SSecurityInfo missing;
       
   610 	TSecurityInfo secInfo(aThread);
       
   611 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   612 	if(!pass)
       
   613 		pass = PlatSec::PolicyCheckFail(aThread.Handle(),missing,aDiagnostic)==KErrNone;
       
   614 	return pass;
       
   615 	}
       
   616 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   617 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RThread aThread, const char* /*aDiagnostic*/) const
       
   618 	{
       
   619 	return DoCheckPolicy(aThread);
       
   620 	}
       
   621 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   622 
       
   623 /** Checks this policy against the platform security attributes of the process
       
   624 owning aThread.
       
   625 
       
   626 	When a check fails the action taken is determined by the system wide Platform Security
       
   627 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   628 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   629 	check failed.
       
   630 
       
   631 @param aThread The thread whose owning process' platform security attributes
       
   632 are to be checked against this TSecurityPolicy.
       
   633 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   634 platform security parameters of the owning process of aThread, EFalse otherwise.
       
   635 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   636 */
       
   637 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RThread aThread) const
       
   638 	{
       
   639 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   640 	return DoCheckPolicy(aThread, NULL);
       
   641 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   642 	SSecurityInfo missing;
       
   643 	TSecurityInfo secInfo(aThread);
       
   644 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   645 	if(!pass)
       
   646 		pass = (PlatSec::EmitDiagnostic() == KErrNone);
       
   647 	return pass;
       
   648 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   649 	}
       
   650 
       
   651 TInt TSecurityPolicy::CheckPolicy(RSessionBase aSession) const
       
   652 	{
       
   653 	SSecurityInfo missing;
       
   654 	TSecurityInfo secInfo;
       
   655 	TInt r = secInfo.Set(aSession);
       
   656 	if (r!=KErrNone)
       
   657 		return r;
       
   658 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   659 	if(!pass)
       
   660 		{
       
   661 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   662 		r = PlatSec::PolicyCheckFail(aSession.Handle(),missing,NULL);
       
   663 #else
       
   664 		r = PlatSec::EmitDiagnostic();
       
   665 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   666 		}
       
   667 	return r;
       
   668 	}
       
   669 
       
   670 /** Checks this policy against the platform security attributes of the process which sent
       
   671 the given message.
       
   672 
       
   673 	When a check fails the action taken is determined by the system wide Platform Security
       
   674 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   675 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   676 	check failed.
       
   677 
       
   678 @param aMsgPtr The RMessagePtr2 object to check against this TSecurityPolicy.
       
   679 @param aDiagnostic A string that will be emitted along with any diagnostic message
       
   680 							that may be issued if the policy check fails.
       
   681 							This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro
       
   682 							which enables it to be easily removed from the system.
       
   683 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   684 platform security attributes of aMsg, EFalse otherwise.
       
   685 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   686 */
       
   687 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   688 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RMessagePtr2 aMsgPtr, const char* aDiagnostic) const
       
   689 	{
       
   690 	SSecurityInfo missing;
       
   691 	TSecurityInfo secInfo(aMsgPtr);
       
   692 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   693 	if(!pass)
       
   694 		pass = PlatSec::PolicyCheckFail(aMsgPtr,missing,aDiagnostic)==KErrNone;
       
   695 	return pass;
       
   696 	}
       
   697 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   698 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RMessagePtr2 aMsgPtr, const char* /*aDiagnostic*/) const
       
   699 	{
       
   700 	return DoCheckPolicy(aMsgPtr);
       
   701 	}
       
   702 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   703 
       
   704 /** Checks this policy against the platform security attributes of the process which sent
       
   705 the given message.
       
   706 
       
   707 	When a check fails the action taken is determined by the system wide Platform Security
       
   708 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   709 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   710 	check failed.
       
   711 
       
   712 @param aMsgPtr The RMessagePtr2 object to check against this TSecurityPolicy.
       
   713 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   714 platform security attributes of aMsg, EFalse otherwise.
       
   715 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   716 */
       
   717 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(RMessagePtr2 aMsgPtr) const
       
   718 	{
       
   719 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   720 	return DoCheckPolicy(aMsgPtr, NULL);
       
   721 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   722 	SSecurityInfo missing;
       
   723 	TSecurityInfo secInfo(aMsgPtr);
       
   724 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   725 	if(!pass)
       
   726 		pass = (PlatSec::EmitDiagnostic() == KErrNone);
       
   727 	return pass;
       
   728 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   729 	}
       
   730 
       
   731 /** Checks this policy against the platform security attributes of the process which sent
       
   732 the given message.
       
   733 
       
   734 	When a check fails the action taken is determined by the system wide Platform Security
       
   735 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   736 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   737 	check failed.
       
   738 
       
   739 @param aMsgPtr The RMessagePtr2 object to check against this TSecurityPolicy.
       
   740 @param aMissing A TSecurityInfo object which this method fills with any capabilities or IDs
       
   741 				it finds to be missing. 
       
   742 @param aDiagnostic A string that will be emitted along with any diagnostic message
       
   743 							that may be issued if the policy check fails.
       
   744 							This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro
       
   745 							which enables it to be easily removed from the system.
       
   746 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   747 platform security attributes of aMsg, EFalse otherwise.
       
   748 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   749 */
       
   750 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   751 TBool TSecurityPolicy::DoCheckPolicy(RMessagePtr2 aMsgPtr, TSecurityInfo& aMissing, const char* aDiagnostic) const
       
   752 	{
       
   753 	TSecurityInfo secInfo(aMsgPtr);
       
   754 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), *((SSecurityInfo*)&aMissing));
       
   755 	if(!pass)
       
   756 		pass = PlatSec::PolicyCheckFail(aMsgPtr,*((SSecurityInfo*)&aMissing),aDiagnostic)==KErrNone;
       
   757 	return pass;
       
   758 	}
       
   759 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   760 
       
   761 /** Checks this policy against the platform security attributes of the process which sent
       
   762 the given message.
       
   763 
       
   764 	When a check fails the action taken is determined by the system wide Platform Security
       
   765 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   766 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   767 	check failed.
       
   768 
       
   769 @param aMsgPtr The RMessagePtr2 object to check against this TSecurityPolicy.
       
   770 @param aMissing A TSecurityInfo object which this method fills with any capabilities or IDs
       
   771 				it finds to be missing. 
       
   772 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   773 platform security attributes of aMsg, EFalse otherwise.
       
   774 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   775 */
       
   776 TBool TSecurityPolicy::DoCheckPolicy(RMessagePtr2 aMsgPtr, TSecurityInfo& aMissing) const
       
   777 	{
       
   778 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   779 	return DoCheckPolicy(aMsgPtr, aMissing, NULL);
       
   780 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   781 	TSecurityInfo secInfo(aMsgPtr);
       
   782 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), *((SSecurityInfo*)&aMissing));
       
   783 	if(!pass)
       
   784 		pass = (PlatSec::EmitDiagnostic() == KErrNone);
       
   785 	return pass;
       
   786 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   787 	}
       
   788 
       
   789 /** Checks this policy against the platform security attributes of this process' creator.
       
   790 
       
   791 	When a check fails the action taken is determined by the system wide Platform Security
       
   792 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   793 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   794 	check failed.
       
   795 
       
   796 @param aProcess The RProcess object to check against this TSecurityPolicy.
       
   797 @param aDiagnostic A string that will be emitted along with any diagnostic message
       
   798 							that may be issued if the policy check fails.
       
   799 							This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro
       
   800 							which enables it to be easily removed from the system.
       
   801 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   802 platform security attributes of this process' creator, EFalse otherwise.
       
   803 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   804 */
       
   805 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   806 EXPORT_C TBool TSecurityPolicy::DoCheckPolicyCreator(const char* aDiagnostic) const
       
   807 	{
       
   808 	SSecurityInfo missing;
       
   809 	TSecurityInfo secInfo;
       
   810 	secInfo.SetToCreatorInfo();
       
   811 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   812 	if(!pass)
       
   813 		pass = PlatSec::CreatorPolicyCheckFail(missing,aDiagnostic)==KErrNone;
       
   814 	return pass;
       
   815 	}
       
   816 #else // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   817 EXPORT_C TBool TSecurityPolicy::DoCheckPolicyCreator(const char* /*aDiagnostic*/) const
       
   818 	{
       
   819 	return DoCheckPolicyCreator();
       
   820 	}
       
   821 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   822 
       
   823 /** Checks this policy against the platform security attributes of this process' creator.
       
   824 
       
   825 	When a check fails the action taken is determined by the system wide Platform Security
       
   826 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   827 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   828 	check failed.
       
   829 
       
   830 @param aProcess The RProcess object to check against this TSecurityPolicy.
       
   831 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   832 platform security attributes of this process' creator, EFalse otherwise.
       
   833 @panic USER 190 if 'this' is an invalid SSecurityInfo object
       
   834 */
       
   835 EXPORT_C TBool TSecurityPolicy::DoCheckPolicyCreator() const
       
   836 	{
       
   837 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   838 	return DoCheckPolicyCreator(NULL);
       
   839 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   840 	SSecurityInfo missing;
       
   841 	TSecurityInfo secInfo;
       
   842 	secInfo.SetToCreatorInfo();
       
   843 	TBool pass = CheckPolicy(*((SSecurityInfo*)&secInfo), missing);
       
   844 	if(!pass)
       
   845 		pass = (PlatSec::EmitDiagnostic() == KErrNone);
       
   846 	return pass;
       
   847 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   848 	}
       
   849 
       
   850 #else //__KERNEL_MODE__
       
   851 
       
   852 /** Checks this policy against the platform security attributes of aProcess.
       
   853 
       
   854 	When a check fails the action taken is determined by the system wide Platform Security
       
   855 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   856 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   857 	check failed.
       
   858 
       
   859 @param aProcess The DProcess object to check against this TSecurityPolicy.
       
   860 @param aDiagnostic A string that will be emitted along with any diagnostic message
       
   861 							that may be issued if the policy check fails.
       
   862 							This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro
       
   863 							which enables it to be easily removed from the system.
       
   864 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   865 platform security attributes of aProcess, EFalse otherwise.
       
   866 @panic KERN-COMMON 190 if 'this' is an invalid SSecurityInfo object
       
   867 */
       
   868 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   869 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(DProcess* aProcess, const char* aDiagnostic) const
       
   870 	{
       
   871 	SSecurityInfo missing;
       
   872 	TBool pass = CheckPolicy(aProcess->iS, missing);
       
   873 	if(!pass)
       
   874 		pass = PlatSec::PolicyCheckFail(aProcess,missing,aDiagnostic)==KErrNone;
       
   875 	return pass;
       
   876 	}
       
   877 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   878 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(DProcess* aProcess, const char* /*aDiagnostic*/) const
       
   879 	{
       
   880 	return DoCheckPolicy(aProcess);
       
   881 	}
       
   882 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   883 
       
   884 /** Checks this policy against the platform security attributes of aProcess.
       
   885 
       
   886 	When a check fails the action taken is determined by the system wide Platform Security
       
   887 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   888 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   889 	check failed.
       
   890 
       
   891 @param aProcess The DProcess object to check against this TSecurityPolicy.
       
   892 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   893 platform security attributes of aProcess, EFalse otherwise.
       
   894 @panic KERN-COMMON 190 if 'this' is an invalid SSecurityInfo object
       
   895 */
       
   896 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(DProcess* aProcess) const
       
   897 	{
       
   898 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   899 	return DoCheckPolicy(aProcess, NULL);
       
   900 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   901 	SSecurityInfo missing;
       
   902 	TBool pass = CheckPolicy(aProcess->iS, missing);
       
   903 	if(!pass)
       
   904 		pass = (PlatSec::EmitDiagnostic() == KErrNone);
       
   905 	return pass;
       
   906 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   907 	}
       
   908 
       
   909 /** Checks this policy against the platform security attributes of the process
       
   910 owning aThread.
       
   911 
       
   912 	When a check fails the action taken is determined by the system wide Platform Security
       
   913 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   914 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   915 	check failed.
       
   916 
       
   917 @param aThread The thread whose owning process' platform security attributes
       
   918 are to be checked against this TSecurityPolicy.
       
   919 @param aDiagnostic A string that will be emitted along with any diagnostic message
       
   920 							that may be issued if the policy check fails.
       
   921 							This string must be enclosed in the __PLATSEC_DIAGNOSTIC_STRING macro
       
   922 							which enables it to be easily removed from the system.
       
   923 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   924 platform security parameters of the owning process of aThread, EFalse otherwise.
       
   925 @panic KERN-COMMON 190 if 'this' is an invalid SSecurityInfo object
       
   926 */
       
   927 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   928 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(DThread* aThread, const char* aDiagnostic) const
       
   929 	{
       
   930 	SSecurityInfo missing;
       
   931 	TBool pass = CheckPolicy(aThread->iOwningProcess->iS, missing);
       
   932 	if(!pass)
       
   933 		pass = PlatSec::PolicyCheckFail(aThread,missing,aDiagnostic)==KErrNone;
       
   934 	return pass;
       
   935 	}
       
   936 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   937 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(DThread* aThread, const char* /*aDiagnostic*/) const
       
   938 	{
       
   939 	return DoCheckPolicy(aThread);
       
   940 	}
       
   941 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   942 
       
   943 /** Checks this policy against the platform security attributes of the process
       
   944 owning aThread.
       
   945 
       
   946 	When a check fails the action taken is determined by the system wide Platform Security
       
   947 	configuration. If PlatSecDiagnostics is ON, then a diagnostic message is emitted.
       
   948 	If PlatSecEnforcement is OFF, then this function will return ETrue even though the
       
   949 	check failed.
       
   950 
       
   951 @param aThread The thread whose owning process' platform security attributes
       
   952 are to be checked against this TSecurityPolicy.
       
   953 @return ETrue if all the requirements of this TSecurityPolicy are met by the
       
   954 platform security parameters of the owning process of aThread, EFalse otherwise.
       
   955 @panic KERN-COMMON 190 if 'this' is an invalid SSecurityInfo object
       
   956 */
       
   957 EXPORT_C TBool TSecurityPolicy::DoCheckPolicy(DThread* aThread) const
       
   958 	{
       
   959 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   960 	return DoCheckPolicy(aThread, NULL);
       
   961 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   962 	SSecurityInfo missing;
       
   963 	TBool pass = CheckPolicy(aThread->iOwningProcess->iS, missing);
       
   964 	if(!pass)
       
   965 		pass = (PlatSec::EmitDiagnostic() == KErrNone);
       
   966 	return pass;
       
   967 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   968 	}
       
   969 
       
   970 #endif // !__KERNEL_MODE__
       
   971 
       
   972 
       
   973 #ifndef __KERNEL_MODE__
       
   974 
       
   975 EXPORT_C TInt PlatSec::ConfigSetting(TConfigSetting aSetting)
       
   976 	{
       
   977 	TUint32 flags = Exec::KernelConfigFlags();
       
   978 	switch(aSetting)
       
   979 		{
       
   980 		case EPlatSecEnforcement:
       
   981 			flags &= EKernelConfigPlatSecEnforcement;
       
   982 			break;
       
   983 		case EPlatSecDiagnotics:
       
   984 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
       
   985 			flags &= EKernelConfigPlatSecDiagnostics;
       
   986 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
       
   987 			flags=0;
       
   988 #endif // !__REMOVE_PLATSEC_DIAGNOSTICS__
       
   989 			break;
       
   990 		case EPlatSecProcessIsolation:
       
   991 			flags &= EKernelConfigPlatSecProcessIsolation;
       
   992 			break;
       
   993 		case EPlatSecEnforceSysBin:
       
   994 			flags &= EKernelConfigPlatSecEnforceSysBin;
       
   995 			break;
       
   996 		case EPlatSecLocked:
       
   997 			flags &= EKernelConfigPlatSecLocked;
       
   998 			break;
       
   999 		default:
       
  1000 			flags = 0;
       
  1001 			break;
       
  1002 		}
       
  1003 	if(flags)
       
  1004 		flags = 1;
       
  1005 	return flags;
       
  1006 	}
       
  1007 
       
  1008 EXPORT_C TBool PlatSec::IsCapabilityEnforced(TCapability aCapability)
       
  1009 	{
       
  1010 	if(!((TCapabilitySet&)AllSupportedCapabilities).HasCapability(aCapability))
       
  1011 		return EFalse;
       
  1012 
       
  1013 	SCapabilitySet disabled;
       
  1014 	Exec::DisabledCapabilities(disabled);
       
  1015 	if(((TCapabilitySet&)disabled).HasCapability(aCapability))
       
  1016 		return EFalse;
       
  1017 
       
  1018 	return PlatSec::ConfigSetting(EPlatSecEnforcement);
       
  1019 	}
       
  1020 
       
  1021 #endif // Not __KERNEL_MODE__
       
  1022 #endif // __TOOLS2__