|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "policyreader.h" |
|
20 #include <ups/ups.hrh> |
|
21 #include <ups/upserr.h> |
|
22 #include "upslog.h" |
|
23 |
|
24 using namespace UserPromptService; |
|
25 |
|
26 /// The policy resource format is versioned. |
|
27 static const TInt KPolicyFormatVersion = 1; |
|
28 |
|
29 TPolicyHeader::TPolicyHeader() |
|
30 /** |
|
31 Constructor |
|
32 */ |
|
33 : iFormatVersion(0), iMajorVersion(0), iMinorVersion(0), iAuthPolicy(EAlwaysCheck), |
|
34 iDefaultPolicyEvaluator(TUid::Null()), iDefaultDialogCreator(TUid::Null()) |
|
35 { |
|
36 } |
|
37 |
|
38 void CPolicyReader::ReadPolicyHeaderL() |
|
39 /** |
|
40 Reads the header information from the policy file. |
|
41 */ |
|
42 { |
|
43 TUint16 formatVersion = iReader.ReadUint16L(); |
|
44 if (formatVersion != KPolicyFormatVersion) |
|
45 { |
|
46 User::Leave(KErrUpsBadPolicyFile); |
|
47 } |
|
48 |
|
49 (void) iReader.ReadUint32L(); // Skip reserved LLINK |
|
50 |
|
51 iHeader.iFormatVersion = formatVersion; |
|
52 iHeader.iMajorVersion = iReader.ReadUint16L(); |
|
53 iHeader.iMinorVersion = iReader.ReadUint16L(); |
|
54 iHeader.iAuthPolicy = static_cast<TAuthorisationPolicy>(iReader.ReadInt8L()); |
|
55 iHeader.iDefaultPolicyEvaluator = TUid::Uid(iReader.ReadInt32L()); |
|
56 iHeader.iDefaultDialogCreator = TUid::Uid(iReader.ReadInt32L()); |
|
57 if (iHeader.iDefaultDialogCreator.iUid == 0) |
|
58 { |
|
59 User::Leave(KErrUpsBadPolicyFile); |
|
60 } |
|
61 } |
|
62 |
|
63 EXPORT_C CPolicyReader* CPolicyReader::NewL(RFs& aRFs, const TDesC& aPolicyFileName) |
|
64 /** |
|
65 Creates a policy reader object. |
|
66 @param aRFs the file server session used by the resource parser. |
|
67 @param aPolicyFileName the name of the User Prompt Service policy file to read. |
|
68 |
|
69 @return The new policy reader. |
|
70 */ |
|
71 { |
|
72 CPolicyReader* self = CPolicyReader::NewLC(aRFs, aPolicyFileName); |
|
73 CleanupStack::Pop(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 EXPORT_C CPolicyReader* CPolicyReader::NewLC(RFs& aRFs, const TDesC& aPolicyFileName) |
|
78 /** |
|
79 Creates a policy reader object and places the pointer on the cleanup stack. |
|
80 @param aRFs the file server session used by the resource parser. |
|
81 @param aPolicyFileName the name of the User Prompt Service policy file to read. |
|
82 |
|
83 @return The new policy reader. |
|
84 */ |
|
85 { |
|
86 CPolicyReader* self = new(ELeave) CPolicyReader(); |
|
87 CleanupStack::PushL(self); |
|
88 self->ConstructL(aRFs, aPolicyFileName); |
|
89 return self; |
|
90 } |
|
91 |
|
92 void CPolicyReader::ConstructL(RFs& aFs, const TDesC& aResourceFileName) |
|
93 /** |
|
94 Second phase constructor. |
|
95 - Creates the resource reader. |
|
96 - Reads the default policy evaluator and dialog creator UIDs. |
|
97 - Reads the number of policies in the resource file. |
|
98 |
|
99 @param aRFs The file server session used by the resource parser. |
|
100 @param aPolicyFileName The name of the User Prompt Service policy file to read. |
|
101 */ |
|
102 { |
|
103 DEBUG_PRINTF2(_L("Loading UPS policy file %S"), &aResourceFileName); |
|
104 |
|
105 RFile r; |
|
106 User::LeaveIfError(r.Open(aFs, aResourceFileName, EFileRead | EFileShareReadersOnly)); |
|
107 CleanupClosePushL(r); |
|
108 TInt size; |
|
109 User::LeaveIfError(r.Size(size)); |
|
110 CleanupStack::PopAndDestroy(&r); |
|
111 |
|
112 iResourceFile = CResourceFile::NewL(aFs, aResourceFileName, 0, size); |
|
113 iReader.OpenL(iResourceFile, KPolicyResourceId); |
|
114 |
|
115 TUidType u(iResourceFile->UidType()); |
|
116 if (u[1] != TUid::Uid(KUidUpsPolicyResourceFile)) |
|
117 { |
|
118 User::Leave(KErrUpsBadPolicyFile); |
|
119 } |
|
120 |
|
121 ReadPolicyHeaderL(); |
|
122 |
|
123 iPolicyCount = iReader.ReadUint16L(); |
|
124 if (iPolicyCount < 0) |
|
125 { |
|
126 User::Leave(KErrUpsBadPolicyFile); |
|
127 } |
|
128 } |
|
129 |
|
130 EXPORT_C const TPolicyHeader& CPolicyReader::Header() const |
|
131 /** |
|
132 Gets the header information for this policy file. |
|
133 @return A const reference to the policy header information. |
|
134 */ |
|
135 { |
|
136 return iHeader; |
|
137 } |
|
138 |
|
139 CPolicyReader::CPolicyReader() |
|
140 /** |
|
141 Constructor |
|
142 */ |
|
143 { |
|
144 } |
|
145 |
|
146 CPolicyReader::~CPolicyReader() |
|
147 /** |
|
148 Destructor |
|
149 */ |
|
150 { |
|
151 iReader.Close(); |
|
152 delete iResourceFile; |
|
153 } |
|
154 |
|
155 EXPORT_C CPolicy* CPolicyReader::DefaultPolicyL() |
|
156 /** |
|
157 Factory method for creating a default policy object from the |
|
158 information in the UPS policy file header. |
|
159 |
|
160 @return A pointer to the default policy object. |
|
161 */ |
|
162 { |
|
163 _LIT(KAllDestinations, "*"); |
|
164 TSidClasses allSidClasses(0xFFFF); |
|
165 RArray<TSecureId> sidList; |
|
166 CleanupClosePushL(sidList); |
|
167 |
|
168 CPolicy* p = CPolicy::NewL( |
|
169 allSidClasses, sidList, KAllDestinations, |
|
170 CPolicy::EYes | CPolicy::ENo, iHeader.iDefaultPolicyEvaluator, iHeader.iDefaultDialogCreator, |
|
171 0, CPolicy::ESystemServerSecurityPassedOrFailed, |
|
172 iHeader.iMajorVersion, iHeader.iMinorVersion, ETrue); |
|
173 |
|
174 CleanupStack::PopAndDestroy(&sidList); |
|
175 return p; |
|
176 } |
|
177 |
|
178 EXPORT_C CPolicy* CPolicyReader::NextPolicyL() |
|
179 /** |
|
180 Gets the next policy from the resource file. |
|
181 |
|
182 @return A pointer to the new policy object or null if the end of |
|
183 the file has been reached. |
|
184 */ |
|
185 { |
|
186 CPolicy* p(0); |
|
187 if (iPolicyNum < iPolicyCount) |
|
188 { |
|
189 p = ReadPolicyL(); |
|
190 ++iPolicyNum; |
|
191 } |
|
192 return p; |
|
193 } |
|
194 |
|
195 EXPORT_C CPolicy* CPolicyReader::ReadPolicyL() |
|
196 /** |
|
197 Reads the next policy from the resource file. |
|
198 |
|
199 @return A pointer to the new policy object. |
|
200 */ |
|
201 { |
|
202 TUint32 classes = iReader.ReadUint32L(); |
|
203 TSidClasses sidClasses(classes); |
|
204 |
|
205 TInt numSids = iReader.ReadInt16L(); |
|
206 if (numSids < 0) |
|
207 { |
|
208 User::Leave(KErrUpsBadPolicyFile); |
|
209 } |
|
210 RArray<TSecureId> sidList(8); |
|
211 CleanupClosePushL(sidList); |
|
212 for (TInt i = 0; i < numSids; ++i) |
|
213 { |
|
214 sidList.AppendL(TSecureId(iReader.ReadUint32L())); |
|
215 } |
|
216 |
|
217 TUint8 ssSecurity = iReader.ReadUint8L(); |
|
218 CPolicy::TSystemServerSecurity systemServerSecurity = |
|
219 CPolicy::ESystemServerSecurityPassedOrFailed; |
|
220 switch (ssSecurity) |
|
221 { |
|
222 case CPolicy::ESystemServerSecurityPassedOrFailed: |
|
223 systemServerSecurity = CPolicy::ESystemServerSecurityPassedOrFailed; |
|
224 break; |
|
225 case CPolicy::ESystemServerSecurityPassed: |
|
226 systemServerSecurity = CPolicy::ESystemServerSecurityPassed; |
|
227 break; |
|
228 case CPolicy::ESystemServerSecurityFailed: |
|
229 systemServerSecurity = CPolicy::ESystemServerSecurityFailed; |
|
230 break; |
|
231 default: |
|
232 User::Leave(KErrUpsBadPolicyFile); |
|
233 break; |
|
234 } |
|
235 |
|
236 HBufC* destination(iReader.ReadHBufCL()); |
|
237 if (! destination) |
|
238 { |
|
239 destination = HBufC::NewL(0); |
|
240 } |
|
241 CleanupStack::PushL(destination); |
|
242 |
|
243 TUint options(iReader.ReadUint32L()); |
|
244 if ((options & |
|
245 ~(CPolicy::EYes|CPolicy::ENo|CPolicy::ESessionYes|CPolicy::ESessionNo|CPolicy::EAlways|CPolicy::ENever)) != 0) |
|
246 { |
|
247 User::Leave(KErrUpsBadPolicyFile); |
|
248 } |
|
249 |
|
250 TUid policyEvaluator = TUid::Uid(iReader.ReadInt32L()); |
|
251 if (policyEvaluator == TUid::Null()) |
|
252 { |
|
253 policyEvaluator = iHeader.iDefaultPolicyEvaluator; |
|
254 } |
|
255 |
|
256 TUid dialogCreator = TUid::Uid(iReader.ReadInt32L()); |
|
257 if (dialogCreator == TUid::Null()) |
|
258 { |
|
259 dialogCreator = iHeader.iDefaultDialogCreator; |
|
260 } |
|
261 |
|
262 TUint16 flags(iReader.ReadUint16L()); |
|
263 iReader.ReadUint16L(); // skip over reserved flags |
|
264 iReader.ReadUint32L(); // skip over reserved link |
|
265 |
|
266 CPolicy* pol = CPolicy::NewL(sidClasses, sidList, *destination, |
|
267 options, policyEvaluator, dialogCreator, flags, systemServerSecurity, |
|
268 iHeader.iMajorVersion, iHeader.iMinorVersion); |
|
269 |
|
270 CleanupStack::PopAndDestroy(2, &sidList); // destination, sidList |
|
271 return pol; |
|
272 } |