|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include "susutilserver.h" |
|
17 #include "susutilsession.h" |
|
18 #include "susutilclisrv.h" |
|
19 #include "suspluginloader.h" |
|
20 #include "suspluginframe.h" |
|
21 #include "suspanic.h" |
|
22 #include "ssmdebug.h" |
|
23 |
|
24 |
|
25 // ------------------- Policy Server Security Setup ---------------------- |
|
26 |
|
27 const TUint KRangeCount = 3; |
|
28 const TInt KRanges[KRangeCount] = |
|
29 { |
|
30 0, |
|
31 KSusUtilServFirstUsedOpCode, //range: KFirstUsedSsmOpCode...(EEndOfSusUtilOpCodes-1) inclusive |
|
32 #ifdef _DEBUG |
|
33 EEndOfSusUtilOpCodes+1 // this op-code is used to shutdown server in debug builds |
|
34 #else |
|
35 EEndOfSusUtilOpCodes |
|
36 #endif //_DEBUG |
|
37 }; |
|
38 |
|
39 /** |
|
40 Maps to index 0 in the array KPolicyElements |
|
41 */ |
|
42 const TInt KCapabilitiesInSsmServer = 0; |
|
43 |
|
44 /** |
|
45 Specifies the appropriate action to take for each range in KRanges. |
|
46 The n:th element of KElementsIndex specifies the appropriate action to take for the n:th range in KRanges. |
|
47 */ |
|
48 const TUint8 KElementsIndex[KRangeCount] = |
|
49 { |
|
50 CPolicyServer::ENotSupported, |
|
51 KCapabilitiesInSsmServer, |
|
52 CPolicyServer::ENotSupported, |
|
53 }; |
|
54 |
|
55 /** |
|
56 Array containing the different security checks performed by this server |
|
57 */ |
|
58 const CPolicyServer::TPolicyElement KPolicyElements[] = |
|
59 { |
|
60 {_INIT_SECURITY_POLICY_C6(ECapabilityDiskAdmin, ECapabilityPowerMgmt, ECapabilityProtServ, ECapabilitySwEvent, ECapabilityWriteDeviceData, ECapabilityReadDeviceData), CPolicyServer::EFailClient} //lint !e778 suppress Constant expression evaluates to 0 in operation '+' |
|
61 }; |
|
62 |
|
63 /** |
|
64 Setup a security policy which require all caps used by the SsmServer for all requests |
|
65 including creating a connection. We don't yet have a usecase for anyone else than |
|
66 SsmServer using SusUtilServer. The caller's SID will also be matched against SsmServer's |
|
67 SID in each ServiceL call. |
|
68 */ |
|
69 const CPolicyServer::TPolicy KSusUtilServerPolicy = |
|
70 { |
|
71 KCapabilitiesInSsmServer, // map connection attempts as well to index [0] in KPolicyElements[] |
|
72 KRangeCount, |
|
73 KRanges, |
|
74 KElementsIndex, |
|
75 KPolicyElements |
|
76 }; |
|
77 |
|
78 // ------------------- SusUtilServer Implementation ---------------------- |
|
79 |
|
80 /** |
|
81 */ |
|
82 CSusUtilServer::CSusUtilServer(TSecureId aClientSecureId) |
|
83 : CPolicyServer(EPriorityStandard, KSusUtilServerPolicy), iClientSecureId(aClientSecureId) |
|
84 { |
|
85 } //lint !e1746 suppress parameter 'aClientSecureId' could be made const reference |
|
86 |
|
87 /** |
|
88 */ |
|
89 CSusUtilServer::~CSusUtilServer() |
|
90 { |
|
91 const TInt ignore = User::SetCritical(User::ENotCritical); |
|
92 iLoadedPlugins.ResetAndDestroy(); |
|
93 } //lint !e529 suppress Symbol 'ignore' not subsequently referenced |
|
94 |
|
95 /** |
|
96 Factory method used by production code. |
|
97 */ |
|
98 CSusUtilServer* CSusUtilServer::NewLC( ) |
|
99 { |
|
100 TSecureId uidOfSysStateMgr(0x2000D75B); //The SID of the only process that will allowed to use this server. |
|
101 return CSusUtilServer::NewLC(KSusUtilServerName, uidOfSysStateMgr); |
|
102 } |
|
103 |
|
104 /** |
|
105 Factory method to be used by testcode only. |
|
106 |
|
107 @param aServerName A non-production server-name is required if the real server was started |
|
108 during TechView startup. |
|
109 @param aClientSecureId The SID of the only process that will allowed to use this server. |
|
110 @internalComponent |
|
111 @released |
|
112 */ |
|
113 CSusUtilServer* CSusUtilServer::NewLC(const TDesC& aServerName, TSecureId aClientSecureId) |
|
114 { |
|
115 CSusUtilServer* server = new(ELeave) CSusUtilServer(aClientSecureId); |
|
116 CleanupStack::PushL(server); |
|
117 server->ConstructL(aServerName); |
|
118 return server; |
|
119 } //lint !e1746 suppress parameter 'aClientSecureId' could be made const reference |
|
120 |
|
121 /** |
|
122 Second-phase construct and start this server. Will rename current thread to |
|
123 KSusUtilServerName and set it to ESystemCritical. |
|
124 @internalComponent |
|
125 @released |
|
126 */ |
|
127 void CSusUtilServer::ConstructL(const TDesC& aServerName) |
|
128 { |
|
129 __ASSERT_ALWAYS( KErrNone == User::SetCritical(User::ESystemCritical), |
|
130 User::Panic(KPanicSsmSus, EUtilServerError1)); |
|
131 |
|
132 __ASSERT_ALWAYS( KErrNone == User::RenameThread(KSusUtilServerName), |
|
133 User::Panic(KPanicSsmSus, EUtilServerError2)); |
|
134 |
|
135 const TInt err = Start(aServerName); |
|
136 SSMLOGLEAVEIFERROR( err ); |
|
137 } |
|
138 |
|
139 /** |
|
140 Create a new session. Boilerplate code for Symbian Client-Server framework. |
|
141 @internalComponent |
|
142 @released |
|
143 */ |
|
144 CSession2* CSusUtilServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const |
|
145 { |
|
146 // Check we're the right version |
|
147 TVersion v(KSusUtilServMajorVersionNumber, KSusUtilServMinorVersionNumber, |
|
148 KSusUtilServBuildVersionNumber); |
|
149 |
|
150 if ( !User::QueryVersionSupported(v,aVersion) ) |
|
151 { |
|
152 User::Leave (KErrNotSupported ); |
|
153 } |
|
154 |
|
155 // version supported, go ahead |
|
156 return CSusUtilSession::NewL ( ); |
|
157 } |
|
158 |
|
159 /** |
|
160 The SID of the only process that will allowed to use this server. |
|
161 @internalComponent |
|
162 @released |
|
163 */ |
|
164 TSecureId CSusUtilServer::ClientSecureId() const |
|
165 { |
|
166 return iClientSecureId; |
|
167 } |
|
168 |
|
169 /** |
|
170 Attempt to load the DLL file named in aSupInfo. If successful, instantiate, initialize and start |
|
171 the contained uitility plugin using the ordinal function specified in aSupInfo and the MSsmUtility |
|
172 interface. |
|
173 @internalComponent |
|
174 @released |
|
175 */ |
|
176 void CSusUtilServer::LoadUtilityPluginL(TSsmSupInfo& aSupInfo) |
|
177 { |
|
178 RLibrary lib; |
|
179 SusPluginLoader::LoadDllFileLC(lib, aSupInfo); // open handle on CleanupStack |
|
180 |
|
181 if (KErrNotFound != IndexOf(lib, aSupInfo.NewLOrdinal())) |
|
182 { |
|
183 //will leave in release builds as well |
|
184 SSMLOGLEAVE(KErrAlreadyExists); //lint !e527 Unreachable |
|
185 } |
|
186 |
|
187 const TInt newL = aSupInfo.NewLOrdinal(); |
|
188 CSusPluginFrame* plugin = SusPluginLoader::CreatePluginLC(lib, newL); |
|
189 iLoadedPlugins.AppendL(plugin); |
|
190 CleanupStack::Pop(plugin); |
|
191 plugin->SetLibrary(lib); // takes ownership of open library handle |
|
192 |
|
193 CleanupStack::Pop(&lib); |
|
194 } |
|
195 |
|
196 /** |
|
197 Check if a Utility Plugin is already loaded. |
|
198 |
|
199 @param A RLibrary based on the DLL file which we want to investigate if its already |
|
200 included in iLoadedPlugins. |
|
201 @return The index of any CSusPluginFrame in iLoadedPlugins which is based on the same DLL file |
|
202 as given in parameter aLibrary. |
|
203 @internalComponent |
|
204 @released |
|
205 */ |
|
206 TInt CSusUtilServer::IndexOf(const RLibrary& aLibrary, TInt aNewLOrdinal) const |
|
207 { |
|
208 const TFileName nameToLookFor = aLibrary.FileName(); |
|
209 const TInt count = iLoadedPlugins.Count(); |
|
210 for(TInt i=0; i<count; i++) |
|
211 { |
|
212 if(0 == nameToLookFor.CompareF(iLoadedPlugins[i]->FileName()) && aNewLOrdinal == iLoadedPlugins[i]->NewLOrdinal()) |
|
213 { |
|
214 return i; |
|
215 } |
|
216 } |
|
217 return KErrNotFound; |
|
218 } |
|
219 |
|
220 /** |
|
221 @return 0 or a positive integer if a plugin was released and deleted, otherwise KErrNotFound |
|
222 @internalComponent |
|
223 @released |
|
224 */ |
|
225 TInt CSusUtilServer::UnLoadUtilityPluginL(TSsmSupInfo& aSupInfo) |
|
226 { |
|
227 RLibrary lib; |
|
228 SusPluginLoader::LoadDllFileLC(lib, aSupInfo); // open handle on CleanupStack |
|
229 const TInt index = IndexOf(lib, aSupInfo.NewLOrdinal()); |
|
230 if( index > KErrNotFound ) |
|
231 { |
|
232 CSusPluginFrame* frame = iLoadedPlugins[index]; |
|
233 iLoadedPlugins.Remove(index); |
|
234 delete frame; |
|
235 } |
|
236 CleanupStack::PopAndDestroy(&lib); |
|
237 return index; |
|
238 } |
|
239 |
|
240 #ifdef _DEBUG |
|
241 // Used for testing memory leaks on server. |
|
242 void CSusUtilServer::CompressPluginArray() |
|
243 { |
|
244 iLoadedPlugins.Compress(); |
|
245 } |
|
246 #endif |