|
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 "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 // CPolicySpace class |
|
15 // |
|
16 // |
|
17 |
|
18 #include <s32file.h> |
|
19 #include "D32Strings.h" |
|
20 #include "D32Map.h" |
|
21 #include "SC_Policy.h" |
|
22 #include "SC_StrmIn.h" |
|
23 #include "SC_PassAllPolicy.h" |
|
24 #include "SC_DomainLoader.h" |
|
25 #include "SC_PolicySpace.h" |
|
26 |
|
27 namespace DBSC |
|
28 { |
|
29 |
|
30 /** |
|
31 */ |
|
32 inline CPolicySpace::CPolicySpace() : |
|
33 iPDCollection(TLinearOrder< TPair<TInt, CPolicyDomain*> > (&Compare<TInt, CPolicyDomain*>)) |
|
34 { |
|
35 } |
|
36 |
|
37 /** |
|
38 Standard phase-one CPolicySpace factory method |
|
39 @param aFs A reference to a file server session object |
|
40 @param aPrivatePath A reference to the DBMS server private directory. |
|
41 @return A pointer to just created CPolicySpace instance. |
|
42 @leave System-wide error codes, including KErrNoMemory |
|
43 */ |
|
44 CPolicySpace* CPolicySpace::NewL(RFs& aFs, const TDesC& aPrivatePath) |
|
45 { |
|
46 CPolicySpace* self = new (ELeave) CPolicySpace; |
|
47 CleanupReleasePushL(*self); |
|
48 self->ConstructL(aFs, aPrivatePath); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 /** |
|
54 Standard phase-two CPolicySpace construction method |
|
55 @param aFs A reference to a file server session object |
|
56 @param aPrivatePath A reference to the DBMS server private directory. |
|
57 @leave System-wide error codes, including KErrNoMemory |
|
58 */ |
|
59 void CPolicySpace::ConstructL(RFs& aFs, const TDesC& aPrivatePath) |
|
60 { |
|
61 iPassAllDbPolicy = new (ELeave) CPassAllPolicy(EPOTDatabase); |
|
62 iPassAllTblPolicy = new (ELeave) CPassAllPolicy(EPOTTable); |
|
63 TBuf<KMaxPath>* policyDir = new (ELeave) TFileName; |
|
64 CleanupStack::PushL(policyDir); |
|
65 policyDir->Copy(aPrivatePath); |
|
66 policyDir->Append(KSecurityPolicyDir); |
|
67 TRAPD(err, LoadPolicyDomainsL(aFs, *policyDir)); |
|
68 if(err != KErrNone && err != KErrNotFound) //it's not an error, if there are no policy files |
|
69 { |
|
70 __LEAVE(err); |
|
71 } |
|
72 CleanupStack::PopAndDestroy(policyDir); |
|
73 } |
|
74 |
|
75 /** |
|
76 The method creates a policy domain object for each binary policy file found in the system. |
|
77 The created objects will be added to iPDCollection collection of policy domain objects. |
|
78 @param aFs A reference to a file server session object |
|
79 @param aPrivatePath A reference to the DBMS server private directory. |
|
80 @leave System-wide error codes, including KErrNoMemory |
|
81 */ |
|
82 void CPolicySpace::LoadPolicyDomainsL(RFs& aFs, const TDesC& aPolicyDir) |
|
83 { |
|
84 CPolicyDomainLoader* loader = CPolicyDomainLoader::NewLC(aFs, aPolicyDir, iPDCollection); |
|
85 loader->RunL(); |
|
86 CleanupStack::PopAndDestroy(loader); |
|
87 } |
|
88 |
|
89 /** |
|
90 The method returns the related with aDomainUid parameter CPolicyDomain object. |
|
91 @param aDomainUid Domain UID |
|
92 @return A pointer to the related with aDomainUid parameter CPolicyDomain object. |
|
93 */ |
|
94 CPolicyDomain* CPolicySpace::PolicyDomain(TUid aDomainUid) const |
|
95 { |
|
96 __ASSERT(aDomainUid != KNullUid); |
|
97 CPolicyDomain* domain = NULL; |
|
98 if(iPDCollection.Find(aDomainUid.iUid, domain) == KErrNone) |
|
99 { |
|
100 __ASSERT(domain); |
|
101 __ASSERT(domain->Uid() == aDomainUid); |
|
102 } |
|
103 return domain; |
|
104 } |
|
105 |
|
106 /** |
|
107 */ |
|
108 CPolicySpace::~CPolicySpace() |
|
109 { |
|
110 TMapIterator<TInt, CPolicyDomain*> it(iPDCollection); |
|
111 TPair<TInt, CPolicyDomain*> pair; |
|
112 while(it.Next(pair)) |
|
113 { |
|
114 delete pair.iData; |
|
115 } |
|
116 iPDCollection.Close(); |
|
117 delete iPassAllTblPolicy; |
|
118 delete iPassAllDbPolicy; |
|
119 } |
|
120 |
|
121 /** |
|
122 Implements MPolicySpace::Release(). |
|
123 Use this method when want to destroy particular CPolicySpace object. |
|
124 */ |
|
125 void CPolicySpace::Release() |
|
126 { |
|
127 delete this; |
|
128 } |
|
129 |
|
130 /** |
|
131 Implements MPolicySpace::DbPolicyL(). |
|
132 @param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID |
|
133 @return A const pointer to the related with the request UID policy object. |
|
134 */ |
|
135 const MPolicy* CPolicySpace::DbPolicyL(const TDbPolicyRequest& aDbPolicyRequest) const |
|
136 { |
|
137 const MPolicy* policy = NULL; |
|
138 if(aDbPolicyRequest.iAccessType == EATNonSecure) |
|
139 { |
|
140 policy = iPassAllDbPolicy; |
|
141 } |
|
142 else//Secure shared database access |
|
143 { |
|
144 __ASSERT(aDbPolicyRequest.iUid != KNullUid); |
|
145 CPolicyDomain* domain = PolicyDomain(aDbPolicyRequest.iUid); |
|
146 if(domain) |
|
147 { |
|
148 policy = domain->DbPolicy(); |
|
149 } |
|
150 } |
|
151 if(aDbPolicyRequest.iAccessType == EATSecure && !policy) |
|
152 {//there is no security policy associated with the supplied uid. |
|
153 __LEAVE(KErrArgument); |
|
154 } |
|
155 __ASSERT(policy); |
|
156 return policy; |
|
157 } |
|
158 |
|
159 /** |
|
160 Implements MPolicySpace::TblPolicyL(). |
|
161 @param aDbPolicyRequest Request params: request type (secure/non-secure) and domain UID |
|
162 @param aTblName Database table name |
|
163 @return A const pointer to the related with the request table policy object. |
|
164 */ |
|
165 const MPolicy* CPolicySpace::TblPolicyL(const TDbPolicyRequest& aDbPolicyRequest, |
|
166 const TDesC& aTblName) const |
|
167 { |
|
168 const MPolicy* policy = NULL; |
|
169 if(aDbPolicyRequest.iAccessType == EATNonSecure) |
|
170 { |
|
171 policy = iPassAllTblPolicy; |
|
172 } |
|
173 else//Secure shared database access |
|
174 { |
|
175 CPolicyDomain* domain = PolicyDomain(aDbPolicyRequest.iUid); |
|
176 if(domain) |
|
177 { |
|
178 policy = domain->TblPolicy(aTblName); |
|
179 if(!policy) |
|
180 { |
|
181 policy = domain->DbPolicy(); |
|
182 } |
|
183 } |
|
184 } |
|
185 if(aDbPolicyRequest.iAccessType == EATSecure && !policy) |
|
186 {//there is no security policy associated with the supplied uid. |
|
187 __LEAVE(KErrArgument); |
|
188 } |
|
189 __ASSERT(policy); |
|
190 return policy; |
|
191 } |
|
192 |
|
193 /** |
|
194 Implements MPolicySpace::BackupSIDL(). |
|
195 Returns backup&restore SID for the databases, the access to which is controlled by the |
|
196 security policy, identified by aDbUid parameter. |
|
197 @param aDbUid Domain UID |
|
198 @return Backup&restore SID for the supplied domain UID |
|
199 @leave KErrArgument if there is no security policy domain for the supplied UID. |
|
200 */ |
|
201 TSecureId CPolicySpace::BackupSIDL(TUid aDbUid) const |
|
202 { |
|
203 CPolicyDomain* domain = PolicyDomain(aDbUid); |
|
204 if(!domain) |
|
205 { |
|
206 __LEAVE(KErrArgument); |
|
207 } |
|
208 return domain->BackupSID(); |
|
209 } |
|
210 |
|
211 } //end of - namespace DBSC |