persistentstorage/sql/SRC/Server/SqlSrvSession.cpp
branchRCL_3
changeset 8 fa9941cf3867
parent 0 08ec8eefde2f
child 9 667e88a979d7
equal deleted inserted replaced
6:5ffdb8f2067f 8:fa9941cf3867
   517 void CSqlSrvSession::DbCreateObjectL(const RMessage2& aMessage, TSqlSrvFunction aFunction)
   517 void CSqlSrvSession::DbCreateObjectL(const RMessage2& aMessage, TSqlSrvFunction aFunction)
   518 	{
   518 	{
   519 	__SQLPANIC_CLIENT(!iDatabase, aMessage, ESqlPanicObjExists);
   519 	__SQLPANIC_CLIENT(!iDatabase, aMessage, ESqlPanicObjExists);
   520 	const TInt KSecurityPolicyLen = (aMessage.Int2() & 0x7fff0000) >> 16;
   520 	const TInt KSecurityPolicyLen = (aMessage.Int2() & 0x7fff0000) >> 16;
   521 	const TInt KConfigStringLen = aMessage.Int2() & 0xffff;
   521 	const TInt KConfigStringLen = aMessage.Int2() & 0xffff;
   522 	if(KSecurityPolicyLen < 0 || KConfigStringLen < 0 || KConfigStringLen > KSqlSrvMaxConfigStrLen)
   522 	if(KSecurityPolicyLen < 0 || (TUint)KConfigStringLen > KSqlSrvMaxConfigStrLen)
   523 		{
   523 		{
   524 		__SQLLEAVE(KErrArgument);	
   524 		__SQLLEAVE(KErrArgument);	
   525 		}
   525 		}
   526 	TBuf8<KSqlSrvMaxConfigStrLen> configStr;
   526 	RBuf8 securityAndConfigBuf;
       
   527 	CleanupClosePushL(securityAndConfigBuf);
       
   528 	if((KSecurityPolicyLen + KConfigStringLen) > 0)
       
   529 	    {
       
   530 	    securityAndConfigBuf.CreateL(KSecurityPolicyLen + KConfigStringLen);
       
   531         aMessage.ReadL(3, securityAndConfigBuf); 
       
   532         SQLPROFILER_REPORT_IPC(ESqlIpcRead, (KSecurityPolicyLen + KConfigStringLen));
       
   533 	    }
       
   534 	TSqlSrvFileData& fileData = Server().FileData();
       
   535 	TPtrC8 configStr(KNullDesC8);
   527 	if(KConfigStringLen > 0)
   536 	if(KConfigStringLen > 0)
   528 		{
   537 	    {
   529 		aMessage.ReadL(3, configStr, KSecurityPolicyLen);
   538 	    configStr.Set(securityAndConfigBuf.Mid(KSecurityPolicyLen));//the first part of the buffer is for the security policies
   530 		SQLPROFILER_REPORT_IPC(ESqlIpcRead, KConfigStringLen);
   539 	    }
   531 		}
       
   532 	TSqlSrvFileData& fileData = Server().FileData();
       
   533 	fileData.SetL(aMessage, aMessage.Int0(), 1, &configStr);
   540 	fileData.SetL(aMessage, aMessage.Int0(), 1, &configStr);
   534 	iDrive = fileData.Drive();
   541 	iDrive = fileData.Drive();
   535 	switch(aFunction)
   542 	switch(aFunction)
   536 		{
   543 		{
   537 		case ESqlSrvDbCreate:
   544 		case ESqlSrvDbCreate:
   541 				}
   548 				}
   542 			iDatabase = CSqlSrvDatabase::CreateL(fileData);
   549 			iDatabase = CSqlSrvDatabase::CreateL(fileData);
   543 			break;
   550 			break;
   544 		case ESqlSrvDbCreateSecure:
   551 		case ESqlSrvDbCreateSecure:
   545 			{
   552 			{
   546 			if(!fileData.IsSecureFileNameFmt())
   553 			if(!fileData.IsSecureFileNameFmt() || KSecurityPolicyLen == 0)
   547 				{
   554 				{
   548 				__SQLLEAVE(KErrArgument);	
   555 				__SQLLEAVE(KErrArgument);	
   549 				}
   556 				}
   550 			//The caller can create a secure database which secure UID matches his secure UID.
   557 			//The caller can create a secure database which secure UID matches his secure UID.
   551 			if(fileData.SecureUid() != aMessage.SecureId())
   558 			if(fileData.SecureUid() != aMessage.SecureId())
   552 				{
   559 				{
   553 				__SQLLEAVE(KErrPermissionDenied);	
   560 				__SQLLEAVE(KErrPermissionDenied);	
   554 				}
   561 				}
   555 			CSqlSecurityPolicy* policy = InternalizeSecurityPolicyL(aMessage);
   562 			CSqlSecurityPolicy* policy = CreateSecurityPolicyL(securityAndConfigBuf.Left(KSecurityPolicyLen));
   556 			iDatabase = CSqlSrvDatabase::CreateSecureL(fileData, policy);
   563 			iDatabase = CSqlSrvDatabase::CreateSecureL(fileData, policy);
   557 			}
   564 			}
   558 			break;
   565 			break;
   559 		case ESqlSrvDbOpen:
   566 		case ESqlSrvDbOpen:
   560 			iDatabase = CSqlSrvDatabase::OpenL(fileData);
   567 			iDatabase = CSqlSrvDatabase::OpenL(fileData);
   561 			break;
   568 			break;
   562 		default:
   569 		default:
   563 			__SQLLEAVE(KErrArgument);	
   570 			__SQLLEAVE(KErrArgument);	
   564 			break;
   571 			break;
   565 		}
   572 		}
       
   573 	CleanupStack::PopAndDestroy(&securityAndConfigBuf);
   566 	}
   574 	}
   567 
   575 
   568 /**
   576 /**
   569 Processes the request for opening a database from file handle.
   577 Processes the request for opening a database from file handle.
   570 The server expects that the database to be opened/created is in the applicatio's private data cage.
   578 The server expects that the database to be opened/created is in the applicatio's private data cage.
   594 	__SQLPANIC_CLIENT(!iDatabase, aMessage, ESqlPanicObjExists);
   602 	__SQLPANIC_CLIENT(!iDatabase, aMessage, ESqlPanicObjExists);
   595 	const TBool KReadOnly = (aMessage.Int0() & 0x80000000) != 0;
   603 	const TBool KReadOnly = (aMessage.Int0() & 0x80000000) != 0;
   596 	const TBool KCreated = (aMessage.Int0() & 0x40000000) != 0;
   604 	const TBool KCreated = (aMessage.Int0() & 0x40000000) != 0;
   597 	const TInt KDbFileNameLen = aMessage.Int0() & 0x0000FFFF;
   605 	const TInt KDbFileNameLen = aMessage.Int0() & 0x0000FFFF;
   598 	const TInt KConfigStringLen = (aMessage.Int0() & 0x3FFF0000) >> 16;
   606 	const TInt KConfigStringLen = (aMessage.Int0() & 0x3FFF0000) >> 16;
   599 	if(KConfigStringLen < 0 || KConfigStringLen > KSqlSrvMaxConfigStrLen)
   607     __SQLPANIC_CLIENT((TUint)KConfigStringLen <= KSqlSrvMaxConfigStrLen, aMessage, ESqlPanicBadArgument);
   600 		{
   608     __SQLPANIC_CLIENT((TUint)KDbFileNameLen <= KMaxFileName, aMessage, ESqlPanicBadArgument);
   601 		__SQLLEAVE(KErrArgument);	
       
   602 		}
       
   603 	if(KDbFileNameLen < 1 || KDbFileNameLen > KMaxFileName)
       
   604 		{
       
   605 		__SQLLEAVE(KErrBadName);
       
   606 		}
       
   607 	TDes16& buffer = Server().GetBuf16L(KDbFileNameLen + KConfigStringLen);
   609 	TDes16& buffer = Server().GetBuf16L(KDbFileNameLen + KConfigStringLen);
   608 	aMessage.ReadL(1, buffer);
   610 	aMessage.ReadL(1, buffer);
   609 	SQLPROFILER_REPORT_IPC(ESqlIpcRead, ((KDbFileNameLen + KConfigStringLen) * sizeof(TText)));
   611 	SQLPROFILER_REPORT_IPC(ESqlIpcRead, ((KDbFileNameLen + KConfigStringLen) * sizeof(TText)));
   610 	TFileName dbFileName;
   612 	TFileName dbFileName;
   611 	dbFileName.Copy(buffer.LeftTPtr(KDbFileNameLen));
   613 	dbFileName.Copy(buffer.LeftTPtr(KDbFileNameLen));
   879 */
   881 */
   880 void CSqlSrvSession::DbSize2L(const RMessage2& aMessage)
   882 void CSqlSrvSession::DbSize2L(const RMessage2& aMessage)
   881 	{
   883 	{
   882 	__SQLPANIC_CLIENT(iDatabase != NULL, aMessage, ESqlPanicInvalidObj);
   884 	__SQLPANIC_CLIENT(iDatabase != NULL, aMessage, ESqlPanicInvalidObj);
   883 	const TInt KDbNameLen = aMessage.Int1();
   885 	const TInt KDbNameLen = aMessage.Int1();
   884 	if(KDbNameLen < 0 || KDbNameLen > KMaxFileName)
   886 	if((TUint)KDbNameLen > KMaxFileName)
   885 		{
   887 		{
   886 		__SQLLEAVE(KErrBadName);
   888 		__SQLLEAVE(KErrBadName);
   887 		}
   889 		}
   888 	TPtrC dbName(KNullDesC);
   890 	TPtrC dbName(KNullDesC);
   889 	if(KDbNameLen > 0)
   891 	if(KDbNameLen > 0)
   926 	if(KSize == 0)
   928 	if(KSize == 0)
   927 		{
   929 		{
   928 		return 0;	
   930 		return 0;	
   929 		}
   931 		}
   930 	const TInt KDbNameLen = aMessage.Int1();
   932 	const TInt KDbNameLen = aMessage.Int1();
   931 	if(KDbNameLen < 0 || KDbNameLen > KMaxFileName)
   933 	if((TUint)KDbNameLen > KMaxFileName)
   932 		{
   934 		{
   933 		__SQLLEAVE(KErrBadName);
   935 		__SQLLEAVE(KErrBadName);
   934 		}
   936 		}
   935 	TPtrC dbName(KNullDesC);
   937 	TPtrC dbName(KNullDesC);
   936 	if(KDbNameLen > 0)
   938 	if(KDbNameLen > 0)
  1138 	 	else
  1140 	 	else
  1139 			{
  1141 			{
  1140 			__SQLLEAVE(KErrBadName);
  1142 			__SQLLEAVE(KErrBadName);
  1141 			}
  1143 			}
  1142 	  	}
  1144 	  	}
  1143 
  1145 	 __SQLASSERT(len > 0, ESqlPanicInternalError);//The "if" above should have hanled the case with "len == 0"
  1144 	 if(len < 1 || len > KMaxFileName)
  1146 	 if((TUint)len > KMaxFileName)
  1145 	  {
  1147 	  {
  1146 	  __SQLLEAVE(KErrBadName);
  1148 	  __SQLLEAVE(KErrBadName);
  1147 	  }
  1149 	  }
  1148 
  1150 
  1149 	 HBufC* buf = HBufC::NewLC(len + 1);
  1151 	 HBufC* buf = HBufC::NewLC(len + 1);
  1615 		}
  1617 		}
  1616 	return buf;
  1618 	return buf;
  1617 	}
  1619 	}
  1618 
  1620 
  1619 /**
  1621 /**
  1620 The method reads the message argument 1 data and constructs a CSqlSecurityPolicy object from the data.
  1622 The method constructs a CSqlSecurityPolicy object from the passed as an argument descriptor.
  1621 
  1623 
  1622 @param aMessage Client request encapsulated in RMessage2 object.
  1624 @param aSecurityPolicyData A descriptor with the security policy data.
  1623 
  1625 
  1624 @return A pointer to the created CSqlSecurityPolicy instance.
  1626 @return A pointer to the created CSqlSecurityPolicy instance.
  1625 
  1627 
  1626 @leave KErrArgument, if aMessage argument 0 length is 0 or negative (no security data);
  1628 @leave KErrNoMemory, out of memory condition has occured.
  1627        KErrNoMemory, out of memory condition has occured.
  1629 */
  1628 
  1630 CSqlSecurityPolicy* CSqlSrvSession::CreateSecurityPolicyL(const TDesC8& aSecurityPolicyData)
  1629 Usage of the IPC call arguments:
  1631 	{
  1630 Arg 2: [in]  security policies buffer length in bytes if aFunction is ESqlSrvDbCreateSecure
       
  1631 Arg 3: [in]  security policies buffer if aFunction is ESqlSrvDbCreateSecure
       
  1632 */
       
  1633 CSqlSecurityPolicy* CSqlSrvSession::InternalizeSecurityPolicyL(const RMessage2& aMessage)
       
  1634 	{
       
  1635 	// Leave if there is no security policy data
       
  1636 	// The format of arg[2] is an unsigned int
       
  1637 	// with the policy length shifted and concated to the config length
       
  1638 	// the policy data is the first part of arg[3]
       
  1639 	const TUint KConfigStrLenBitWidth = 16;
       
  1640 	TInt securityPolicyLen = aMessage.Int2() >> KConfigStrLenBitWidth;
       
  1641 	if(securityPolicyLen < 1)
       
  1642 		{
       
  1643 		__SQLLEAVE(KErrArgument);
       
  1644 		}
       
  1645 	TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysFail);
  1632 	TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysFail);
  1646 	CSqlSecurityPolicy* dbPolicy = CSqlSecurityPolicy::NewLC(defaultPolicy);
  1633 	CSqlSecurityPolicy* dbPolicy = CSqlSecurityPolicy::NewLC(defaultPolicy);
  1647 	RSqlBufFlat& bufFlat = dbPolicy->BufFlat();
  1634 	RSqlBufFlat& bufFlat = dbPolicy->BufFlat();
  1648 	if(securityPolicyLen > bufFlat.MaxSize())
  1635     __SQLLEAVE_IF_ERROR(bufFlat.ReAlloc(aSecurityPolicyData.Length()));
  1649 		{
  1636 	bufFlat.BufPtr().Copy(aSecurityPolicyData);
  1650 		__SQLLEAVE_IF_ERROR(bufFlat.ReAlloc(securityPolicyLen));
       
  1651 		}
       
  1652 	TPtr8& ptr = bufFlat.BufPtr();
       
  1653 	aMessage.ReadL(3, ptr);
       
  1654 	SQLPROFILER_REPORT_IPC(ESqlIpcRead, securityPolicyLen);
       
  1655 	// trim off config data if any
       
  1656 	TInt extraBytes = ptr.Length() - securityPolicyLen;
       
  1657 	if(extraBytes > 0)
       
  1658 		{
       
  1659 		ptr.Delete(securityPolicyLen, extraBytes);
       
  1660 		}
       
  1661 	CleanupStack::Pop(dbPolicy);
  1637 	CleanupStack::Pop(dbPolicy);
  1662 	return dbPolicy;
  1638 	return dbPolicy;
  1663 	}
  1639 	}
  1664 
  1640 
  1665 /**
  1641 /**