persistentstorage/sql/SRC/Security/SqlSecurity.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
     1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include "SqlSecurityImpl.h"
    16 #include "SqlSecurityImpl.h"
    17 #include "SqlAssert.h"
    17 #include "SqlPanic.h"
    18 #include "OstTraceDefinitions.h"
    18 #include "UTraceSql.h"
    19 #ifdef OST_TRACE_COMPILER_IN_USE
       
    20 #include "SqlSecurityTraces.h"
       
    21 #endif
       
    22 #include "SqlTraceDef.h"
       
    23 
    19 
    24 const TInt32 KEndOfSPStream = -1;//If found in the stream, given as an argument to RSqlSecurityPolicy::InternalizeL(),
    20 const TInt32 KEndOfSPStream = -1;//If found in the stream, given as an argument to RSqlSecurityPolicy::InternalizeL(),
    25 							     //then there are no more policies in the stream.
    21 							     //then there are no more policies in the stream.
    26 
    22 
    27 /**
    23 /**
    48 
    44 
    49 @capability None
    45 @capability None
    50 */
    46 */
    51 EXPORT_C TInt RSqlSecurityPolicy::Create(const TSecurityPolicy& aDefaultPolicy)
    47 EXPORT_C TInt RSqlSecurityPolicy::Create(const TSecurityPolicy& aDefaultPolicy)
    52 	{
    48 	{
    53 	SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLSECURITYPOLICY_CREATE_ENTRY , "Entry;0x%X;RSqlSecurityPolicy::Create;aDefaultPolicy=0x%X", (TUint)this, (TUint)&aDefaultPolicy));
    49 	SQLUTRACE_PROFILER(this);
    54 	TRAPD(err, CreateL(aDefaultPolicy));
    50 	TRAPD(err, CreateL(aDefaultPolicy));
    55     SQL_TRACE_BORDER(OstTraceExt3(TRACE_BORDER, RSQLSECURITYPOLICY_CREATE_EXIT, "Exit;0x%X;RSqlSecurityPolicy::Create;iImpl=0x%X;err=%d", (TUint)this, (TUint)iImpl, err));
       
    56 	return err;
    51 	return err;
    57 	}
    52 	}
    58 
    53 
    59 /**
    54 /**
    60 Initializes RSqlSecurityPolicy instance.
    55 Initializes RSqlSecurityPolicy instance.
    69 
    64 
    70 @capability None
    65 @capability None
    71 */
    66 */
    72 EXPORT_C void RSqlSecurityPolicy::CreateL(const TSecurityPolicy& aDefaultPolicy)
    67 EXPORT_C void RSqlSecurityPolicy::CreateL(const TSecurityPolicy& aDefaultPolicy)
    73 	{
    68 	{
    74     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLSECURITYPOLICY_CREATEL_ENTRY , "Entry;0x%X;RSqlSecurityPolicy::CreateL;aDefaultPolicy=0x%X", (TUint)this, (TUint)&aDefaultPolicy));
    69 	SQLUTRACE_PROFILER(this);
    75 	iImpl = CSqlSecurityPolicy::NewL(aDefaultPolicy);
    70 	iImpl = CSqlSecurityPolicy::NewL(aDefaultPolicy);
    76     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLSECURITYPOLICY_CREATEL_EXIT, "Exit;0x%X;RSqlSecurityPolicy::CreateL;iImpl=0x%X", (TUint)this, (TUint)iImpl));
       
    77 	}
    71 	}
    78 
    72 
    79 /**
    73 /**
    80 Frees the allocated by RSqlSecurityPolicy instance memory and other resources.
    74 Frees the allocated by RSqlSecurityPolicy instance memory and other resources.
    81 
    75 
    82 @capability None
    76 @capability None
    83 */
    77 */
    84 EXPORT_C void RSqlSecurityPolicy::Close()
    78 EXPORT_C void RSqlSecurityPolicy::Close()
    85 	{
    79 	{
    86     SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLSECURITYPOLICY_CLOSE_ENTRY , "Entry;0x%X;RSqlSecurityPolicy::Close", (TUint)this));
    80 	SQLUTRACE_PROFILER(this);
    87 	delete iImpl;
    81 	delete iImpl;
    88     SQL_TRACE_BORDER(OstTraceExt2(TRACE_BORDER, RSQLSECURITYPOLICY_CLOSE_EXIT, "Exit;0x%X;RSqlSecurityPolicy::Close;iImpl=0x%X", (TUint)this, (TUint)iImpl));
       
    89 	iImpl = NULL;
    82 	iImpl = NULL;
    90 	}
    83 	}
    91 
    84 
    92 
    85 
    93 /**
    86 /**
   108 
   101 
   109 @capability None
   102 @capability None
   110 */
   103 */
   111 EXPORT_C TInt RSqlSecurityPolicy::SetDbPolicy(TPolicyType aPolicyType, const TSecurityPolicy& aPolicy)
   104 EXPORT_C TInt RSqlSecurityPolicy::SetDbPolicy(TPolicyType aPolicyType, const TSecurityPolicy& aPolicy)
   112 	{
   105 	{
   113 	__ASSERT_ALWAYS(aPolicyType >= ESchemaPolicy && aPolicyType <= EWritePolicy, __SQLPANIC(ESqlPanicBadArgument));
   106 	SQLUTRACE_PROFILER(this);
       
   107 	__SQLASSERT_ALWAYS(aPolicyType >= ESchemaPolicy && aPolicyType <= EWritePolicy, ESqlPanicBadArgument);
   114 	Impl().SetDbPolicy(aPolicyType, aPolicy);
   108 	Impl().SetDbPolicy(aPolicyType, aPolicy);
   115 	return KErrNone;
   109 	return KErrNone;
   116 	}
   110 	}
   117 	
   111 	
   118 /**
   112 /**
   144 @capability None
   138 @capability None
   145 */
   139 */
   146 EXPORT_C TInt RSqlSecurityPolicy::SetPolicy(TObjectType aObjectType, const TDesC& aObjectName, 
   140 EXPORT_C TInt RSqlSecurityPolicy::SetPolicy(TObjectType aObjectType, const TDesC& aObjectName, 
   147 									  TPolicyType aPolicyType, const TSecurityPolicy& aPolicy)
   141 									  TPolicyType aPolicyType, const TSecurityPolicy& aPolicy)
   148 	{
   142 	{
   149 	__ASSERT_ALWAYS(aObjectType == ETable, __SQLPANIC(ESqlPanicBadArgument));
   143 	SQLUTRACE_PROFILER(this);
   150 	__ASSERT_ALWAYS(aObjectName.Length() > 0, __SQLPANIC(ESqlPanicBadArgument));
   144 	__SQLASSERT_ALWAYS(aObjectType == ETable, ESqlPanicBadArgument);
   151 	__ASSERT_ALWAYS(aPolicyType >= EReadPolicy && aPolicyType <= EWritePolicy, __SQLPANIC(ESqlPanicBadArgument));
   145 	__SQLASSERT_ALWAYS(aObjectName.Length() > 0, ESqlPanicBadArgument);
       
   146 	__SQLASSERT_ALWAYS(aPolicyType >= EReadPolicy && aPolicyType <= EWritePolicy, ESqlPanicBadArgument);
   152 	return Impl().SetPolicy(aObjectType, aObjectName, aPolicyType, aPolicy);
   147 	return Impl().SetPolicy(aObjectType, aObjectName, aPolicyType, aPolicy);
   153 	}
   148 	}
   154 
   149 
   155 /**
   150 /**
   156 Gets the default database security policy.
   151 Gets the default database security policy.
   161 
   156 
   162 @capability None
   157 @capability None
   163 */	
   158 */	
   164 EXPORT_C TSecurityPolicy RSqlSecurityPolicy::DefaultPolicy() const
   159 EXPORT_C TSecurityPolicy RSqlSecurityPolicy::DefaultPolicy() const
   165 	{
   160 	{
       
   161 	SQLUTRACE_PROFILER(this);
   166 	return Impl().DefaultPolicy();
   162 	return Impl().DefaultPolicy();
   167 	}
   163 	}
   168 
   164 
   169 /**
   165 /**
   170 Gets a database security policy of the specified type.
   166 Gets a database security policy of the specified type.
   181 
   177 
   182 @capability None
   178 @capability None
   183 */	
   179 */	
   184 EXPORT_C TSecurityPolicy RSqlSecurityPolicy::DbPolicy(TPolicyType aPolicyType) const
   180 EXPORT_C TSecurityPolicy RSqlSecurityPolicy::DbPolicy(TPolicyType aPolicyType) const
   185 	{
   181 	{
   186 	__ASSERT_ALWAYS(aPolicyType >= ESchemaPolicy && aPolicyType <= EWritePolicy, __SQLPANIC(ESqlPanicBadArgument));
   182 	SQLUTRACE_PROFILER(this);
       
   183 	__SQLASSERT_ALWAYS(aPolicyType >= ESchemaPolicy && aPolicyType <= EWritePolicy, ESqlPanicBadArgument);
   187 	return Impl().DbPolicy(aPolicyType);
   184 	return Impl().DbPolicy(aPolicyType);
   188 	}
   185 	}
   189 	
   186 	
   190 /**
   187 /**
   191 Gets a database object security policy of the specified type.
   188 Gets a database object security policy of the specified type.
   210 @capability None
   207 @capability None
   211 */
   208 */
   212 EXPORT_C TSecurityPolicy RSqlSecurityPolicy::Policy(TObjectType aObjectType, const TDesC& aObjectName, 
   209 EXPORT_C TSecurityPolicy RSqlSecurityPolicy::Policy(TObjectType aObjectType, const TDesC& aObjectName, 
   213 												 TPolicyType aPolicyType) const
   210 												 TPolicyType aPolicyType) const
   214 	{
   211 	{
   215 	__ASSERT_ALWAYS(aObjectType == ETable, __SQLPANIC(ESqlPanicBadArgument));
   212 	SQLUTRACE_PROFILER(this);
   216 	__ASSERT_ALWAYS(aObjectName.Length() > 0, __SQLPANIC(ESqlPanicBadArgument));
   213 	__SQLASSERT_ALWAYS(aObjectType == ETable, ESqlPanicBadArgument);
   217 	__ASSERT_ALWAYS(aPolicyType >= EReadPolicy && aPolicyType <= EWritePolicy, __SQLPANIC(ESqlPanicBadArgument));
   214 	__SQLASSERT_ALWAYS(aObjectName.Length() > 0, ESqlPanicBadArgument);
       
   215 	__SQLASSERT_ALWAYS(aPolicyType >= EReadPolicy && aPolicyType <= EWritePolicy, ESqlPanicBadArgument);
   218 	return Impl().Policy(aObjectType, aObjectName, aPolicyType);
   216 	return Impl().Policy(aObjectType, aObjectName, aPolicyType);
   219 	}
   217 	}
   220 
   218 
   221 /**
   219 /**
   222 Externalizes RSqlSecurityPolicy instance to a write stream.
   220 Externalizes RSqlSecurityPolicy instance to a write stream.
   227 
   225 
   228 @capability None
   226 @capability None
   229 */
   227 */
   230 EXPORT_C void RSqlSecurityPolicy::ExternalizeL(RWriteStream& aStream) const
   228 EXPORT_C void RSqlSecurityPolicy::ExternalizeL(RWriteStream& aStream) const
   231 	{
   229 	{
   232     SQL_TRACE_BORDER(OstTraceExt3(TRACE_BORDER, RSQLSECURITYPOLICY_EXTERNALIZEL_ENTRY , "Entry;0x%X;RSqlSecurityPolicy::ExternalizeL;aStream=0x%X;aStream.Sink()=0x%X", (TUint)this, (TUint)&aStream, (TUint)aStream.Sink()));
   230 	SQLUTRACE_PROFILER(this);
   233 	RSqlSecurityPolicy::TObjectType objectType;
   231 	RSqlSecurityPolicy::TObjectType objectType;
   234 	TPtrC objectName;
   232 	TPtrC objectName;
   235 	RSqlSecurityPolicy::TPolicyType policyType;
   233 	RSqlSecurityPolicy::TPolicyType policyType;
   236 	TSecurityPolicy policy;
   234 	TSecurityPolicy policy;
   237 	//Default policy
   235 	//Default policy
   253 		aStream << static_cast <TInt32> (policyType);
   251 		aStream << static_cast <TInt32> (policyType);
   254 		aStream << policy.Package();
   252 		aStream << policy.Package();
   255 		}
   253 		}
   256 	//Object policy stream - end
   254 	//Object policy stream - end
   257 	aStream << KEndOfSPStream;
   255 	aStream << KEndOfSPStream;
   258     SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLSECURITYPOLICY_EXTERNALIZEL_EXIT, "Exit;0x%X;RSqlSecurityPolicy::ExternalizeL", (TUint)this));
       
   259 	}
   256 	}
   260 	
   257 	
   261 /**
   258 /**
   262 Initializes RSqlSecurityPolicy instance from a stream.
   259 Initializes RSqlSecurityPolicy instance from a stream.
   263 In case of an error the original security policy data is preserved.
   260 In case of an error the original security policy data is preserved.
   269 
   266 
   270 @capability None
   267 @capability None
   271 */
   268 */
   272 EXPORT_C void RSqlSecurityPolicy::InternalizeL(RReadStream& aStream)
   269 EXPORT_C void RSqlSecurityPolicy::InternalizeL(RReadStream& aStream)
   273 	{
   270 	{
   274     SQL_TRACE_BORDER(OstTraceExt3(TRACE_BORDER, RSQLSECURITYPOLICY_INTERNALIZEL_ENTRY , "Entry;0x%X;RSqlSecurityPolicy::InternalizeL;aStream=0x%X;aStream.Source()=0x%X", (TUint)this, (TUint)&aStream, (TUint)aStream.Source()));
   271 	SQLUTRACE_PROFILER(this);
   275 	TSecurityPolicy policy;
   272 	TSecurityPolicy policy;
   276 	TBuf8<sizeof(TSecurityPolicy)> policyBuf;
   273 	TBuf8<sizeof(TSecurityPolicy)> policyBuf;
   277 	//Default policy
   274 	//Default policy
   278 	aStream >> policyBuf;
   275 	aStream >> policyBuf;
   279 	policy.Set(policyBuf);
   276 	policy.Set(policyBuf);
   312 	CSqlSecurityPolicy* temp = newPolicy.iImpl;
   309 	CSqlSecurityPolicy* temp = newPolicy.iImpl;
   313 	newPolicy.iImpl = iImpl;
   310 	newPolicy.iImpl = iImpl;
   314 	iImpl = temp;
   311 	iImpl = temp;
   315 	//Destroy the old policy (which was swapped)
   312 	//Destroy the old policy (which was swapped)
   316 	CleanupStack::PopAndDestroy(&newPolicy);
   313 	CleanupStack::PopAndDestroy(&newPolicy);
   317     SQL_TRACE_BORDER(OstTrace1(TRACE_BORDER, RSQLSECURITYPOLICY_INTERNALIZEL_EXIT, "Exit;0x%X;RSqlSecurityPolicy::InternalizeL", (TUint)this));
       
   318 	}
   314 	}
   319 
   315 
   320 /**
   316 /**
   321 Destroys the existing iImpl object and replaces it with aImpl parameter.
   317 Destroys the existing iImpl object and replaces it with aImpl parameter.
   322 
   318 
   335 
   331 
   336 @internalComponent
   332 @internalComponent
   337 */
   333 */
   338 CSqlSecurityPolicy& RSqlSecurityPolicy::Impl() const
   334 CSqlSecurityPolicy& RSqlSecurityPolicy::Impl() const
   339 	{
   335 	{
   340 	__ASSERT_ALWAYS(iImpl != NULL, __SQLPANIC(ESqlPanicInvalidObj));
   336 	__SQLASSERT_ALWAYS(iImpl != NULL, ESqlPanicInvalidObj);
   341 	return *iImpl;	
   337 	return *iImpl;	
   342 	}
   338 	}