|
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 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 |
|
20 |
|
21 |
|
22 #include <e32svr.h> |
|
23 #include <e32uid.h> |
|
24 |
|
25 #include "rtsecmgrserver.h" |
|
26 #include "rtsecmgrdata.h" |
|
27 #include "rtsecmgrpolicyparser.h" |
|
28 #include "rtsecmgrsession.h" |
|
29 #include "rtsecmgrsubsession.h" |
|
30 |
|
31 /** |
|
32 * Called by client/server framework after |
|
33 * session has been successfully created. |
|
34 * In effect, a second-phase constructor. |
|
35 * creates: |
|
36 * |
|
37 * 1. the object index |
|
38 * 2. the object container for this session. |
|
39 * |
|
40 */ |
|
41 void CRTSecMgrSession::CreateL() |
|
42 { |
|
43 if(!iSecMgrServer) |
|
44 iSecMgrServer = dynamic_cast<CRTSecMgrServer*> (const_cast<CServer2*> (Server())); |
|
45 |
|
46 iSecMgrServer->AddSession (); |
|
47 |
|
48 iSubSessionObjectIndex = CObjectIx::NewL (); |
|
49 iContainer = iSecMgrServer->NewContainerL (); |
|
50 } |
|
51 |
|
52 void CRTSecMgrSession::CloseSession() |
|
53 { |
|
54 //delete the object index (this stores the objects for this session) |
|
55 Delete (iSubSessionObjectIndex); |
|
56 //delete the object container (this provides unique ids for the objects of this session ) |
|
57 |
|
58 iSecMgrServer->RemoveFromContainerIx (iContainer); |
|
59 iSecMgrServer->RemoveSession (); |
|
60 } |
|
61 |
|
62 /** |
|
63 * A simple utility function to return the appropriate |
|
64 * CRTSecMgrSubSession object given a client's subsession handle. |
|
65 */ |
|
66 CRTSecMgrSubSession* CRTSecMgrSession::SubSessionFromHandle( |
|
67 const RMessage2& aMessage, TInt aHandle) |
|
68 { |
|
69 CRTSecMgrSubSession* subSession = (CRTSecMgrSubSession*)iSubSessionObjectIndex->At(aHandle); |
|
70 |
|
71 if ( !subSession) |
|
72 { |
|
73 PanicClient (aMessage, EBadSubsessionHandle); |
|
74 } |
|
75 return subSession; |
|
76 } |
|
77 |
|
78 void CRTSecMgrSession::DispatchMessageL(const RMessage2& aMessage) |
|
79 { |
|
80 // First check for session-relative requests |
|
81 switch (aMessage.Function ()) |
|
82 { |
|
83 case ESetPolicy: |
|
84 SetPolicy (aMessage); |
|
85 return; |
|
86 case EUpdatePolicy: |
|
87 UpdatePolicy (aMessage); |
|
88 return; |
|
89 case EUnsetPolicy: |
|
90 UnsetPolicy (aMessage); |
|
91 return; |
|
92 case ERegisterScript: |
|
93 RegisterScript (aMessage); |
|
94 return; |
|
95 case ERegisterScriptWithHash: |
|
96 RegisterScript (aMessage, ETrue); |
|
97 return; |
|
98 case EUnRegisterScript: |
|
99 UnregisterScript (aMessage); |
|
100 return; |
|
101 case EGetScriptSession: |
|
102 GetScriptSessionL (aMessage); |
|
103 return; |
|
104 case EGetTrustedUnRegScriptSession: |
|
105 GetTrustedUnRegScriptSessionL (aMessage); |
|
106 return; |
|
107 case ESecServCloseSession: |
|
108 CloseSession (); |
|
109 return; |
|
110 } |
|
111 |
|
112 // All other function codes must be subsession relative. |
|
113 // We need to find the appropriate server side subsession |
|
114 // i.e. the CRTSecMgrSubSession object. |
|
115 // The handle value is passed as the 4th aregument. |
|
116 CRTSecMgrSubSession* subSession = SubSessionFromHandle (aMessage, |
|
117 aMessage.Int3 ()); |
|
118 switch (aMessage.Function ()) |
|
119 { |
|
120 case ECloseScriptSession: |
|
121 DeleteSubSession (aMessage.Int3 ()); |
|
122 return; |
|
123 case EUpdatePermanentGrant: |
|
124 subSession->UpdatePermGrantL (aMessage); |
|
125 return; |
|
126 case EGetScriptFile: |
|
127 subSession->GetScriptFile (aMessage); |
|
128 return; |
|
129 default: |
|
130 PanicClient (aMessage, EBadRequest); |
|
131 return; |
|
132 } |
|
133 } |
|
134 TBool CRTSecMgrSession::IsScriptOpenWithPolicy(TPolicyID aPolicyID) |
|
135 { |
|
136 for (TInt i(0); i!=iSubSessionObjectIndex->Count ();++i) |
|
137 { |
|
138 CRTSecMgrSubSession |
|
139 * subsession = ((CRTSecMgrSubSession*)iSubSessionObjectIndex->operator[](i)); |
|
140 if ( subsession) |
|
141 { |
|
142 if ( aPolicyID==subsession->Script().PolicyID ()) |
|
143 { |
|
144 return ETrue; |
|
145 } |
|
146 } |
|
147 else |
|
148 { |
|
149 continue; |
|
150 } |
|
151 |
|
152 } |
|
153 return EFalse; |
|
154 } |
|
155 |
|
156 TBool CRTSecMgrSession::IsScriptSessionOpen(TExecutableID aScriptID,CRTSecMgrSubSession* aCurrentSession) |
|
157 { |
|
158 for (TInt i(0); i!=iSubSessionObjectIndex->Count ();++i) |
|
159 { |
|
160 CRTSecMgrSubSession |
|
161 * subsession = ((CRTSecMgrSubSession*)iSubSessionObjectIndex->operator[](i)); |
|
162 if ( subsession && ( subsession != aCurrentSession)) |
|
163 { |
|
164 if ( aScriptID==subsession->ScriptID ()) |
|
165 { |
|
166 return ETrue; |
|
167 } |
|
168 } |
|
169 else |
|
170 { |
|
171 continue; |
|
172 } |
|
173 |
|
174 } |
|
175 return EFalse; |
|
176 } |