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