1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/property/t_prop_define.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,170 @@
1.4 +// Copyright (c) 2005-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 +// t_prop_define.cpp.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include <e32svr.h>
1.23 +
1.24 +#include "t_property.h"
1.25 +
1.26 +TSecureId MySecureId;
1.27 +TBool IHaveWriteDeviceData;
1.28 +
1.29 +_LIT(KSecurityOwnerName, "RProperty Security: Owner Basics");
1.30 +
1.31 +class CPropSecurityOwner : public CTestProgram
1.32 + {
1.33 +public:
1.34 + CPropSecurityOwner(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) :
1.35 + CTestProgram(KSecurityOwnerName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey),
1.36 + iType(aType)
1.37 + {
1.38 + }
1.39 +
1.40 + void Run(TUint aCount);
1.41 +
1.42 +private:
1.43 + TUid iCategory;
1.44 + TUint iMasterKey;
1.45 + TUint iSlaveKey;
1.46 + RProperty::TType iType;
1.47 + };
1.48 +
1.49 +void CPropSecurityOwner::Run(TUint aCount)
1.50 + {
1.51 + for (TUint i = 0; i < aCount; ++i)
1.52 + {
1.53 + // Delete() can only be called by the property owner, as defined by the process Security ID,
1.54 + // any other process will get a KErrPermissionDenied error.
1.55 + RProperty mProp;
1.56 + TInt r = mProp.Delete(iCategory, iMasterKey);
1.57 + TF_ERROR(r, r == KErrPermissionDenied);
1.58 + }
1.59 + }
1.60 +
1.61 +
1.62 +
1.63 +_LIT(KPropDefineSecurityName, "RProperty Security: Define category security");
1.64 +
1.65 +class CPropDefineSecurity : public CTestProgram
1.66 + {
1.67 +public:
1.68 + CPropDefineSecurity(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) :
1.69 + CTestProgram(KPropDefineSecurityName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey),
1.70 + iType(aType)
1.71 + {
1.72 + }
1.73 +
1.74 + void Run(TUint aCount);
1.75 +
1.76 +private:
1.77 + TUid iCategory;
1.78 + TUint iMasterKey;
1.79 + TUint iSlaveKey;
1.80 + RProperty::TType iType;
1.81 + };
1.82 +
1.83 +void CPropDefineSecurity::Run(TUint aCount)
1.84 + {
1.85 + for (TUint i = 0; i < aCount; ++i)
1.86 + {
1.87 + // Test defining in the system category
1.88 + RProperty prop;
1.89 + TInt r = prop.Define(KUidSystemCategory, iSlaveKey, iType, KPassPolicy, KPassPolicy);
1.90 + RDebug::Printf("CPropDefineSecurity define with System Category returns %d",r);
1.91 + TF_ERROR(r, r == IHaveWriteDeviceData ? KErrNone : KErrPermissionDenied);
1.92 + if(r==KErrNone)
1.93 + {
1.94 + r = prop.Delete(KUidSystemCategory, iSlaveKey);
1.95 + TF_ERROR(r, r == KErrNone);
1.96 + }
1.97 +
1.98 + // Tesk defining properties with categories above and below security threshold
1.99 + TUid categoryA = { KUidSecurityThresholdCategoryValue-1 };
1.100 + r = prop.Define(categoryA, iSlaveKey, iType, KPassPolicy, KPassPolicy);
1.101 + RDebug::Printf("CPropDefineSecurity define with Category A returns %d",r);
1.102 + TF_ERROR(r, r == (categoryA==MySecureId || IHaveWriteDeviceData) ? KErrNone : KErrPermissionDenied);
1.103 + if(r==KErrNone)
1.104 + {
1.105 + r = prop.Delete(categoryA, iSlaveKey);
1.106 + TF_ERROR(r, r == KErrNone);
1.107 + }
1.108 + TUid categoryB = { KUidSecurityThresholdCategoryValue };
1.109 + r = prop.Define(categoryB, iSlaveKey, iType, KPassPolicy, KPassPolicy);
1.110 + RDebug::Printf("CPropDefineSecurity define with Category B returns %d",r);
1.111 + TF_ERROR(r, r == (categoryB==MySecureId) ? KErrNone : KErrPermissionDenied);
1.112 + if(r==KErrNone)
1.113 + {
1.114 + r = prop.Delete(categoryB, iSlaveKey);
1.115 + TF_ERROR(r, r == KErrNone);
1.116 + }
1.117 + TUid categoryC = { KUidSecurityThresholdCategoryValue+1 };
1.118 + r = prop.Define(categoryC, iSlaveKey, iType, KPassPolicy, KPassPolicy);
1.119 + RDebug::Printf("CPropDefineSecurity define with Category C returns %d",r);
1.120 + TF_ERROR(r, r == KErrPermissionDenied);
1.121 +
1.122 + }
1.123 + }
1.124 +
1.125 +
1.126 +
1.127 +
1.128 +GLDEF_C TInt E32Main()
1.129 + {
1.130 + TSecurityInfo info;
1.131 + info.Set(RProcess());
1.132 + MySecureId = info.iSecureId;
1.133 + IHaveWriteDeviceData = info.iCaps.HasCapability(ECapabilityWriteDeviceData);
1.134 +
1.135 + TInt len = User::CommandLineLength();
1.136 + __ASSERT_ALWAYS(len, User::Panic(_L("t_prop_sec: bad args"), 0));
1.137 +
1.138 + // Get arguments for the command line
1.139 + TInt size = len * sizeof(TUint16);
1.140 + HBufC8* hb = HBufC8::NewMax(size);
1.141 + __ASSERT_ALWAYS(hb, User::Panic(_L("t_prop_sec: no memory"), 0));
1.142 + TPtr cmd((TUint16*) hb->Ptr(), len);
1.143 + User::CommandLine(cmd);
1.144 + CPropSecurity::TArgs* args = (CPropSecurity::TArgs*) hb->Ptr();
1.145 +
1.146 + CTestProgram::Start();
1.147 +
1.148 + CTestProgram* progs[] =
1.149 + {
1.150 + new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt),
1.151 + new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot + 1, RProperty::EByteArray),
1.152 + new CPropDefineSecurity(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt),
1.153 + NULL
1.154 + };
1.155 +
1.156 + TInt i;
1.157 + TInt n = (sizeof(progs)/sizeof(*progs)) - 1;
1.158 + for (i = 0; i < n; ++i)
1.159 + {
1.160 + __ASSERT_ALWAYS(progs[i], User::Panic(_L("t_property: no memory"), 0));
1.161 + }
1.162 +
1.163 + CTestProgram::LaunchGroup(progs, 2);
1.164 +
1.165 + for (i = 0; i < n; ++i)
1.166 + {
1.167 + delete progs[i];
1.168 + }
1.169 +
1.170 + CTestProgram::End();
1.171 +
1.172 + return KErrNone;
1.173 + }