sl@0: // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "logservsecurity.h" sl@0: #include sl@0: #include "LogServResourceInterpreter.h" sl@0: #include "LogCliServShared.h" sl@0: #include "logservpanic.h" sl@0: sl@0: /** sl@0: The max number of TCapability(s) that can be used to instantiate a TSecurityPolicy sl@0: @internalComponent sl@0: */ sl@0: const TInt KMaxCapsPerOp = 7; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // TCaps class - declaration and implementation sl@0: sl@0: /** sl@0: The class represents a static array of TCapability items (it can't grow or shrink). sl@0: The class should be used every time when there is a need of a static TCapability array. sl@0: It offers an overloaded "[]" operator with run-time bounds checks. sl@0: @internalComponent sl@0: */ sl@0: class TCaps sl@0: { sl@0: public: sl@0: TCaps(); sl@0: inline TInt MaxSize() const sl@0: { sl@0: return KMaxCapsPerOp; sl@0: } sl@0: inline TCapability& operator [](TInt aIndex) sl@0: { sl@0: __ASSERT_DEBUG(aIndex >= 0 && aIndex < MaxSize(), User::Invariant()); sl@0: return iItems[aIndex]; sl@0: } sl@0: sl@0: inline const TCapability& operator [](TInt aIndex) const sl@0: { sl@0: __ASSERT_DEBUG(aIndex >= 0 && aIndex < MaxSize(), User::Invariant()); sl@0: return iItems[aIndex]; sl@0: } sl@0: sl@0: private: sl@0: TCapability iItems[KMaxCapsPerOp]; sl@0: sl@0: }; sl@0: sl@0: /** sl@0: The controlled capabilities are initialized with ECapability_None value. sl@0: */ sl@0: TCaps::TCaps() sl@0: { sl@0: for(TInt i=0;i iPolicyCon; sl@0: TSecurityPolicy iPassAllPolicy; sl@0: sl@0: }; sl@0: sl@0: /** sl@0: Standard, phase-one factory method for creation of objects of CLogServSecurityImpl type. sl@0: @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading sl@0: the LogEngServer resource file (logwrap.rss). It is used only durring sl@0: the construction phase of CLogServSecurityImpl instance. sl@0: @return A pointer to the created CLogServSecurityImpl instance. sl@0: @leave System-wide error codes, including KErrNoMemory and reading file errors. sl@0: */ sl@0: CLogServSecurityImpl* CLogServSecurityImpl::NewL(CLogServResourceInterpreter& aResourceInterface) sl@0: { sl@0: CLogServSecurityImpl* self = new (ELeave) CLogServSecurityImpl; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aResourceInterface); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: CLogServSecurityImpl::~CLogServSecurityImpl() sl@0: { sl@0: iPolicyCon.Close(); sl@0: } sl@0: sl@0: /** sl@0: The method compares the caller's capabilities against the set of capabilities, sl@0: required for that kind of operation (read or write) and returns ETrue or EFalse. sl@0: @param aMsg The message, containing the caller capabilities which have to be checked. sl@0: @param aEventType Event type. For more details see LOGWRAP.RSS file where the sl@0: UID constants are defined. sl@0: @param aEventOp The type of the operation which is about to be performed by the sl@0: caller. It could be EReadOp or EWriteOp. sl@0: @return ETrue - the caller is allowed to execute the operation, EFalse - the caller's sl@0: capabilities do not match the required set of capabilities for that sl@0: kind of operation (read or write). sl@0: Note: Only built-in types (included in logwrap.rss) are policed. sl@0: So, return ETrue if TUid argument isn't a built-in type. sl@0: */ sl@0: TBool CLogServSecurityImpl::IsAllowed(const RMessage2& aMsg, TUid aEventType, TEventOp aEventOp, const char* aDiagnostic) sl@0: { sl@0: const TSecurityPolicy& policy = FindPolicy(aEventType, aEventOp); sl@0: return policy.CheckPolicy(aMsg, aDiagnostic); sl@0: } sl@0: sl@0: #ifdef LOGSERV_CAPABILITY_TEST sl@0: /** sl@0: This method is declared and implemented only if "LOGSERV_CAPABILITY_TEST" macro is defined sl@0: @param aEventType Event type. For more details see LOGWRAP.RSS file where the sl@0: UID constants are defined. sl@0: @param aEventOp The type of the event operation: EReadOp or EWriteOp. sl@0: @return The related with {aEventType, aEventOp} pair TSecurityPOlicy object. sl@0: */ sl@0: TSecurityPolicy CLogServSecurityImpl::SecurityPolicy(TUid aEventType, TEventOp aEventOp) sl@0: { sl@0: const TSecurityPolicy& policy = FindPolicy(aEventType, aEventOp); sl@0: return policy; sl@0: } sl@0: #endif //LOGSERV_CAPABILITY_TEST sl@0: sl@0: /** sl@0: */ sl@0: CLogServSecurityImpl::CLogServSecurityImpl() : sl@0: iPassAllPolicy(TSecurityPolicy::EAlwaysPass) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Standard, phase-two construction method for creation of CLogServSecurityImpl objects. sl@0: @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading sl@0: the LogEngServer resource file (logwrap.rss). It is used only durring sl@0: the construction phase of CLogServSecurityImpl instance. sl@0: @leave System-wide error codes, including KErrNoMemory and reading file errors. sl@0: */ sl@0: void CLogServSecurityImpl::ConstructL(CLogServResourceInterpreter& aResourceInterface) sl@0: { sl@0: TSecurityInfoReader reader(aResourceInterface, *this); sl@0: reader.ReadL(); sl@0: } sl@0: sl@0: /** sl@0: The method performs a search for the related to {aEventType, aOperationType} pair sl@0: TSecurityPolicy object. If there is no registered TSecurityPolicy object for the sl@0: supplied pair of arguments (which is possible, if aEventType argument is not a sl@0: built-in type, specified in LOGWRAP.RSS file), then the method returns a reference sl@0: to pass-all TSecurityPolicy object. sl@0: @param aEventType Event type. For more details see LOGWRAP.RSS file where the sl@0: UID constants are defined. sl@0: @param aAccessType The type of the operation which is about to be performed by the sl@0: caller. It could be ERead or EWrite. sl@0: @return A const reference to TSecurityPolicy object, which defines a set of capabilities, sl@0: required for that kind of operation (read or write). sl@0: */ sl@0: const TSecurityPolicy& CLogServSecurityImpl::FindPolicy(TUid aEventType, TEventOp aEventOp) const sl@0: { sl@0: for(TInt i=iPolicyCon.Count()-1;i>=0;--i) sl@0: { sl@0: const TEventPolicy& eventPolicy = iPolicyCon[i]; sl@0: if(eventPolicy.iEventType == aEventType) sl@0: { sl@0: return aEventOp == EWriteOp ? eventPolicy.iWritePolicy : eventPolicy.iReadPolicy; sl@0: } sl@0: } sl@0: // aEventType wasn't found - it doesn't represent a policed event type. sl@0: return iPassAllPolicy; sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // CLogServSecurity implementation sl@0: sl@0: /** sl@0: Standard, phase-one factory method for creation of objects of CLogServSecurity type. sl@0: @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading sl@0: the LogEngServer resource file (logwrap.rss). sl@0: @return A pointer to the created CLogServSecurity instance. sl@0: @leave System-wide error codes, including KErrNoMemory and reading file errors. sl@0: */ sl@0: CLogServSecurity* CLogServSecurity::NewL(CLogServResourceInterpreter& aResourceInterface) sl@0: { sl@0: return CLogServSecurityImpl::NewL(aResourceInterface); sl@0: } sl@0: sl@0: /** sl@0: */ sl@0: CLogServSecurity::~CLogServSecurity() sl@0: { sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // TSecurityInfoReader class implementation sl@0: sl@0: /** sl@0: @param aResourceInterface A reference to CLogServResourceInterpreter object used for reading sl@0: the LogEngServer resource file (logwrap.rss). sl@0: @param aLogServSecurity A reference to CLogServSecurityImpl instance, which internal content sl@0: will be initialized with the related information from the sl@0: LogEngServer resource file. sl@0: */ sl@0: TSecurityInfoReader::TSecurityInfoReader(CLogServResourceInterpreter& aResourceInterface, sl@0: CLogServSecurityImpl& aLogServSecurity) : sl@0: iResourceInterface(aResourceInterface), sl@0: iLogServSecurity(aLogServSecurity) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: The method reads the LogEngServer events capabilities from the resource file and sl@0: initializes with them iLogServSecurity data member; sl@0: @leave System-wide error codes, including KErrNoMemory and reading file errors. sl@0: @panic ELogSecurityCapabilitiesUndefined (107) if the total number of event types sl@0: don't match the total number of the event capability sets. sl@0: */ sl@0: void TSecurityInfoReader::ReadL() sl@0: { sl@0: TInt eventTypeCount = GetEventTypeCountL(); sl@0: sl@0: TResourceReader reader; sl@0: iResourceInterface.CreateResourceReaderLC(reader, R_LOG_SECURITY); sl@0: sl@0: TInt securityNodeCount = reader.ReadInt16(); sl@0: sl@0: // For all built-in event types there _MUST_ be a corresponding set of sl@0: // capabilities defined in logwrap.rss. sl@0: __ASSERT_ALWAYS(eventTypeCount == securityNodeCount, Panic(ELogSecurityCapabilitiesUndefined)); sl@0: sl@0: iLogServSecurity.iPolicyCon.ReserveL(eventTypeCount); sl@0: for(TInt i=0;i= ECapability_None && n < ECapability_Limit, Panic(ELogUnknownCapability));// its not in e32capability.h ! sl@0: aCaps[i] = TCapability(n); sl@0: } sl@0: }