|
1 /* |
|
2 * Copyright (c) 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 "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: Implementation of policymanagement components |
|
15 * |
|
16 */ |
|
17 /* PolicyEngineClient.cpp |
|
18 */ |
|
19 |
|
20 #include <eikenv.h> |
|
21 #include <eikappui.h> |
|
22 #include <e32svr.h> |
|
23 #include <featmgr.h> |
|
24 #include <bldvariant.hrh> |
|
25 |
|
26 #include "PolicyEngineClientServer.h" |
|
27 #include "PolicyEngineClientServerDefs.h" |
|
28 #include "PolicyEngineClient.h" |
|
29 #include "ErrorCodes.h" |
|
30 #include "debug.h" |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 // Standard server startup code |
|
36 // |
|
37 static TInt StartServer() |
|
38 { |
|
39 RDEBUG("PolicyEngineServer: Starting server..."); |
|
40 |
|
41 const TUidType serverUid(KNullUid,KNullUid,KPolicyEngineServerUid); |
|
42 |
|
43 // EPOC and EKA 2 is easy, we just create a new server process. Simultaneous |
|
44 // launching of two such processes should be detected when the second one |
|
45 // attempts to create the server object, failing with KErrAlreadyExists. |
|
46 RProcess server; |
|
47 //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid); |
|
48 TInt r=server.Create(KPolicyEngineServerImg,KNullDesC); |
|
49 |
|
50 if (r!=KErrNone) |
|
51 { |
|
52 RDEBUG_2("PolicyEngineClient: server start failed %d",r); |
|
53 return r; |
|
54 } |
|
55 TRequestStatus stat; |
|
56 server.Rendezvous(stat); |
|
57 if (stat!=KRequestPending) |
|
58 server.Kill(0); // abort startup |
|
59 else |
|
60 server.Resume(); // logon OK - start the server |
|
61 RDEBUG("PolicyEngineClient: Started"); |
|
62 |
|
63 User::WaitForRequest(stat); // wait for start or death |
|
64 // we can't use the 'exit reason' if the server panicked as this |
|
65 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
66 // from KErrNone |
|
67 r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
68 server.Close(); |
|
69 return r; |
|
70 } |
|
71 |
|
72 |
|
73 // This is the standard retry pattern for server connection |
|
74 EXPORT_C TInt RPolicyEngine::Connect() |
|
75 { |
|
76 TRAPD( e, FeatureManager::InitializeLibL() ); |
|
77 if( e != KErrNone ) |
|
78 { |
|
79 return e; |
|
80 } |
|
81 |
|
82 TBool iSupported = FeatureManager::FeatureSupported( KFeatureIdSapPolicyManagement); |
|
83 FeatureManager::UnInitializeLib(); |
|
84 |
|
85 if( !iSupported ) |
|
86 { |
|
87 return KErrNotSupported; |
|
88 } |
|
89 |
|
90 TInt retry=2; |
|
91 for (;;) |
|
92 { |
|
93 TInt r=CreateSession(KPolicyEngineServerName,TVersion(0,0,0),1); |
|
94 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
95 return r; |
|
96 if (--retry==0) |
|
97 return r; |
|
98 r=StartServer(); |
|
99 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
100 return r; |
|
101 } |
|
102 } |
|
103 |
|
104 EXPORT_C void RPolicyEngine::Close() |
|
105 { |
|
106 RSessionBase::Close(); //basecall |
|
107 } |
|
108 |
|
109 |
|
110 EXPORT_C TInt RPolicyEngine::PerformRFS() |
|
111 { |
|
112 RDEBUG("PolicyEngineClient: Perform RFS"); |
|
113 return SendReceive( EPerformPMRFS); |
|
114 } |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 // ---------------------------------------------------------------------------------------- |
|
120 // RPolicyManagement subsessions |
|
121 // ---------------------------------------------------------------------------------------- |
|
122 |
|
123 // create new subsession |
|
124 EXPORT_C TInt RPolicyManagement::Open(RPolicyEngine &aServer ) |
|
125 { |
|
126 RDEBUG("PolicyEngineClient: Create new managemenet subsession"); |
|
127 return CreateSubSession(aServer,ECreateManagementSubSession,TIpcArgs(NULL,NULL)); |
|
128 } |
|
129 |
|
130 // close a subsession |
|
131 EXPORT_C void RPolicyManagement::Close() |
|
132 { |
|
133 RDEBUG("PolicyEngineClient: Close managemenet subsession"); |
|
134 RSubSessionBase::CloseSubSession(ECloseManagementSubSession); |
|
135 } |
|
136 |
|
137 |
|
138 EXPORT_C TInt RPolicyManagement::ExecuteOperation( const TDesC8& aOperationDescription, |
|
139 TParserResponse &aResponse) |
|
140 { |
|
141 RDEBUG("PolicyEngineClient: Execute operation"); |
|
142 |
|
143 TPckg<TParserResponse> pack(aResponse); |
|
144 TInt err = SendReceive( EExecuteOperation, TIpcArgs(&aOperationDescription, &pack)); |
|
145 |
|
146 return err; |
|
147 } |
|
148 |
|
149 EXPORT_C TInt RPolicyManagement::ExecuteOperation( const TDesC8& aOperationDescription ) |
|
150 { |
|
151 TParserResponse response; |
|
152 TInt err = ExecuteOperation( aOperationDescription, response); |
|
153 |
|
154 if ( err == KErrNone ) |
|
155 { |
|
156 if ( response.GetReturnMessage().Compare( ManagementErrors::OperationOk) != 0) |
|
157 { |
|
158 err = KErrAbort; |
|
159 } |
|
160 } |
|
161 |
|
162 return err; |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 EXPORT_C TInt RPolicyManagement::GetElementL( TElementInfo& aElementInfo) |
|
168 { |
|
169 RDEBUG("PolicyEngineClient: Get element"); |
|
170 |
|
171 TElementInfoHelpPack helper; |
|
172 helper.iDescriptionLength = 0; |
|
173 helper.iChildListLength = 0; |
|
174 |
|
175 TPckg<TElementInfoHelpPack> helperPack(helper); |
|
176 |
|
177 TInt err = SendReceive( EGetElementDescriptionAndChildListLength, TIpcArgs( &aElementInfo.iElementId, &helperPack)); |
|
178 |
|
179 if ( err == KErrNone) |
|
180 { |
|
181 HBufC8 * childs = HBufC8::NewLC( helper.iChildListLength); |
|
182 |
|
183 aElementInfo.iDescription = HBufC8::NewL( helper.iDescriptionLength); |
|
184 |
|
185 TPtr8 descriptionArgs = aElementInfo.iDescription->Des(); |
|
186 TPtr8 childsArgs = childs->Des(); |
|
187 |
|
188 err = SendReceive( EReadElementAndChildList, |
|
189 TIpcArgs( &descriptionArgs, &childsArgs)); |
|
190 |
|
191 if ( err == KErrNone ) |
|
192 { |
|
193 aElementInfo.iChildElements.SetListL( *childs); |
|
194 } |
|
195 |
|
196 CleanupStack::PopAndDestroy(); |
|
197 } |
|
198 |
|
199 return err; |
|
200 } |
|
201 |
|
202 EXPORT_C TInt RPolicyManagement::GetXACMLDescriptionL( TElementInfo& aElementInfo) |
|
203 { |
|
204 RDEBUG("PolicyEngineClient: Get XACML description"); |
|
205 |
|
206 TInt XACMLLength; |
|
207 TPckg<TInt> lengthPack(XACMLLength); |
|
208 |
|
209 TInt err = SendReceive( EGetElementXACMLLength, TIpcArgs( &aElementInfo.iElementId, &lengthPack)); |
|
210 |
|
211 if ( err == KErrNone) |
|
212 { |
|
213 aElementInfo.iXACMLContent = HBufC8::NewL( XACMLLength); |
|
214 TPtr8 contentArgs = aElementInfo.iXACMLContent->Des(); |
|
215 |
|
216 err = SendReceive( EReadElementXACML, |
|
217 TIpcArgs( &contentArgs)); |
|
218 } |
|
219 |
|
220 return err; |
|
221 } |
|
222 |
|
223 EXPORT_C TInt RPolicyManagement::GetElementListL( const TElementType& aElementType, RElementIdArray& aElementIdArray) |
|
224 { |
|
225 RDEBUG("PolicyEngineClient: Get element list"); |
|
226 |
|
227 |
|
228 //Create packages for data |
|
229 TInt listLength; |
|
230 TPckg<TInt> lengthPack(listLength); |
|
231 TPckg<TElementType> typePack(aElementType); |
|
232 |
|
233 //get element list length from server side |
|
234 TInt err = SendReceive( EGetElementListLength, TIpcArgs( &typePack, &lengthPack)); |
|
235 |
|
236 //and if operation ok, get also element list |
|
237 if ( err == KErrNone) |
|
238 { |
|
239 //create buffer for list |
|
240 TPtr8 ptr = HBufC8::NewLC( listLength)->Des(); |
|
241 |
|
242 //get element list descriptor |
|
243 err = SendReceive( EReadElementList, TIpcArgs( &ptr)); |
|
244 |
|
245 //feed list descriptor for IDArray element, which decode descriptor to list format |
|
246 if ( err == KErrNone) |
|
247 { |
|
248 aElementIdArray.SetListL( ptr); |
|
249 } |
|
250 |
|
251 //HBufC8 |
|
252 CleanupStack::PopAndDestroy(); |
|
253 } |
|
254 |
|
255 return err; |
|
256 } |
|
257 |
|
258 |
|
259 EXPORT_C TInt RPolicyManagement::AddSessionTrust( TCertInfo& aCertInfo) |
|
260 { |
|
261 RDEBUG("PolicyEngineClient: Add session trust"); |
|
262 |
|
263 |
|
264 //Create package for data |
|
265 TPckg<TCertInfo> certInfoPck( aCertInfo); |
|
266 |
|
267 //Send CertInfo to server |
|
268 return SendReceive( EAddSessionTrust, TIpcArgs( &certInfoPck)); |
|
269 } |
|
270 |
|
271 EXPORT_C TInt RPolicyManagement::IsAllowedServerId( const TDesC& aServerID) |
|
272 { |
|
273 RDEBUG_2("RPolicyManagement::IsAllowedServerId( %S )", &aServerID ); |
|
274 |
|
275 //Create package for data |
|
276 TBool response; |
|
277 TPckg<TBool> respPck( response); |
|
278 |
|
279 //make 8-bit descriptor |
|
280 HBufC8* buf = NULL; |
|
281 TRAPD( e, buf = HBufC8::NewL( aServerID.Length()) ); |
|
282 if( e != KErrNone ) |
|
283 { |
|
284 return e; |
|
285 } |
|
286 |
|
287 buf->Des().Append( aServerID); |
|
288 |
|
289 //Send parameters to server |
|
290 TInt err = SendReceive( EIsServerIdValid, TIpcArgs( buf, &respPck)); |
|
291 |
|
292 if ( err == KErrNone ) |
|
293 { |
|
294 if ( !response ) |
|
295 { |
|
296 err = KErrAccessDenied; |
|
297 } |
|
298 } |
|
299 |
|
300 delete buf; |
|
301 buf = NULL; |
|
302 |
|
303 return err; |
|
304 } |
|
305 |
|
306 |
|
307 EXPORT_C TInt RPolicyManagement::CertificateRole( TCertInfo& aCertInfo, TRole& aRole) |
|
308 { |
|
309 RDEBUG("PolicyEngineClient: Certificate role"); |
|
310 |
|
311 //Create package for data |
|
312 TPckg<TCertInfo> certInfoPck( aCertInfo); |
|
313 TPckg<TRole> rolePck( aRole); |
|
314 |
|
315 //Send parameters to server |
|
316 return SendReceive( ECertificateRole, TIpcArgs( &certInfoPck, &rolePck)); |
|
317 } |
|
318 |
|
319 |
|
320 // ---------------------------------------------------------------------------------------- |
|
321 // RPolicyRequest subsessions |
|
322 // ---------------------------------------------------------------------------------------- |
|
323 |
|
324 // create new subsession |
|
325 EXPORT_C TInt RPolicyRequest::Open(RPolicyEngine &aServer ) |
|
326 { |
|
327 RDEBUG("PolicyEngineClient: Open policy request subsession"); |
|
328 return CreateSubSession(aServer,ECreateRequestSubSession,TIpcArgs(NULL,NULL)); |
|
329 } |
|
330 |
|
331 // close a subsession |
|
332 EXPORT_C void RPolicyRequest::Close() |
|
333 { |
|
334 RDEBUG("PolicyEngineClient: Close policy request subsession"); |
|
335 RSubSessionBase::CloseSubSession(ECloseRequestSubSessio); |
|
336 } |
|
337 |
|
338 EXPORT_C TInt RPolicyRequest::MakeRequest( TRequestContext& aRequestContext, TResponse& aResponse) |
|
339 { |
|
340 RDEBUG("PolicyEngineClient: Make policy request"); |
|
341 TPckg<TResponse> pack( aResponse); |
|
342 return SendReceive( EPolicyRequest, TIpcArgs( &aRequestContext.RequestDescription(), &pack)); |
|
343 } |
|
344 |
|
345 |