|
1 // Copyright (c) 1997-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 |
|
17 /** @file |
|
18 * |
|
19 * Implements CC32Server, CCommScheduler and some thread functions |
|
20 */ |
|
21 |
|
22 #include "CS_STD.H" |
|
23 #include "cs_common.h" |
|
24 #include <f32file.h> |
|
25 |
|
26 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
27 #include <c32comm_internal.h> |
|
28 #endif |
|
29 |
|
30 #include "C32LOG.H" |
|
31 #include "cs_thread.h" |
|
32 #include "cs_roles.h" |
|
33 #include "cs_glob.h" |
|
34 |
|
35 // |
|
36 // implementation of CC32Server |
|
37 // |
|
38 |
|
39 class CC32WorkerThread; |
|
40 class CC32ThreadManager; |
|
41 |
|
42 CC32Server::CC32Server(CC32WorkerThread* aOwnerThread, TInt aPriority) |
|
43 /** |
|
44 * Constructor. |
|
45 * |
|
46 * @param aPriority |
|
47 */ |
|
48 : CPolicyServer(aPriority, iPolicy), |
|
49 iOwnerThread(aOwnerThread) |
|
50 { |
|
51 C32LOG1(KC32Dealer, _L8("CC32Server::CC32Server()")); |
|
52 } |
|
53 |
|
54 void CC32Server::ConstructL(CC32ThreadManager* aThreadManager) |
|
55 /** |
|
56 * start the server |
|
57 */ |
|
58 { |
|
59 iThreadManager = aThreadManager; |
|
60 C32LOG1(KC32Dealer, _L8("Starting Server")); |
|
61 StartL(KCommServerName()); |
|
62 |
|
63 #ifdef _DEBUG |
|
64 TInt processHandles; |
|
65 RThread thread; |
|
66 thread.HandleCount(processHandles, iThreadHandles); |
|
67 #endif |
|
68 } |
|
69 |
|
70 CC32Server::~CC32Server() |
|
71 // |
|
72 // Destructor. |
|
73 // |
|
74 { |
|
75 #ifdef _DEBUG |
|
76 RThread thread; |
|
77 TInt processHandles; |
|
78 TInt threadHandles; |
|
79 thread.HandleCount(processHandles, threadHandles); |
|
80 |
|
81 if (threadHandles != iThreadHandles) |
|
82 { |
|
83 C32LOG2(KC32Detail,_L8("CC32Server::~CC32Server() %d handles were leaked"), threadHandles - iThreadHandles); |
|
84 __ASSERT_DEBUG(EFalse, Fault(EDbgHandleLeak, _L("CC32Server::~CC32Server() Leaked a handle"))); |
|
85 } |
|
86 #endif |
|
87 } |
|
88 |
|
89 CSession2* CC32Server::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/) const |
|
90 /** |
|
91 * Create a new client for this server. |
|
92 * |
|
93 * @param aVersion Client version number |
|
94 */ |
|
95 { |
|
96 C32LOG1(KC32Dealer, _L8("CC32Server::NewSessionL()")); |
|
97 TVersion v(KEC32MajorVersionNumber, KEC32MinorVersionNumber, KEC32BuildVersionNumber); |
|
98 if (!User::QueryVersionSupported(v, aVersion)) |
|
99 User::Leave(KErrNotSupported); |
|
100 |
|
101 CCommSession* session = CCommSession::NewL(iThreadManager); |
|
102 return session; |
|
103 } |
|
104 |
|
105 CPolicyServer::TCustomResult CC32Server::CustomSecurityCheckL(const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/) |
|
106 /** |
|
107 Perform custom security policy check on an IPC. Request from the CSY the capabilities required to process this call. |
|
108 |
|
109 It is possible that in attempting to read the port name from the client that this might fail which will panic the client. This completes the message |
|
110 so to avoid a double-completion (which will panic us) we return EASync wich means the policy server will not do anything further with the message. |
|
111 |
|
112 @param aMsg RMessage2 containing client capabilites and request IPC. |
|
113 @param aAction A reference to the action to take if the security check fails. |
|
114 @param aMissing reference to the list of security attributes missing from the checked process. |
|
115 @return EPass, EFail or EAsync |
|
116 */ |
|
117 { |
|
118 C32LOG1(KC32Dealer, _L8("CC32Server::CustomSecurityCheckL()")); |
|
119 TSecurityPolicy csySecurityPolicy(TSecurityPolicy::EAlwaysFail); |
|
120 |
|
121 CCommSession* session=static_cast<CCommSession*>(aMsg.Session()); |
|
122 CPolicyServer::TCustomResult retCode = EFail; |
|
123 if(session) |
|
124 { |
|
125 TFullName name; |
|
126 TUint port; |
|
127 TInt len; |
|
128 // Extract port name and number |
|
129 if(session->ExtractPortNameAndNumber(aMsg, name, port, len) == KErrNone) |
|
130 { |
|
131 CSerial *serial=NULL; |
|
132 TRAPD(res, serial=iThreadManager->GetSerialL(name.Left(len))); |
|
133 if (res==KErrNone) |
|
134 { |
|
135 //get policy from CSY |
|
136 csySecurityPolicy = serial->PortPlatSecCapability(port); |
|
137 } |
|
138 } |
|
139 } |
|
140 //check policy. First check message handle is valid otherwise we panic ourselves. |
|
141 if(aMsg.Handle() != 0 && csySecurityPolicy.CheckPolicy(aMsg, __PLATSEC_DIAGNOSTIC_STRING("Checked in CC32Server::CustomSecurityCheckL"))) |
|
142 { |
|
143 //The message has not been nulled and the policy has passed. |
|
144 retCode = EPass; |
|
145 } |
|
146 else if(aMsg.Handle() ==0) |
|
147 { |
|
148 //The message has been nulled so stop policy server attempting further completion by returning EASync |
|
149 retCode = EAsync; |
|
150 } |
|
151 return retCode; |
|
152 } |
|
153 |
|
154 |
|
155 // |
|
156 // implementation of CCommScheduler |
|
157 // |
|
158 |
|
159 CCommScheduler* CCommScheduler::New() |
|
160 /** |
|
161 * Create and install the active scheduler. |
|
162 * Return the CCommScheduler* |
|
163 */ |
|
164 { |
|
165 CCommScheduler* pA = new CCommScheduler; |
|
166 __ASSERT_ALWAYS(pA!=NULL, Fault(EMainSchedulerError)); |
|
167 CCommScheduler::Install(pA); |
|
168 return pA; |
|
169 } |
|
170 |
|
171 |
|
172 void CCommScheduler::Error(TInt aError) const |
|
173 /** |
|
174 * Called if any RunL() method leaves. |
|
175 */ |
|
176 { |
|
177 C32LOG2(KC32Dealer, _L8("CCommScheduler::Error() - a RunL or ServiceL has Left! panicking. Leavecode was: %d"),aError); |
|
178 (void)aError; |
|
179 Fault(EMainSchedulerError); |
|
180 } |
|
181 |
|
182 |
|
183 // Definition of iPolicy dictating the capability checking for C32 server |
|
184 const TUint CC32Server::iRangeCount = 7; |
|
185 |
|
186 const TInt CC32Server::iRanges[iRangeCount] = |
|
187 { |
|
188 0, //range is 0-5 inclusive |
|
189 6, //range is 6 |
|
190 7, //range is 7 |
|
191 8, //range is 8-49 inclusive |
|
192 50, //range is 50 |
|
193 51, //range is 51 |
|
194 52, //range is 52-KMaxTInt inclusive |
|
195 }; |
|
196 |
|
197 const TUint8 CC32Server::iElementsIndex[iRangeCount] = |
|
198 { |
|
199 0, |
|
200 1, |
|
201 CPolicyServer::ECustomCheck, |
|
202 2, |
|
203 CPolicyServer::ECustomCheck, |
|
204 3, |
|
205 CPolicyServer::ENotSupported, |
|
206 }; |
|
207 |
|
208 |
|
209 const CPolicyServer::TPolicyElement CC32Server::iElements[] = |
|
210 { |
|
211 { _INIT_SECURITY_POLICY_C1( ECapability_None), CPolicyServer::EFailClient}, // policy 0: range 0 - 5 |
|
212 { _INIT_SECURITY_POLICY_C1( ECapabilityCommDD), CPolicyServer::EFailClient}, // policy 1: range 6 - 6 |
|
213 { _INIT_SECURITY_POLICY_C1( ECapability_None), CPolicyServer::EFailClient}, // policy 2: range 8 - 8 |
|
214 { _INIT_SECURITY_POLICY_C1( ECapability_None), CPolicyServer::EFailClient}, // policy 2: range 51 |
|
215 }; |
|
216 |
|
217 |
|
218 const CPolicyServer::TPolicy CC32Server::iPolicy = |
|
219 { |
|
220 CPolicyServer::EAlwaysPass , |
|
221 iRangeCount, |
|
222 iRanges, |
|
223 iElementsIndex, |
|
224 iElements |
|
225 }; |
|
226 |
|
227 // EOF - CS_SVR.CPP |