1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/us_secure.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,353 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\euser\us_secure.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <u32exec.h>
1.22 +
1.23 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.24 +EXPORT_C TInt PlatSec::EmitDiagnostic(TPlatSecDiagnostic& aDiagnostic, const char* aContextText)
1.25 + {
1.26 + if(aContextText == KSuppressPlatSecDiagnosticMagicValue)
1.27 + return Exec::PlatSecDiagnostic(NULL);
1.28 + aDiagnostic.iContextText = aContextText;
1.29 + if(aContextText)
1.30 + aDiagnostic.iContextTextLength=User::StringLength((const TUint8*)aContextText);
1.31 + return Exec::PlatSecDiagnostic(&aDiagnostic);
1.32 + }
1.33 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.34 +EXPORT_C TInt PlatSec::EmitDiagnostic(TPlatSecDiagnostic& /*aDiagnostic*/, const char* /*aContextText*/)
1.35 + {
1.36 + return Exec::PlatSecDiagnostic(NULL);
1.37 + }
1.38 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.39 +
1.40 +EXPORT_C TInt PlatSec::EmitDiagnostic()
1.41 + {
1.42 + return Exec::PlatSecDiagnostic(NULL);
1.43 + }
1.44 +
1.45 +EXPORT_C TSecureId RProcess::SecureId() const
1.46 + {
1.47 + SSecurityInfo info;
1.48 + Exec::ProcessSecurityInfo(iHandle,info);
1.49 + return info.iSecureId;
1.50 + }
1.51 +
1.52 +EXPORT_C TVendorId RProcess::VendorId() const
1.53 + {
1.54 + SSecurityInfo info;
1.55 + Exec::ProcessSecurityInfo(iHandle,info);
1.56 + return info.iVendorId;
1.57 + }
1.58 +
1.59 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.60 +EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability, const char* aDiagnostic) const
1.61 + {
1.62 + SSecurityInfo info;
1.63 + Exec::ProcessSecurityInfo(iHandle,info);
1.64 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.65 + if(caps.HasCapability(aCapability))
1.66 + return ETrue;
1.67 + return KErrNone==PlatSec::CapabilityCheckFail(iHandle,aCapability,aDiagnostic);
1.68 + }
1.69 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.70 +EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability, const char* /*aDiagnostic*/) const
1.71 + {
1.72 + return DoHasCapability(aCapability);
1.73 + }
1.74 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.75 +
1.76 +EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability) const
1.77 + {
1.78 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.79 + return DoHasCapability(aCapability, NULL);
1.80 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.81 + SSecurityInfo info;
1.82 + Exec::ProcessSecurityInfo(iHandle,info);
1.83 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.84 + if(caps.HasCapability(aCapability))
1.85 + return ETrue;
1.86 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.87 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.88 + }
1.89 +
1.90 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.91 +EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic) const
1.92 + {
1.93 + SSecurityInfo info;
1.94 + Exec::ProcessSecurityInfo(iHandle,info);
1.95 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.96 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.97 + return ETrue;
1.98 + TCapabilitySet missing(aCapability1,aCapability2);
1.99 + missing.Remove(caps);
1.100 + return KErrNone==PlatSec::CapabilityCheckFail(iHandle,missing,aDiagnostic);
1.101 + }
1.102 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.103 +EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/) const
1.104 + {
1.105 + return DoHasCapability(aCapability1, aCapability2);
1.106 + }
1.107 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.108 +
1.109 +EXPORT_C TBool RProcess::DoHasCapability(TCapability aCapability1, TCapability aCapability2) const
1.110 + {
1.111 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.112 + return DoHasCapability(aCapability1, aCapability2, NULL);
1.113 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.114 + SSecurityInfo info;
1.115 + Exec::ProcessSecurityInfo(iHandle, info);
1.116 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.117 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.118 + return ETrue;
1.119 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.120 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.121 + }
1.122 +
1.123 +EXPORT_C TSecureId RThread::SecureId() const
1.124 + {
1.125 + SSecurityInfo info;
1.126 + Exec::ThreadSecurityInfo(iHandle,info);
1.127 + return info.iSecureId;
1.128 + }
1.129 +
1.130 +EXPORT_C TVendorId RThread::VendorId() const
1.131 + {
1.132 + SSecurityInfo info;
1.133 + Exec::ThreadSecurityInfo(iHandle,info);
1.134 + return info.iVendorId;
1.135 + }
1.136 +
1.137 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.138 +EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability, const char* aDiagnostic) const
1.139 + {
1.140 + SSecurityInfo info;
1.141 + Exec::ThreadSecurityInfo(iHandle,info);
1.142 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.143 + if(caps.HasCapability(aCapability))
1.144 + return ETrue;
1.145 + return KErrNone==PlatSec::CapabilityCheckFail(iHandle,aCapability,aDiagnostic);
1.146 + }
1.147 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.148 +EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability, const char* /*aDiagnostic*/) const
1.149 + {
1.150 + return DoHasCapability(aCapability);
1.151 + }
1.152 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.153 +
1.154 +EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability) const
1.155 + {
1.156 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.157 + return DoHasCapability(aCapability, NULL);
1.158 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.159 + SSecurityInfo info;
1.160 + Exec::ThreadSecurityInfo(iHandle, info);
1.161 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.162 + if(caps.HasCapability(aCapability))
1.163 + return ETrue;
1.164 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.165 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.166 + }
1.167 +
1.168 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.169 +EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic) const
1.170 + {
1.171 + SSecurityInfo info;
1.172 + Exec::ThreadSecurityInfo(iHandle,info);
1.173 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.174 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.175 + return ETrue;
1.176 + TCapabilitySet missing(aCapability1,aCapability2);
1.177 + missing.Remove(caps);
1.178 + return KErrNone==PlatSec::CapabilityCheckFail(iHandle,missing,aDiagnostic);
1.179 + }
1.180 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.181 +EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/) const
1.182 + {
1.183 + return DoHasCapability(aCapability1, aCapability2);
1.184 + }
1.185 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.186 +
1.187 +EXPORT_C TBool RThread::DoHasCapability(TCapability aCapability1, TCapability aCapability2) const
1.188 + {
1.189 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.190 + return DoHasCapability(aCapability1, aCapability2, NULL);
1.191 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.192 + SSecurityInfo info;
1.193 + Exec::ThreadSecurityInfo(iHandle, info);
1.194 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.195 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.196 + return ETrue;
1.197 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.198 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.199 + }
1.200 +
1.201 +
1.202 +EXPORT_C TSecureId RMessagePtr2::SecureId() const
1.203 + {
1.204 + SSecurityInfo info;
1.205 + Exec::MessageSecurityInfo(iHandle,info);
1.206 + return info.iSecureId;
1.207 + }
1.208 +
1.209 +EXPORT_C TVendorId RMessagePtr2::VendorId() const
1.210 + {
1.211 + SSecurityInfo info;
1.212 + Exec::MessageSecurityInfo(iHandle,info);
1.213 + return info.iVendorId;
1.214 + }
1.215 +
1.216 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.217 +EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability, const char* aDiagnostic) const
1.218 + {
1.219 + SSecurityInfo info;
1.220 + Exec::MessageSecurityInfo(iHandle,info);
1.221 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.222 + if(caps.HasCapability(aCapability))
1.223 + return ETrue;
1.224 + return KErrNone==PlatSec::CapabilityCheckFail(*this,aCapability,aDiagnostic);
1.225 + }
1.226 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.227 +EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability, const char* /*aDiagnostic*/) const
1.228 + {
1.229 + return DoHasCapability(aCapability);
1.230 + }
1.231 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.232 +
1.233 +EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability) const
1.234 + {
1.235 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.236 + return DoHasCapability(aCapability, NULL);
1.237 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.238 + SSecurityInfo info;
1.239 + Exec::MessageSecurityInfo(iHandle,info);
1.240 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.241 + if (caps.HasCapability(aCapability))
1.242 + return ETrue;
1.243 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.244 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.245 + }
1.246 +
1.247 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.248 +EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic) const
1.249 + {
1.250 + SSecurityInfo info;
1.251 + Exec::MessageSecurityInfo(iHandle,info);
1.252 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.253 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.254 + return ETrue;
1.255 + TCapabilitySet missing(aCapability1,aCapability2);
1.256 + missing.Remove(caps);
1.257 + return KErrNone==PlatSec::CapabilityCheckFail(*this,missing,aDiagnostic);
1.258 + }
1.259 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.260 +EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/) const
1.261 + {
1.262 + return DoHasCapability(aCapability1, aCapability2);
1.263 + }
1.264 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.265 +
1.266 +EXPORT_C TBool RMessagePtr2::DoHasCapability(TCapability aCapability1, TCapability aCapability2) const
1.267 + {
1.268 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.269 + return DoHasCapability(aCapability1, aCapability2, NULL);
1.270 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.271 + SSecurityInfo info;
1.272 + Exec::MessageSecurityInfo(iHandle,info);
1.273 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.274 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.275 + return ETrue;
1.276 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.277 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.278 + }
1.279 +
1.280 +EXPORT_C TSecureId User::CreatorSecureId()
1.281 + {
1.282 + SSecurityInfo info;
1.283 + Exec::CreatorSecurityInfo(info);
1.284 + return info.iSecureId;
1.285 + }
1.286 +
1.287 +EXPORT_C TVendorId User::CreatorVendorId()
1.288 + {
1.289 + SSecurityInfo info;
1.290 + Exec::CreatorSecurityInfo(info);
1.291 + return info.iVendorId;
1.292 + }
1.293 +
1.294 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.295 +EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability, const char* aDiagnostic)
1.296 + {
1.297 + SSecurityInfo info;
1.298 + Exec::CreatorSecurityInfo(info);
1.299 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.300 + if(caps.HasCapability(aCapability))
1.301 + return ETrue;
1.302 + return KErrNone==PlatSec::CreatorCapabilityCheckFail(aCapability,aDiagnostic);
1.303 + }
1.304 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.305 +EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability, const char* /*aDiagnostic*/)
1.306 + {
1.307 + return DoCreatorHasCapability(aCapability);
1.308 + }
1.309 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.310 +
1.311 +EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability)
1.312 + {
1.313 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.314 + return DoCreatorHasCapability(aCapability, NULL);
1.315 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.316 + SSecurityInfo info;
1.317 + Exec::CreatorSecurityInfo(info);
1.318 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.319 + if(caps.HasCapability(aCapability))
1.320 + return ETrue;
1.321 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.322 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.323 + }
1.324 +
1.325 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.326 +EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability1, TCapability aCapability2, const char* aDiagnostic)
1.327 + {
1.328 + SSecurityInfo info;
1.329 + Exec::CreatorSecurityInfo(info);
1.330 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.331 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.332 + return ETrue;
1.333 + TCapabilitySet missing(aCapability1,aCapability2);
1.334 + missing.Remove(caps);
1.335 + return KErrNone==PlatSec::CreatorCapabilityCheckFail(missing,aDiagnostic);
1.336 + }
1.337 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.338 +EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability1, TCapability aCapability2, const char* /*aDiagnostic*/)
1.339 + {
1.340 + return DoCreatorHasCapability(aCapability1, aCapability2);
1.341 + }
1.342 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.343 +
1.344 +EXPORT_C TBool User::DoCreatorHasCapability(TCapability aCapability1, TCapability aCapability2)
1.345 + {
1.346 +#ifndef __REMOVE_PLATSEC_DIAGNOSTICS__
1.347 + return DoCreatorHasCapability(aCapability1, aCapability2, NULL);
1.348 +#else //__REMOVE_PLATSEC_DIAGNOSTICS__
1.349 + SSecurityInfo info;
1.350 + Exec::CreatorSecurityInfo(info);
1.351 + TCapabilitySet& caps = (TCapabilitySet&)info.iCaps;
1.352 + if(caps.HasCapability(aCapability1) && caps.HasCapability(aCapability2))
1.353 + return ETrue;
1.354 + return (PlatSec::EmitDiagnostic() == KErrNone);
1.355 +#endif //!__REMOVE_PLATSEC_DIAGNOSTICS__
1.356 + }