os/security/authorisation/userpromptservice/server/source/upsclient/rupssubsession.cpp
First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * RUpsSubsession implementation. See class and function definitions
25 #include <ups/upsclient.h>
26 #include "upsclientconfig.h"
27 #include "upscommon.h"
28 #include <ups/upserr.h>
30 namespace UserPromptService
34 EXPORT_C RUpsSubsession::RUpsSubsession()
36 This constructor provides a single point of definition from
37 which the superclass constructor is called.
39 : RScsClientSubsessionBase(),
41 iSubsessionCreated(EFalse), iClientTid(), iClientSid(TUid::Null()), iClientPid(0), iUpsSession(0)
46 EXPORT_C TInt RUpsSubsession::Initialise(RUpsSession& aSession, const RThread& aClient)
48 Saves the details required to create a subsession specific to the client thread.
50 The actual subsession creation is defered until the subsession is required (which
51 may be never if the policy says server checks are sufficient).
53 Several RUpsSubsession objects can share a single RUpsSession.
55 If any of the RUpsSubsession objects are to be used in a different thread to the RUpsSession, then
56 ShareAuto() must be called on the RUpsSession.
58 @see RSubSessionBase::CreateSubsession
60 @param aSession Connected session to the UPS server.
61 @param aClient SS client for whom this session is set up.
62 @return Symbian OS error code where KErrNone indicates success
63 and any other value indicates failure.
66 iClientTid = aClient.Id();
67 iClientSid = aClient.SecureId();
69 // Need to obtain the drive letter for the exe
70 RProcess clientProcess;
71 TInt r = aClient.Process(clientProcess);
74 return r; // Presumably it exited...
76 iClientPid = clientProcess.Id();
77 clientProcess.Close();
79 iUpsSession = &aSession;
83 TInt RUpsSubsession::CreateSubsession()
85 Create a subsession for a specific SS client over the supplied session.
87 @param aSession Connected session to the UPS server.
88 @param aClient SS client for whom this session is set up.
89 @return Symbian OS error code where KErrNone indicates success
90 and any other value indicates failure.
94 __ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
95 TPckgBuf<TThreadId> tidBuf = iClientTid;
96 TPckgBuf<TProcessId> pidBuf = iClientPid;
97 TIpcArgs args(&tidBuf, &pidBuf);
98 return RScsClientSubsessionBase::CreateSubsession(*iUpsSession, ESessSubsessFromThreadId, args);
101 EXPORT_C void RUpsSubsession::Authorise(TBool aServerCheckOk,
102 const TServiceId& aServiceId, const TDesC& aDestination,
103 TUpsDecision& aDecision, TRequestStatus& aStatus)
105 Determines whether the system server should perform the service requested
106 by the client application. Depending on licensee configuration this function
107 will either complete immediately if the client passed the system servers
108 security policy check. Alternatively, every request may require additional
109 authorisation by the User Prompt Service.
111 @see RUpsSubsession::AuthoriseInternal
113 @param aServerCheckOk Whether the client request passed the security check
114 implemented by the system server e.g. does the client
115 have the correct capabilities for the requested service.
116 @param aServiceId Service which the client wants to use.
117 @param aDestination More information about the service, e.g. this
118 could be a telephone number is the client wanted
120 @param aDecision When the request completes successfully, the verdict
121 is written to this variable.
122 @param aStatus The server completes this request object when it
123 has finished handling the request.
127 __ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
129 AuthoriseInternal(aServerCheckOk, aServiceId, aDestination, KNullDesC8, aDecision, aStatus);
132 EXPORT_C void RUpsSubsession::Authorise(TBool aServerCheckOk,
133 const TServiceId& aServiceId, const TDesC& aDestination,
134 const TDesC8& aOpaqueData,
135 TUpsDecision& aDecision, TRequestStatus& aStatus)
137 Determines whether the system server should perform the service requested
138 by the client application. Depending on licensee configuration this function
139 will either complete immediately if the client passed the system servers
140 security policy check. Alternatively, every request may require additional
141 authorisation by the User Prompt Service.
143 @see RUpsSubsession::AuthoriseInternal
145 @param aServerCheckOk Whether the client request passed the security check
146 implemented by the system server e.g. does the client
147 have the correct capabilities for the requested service.
148 @param aServiceId Service which the client wants to use.
149 @param aDestination More information about the service, e.g. this
150 could be a telephone number is the client wanted
152 @param aOpaqueData Additional information to describe the request.
153 @param aDecision When the request completes successfully, the verdict
154 is written to this variable.
155 @param aStatus The server completes this request object when it
156 has finished handling the request.
160 __ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
162 AuthoriseInternal(aServerCheckOk, aServiceId, aDestination, aOpaqueData, aDecision, aStatus);
166 void RUpsSubsession::AuthoriseInternal(
167 TBool aServerCheckOk,
168 const TServiceId& aServiceId,
169 const TDesC& aDestination,
170 const TDesC8& aOpaqueData,
171 TUpsDecision& aDecision,
172 TRequestStatus& aStatus)
174 This helper function is called by the exported overloads of Authorise.
175 It sends the data supplied by the SS to the UPS server.
177 @param aServerCheckOk Did the system server checks pass?
178 @param aServiceId Service which the client wants to use.
179 @param aDestination More information about the service, e.g. this
180 could be a telephone number is the client wanted
182 @param aOpaqueData Additional information to describe the request.
183 This is KNullDesC8 if the SS used the Authorise overload
184 which did not take opaque data.
185 @param aDecision When the request completes successfully, the verdict
186 is written to this variable.
187 @param aStatus The server completes this request object when it
188 has finished handling the request.
192 TBool decided = EFalse;
195 __ASSERT_ALWAYS(iUpsSession, User::Panic(KUpsClientPanicCat, EUpsClientNotInitialised));
196 CUpsClientConfig::TQueryUpsResult result = iUpsSession->iClientConfig->QueryUps(aServerCheckOk, aServiceId, iClientSid, iClientPid);
199 case CUpsClientConfig::EAllow:
201 aDecision = EUpsDecYes;
204 case CUpsClientConfig::EQueryUps:
207 case CUpsClientConfig::EReject:
209 aDecision = EUpsDecNo;
217 if(!decided && !iSubsessionCreated)
219 // We need to query the UPS, but have not created the subsession yet.
220 err = CreateSubsession();
223 aDecision = EUpsDecNo;
228 iSubsessionCreated = ETrue;
229 // aDecision will be set when we query the UPS
235 // Either do not need to query UPS, or an error occured, so complete client
237 aStatus = KRequestPending;
238 TRequestStatus* status = &aStatus;
239 User::RequestComplete(status, err);
240 return; // Either do not need to query UPS, or an error occured, so return
246 // only three arguments can be sent to a subsession, so split
247 // this operation into two stages.
249 TInt r = PreparePrompt(aServiceId, aDestination, aOpaqueData);
252 TRequestStatus* prs = &aStatus;
253 User::RequestComplete(prs, r);
257 ExecutePrompt(aServerCheckOk, aDecision, aStatus);
260 TInt RUpsSubsession::PreparePrompt(const TServiceId& aServiceId, const TDesC& aDestination, const TDesC8& aOpaqueData)
262 Ask the UPS server to prepare to make a decision. This will be followed
263 by a call to ExecutePrompt.
265 @param aServiceId Service which the client wants to use.
266 @param aDestination More information about the service, e.g. this
267 could be a telephone number is the client wanted
269 @param aOpaqueData Additional information to describe the request.
270 This is KNullDesC8 if the SS used the Authorise overload
271 which did not take opaque data.
272 @return Error code with which the server completed the request.
277 TIpcArgs args(aServiceId.iUid, &aDestination, &aOpaqueData);
278 return CallSubsessionFunction(ESubsessPreparePrompt, args);
281 void RUpsSubsession::ExecutePrompt(TBool aServerCheckOk, TUpsDecision& aDecision, TRequestStatus& aStatus)
283 Ask the UPS to execute the request which was set up with PreparePrompt.
285 @param aDecision When the request completes successfully, this argument
286 is updated with the verdict.
287 @param aStatus The server completes this request object when it
288 has finished handling the request.
293 TUint8* decPtr = reinterpret_cast<TUint8*>(&aDecision);
294 iDecPtr.Set(decPtr, sizeof(TUpsDecision), sizeof(TUpsDecision));
296 TIpcArgs args(&iDecPtr, aServerCheckOk);
297 CallSubsessionFunction(ESubsessExecutePrompt, args, aStatus);
300 EXPORT_C void RUpsSubsession::CancelPrompt()
302 Cancel the prompt request which was launched by calling Authorise.
304 This function has no effect if there is no outstanding request.
308 if(iSubsessionCreated)
310 CancelSubsessionFunction(ESubsessExecutePrompt);
314 EXPORT_C void RUpsSubsession::Close()
316 Close and clean up this subsession object.
319 if(iSubsessionCreated)
321 RScsClientSubsessionBase::Close();
327 } // End of namespace UserPromptService