userlibandfileserver/fileserver/sfile/sf_utl.cpp
changeset 299 b5a01337d018
parent 254 1560c419b176
equal deleted inserted replaced
297:b2826f67641f 299:b5a01337d018
   131 		return EFalse;
   131 		return EFalse;
   132 
   132 
   133 	return ETrue;
   133 	return ETrue;
   134 	}
   134 	}
   135 
   135 
   136 TBool SIDCheck(CFsRequest* aRequest, const TDesC& aThePath)
   136 TBool SIDCheck(const RMessage2& aMessage, const TDesC& aThePath)
   137 //
   137 //
   138 //	Compare the Private/XXXXXXXX/ portion of a path be accessed to make sure it matches the process SID 
   138 //	Compare the Private/XXXXXXXX/ portion of a path be accessed to make sure it matches the process SID 
   139 //
   139 //
   140 	{
   140 	{
   141 	if(aThePath.Length() >= KPrivateLengthCheck)
   141 	if(aThePath.Length() >= KPrivateLengthCheck)
   142 		{
   142 		{
   143 		TSecureId appUID = aRequest->Message().SecureId();
   143         TSecureId appUID = aMessage.SecureId();
   144 		TBuf<KSIDLength+1> dirName;
   144 		TBuf<KSIDLength+1> dirName;
   145 		dirName.AppendNumFixedWidth(appUID.iId, EHex, 8);
   145 		dirName.AppendNumFixedWidth(appUID.iId, EHex, 8);
   146 	
   146 	
   147 		TInt match = dirName.CompareF(aThePath.Mid(KSIDPathOffset,KPrivateLength));
   147 		TInt match = dirName.CompareF(aThePath.Mid(KSIDPathOffset,KPrivateLength));
   148 		if(match==KErrNone)
   148 		if(match==KErrNone)
   153 	
   153 	
   154 	return EFalse;
   154 	return EFalse;
   155 	}
   155 	}
   156 
   156 
   157 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   157 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   158 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, const char* aDiag)
   158 TInt PathCheck(const RMessage2& aMessage, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, const char* aDiag)
   159 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   159 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   160 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, OnlyCreateWithNull /*aDiag*/)
   160 TInt PathCheck(const RMessage2& aMessage, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const TSecurityPolicy* aROCap, OnlyCreateWithNull /*aDiag*/)
   161 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   161 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   162 //
   162 //
   163 //	Compare the parsed path with protected path names path must be parsed b4 using
   163 //	Compare the parsed path with protected path names path must be parsed b4 using
   164 //
   164 //
   165 	{
   165 	{
   166 
   166 
   167 	if(aRequest->Message().Handle() == KLocalMessageHandle)
   167 	if(aMessage.Handle() == KLocalMessageHandle)
   168 		return KErrNone;
   168 		return KErrNone;
   169 
   169 
   170 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   170 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   171 #ifdef _DEBUG
   171 #ifdef _DEBUG
   172 	TBuf8<512> diagmsg;
   172 	TBuf8<512> diagmsg;
   183 #endif //_DEBUG
   183 #endif //_DEBUG
   184 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   184 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   185 
   185 
   186 	if(ComparePrivate(aThePath))
   186 	if(ComparePrivate(aThePath))
   187 		{	
   187 		{	
   188 		if(SIDCheck(aRequest, aThePath))
   188 		if(SIDCheck(aMessage, aThePath))
   189 			return KErrNone;	
   189 			return KErrNone;	
   190 		else
   190 		else
   191 			{
   191 			{
   192 			if(aPriCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   192 			if(aPriCap->CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   193 				return KErrNone;
   193 				return KErrNone;
   194 			else
   194 			else
   195 				return KErrPermissionDenied;
   195 				return KErrPermissionDenied;
   196 			}
   196 			}
   197 		}
   197 		}
   198 	else if(CompareSystem(aThePath))
   198 	else if(CompareSystem(aThePath))
   199 		{
   199 		{
   200 		if(aSysCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   200 		if(aSysCap->CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   201 			return KErrNone;
   201 			return KErrNone;
   202 		else
   202 		else
   203 			return KErrPermissionDenied;
   203 			return KErrPermissionDenied;
   204 		}
   204 		}
   205 	else if(CompareResource(aThePath))
   205 	else if(CompareResource(aThePath))
   206 		{
   206 		{
   207 		if(aROCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   207 		if(aROCap->CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   208 			return KErrNone;
   208 			return KErrNone;
   209 		else
   209 		else
   210 			return KErrPermissionDenied;
   210 			return KErrPermissionDenied;
   211 		}
   211 		}
   212 	else
   212 	else
   213 		return KErrNone;
   213 		return KErrNone;
   214  	}
   214  	}
   215 
   215 
   216 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   216 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   217 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const char* aDiag) 
   217 TInt PathCheck(const RMessage2& aMessage, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, const char* aDiag) 
   218 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   218 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   219 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, OnlyCreateWithNull /*aDiag*/) 
   219 TInt PathCheck(const RMessage2& aMessage, const TDesC& aThePath, const TSecurityPolicy* aSysCap, const TSecurityPolicy* aPriCap, OnlyCreateWithNull /*aDiag*/) 
   220 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   220 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   221 //
   221 //
   222 //	Compare the parsed path with protected path names path must be parsed b4 using
   222 //	Compare the parsed path with protected path names path must be parsed b4 using
   223 //
   223 //
   224 	{
   224 	{
   225 
   225 
   226 	if(aRequest->Message().Handle() == KLocalMessageHandle)
   226 	if(aMessage.Handle() == KLocalMessageHandle)
   227 		return KErrNone;
   227 		return KErrNone;
   228 
   228 
   229 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   229 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   230 #ifdef _DEBUG
   230 #ifdef _DEBUG
   231 	TBuf8<512> diagmsg;
   231 	TBuf8<512> diagmsg;
   242 #endif //_DEBUG
   242 #endif //_DEBUG
   243 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   243 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   244 
   244 
   245 	if(ComparePrivate(aThePath))
   245 	if(ComparePrivate(aThePath))
   246 		{	
   246 		{	
   247 		if(SIDCheck(aRequest, aThePath))
   247 		if(SIDCheck(aMessage, aThePath))
   248 			return KErrNone;	
   248 			return KErrNone;	
   249 		else
   249 		else
   250 			{
   250 			{
   251 			if(aPriCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   251 			if(aPriCap->CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   252 				return KErrNone;
   252 				return KErrNone;
   253 			else
   253 			else
   254 				return KErrPermissionDenied;
   254 				return KErrPermissionDenied;
   255 			}
   255 			}
   256 		}
   256 		}
   257 	else if(CompareSystem(aThePath))
   257 	else if(CompareSystem(aThePath))
   258 		{
   258 		{
   259 		if(aSysCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   259 		if(aSysCap->CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   260 			return KErrNone;
   260 			return KErrNone;
   261 		else
   261 		else
   262 			return KErrPermissionDenied;
   262 			return KErrPermissionDenied;
   263 		}
   263 		}
   264 	else
   264 	else
   265 		return KErrNone;
   265 		return KErrNone;
   266  	}
   266  	}
   267 
   267 
   268 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   268 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   269 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aCap, const char* aDiag, TBool aExactMatchAllowed) 
   269 TInt PathCheck(const RMessage2& aMessage, const TDesC& aThePath, const TSecurityPolicy* aCap, const char* aDiag, TBool aExactMatchAllowed) 
   270 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   270 #else //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   271 TInt PathCheck(CFsRequest* aRequest, const TDesC& aThePath, const TSecurityPolicy* aCap, OnlyCreateWithNull /*aDiag*/, TBool aExactMatchAllowed) 
   271 TInt PathCheck(const RMessage2& aMessage, const TDesC& aThePath, const TSecurityPolicy* aCap, OnlyCreateWithNull /*aDiag*/, TBool aExactMatchAllowed) 
   272 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   272 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   273 //
   273 //
   274 //	Compare the parsed path with protected path names path must be parsed b4 using
   274 //	Compare the parsed path with protected path names path must be parsed b4 using
   275 //
   275 //
   276 	{
   276 	{
   277 
   277 
   278 	if(aRequest->Message().Handle() == KLocalMessageHandle)
   278 	if(aMessage.Handle() == KLocalMessageHandle)
   279 		return KErrNone;
   279 		return KErrNone;
   280 
   280 
   281 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   281 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   282 #ifdef _DEBUG
   282 #ifdef _DEBUG
   283 	TBuf8<512> diagmsg;
   283 	TBuf8<512> diagmsg;
   294 #endif //_DEBUG
   294 #endif //_DEBUG
   295 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   295 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   296 
   296 
   297 	if(ComparePrivate(aThePath))
   297 	if(ComparePrivate(aThePath))
   298 		{	
   298 		{	
   299 		if(SIDCheck(aRequest, aThePath))
   299 		if(SIDCheck(aMessage, aThePath))
   300 			return KErrNone;	
   300 			return KErrNone;	
   301 		else
   301 		else
   302 			{
   302 			{
   303 			if(aCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   303 			if(aCap->CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   304 				return KErrNone;
   304 				return KErrNone;
   305 			else if (aExactMatchAllowed && aThePath.Length() <= KPrivateLength + 1)
   305 			else if (aExactMatchAllowed && aThePath.Length() <= KPrivateLength + 1)
   306 				return KErrNone;
   306 				return KErrNone;
   307 			else
   307 			else
   308 				return KErrPermissionDenied;
   308 				return KErrPermissionDenied;
   309 			}
   309 			}
   310 		}
   310 		}
   311 	else if(CompareSystem(aThePath))
   311 	else if(CompareSystem(aThePath))
   312 		{
   312 		{
   313 		if(aCap->CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   313 		if(aCap->CheckPolicy(aMessage, __PLATSEC_DIAGNOSTIC_STRING(diagout)))
   314 			return KErrNone;
   314 			return KErrNone;
   315 		else if (aExactMatchAllowed && aThePath.Length() <= KSystemLength + 1)
   315 		else if (aExactMatchAllowed && aThePath.Length() <= KSystemLength + 1)
   316 			return KErrNone;
   316 			return KErrNone;
   317 		else
   317 		else
   318 			return KErrPermissionDenied;
   318 			return KErrPermissionDenied;