Update contrib.
1 // Copyright (c) 2005-2010 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "logservsecurity.h"
17 #include <e32capability.h>
18 #include "LogServResourceInterpreter.h"
19 #include "LogCliServShared.h"
20 #include "logservpanic.h"
23 The max number of TCapability(s) that can be used to instantiate a TSecurityPolicy
26 const TInt KMaxCapsPerOp = 7;
28 ///////////////////////////////////////////////////////////////////////////////
29 // TCaps class - declaration and implementation
32 The class represents a static array of TCapability items (it can't grow or shrink).
33 The class should be used every time when there is a need of a static TCapability array.
34 It offers an overloaded "[]" operator with run-time bounds checks.
41 inline TInt MaxSize() const
45 inline TCapability& operator [](TInt aIndex)
47 __ASSERT_DEBUG(aIndex >= 0 && aIndex < MaxSize(), User::Invariant());
48 return iItems[aIndex];
51 inline const TCapability& operator [](TInt aIndex) const
53 __ASSERT_DEBUG(aIndex >= 0 && aIndex < MaxSize(), User::Invariant());
54 return iItems[aIndex];
58 TCapability iItems[KMaxCapsPerOp];
63 The controlled capabilities are initialized with ECapability_None value.
67 for(TInt i=0;i<MaxSize();++i)
69 iItems[i] = ECapability_None;
73 ///////////////////////////////////////////////////////////////////////////////
74 // TEventPolicy structure - declaration and implementation
77 Each LogEngServer event defined in Logwrap.rss has two associated
78 TSecurityPolicy(s) - one each for read/write operations. This structure
79 contains one read and one write policy per defined LogEngServer event.
84 TEventPolicy(TUid aEventType, const TCaps& aReadCaps, const TCaps& aWriteCaps);
86 TUid iEventType;// event type defined in LOGWRAP.RSS
87 TSecurityPolicy iReadPolicy;
88 TSecurityPolicy iWritePolicy;
92 @param aEventType Event type. It could be one of the following: KLogCallEventType,
93 KLogDataEventType, KLogFaxEventType, KLogShortMessageEventType,
94 KLogMailEventType, KLogTaskSchedulerEventType, KLogPacketDataEventType.
95 See LOGWRAP.RSS file where these constants are defined.
96 @param aReadCaps Read capablities for aEventType argument. The client, who wants to use
97 that event type ("read" operations), must satisfy aRead set of capabilities.
98 @param aWriteCaps Write capablities for aEventType argument. The client, who wants to use
99 that event type ("write" operations), must satisfy aWrite set of capabilities.
101 TEventPolicy::TEventPolicy(TUid aEventType, const TCaps& aReadCaps, const TCaps& aWriteCaps) :
102 iEventType(aEventType),
103 iReadPolicy(aReadCaps[0],aReadCaps[1],aReadCaps[2],aReadCaps[3],aReadCaps[4],aReadCaps[5],aReadCaps[6]),
104 iWritePolicy(aWriteCaps[0],aWriteCaps[1],aWriteCaps[2],aWriteCaps[3],aWriteCaps[4],aWriteCaps[5],aWriteCaps[6])
108 ///////////////////////////////////////////////////////////////////////////////
109 // TSecurityInfoReader class declaration
111 //Forward declaration
112 class CLogServSecurityImpl;
115 The class manages the reading of the Security policy data from Logwrap.rss and storing
116 it in the supplied as an argument CLogServSecurityImpl object.
119 class TSecurityInfoReader
122 TSecurityInfoReader(CLogServResourceInterpreter& aResourceInterface,
123 CLogServSecurityImpl& aLogServSecurity);
127 TInt GetEventTypeCountL();
128 void GetCapabilities(TResourceReader& aReader, TCaps& aCaps);
131 CLogServResourceInterpreter& iResourceInterface;
132 CLogServSecurityImpl& iLogServSecurity;
136 ///////////////////////////////////////////////////////////////////////////////
137 // CLogServSecurityImpl class declaration and implementation.
140 The class implements pure virtual methods in CLogServSecurity class.
141 All functionality, related to processing the data in LogEngServer resource file,
142 is delegated to an instance of TSecurityInfoReader class.
145 class CLogServSecurityImpl : public CLogServSecurity
147 friend class TSecurityInfoReader;
150 static CLogServSecurityImpl* NewL(CLogServResourceInterpreter& aResourceInterface);
151 virtual ~CLogServSecurityImpl();
152 virtual TBool IsAllowed(const RMessage2& aMsg, TUid aEventType, TEventOp aEventOp, const char* aDiagnostic);
153 #ifdef LOGSERV_CAPABILITY_TEST
154 virtual TSecurityPolicy SecurityPolicy(TUid aEventType, TEventOp aEventOp);
155 #endif //LOGSERV_CAPABILITY_TEST
158 CLogServSecurityImpl();
159 void ConstructL(CLogServResourceInterpreter& aResourceInterface);
160 const TSecurityPolicy& FindPolicy(TUid aEventType, TEventOp aEventOp) const;
163 RArray<TEventPolicy> iPolicyCon;
164 TSecurityPolicy iPassAllPolicy;
169 Standard, phase-one factory method for creation of objects of CLogServSecurityImpl type.
170 @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading
171 the LogEngServer resource file (logwrap.rss). It is used only durring
172 the construction phase of CLogServSecurityImpl instance.
173 @return A pointer to the created CLogServSecurityImpl instance.
174 @leave System-wide error codes, including KErrNoMemory and reading file errors.
176 CLogServSecurityImpl* CLogServSecurityImpl::NewL(CLogServResourceInterpreter& aResourceInterface)
178 CLogServSecurityImpl* self = new (ELeave) CLogServSecurityImpl;
179 CleanupStack::PushL(self);
180 self->ConstructL(aResourceInterface);
181 CleanupStack::Pop(self);
187 CLogServSecurityImpl::~CLogServSecurityImpl()
193 The method compares the caller's capabilities against the set of capabilities,
194 required for that kind of operation (read or write) and returns ETrue or EFalse.
195 @param aMsg The message, containing the caller capabilities which have to be checked.
196 @param aEventType Event type. For more details see LOGWRAP.RSS file where the
197 UID constants are defined.
198 @param aEventOp The type of the operation which is about to be performed by the
199 caller. It could be EReadOp or EWriteOp.
200 @return ETrue - the caller is allowed to execute the operation, EFalse - the caller's
201 capabilities do not match the required set of capabilities for that
202 kind of operation (read or write).
203 Note: Only built-in types (included in logwrap.rss) are policed.
204 So, return ETrue if TUid argument isn't a built-in type.
206 TBool CLogServSecurityImpl::IsAllowed(const RMessage2& aMsg, TUid aEventType, TEventOp aEventOp, const char* aDiagnostic)
208 const TSecurityPolicy& policy = FindPolicy(aEventType, aEventOp);
209 return policy.CheckPolicy(aMsg, aDiagnostic);
212 #ifdef LOGSERV_CAPABILITY_TEST
214 This method is declared and implemented only if "LOGSERV_CAPABILITY_TEST" macro is defined
215 @param aEventType Event type. For more details see LOGWRAP.RSS file where the
216 UID constants are defined.
217 @param aEventOp The type of the event operation: EReadOp or EWriteOp.
218 @return The related with {aEventType, aEventOp} pair TSecurityPOlicy object.
220 TSecurityPolicy CLogServSecurityImpl::SecurityPolicy(TUid aEventType, TEventOp aEventOp)
222 const TSecurityPolicy& policy = FindPolicy(aEventType, aEventOp);
225 #endif //LOGSERV_CAPABILITY_TEST
229 CLogServSecurityImpl::CLogServSecurityImpl() :
230 iPassAllPolicy(TSecurityPolicy::EAlwaysPass)
235 Standard, phase-two construction method for creation of CLogServSecurityImpl objects.
236 @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading
237 the LogEngServer resource file (logwrap.rss). It is used only durring
238 the construction phase of CLogServSecurityImpl instance.
239 @leave System-wide error codes, including KErrNoMemory and reading file errors.
241 void CLogServSecurityImpl::ConstructL(CLogServResourceInterpreter& aResourceInterface)
243 TSecurityInfoReader reader(aResourceInterface, *this);
248 The method performs a search for the related to {aEventType, aOperationType} pair
249 TSecurityPolicy object. If there is no registered TSecurityPolicy object for the
250 supplied pair of arguments (which is possible, if aEventType argument is not a
251 built-in type, specified in LOGWRAP.RSS file), then the method returns a reference
252 to pass-all TSecurityPolicy object.
253 @param aEventType Event type. For more details see LOGWRAP.RSS file where the
254 UID constants are defined.
255 @param aAccessType The type of the operation which is about to be performed by the
256 caller. It could be ERead or EWrite.
257 @return A const reference to TSecurityPolicy object, which defines a set of capabilities,
258 required for that kind of operation (read or write).
260 const TSecurityPolicy& CLogServSecurityImpl::FindPolicy(TUid aEventType, TEventOp aEventOp) const
262 for(TInt i=iPolicyCon.Count()-1;i>=0;--i)
264 const TEventPolicy& eventPolicy = iPolicyCon[i];
265 if(eventPolicy.iEventType == aEventType)
267 return aEventOp == EWriteOp ? eventPolicy.iWritePolicy : eventPolicy.iReadPolicy;
270 // aEventType wasn't found - it doesn't represent a policed event type.
271 return iPassAllPolicy;
274 ///////////////////////////////////////////////////////////////////////////////
275 // CLogServSecurity implementation
278 Standard, phase-one factory method for creation of objects of CLogServSecurity type.
279 @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading
280 the LogEngServer resource file (logwrap.rss).
281 @return A pointer to the created CLogServSecurity instance.
282 @leave System-wide error codes, including KErrNoMemory and reading file errors.
284 CLogServSecurity* CLogServSecurity::NewL(CLogServResourceInterpreter& aResourceInterface)
286 return CLogServSecurityImpl::NewL(aResourceInterface);
291 CLogServSecurity::~CLogServSecurity()
295 ///////////////////////////////////////////////////////////////////////////////
296 // TSecurityInfoReader class implementation
299 @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading
300 the LogEngServer resource file (logwrap.rss).
301 @param aLogServSecurity A reference to CLogServSecurityImpl instance, which internal content
302 will be initialized with the related information from the
303 LogEngServer resource file.
305 TSecurityInfoReader::TSecurityInfoReader(CLogServResourceInterpreter& aResourceInterface,
306 CLogServSecurityImpl& aLogServSecurity) :
307 iResourceInterface(aResourceInterface),
308 iLogServSecurity(aLogServSecurity)
313 The method reads the LogEngServer events capabilities from the resource file and
314 initializes with them iLogServSecurity data member;
315 @leave System-wide error codes, including KErrNoMemory and reading file errors.
316 @panic ELogSecurityCapabilitiesUndefined (107) if the total number of event types
317 don't match the total number of the event capability sets.
319 void TSecurityInfoReader::ReadL()
321 TInt eventTypeCount = GetEventTypeCountL();
323 TResourceReader reader;
324 iResourceInterface.CreateResourceReaderLC(reader, R_LOG_SECURITY);
326 TInt securityNodeCount = reader.ReadInt16();
328 // For all built-in event types there _MUST_ be a corresponding set of
329 // capabilities defined in logwrap.rss.
330 __ASSERT_ALWAYS(eventTypeCount == securityNodeCount, Panic(ELogSecurityCapabilitiesUndefined));
332 iLogServSecurity.iPolicyCon.ReserveL(eventTypeCount);
333 for(TInt i=0;i<eventTypeCount;++i)
335 TUid eventType = {reader.ReadUint32()};
338 GetCapabilities(reader, readCaps);
341 GetCapabilities(reader, writeCaps);
343 TInt err = iLogServSecurity.iPolicyCon.Append(TEventPolicy(eventType, readCaps, writeCaps));
344 __ASSERT_ALWAYS(err == KErrNone, Panic(ELogArrayReserved));
347 CleanupStack::PopAndDestroy(); // the resource reader
351 The method returns the number of built-in event types defined for the LogEngServer
352 in logwrap.rss - see section entitled 'r_log_initial_events'.
353 @return An integer number representing the number of the event types found in the
355 @leave System-wide error codes, including KErrNoMemory and reading file errors.
357 TInt TSecurityInfoReader::GetEventTypeCountL()
359 TResourceReader reader;
360 iResourceInterface.CreateResourceReaderLC(reader, R_LOG_INITIAL_EVENTS);
361 TInt count = reader.ReadInt16();
362 CleanupStack::PopAndDestroy();
367 The method reads the capabilities for the currently processed event.
368 @param aReader TResourceReader object used for reading the related resource file entries.
369 @param aCaps An output parameter, reference to the array where the capabilities will be
371 @panic ELogTooManyCapabilities (108) if the number of the capabilities in the resource
372 file exceeds the max allowed number, which is currently set to KMaxCapsPerOp (7).
373 @panic ELogUnknownCapability (109) if the found capability is of unknown type.
375 void TSecurityInfoReader::GetCapabilities(TResourceReader& aReader, TCaps& aCaps)
377 TInt capsCount = aReader.ReadInt16();
378 __ASSERT_ALWAYS((TUint)capsCount <= aCaps.MaxSize(), Panic(ELogTooManyCapabilities));
380 for(TInt i=0;i<capsCount;++i)
382 TInt n = aReader.ReadInt32();
383 __ASSERT_ALWAYS(n >= ECapability_None && n < ECapability_Limit, Panic(ELogUnknownCapability));// its not in e32capability.h !
384 aCaps[i] = TCapability(n);