rtsecuritymanager/rtsecuritymanagerutil/src/rtsecmgrscript.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:      
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include <rtsecmgrutility.h>
       
    23 #include <rtsecmgrscript.h>
       
    24 #include <s32mem.h>
       
    25 
       
    26 const TReal DEFAULT_VERSION(1.0);
       
    27 const TReal VERSION_TWO(2.0);
       
    28 // ---------------------------------------------------------------------------
       
    29 // Destructor
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 EXPORT_C CScript::~CScript()
       
    33 	{
       
    34 	delete iPermissionSet;
       
    35 	if(iHashMark)
       
    36 		delete iHashMark;
       
    37 	iAllowedProviders.Close();
       
    38 	iDeniedProviders.Close();
       
    39 	}
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Two-phased constructor
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 EXPORT_C CScript* CScript::NewL(TPolicyID aPolicyID,TExecutableID aScriptID)
       
    46 	{
       
    47 	CScript* self = CScript::NewLC(aPolicyID,aScriptID);
       
    48 	CleanupStack::Pop(self);
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Two-phased constructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CScript* CScript::NewLC(TPolicyID aPolicyID,TExecutableID aScriptID)
       
    57 	{
       
    58 	CScript* self = new (ELeave) CScript(aPolicyID,aScriptID);
       
    59 	CleanupStack::PushL(self);
       
    60 	self->ConstructL();
       
    61 	return self;
       
    62 	}
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Two-phased constructor
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CScript::ConstructL()
       
    69 	{
       
    70 	iPermissionSet = CPermissionSet::NewL ();
       
    71 	}
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Overloaded assignment operator
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C const CScript& CScript::operator=(const CScript& aRhs)
       
    78 	{
       
    79 	if(iPermissionSet )
       
    80 		{
       
    81 		delete iPermissionSet;
       
    82 		iPermissionSet = NULL;
       
    83 		}
       
    84 
       
    85 	iPermissionSet = CPermissionSet::NewL(*aRhs.iPermissionSet);
       
    86 	iScriptID = aRhs.iScriptID;
       
    87 	iPolicyID = aRhs.iPolicyID;
       
    88 	iPermGrant = aRhs.iPermGrant;
       
    89 	iPermDenied = aRhs.iPermDenied;
       
    90 	iAllowedProviders.Reset();
       
    91 	for(TInt i(0); i < aRhs.iAllowedProviders.Count(); i++)
       
    92 	    iAllowedProviders.Append(aRhs.iAllowedProviders[i]);
       
    93 	iDeniedProviders.Reset();
       
    94 	for(TInt i(0); i < aRhs.iDeniedProviders.Count(); i++)
       
    95         iDeniedProviders.Append(aRhs.iDeniedProviders[i]);
       
    96 	
       
    97 	if(iHashMark)
       
    98 		{
       
    99 			delete iHashMark;
       
   100 			iHashMark = NULL;
       
   101 		}
       
   102 	
       
   103 	if(aRhs.iHashMark)
       
   104 		{
       
   105 		iHashMark = aRhs.iHashMark->AllocLC();
       
   106 		CleanupStack::Pop(iHashMark);
       
   107 		}
       
   108 	return *this;
       
   109 	}
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // Gets script identifier
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C TExecutableID CScript::ScriptID() const
       
   116 	{
       
   117 	return iScriptID;
       
   118 	}
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // Gets policy identifier
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C TPolicyID CScript::PolicyID() const
       
   125 	{
       
   126 	return iPolicyID;
       
   127 	}
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // Sets permission set data of the script
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C void CScript::SetPermissionSet(const CPermissionSet& aPermSet)
       
   134 	{
       
   135 	if ( iPermissionSet)
       
   136 		{
       
   137 		delete iPermissionSet;
       
   138 		iPermissionSet=NULL;
       
   139 		}
       
   140 
       
   141 	iPermissionSet = CPermissionSet::NewL (aPermSet);
       
   142 	}
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Gets permission set data of the script
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C const CPermissionSet& CScript::PermissionSet() const
       
   149 	{
       
   150 	return *iPermissionSet;
       
   151 	}
       
   152 // ---------------------------------------------------------------------------
       
   153 // Gets permission set data of the script
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 EXPORT_C CPermissionSet& CScript::PermissionSet()
       
   157 	{
       
   158 	return *iPermissionSet;
       
   159 	}
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // Gets permanently granted permissions of the script
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C TPermGrant CScript::PermGranted() const
       
   166 	{
       
   167 	return iPermGrant;
       
   168 	}
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // Gets permanently denied permissions of the script
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 EXPORT_C TPermGrant CScript::PermDenied() const
       
   175 	{
       
   176 	return iPermDenied;
       
   177 	}
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // Gets permanently granted permissions of the script
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 EXPORT_C void CScript::PermGranted(RProviderArray& aAllowedProviders) 
       
   184     {
       
   185     aAllowedProviders.Reset();
       
   186     for(TInt i(0); i < iAllowedProviders.Count(); i++)
       
   187         aAllowedProviders.Append(iAllowedProviders[i]);
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // Gets permanently denied permissions of the script
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C void CScript::PermDenied(RProviderArray& aDeniedProviders) 
       
   195     {
       
   196     aDeniedProviders.Reset();
       
   197     for(TInt i(0); i < iDeniedProviders.Count(); i++)
       
   198         aDeniedProviders.Append(iDeniedProviders[i]);
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // ExternalizeLs script data to stream
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C void CScript::ExternalizeL(RWriteStream& aSink) const
       
   206 	{
       
   207 	aSink.WriteReal32L(VERSION_TWO);
       
   208 	iPermissionSet->ExternalizeL (aSink);
       
   209 	aSink.WriteInt32L (iScriptID);
       
   210 	aSink.WriteInt32L (iPolicyID);
       
   211 	aSink.WriteUint32L (iPermGrant);
       
   212 	aSink.WriteUint32L (iPermDenied);
       
   213 	if(iHashMark)
       
   214 		{
       
   215 			aSink.WriteUint32L(iHashMark->Length());
       
   216 			aSink.WriteL(*iHashMark,iHashMark->Length());
       
   217 		}
       
   218 	else
       
   219 		aSink.WriteInt32L(0);
       
   220 	
       
   221 	//Present only in version 2 and forward.
       
   222 	aSink.WriteInt32L(iAllowedProviders.Count());
       
   223 	for(TInt i(0); i < iAllowedProviders.Count(); i++)
       
   224 	    aSink.WriteInt32L(iAllowedProviders[i].iUid);
       
   225 	aSink.WriteInt32L(iDeniedProviders.Count());
       
   226     for(TInt i(0); i < iDeniedProviders.Count(); i++)
       
   227         aSink.WriteInt32L(iDeniedProviders[i].iUid);
       
   228 	}
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // InternalizeLs script data from stream
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 EXPORT_C void CScript::InternalizeL(RReadStream& aSource)
       
   235 	{
       
   236 	if ( iPermissionSet)
       
   237 		{
       
   238 		delete iPermissionSet;
       
   239 		iPermissionSet=NULL;
       
   240 		iPermissionSet = CPermissionSet::NewL ();
       
   241 		}
       
   242 	TReal version(aSource.ReadReal32L());
       
   243 	iPermissionSet->InternalizeL (aSource);
       
   244 	iScriptID = aSource.ReadInt32L ();
       
   245 	iPolicyID = aSource.ReadInt32L ();
       
   246 	iPermGrant = aSource.ReadUint32L ();
       
   247 	iPermDenied = aSource.ReadUint32L ();
       
   248 	TInt hashMarkLen(aSource.ReadUint32L());
       
   249 	if(iHashMark)
       
   250 		{
       
   251 			delete iHashMark;
       
   252 			iHashMark = NULL;
       
   253 		}
       
   254 		
       
   255 	if(hashMarkLen)	
       
   256 		{
       
   257 		iHashMark = HBufC::NewL(hashMarkLen);
       
   258 		TPtr ptr(iHashMark->Des());
       
   259 		aSource.ReadL(ptr,hashMarkLen);
       
   260 		}
       
   261 	if(version >= VERSION_TWO)
       
   262 	    {
       
   263 	    TInt allowCnt = aSource.ReadInt32L();
       
   264 	    iAllowedProviders.Reset();
       
   265 	    for(TInt i(0); i < allowCnt; i++)
       
   266 	        {
       
   267 	        TInt uid = aSource.ReadInt32L();
       
   268 	        TUid allowPid = TUid::Uid(uid);
       
   269 	        iAllowedProviders.Append(allowPid);
       
   270 	        }
       
   271 	    TInt denyCnt = aSource.ReadInt32L();
       
   272         iDeniedProviders.Reset();
       
   273         for(TInt i(0); i < denyCnt; i++)
       
   274             {
       
   275             TInt uid = aSource.ReadInt32L();
       
   276             TUid denyPid = TUid::Uid(uid);
       
   277             iDeniedProviders.Append(denyPid);
       
   278             }
       
   279 	    }
       
   280 	}
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // Sets permanently granted permissions of the script
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 EXPORT_C void CScript::SetPermGranted(TPermGrant aPermGrant)
       
   287 	{
       
   288 	iPermGrant = aPermGrant;
       
   289 	}
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // Sets permanently denied permissions of the script
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 EXPORT_C void CScript::SetPermDenied(TPermGrant aPermDenied)
       
   296 	{
       
   297 	iPermDenied = aPermDenied;
       
   298 	}
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // Sets permanently granted permissions of the script
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 EXPORT_C void CScript::SetPermGranted(RProviderArray aPermGrantProvider)
       
   305     {
       
   306     iAllowedProviders.Reset();
       
   307     for(TInt i(0); i < aPermGrantProvider.Count(); i++)
       
   308            iAllowedProviders.Append(aPermGrantProvider[i]);
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // Sets permanently denied permissions of the script
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 EXPORT_C void CScript::SetPermDenied(RProviderArray aPermDeniedProvider)
       
   316     {
       
   317     iDeniedProviders.Reset();
       
   318     for(TInt i(0); i < aPermDeniedProvider.Count(); i++)
       
   319             iDeniedProviders.Append(aPermDeniedProvider[i]);
       
   320     }