os/kernelhwsrv/kernel/eka/euser/us_secure.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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\euser\us_secure.cpp
    15 // 
    16 //
    17 
    18 #include <u32exec.h>
    19 
    20 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
    21 EXPORT_C TInt PlatSec::EmitDiagnostic(TPlatSecDiagnostic& aDiagnostic, const char* aContextText)
    22 	{
    23 	if(aContextText == KSuppressPlatSecDiagnosticMagicValue)
    24 		return Exec::PlatSecDiagnostic(NULL);
    25 	aDiagnostic.iContextText = aContextText;
    26 	if(aContextText)
    27 		aDiagnostic.iContextTextLength=User::StringLength((const TUint8*)aContextText);
    28 	return Exec::PlatSecDiagnostic(&aDiagnostic);
    29 	}
    30 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
    31 EXPORT_C TInt PlatSec::EmitDiagnostic(TPlatSecDiagnostic& /*aDiagnostic*/, const char* /*aContextText*/)
    32 	{
    33 	return Exec::PlatSecDiagnostic(NULL);
    34 	}
    35 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
    36 
    37 EXPORT_C TInt PlatSec::EmitDiagnostic()
    38 	{
    39 	return Exec::PlatSecDiagnostic(NULL);
    40 	}
    41 
    42 EXPORT_C TSecureId RProcess::SecureId() const
    43 	{
    44 	SSecurityInfo info;
    45 	Exec::ProcessSecurityInfo(iHandle,info);
    46 	return info.iSecureId;
    47 	}
    48 
    49 EXPORT_C TVendorId RProcess::VendorId() const
    50 	{
    51 	SSecurityInfo info;
    52 	Exec::ProcessSecurityInfo(iHandle,info);
    53 	return info.iVendorId;
    54 	}
    55 
    56 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
    57 EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability, const char* aDiagnostic) const
    58 	{
    59 	SSecurityInfo info;
    60 	Exec::ProcessSecurityInfo(iHandle,info);
    61 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
    62 	if(caps.HasCapability(aCapability))
    63 		return ETrue;
    64 	return KErrNone==PlatSec::CapabilityCheckFail(iHandle,aCapability,aDiagnostic);
    65 	}
    66 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
    67 EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability, const char* /*aDiagnostic*/) const
    68 	{
    69 	return DoHasCapability(aCapability);
    70 	}
    71 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
    72 
    73 EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability) const
    74 	{
    75 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
    76 	return DoHasCapability(aCapability, NULL);
    77 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
    78 	SSecurityInfo info;
    79 	Exec::ProcessSecurityInfo(iHandle,info);
    80 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
    81 	if(caps.HasCapability(aCapability))
    82 		return ETrue;
    83 	return (PlatSec::EmitDiagnostic() == KErrNone);
    84 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
    85 	}
    86 
    87 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
    88 EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic) const
    89 	{
    90 	SSecurityInfo info;
    91 	Exec::ProcessSecurityInfo(iHandle,info);
    92 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
    93 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
    94 		return ETrue;
    95 	TCapabilitySet missing(aCapability1,aCapability2);
    96 	missing.Remove(caps);
    97 	return KErrNone==PlatSec::CapabilityCheckFail(iHandle,missing,aDiagnostic);
    98 	}
    99 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   100 EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/) const
   101 	{
   102 	return DoHasCapability(aCapability1, aCapability2);
   103 	}
   104 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   105 
   106 EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability1, TCapability aCapability2) const
   107 	{
   108 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   109 	return DoHasCapability(aCapability1, aCapability2, NULL);
   110 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   111 	SSecurityInfo info;
   112 	Exec::ProcessSecurityInfo(iHandle, info);
   113 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   114 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
   115 		return ETrue;
   116 	return (PlatSec::EmitDiagnostic() == KErrNone);
   117 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   118 	}
   119 
   120 EXPORT_C TSecureId RThread::SecureId() const
   121 	{
   122 	SSecurityInfo info;
   123 	Exec::ThreadSecurityInfo(iHandle,info);
   124 	return info.iSecureId;
   125 	}
   126 
   127 EXPORT_C TVendorId RThread::VendorId() const
   128 	{
   129 	SSecurityInfo info;
   130 	Exec::ThreadSecurityInfo(iHandle,info);
   131 	return info.iVendorId;
   132 	}
   133 
   134 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   135 EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability, const char* aDiagnostic) const
   136 	{
   137 	SSecurityInfo info;
   138 	Exec::ThreadSecurityInfo(iHandle,info);
   139 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   140 	if(caps.HasCapability(aCapability))
   141 		return ETrue;
   142 	return KErrNone==PlatSec::CapabilityCheckFail(iHandle,aCapability,aDiagnostic);
   143 	}
   144 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   145 EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability, const char* /*aDiagnostic*/) const
   146 	{
   147 	return DoHasCapability(aCapability);
   148 	}
   149 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   150 
   151 EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability) const
   152 	{
   153 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   154 	return DoHasCapability(aCapability, NULL);
   155 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   156 	SSecurityInfo info;
   157 	Exec::ThreadSecurityInfo(iHandle, info);
   158 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   159 	if(caps.HasCapability(aCapability))
   160 		return ETrue;
   161 	return (PlatSec::EmitDiagnostic() == KErrNone);
   162 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   163 	}
   164 
   165 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   166 EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic) const
   167 	{
   168 	SSecurityInfo info;
   169 	Exec::ThreadSecurityInfo(iHandle,info);
   170 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   171 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
   172 		return ETrue;
   173 	TCapabilitySet missing(aCapability1,aCapability2);
   174 	missing.Remove(caps);
   175 	return KErrNone==PlatSec::CapabilityCheckFail(iHandle,missing,aDiagnostic);
   176 	}
   177 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   178 EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/) const
   179 	{
   180 	return DoHasCapability(aCapability1, aCapability2);
   181 	}
   182 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   183 
   184 EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability1, TCapability aCapability2) const
   185 	{
   186 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   187 	return DoHasCapability(aCapability1, aCapability2, NULL);
   188 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   189 	SSecurityInfo info;
   190 	Exec::ThreadSecurityInfo(iHandle, info);
   191 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   192 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
   193 		return ETrue;
   194 	return (PlatSec::EmitDiagnostic() == KErrNone);
   195 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   196 	}
   197 
   198 
   199 EXPORT_C TSecureId RMessagePtr2::SecureId() const
   200 	{
   201 	SSecurityInfo info;
   202 	Exec::MessageSecurityInfo(iHandle,info);
   203 	return info.iSecureId;
   204 	}
   205 
   206 EXPORT_C TVendorId RMessagePtr2::VendorId() const
   207 	{
   208 	SSecurityInfo info;
   209 	Exec::MessageSecurityInfo(iHandle,info);
   210 	return info.iVendorId;
   211 	}
   212 
   213 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   214 EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability, const char* aDiagnostic) const
   215 	{
   216 	SSecurityInfo info;
   217 	Exec::MessageSecurityInfo(iHandle,info);
   218 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   219 	if(caps.HasCapability(aCapability))
   220 		return ETrue;
   221 	return KErrNone==PlatSec::CapabilityCheckFail(*this,aCapability,aDiagnostic);
   222 	}
   223 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   224 EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability, const char* /*aDiagnostic*/) const
   225 	{
   226 	return DoHasCapability(aCapability);
   227 	}
   228 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   229 
   230 EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability) const
   231 	{
   232 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   233 	return DoHasCapability(aCapability, NULL);
   234 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   235 	SSecurityInfo info;
   236 	Exec::MessageSecurityInfo(iHandle,info);
   237 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   238 	if (caps.HasCapability(aCapability))
   239 		return ETrue;
   240 	return (PlatSec::EmitDiagnostic() == KErrNone);
   241 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   242 	}
   243 
   244 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   245 EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic) const
   246 	{
   247 	SSecurityInfo info;
   248 	Exec::MessageSecurityInfo(iHandle,info);
   249 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   250 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
   251 		return ETrue;
   252 	TCapabilitySet missing(aCapability1,aCapability2);
   253 	missing.Remove(caps);
   254 	return KErrNone==PlatSec::CapabilityCheckFail(*this,missing,aDiagnostic);
   255 	}
   256 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   257 EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/) const
   258 	{
   259 	return DoHasCapability(aCapability1, aCapability2);
   260 	}
   261 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   262 
   263 EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability1, TCapability aCapability2) const
   264 	{
   265 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   266 	return DoHasCapability(aCapability1, aCapability2, NULL);
   267 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   268 	SSecurityInfo info;
   269 	Exec::MessageSecurityInfo(iHandle,info);
   270 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   271 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
   272 		return ETrue;
   273 	return (PlatSec::EmitDiagnostic() == KErrNone);
   274 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   275 	}
   276 
   277 EXPORT_C TSecureId User::CreatorSecureId()
   278 	{
   279 	SSecurityInfo info;
   280 	Exec::CreatorSecurityInfo(info);
   281 	return info.iSecureId;
   282 	}
   283 
   284 EXPORT_C TVendorId User::CreatorVendorId()
   285 	{
   286 	SSecurityInfo info;
   287 	Exec::CreatorSecurityInfo(info);
   288 	return info.iVendorId;
   289 	}
   290 
   291 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   292 EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability, const char* aDiagnostic)
   293 	{
   294 	SSecurityInfo info;
   295 	Exec::CreatorSecurityInfo(info);
   296 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   297 	if(caps.HasCapability(aCapability))
   298 		return ETrue;
   299 	return KErrNone==PlatSec::CreatorCapabilityCheckFail(aCapability,aDiagnostic);
   300 	}
   301 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   302 EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability, const char* /*aDiagnostic*/)
   303 	{
   304 	return DoCreatorHasCapability(aCapability);
   305 	}
   306 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   307 
   308 EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability)
   309 	{
   310 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   311 	return DoCreatorHasCapability(aCapability, NULL);
   312 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   313 	SSecurityInfo info;
   314 	Exec::CreatorSecurityInfo(info);
   315 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   316 	if(caps.HasCapability(aCapability))
   317 		return ETrue;
   318 	return (PlatSec::EmitDiagnostic() == KErrNone);
   319 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   320 	}
   321 
   322 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   323 EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic)
   324 	{
   325 	SSecurityInfo info;
   326 	Exec::CreatorSecurityInfo(info);
   327 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   328 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
   329 		return ETrue;
   330 	TCapabilitySet missing(aCapability1,aCapability2);
   331 	missing.Remove(caps);
   332 	return KErrNone==PlatSec::CreatorCapabilityCheckFail(missing,aDiagnostic);
   333 	}
   334 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   335 EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/)
   336 	{
   337 	return DoCreatorHasCapability(aCapability1, aCapability2);
   338 	}
   339 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   340 
   341 EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability1, TCapability aCapability2)
   342 	{
   343 #ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
   344 	return DoCreatorHasCapability(aCapability1, aCapability2, NULL);
   345 #else //__REMOVE_PLATSEC_DIAGNOSTICS__
   346 	SSecurityInfo info;
   347 	Exec::CreatorSecurityInfo(info);
   348 	TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
   349 	if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
   350 		return ETrue;
   351 	return (PlatSec::EmitDiagnostic() == KErrNone);
   352 #endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
   353 	}