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