secureswitools/swisistools/source/interpretsislib/installer.cpp
changeset 60 245df5276b97
parent 42 d17dc5398051
child 75 2d2d25361590
equal deleted inserted replaced
53:ae54820ef82c 60:245df5276b97
    55 #include "adornedutilities.h"
    55 #include "adornedutilities.h"
    56 
    56 
    57 // Constants
    57 // Constants
    58 const char KRomDriveLetter = 'z';
    58 const char KRomDriveLetter = 'z';
    59 const TUint32 KSwiDaemonUid = 0x10202DCE;
    59 const TUint32 KSwiDaemonUid = 0x10202DCE;
       
    60 #ifndef __TOOLS2_LINUX__
    60 const std::wstring KSysBinPath = L"\\sys\\bin\\";
    61 const std::wstring KSysBinPath = L"\\sys\\bin\\";
       
    62 #else
       
    63 const std::wstring KSysBinPath = L"/sys/bin/";
       
    64 #endif
    61 
    65 
    62 TInt CheckWildCard(TInt aVal, TInt aReplace)
    66 TInt CheckWildCard(TInt aVal, TInt aReplace)
    63 {
    67 {
    64 	return
    68 	return
    65 		aVal == -1
    69 		aVal == -1
   112 	{
   116 	{
   113 		std::wstring shortName(curr->iFileName);
   117 		std::wstring shortName(curr->iFileName);
   114 
   118 
   115 		// Ensure formatting is correct
   119 		// Ensure formatting is correct
   116 		if ( StringUtils::IsLastCharacter( shortName, KDirectorySeparator[ 0 ] ) ||
   120 		if ( StringUtils::IsLastCharacter( shortName, KDirectorySeparator[ 0 ] ) ||
       
   121 			 #ifndef __TOOLS2_LINUX__
   117              StringUtils::IsLastCharacter( shortName, L'/' ) )
   122              StringUtils::IsLastCharacter( shortName, L'/' ) )
       
   123              #else
       
   124 			 StringUtils::IsLastCharacter( shortName, L'\\' ) )
       
   125 			 #endif
   118 		{
   126 		{
   119 			shortName.erase(shortName.length()-1,1);
   127 			shortName.erase(shortName.length()-1,1);
   120 		}
   128 		}
   121 
   129 
   122 		if ( IsDirectory(shortName) )
   130 		if ( IsDirectory(shortName) )
   199 					result =  FILE_ERROR;
   207 					result =  FILE_ERROR;
   200 				}
   208 				}
   201 			catch  (InterpretSisError& e)
   209 			catch  (InterpretSisError& e)
   202 				{
   210 				{
   203 				LERROR(L"Failed installing " << (curr->iFileName));
   211 				LERROR(L"Failed installing " << (curr->iFileName));
   204 				LERROR(L"\t" << Utf8ToUcs2(e.what()));
   212 				LERROR(L"\t" << string2wstring(e.what()));
   205 				curr = sisFiles.erase(curr);
   213 				curr = sisFiles.erase(curr);
   206 				
   214 				
   207 				if (result == 0)
   215 				if (result == 0)
   208 					result =  e.GetErrorCode();
   216 					result =  e.GetErrorCode();
   209 				}
   217 				}
   360 	}
   368 	}
   361 	catch  (InterpretSisError& e)
   369 	catch  (InterpretSisError& e)
   362 	{
   370 	{
   363 		RestoreAll(file, installable, iBackupFlag);
   371 		RestoreAll(file, installable, iBackupFlag);
   364 
   372 
   365 		LERROR(L"\t" << Utf8ToUcs2(e.what()));
   373 		LERROR(L"\t" << string2wstring(e.what()));
   366 		int result =  e.GetErrorCode();
   374 		int result =  e.GetErrorCode();
   367 		return result;
   375 		return result;
   368 	
   376 	
   369 	}
   377 	}
   370 	catch  (...)
   378 	catch  (...)
   496 	}
   504 	}
   497 
   505 
   498 	if (installType == CSISInfo::EInstAugmentation)
   506 	if (installType == CSISInfo::EInstAugmentation)
   499 	{
   507 	{
   500 		// Clean up the installed files from the specified SP package and the SisRegistry Entry
   508 		// Clean up the installed files from the specified SP package and the SisRegistry Entry
   501 		iRegistry.RemoveEntry(uid, aSis.GetPackageName(), aSis.GetVendorName());
   509 		iRegistry.RemoveEntry(uid, aSis.GetPackageName().c_str(), aSis.GetVendorName().c_str());
   502 	}
   510 	}
   503 
   511 
   504 	// Regenerate the ROM stub registry entries for eclipsing check later.
   512 	// Regenerate the ROM stub registry entries for eclipsing check later.
   505 	iRegistry.GenerateStubRegistry();
   513 	iRegistry.GenerateStubRegistry();
   506 }
   514 }
   528 		{	
   536 		{	
   529 			std::string BackupDb(DbPath);
   537 			std::string BackupDb(DbPath);
   530 			BackupDb.append("_backup");
   538 			BackupDb.append("_backup");
   531 
   539 
   532 		 	err=FileCopyA(DbPath.c_str(),BackupDb.c_str(),0);
   540 		 	err=FileCopyA(DbPath.c_str(),BackupDb.c_str(),0);
   533 			if (err == 0)
   541 			if (err != 0)
   534 				LERROR(L"Failed to Backup Database scr.db ");
   542 				LERROR(L"Failed to Backup Database scr.db ");
   535 		}
   543 		}
   536 
   544 
   537 		// Backup all installed files for this Uid's packages and all the SisRegistry Entries
   545 		// Backup all installed files for this Uid's packages and all the SisRegistry Entries
   538 		InstallableFiles::const_iterator filedesIter; 
   546 		InstallableFiles::const_iterator filedesIter; 
   541 		{
   549 		{
   542 			std::wstring itargetLocalFile = (*filedesIter)->GetLocalTarget();
   550 			std::wstring itargetLocalFile = (*filedesIter)->GetLocalTarget();
   543 			if (FileExists(itargetLocalFile))
   551 			if (FileExists(itargetLocalFile))
   544 			{
   552 			{
   545 				std::wstring itargetBackupFile = (*filedesIter)->GetLocalTarget();
   553 				std::wstring itargetBackupFile = (*filedesIter)->GetLocalTarget();
   546 				itargetBackupFile.append(L"_backup");
   554 				std::wstring temp = itargetBackupFile.c_str();
       
   555 				temp.append(L"_backup");
       
   556 				itargetBackupFile = temp;
       
   557 
       
   558 
   547 				int pos =0;
   559 				int pos =0;
   548 				if((pos = itargetBackupFile.find(L"\\sys\\bin\\", 0)) != std::wstring::npos)
   560 				#ifdef __LINUX__
       
   561 				std::wstring sysBin = L"/sys/bin/";
       
   562 				#else
       
   563 				std::wstring sysBin = L"\\sys\\bin\\";
       
   564 				#endif
       
   565 
       
   566 				if((pos = itargetBackupFile.find(sysBin, 0)) != std::wstring::npos)
   549 				{
   567 				{
   550 					BackupHashForFile(itargetLocalFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   568 					BackupHashForFile(itargetLocalFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   551 				}
   569 				}
   552 
   570 
   553 				std::string iLocalFile = wstring2string(itargetLocalFile);
   571 				std::string iLocalFile = wstring2string(itargetLocalFile);
   554 				std::string iBackupFile = wstring2string(itargetBackupFile);
   572 				std::string iBackupFile = wstring2string(itargetBackupFile);
   555 
   573 
   556 				err=FileCopyA(iLocalFile.c_str(),iBackupFile.c_str(),0);
   574 				err=FileCopyA(iLocalFile.c_str(),iBackupFile.c_str(),0);
   557 				if (err == 0)
   575 				if (err != 0)
   558 					LERROR(L"Failed to Backup installable file ");
   576 					LERROR(L"Failed to Backup installable file ");
   559 			}
   577 			}
   560 		}
   578 		}
   561 	}
   579 	}
   562 }
   580 }
   590 
   608 
   591 		for(filedesIter = aInstallable.begin() ; filedesIter != aInstallable.end(); ++filedesIter)
   609 		for(filedesIter = aInstallable.begin() ; filedesIter != aInstallable.end(); ++filedesIter)
   592 		{
   610 		{
   593 		    itargetLocalFile = (*filedesIter)->GetLocalTarget();
   611 		    itargetLocalFile = (*filedesIter)->GetLocalTarget();
   594 			itargetBackupFile = (*filedesIter)->GetLocalTarget();
   612 			itargetBackupFile = (*filedesIter)->GetLocalTarget();
   595 			itargetBackupFile.append(L"_backup");
   613 			std::wstring temp = itargetBackupFile.c_str();
       
   614 			temp.append(L"_backup");
       
   615 			itargetBackupFile = temp;
   596 			
   616 			
   597 			if (FileExists(itargetBackupFile))
   617 			if (FileExists(itargetBackupFile))
   598 			{
   618 			{
   599 				RemoveFile(itargetBackupFile);
   619 				RemoveFile(itargetBackupFile);
   600 				RemoveHashForFile(itargetBackupFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   620 				RemoveHashForFile(itargetBackupFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   625 			std::wstring itargetBackupFile = (*filedesIter)->GetLocalTarget();
   645 			std::wstring itargetBackupFile = (*filedesIter)->GetLocalTarget();
   626 			itargetBackupFile.append(L"_backup");
   646 			itargetBackupFile.append(L"_backup");
   627 			if (FileExists(itargetBackupFile))
   647 			if (FileExists(itargetBackupFile))
   628 			{
   648 			{
   629 				int pos =0;
   649 				int pos =0;
   630 				if((pos = itargetBackupFile.find(L"\\sys\\bin\\", 0)) != std::wstring::npos)
   650 				#ifdef __LINUX__
       
   651 				std::wstring sysBin = L"/sys/bin/";
       
   652 				#else
       
   653 				std::wstring sysBin = L"\\sys\\bin\\";
       
   654 				#endif
       
   655 
       
   656 				if((pos = itargetBackupFile.find(sysBin, 0)) != std::wstring::npos)
   631 				{
   657 				{
   632 					RestoreHashForFile(itargetLocalFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   658 					RestoreHashForFile(itargetLocalFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   633 				}
   659 				}
   634 
   660 
   635 				std::string iLocalFile = wstring2string(itargetLocalFile);
   661 				std::string iLocalFile = wstring2string(itargetLocalFile);
   636 				std::string iBackupFile = wstring2string(itargetBackupFile);
   662 				std::string iBackupFile = wstring2string(itargetBackupFile);
   637 				
   663 				
   638 				int err = FileMoveA(iBackupFile.c_str(),iLocalFile.c_str());
   664 				int err = FileMoveA(iBackupFile.c_str(),iLocalFile.c_str());
   639 
   665 				if (err != 0)
   640 				if (err == 0)
       
   641 					LERROR(L"Failed to Restore file ");
   666 					LERROR(L"Failed to Restore file ");
   642 			}
   667 			}
   643 		}
   668 		}
   644 	}
   669 	}
   645 }
   670 }
   921 			LINFO(L"Skipping file with empty destination filename");
   946 			LINFO(L"Skipping file with empty destination filename");
   922             }
   947             }
   923         else
   948         else
   924             {
   949             {
   925 			// Unicode characters can not be displayed on DOS prompt
   950 			// Unicode characters can not be displayed on DOS prompt
   926  			std::string temporary = Ucs2ToUtf8(target);
   951  			std::string temporary = wstring2string(target);
   927 			std::wstring targetDisplay = Utf8ToUcs2( temporary );
   952 			std::wstring targetDisplay = string2wstring( temporary );
   928 		    LINFO(L"Installing file: " << targetDisplay);
   953 		    LINFO(L"Installing file: " << targetDisplay);
   929 
   954 
   930             std::wstring targetDirectory = localTarget.substr( 0, localTarget.rfind( KDirectorySeparator ) );    		
   955             std::wstring targetDirectory = localTarget.substr( 0, localTarget.rfind( KDirectorySeparator ) );    		
   931 			const unsigned char* buffer = NULL;
   956 			const unsigned char* buffer = NULL;
   932 			TUint32 len;
   957 			TUint32 len;
   973 
   998 
   974 			if (aFile->IsExecutable() && !fileNullOption)
   999 			if (aFile->IsExecutable() && !fileNullOption)
   975 			{
  1000 			{
   976 				// register the hash
  1001 				// register the hash
   977 				std::wstring basename = localTarget.substr( localTarget.rfind( KDirectorySeparator ) + 1 );
  1002 				std::wstring basename = localTarget.substr( localTarget.rfind( KDirectorySeparator ) + 1 );
   978 				std::wstring hashdir = iSystemDrivePath + L"\\sys\\hash\\";
  1003 				#ifndef __TOOLS2_LINUX__
       
  1004 				// Remove the null character at the end and.
       
  1005 				std::wstring tempStr = iSystemDrivePath.c_str();
       
  1006 				std::wstring hashdir =  tempStr + L"\\sys\\hash\\";				
   979 				std::wstring reghashdir = L"$:\\sys\\hash\\";
  1007 				std::wstring reghashdir = L"$:\\sys\\hash\\";
       
  1008 				#else
       
  1009 				std::wstring hashdir = iSystemDrivePath + L"/sys/hash/";
       
  1010 				std::wstring reghashdir = L"$:/sys/hash/";
       
  1011 				#endif
   980 
  1012 
   981 				if ( !MakeDir( hashdir ) )
  1013 				if ( !MakeDir( hashdir ) )
   982 				{
  1014 				{
   983 					throw InterpretSisError(L"Directory Creation Error - "+hashdir,
  1015 					throw InterpretSisError(L"Directory Creation Error - "+hashdir,
   984 													DIRECTORY_CREATION_ERROR);
  1016 													DIRECTORY_CREATION_ERROR);
   985 				}
  1017 				}
   986 
  1018 
   987 				// hash file is always created on the system drive
  1019 				// hash file is always created on the system drive
   988 				reghashdir[0] = iSystemDrive;
  1020 				reghashdir[0] = iSystemDrive;
   989 
  1021 
   990 				LINFO(L"\tCreating hash: " << reghashdir << basename);
  1022 				LINFO(L"\tCreating hash: " << reghashdir << basename);				
   991 
       
   992 				std::wstring hash = hashdir + basename;
  1023 				std::wstring hash = hashdir + basename;
   993 				HANDLE hFile = MakeSISOpenFile(hash.c_str(), GENERIC_WRITE, CREATE_ALWAYS);		
  1024 				HANDLE hFile = MakeSISOpenFile(hash.c_str(), GENERIC_WRITE, CREATE_ALWAYS);		
   994 				if( INVALID_HANDLE_VALUE == hFile )
  1025 				if( INVALID_HANDLE_VALUE == hFile )
   995 				{
  1026 				{
   996 					throw InterpretSisError(L"FileOpenError - " + hashdir + basename, FILE_ERROR);
  1027 					throw InterpretSisError(L"FileOpenError - " + hashdir + basename, FILE_ERROR);
  1060 	FindAllAdornedVariants(searchNameWild, KSysBinPath, aAdornedFileNamesFound, driveMap);
  1091 	FindAllAdornedVariants(searchNameWild, KSysBinPath, aAdornedFileNamesFound, driveMap);
  1061 
  1092 
  1062 	// find all adorned variants in the ROM/ROFS logs
  1093 	// find all adorned variants in the ROM/ROFS logs
  1063 	if (iParamList.IsFlagSet(CParameterList::EFlagsRomRofsLogFilesSet))
  1094 	if (iParamList.IsFlagSet(CParameterList::EFlagsRomRofsLogFilesSet))
  1064 	{
  1095 	{
       
  1096 	#ifndef __TOOLS2_LINUX__
  1065 		std::wstring romSearchNameWild = L"z:\\sys\\bin\\";
  1097 		std::wstring romSearchNameWild = L"z:\\sys\\bin\\";
       
  1098 	#else
       
  1099 		std::wstring romSearchNameWild = L"z:/sys/bin/";
       
  1100 	#endif
  1066 		romSearchNameWild.append(searchNameWild);
  1101 		romSearchNameWild.append(searchNameWild);
  1067 		iRomManager.FindAllAdornedVariants(romSearchNameWild, aAdornedFileNamesFound);
  1102 		iRomManager.FindAllAdornedVariants(romSearchNameWild, aAdornedFileNamesFound);
  1068 	}
  1103 	}
  1069 }
  1104 }
  1070 
  1105 
  1173 		}
  1208 		}
  1174 		else if (disk == 'z') // case (2)
  1209 		else if (disk == 'z') // case (2)
  1175 		{
  1210 		{
  1176 			// we are eclipsing a ROM file, check if this is authorised:
  1211 			// we are eclipsing a ROM file, check if this is authorised:
  1177 			// see implementation of IsEclipsable()
  1212 			// see implementation of IsEclipsable()
       
  1213 			#ifndef __TOOLS2_LINUX__
  1178 			if (!IsEclipsable(searchNameUnadorned, aSUFlag))
  1214 			if (!IsEclipsable(searchNameUnadorned, aSUFlag))
       
  1215 			#else
       
  1216 			if (!IsEclipsable(searchNameUnadorned, aSUFlag, localDir))
       
  1217 			#endif
  1179 			{
  1218 			{
  1180 				result = false;
  1219 				result = false;
  1181 				break;
  1220 				break;
  1182 			}
  1221 			}
  1183 		}
  1222 		}
  1188 
  1227 
  1189 		// now check to see whether the unadorned or the adorned filename found on 
  1228 		// now check to see whether the unadorned or the adorned filename found on 
  1190 		// this drive should be added to iEclipsableOverwriteFiles.
  1229 		// this drive should be added to iEclipsableOverwriteFiles.
  1191 		if (processEclipsingSuspectsFoundOnThisDrive && unadornedFound)
  1230 		if (processEclipsingSuspectsFoundOnThisDrive && unadornedFound)
  1192 		{
  1231 		{
  1193 			iEclipsableOverwriteFiles.push_back(searchNameUnadorned);
  1232 			iEclipsableOverwriteFiles.push_back(searchNameUnadorned.c_str());
  1194 		}
  1233 		}
  1195 
  1234 
  1196 		if (processEclipsingSuspectsFoundOnThisDrive && adornedFound)
  1235 		if (processEclipsingSuspectsFoundOnThisDrive && adornedFound)
  1197 		{
  1236 		{
  1198 			nrOfAdornedFilenamesFound = adornedFileNamesFound.size();
  1237 			nrOfAdornedFilenamesFound = adornedFileNamesFound.size();
  1204 			{
  1243 			{
  1205 				std::wstring adornedFile = *index;
  1244 				std::wstring adornedFile = *index;
  1206 				int drive = tolower(adornedFile[0]);
  1245 				int drive = tolower(adornedFile[0]);
  1207 				if (drive == disk)
  1246 				if (drive == disk)
  1208 				{
  1247 				{
  1209 					iEclipsableOverwriteFiles.push_back(adornedFile);
  1248 					iEclipsableOverwriteFiles.push_back(adornedFile.c_str());
  1210 				}
  1249 				}
  1211 			}
  1250 			}
  1212 		}
  1251 		}
  1213 	}
  1252 	}
  1214 	// end of loop
  1253 	// end of loop
  1277       and we have z:\sys\bin\A.dll as an eclipsable file or any z:\sys\bin\A{????????}.dll
  1316       and we have z:\sys\bin\A.dll as an eclipsable file or any z:\sys\bin\A{????????}.dll
  1278       then we are allowed to eclipse.
  1317       then we are allowed to eclipse.
  1279  @param aRomFile fully qualified filename in ROM that is to be checked for eclipising (i.e: z:\sys\bin\some.dll)
  1318  @param aRomFile fully qualified filename in ROM that is to be checked for eclipising (i.e: z:\sys\bin\some.dll)
  1280  @param aSUFlag specifies if the installing SIS file has been signed by a SU certificate
  1319  @param aSUFlag specifies if the installing SIS file has been signed by a SU certificate
  1281 */
  1320 */
       
  1321 #ifndef __TOOLS2_LINUX__
  1282 bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag)
  1322 bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag)
       
  1323 #else
       
  1324 bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag, const std::wstring& aDrivePath)
       
  1325 #endif
  1283 {
  1326 {
  1284 	// SA/SP/PU sis + RU flag + signed by SU root cert is allowed
  1327 	// SA/SP/PU sis + RU flag + signed by SU root cert is allowed
  1285 	if (aSUFlag)
  1328 	if (aSUFlag)
  1286 		return true;
  1329 		return true;
  1287 
  1330 
  1301 			isEclipsable = true;
  1344 			isEclipsable = true;
  1302 			break;
  1345 			break;
  1303 		}
  1346 		}
  1304 		else if (goesToSysBin) // case 2
  1347 		else if (goesToSysBin) // case 2
  1305 		{
  1348 		{
       
  1349 			#ifndef __TOOLS2_LINUX__
  1306 			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile))
  1350 			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile))
       
  1351 			#else
       
  1352 			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile,aDrivePath))
       
  1353 			#endif
  1307 			{
  1354 			{
  1308 				isEclipsable = true;
  1355 				isEclipsable = true;
  1309 				break;
  1356 				break;
  1310 			}
  1357 			}
  1311 		}
  1358 		}
  1335 	if (owningUid == 0)
  1382 	if (owningUid == 0)
  1336 	{
  1383 	{
  1337 		// do not display a warning if the installing file is a PA. The user
  1384 		// do not display a warning if the installing file is a PA. The user
  1338 		// needs to copy the installing files to the installing directory
  1385 		// needs to copy the installing files to the installing directory
  1339 		// prior to installing the SIS file.
  1386 		// prior to installing the SIS file.
  1340 		std::string tempTarget = Ucs2ToUtf8(aTarget);
  1387 		std::string tempTarget = wstring2string(aTarget);
  1341   	  	std::wstring targetDisplay = Utf8ToUcs2( tempTarget );
  1388   	  	std::wstring targetDisplay = string2wstring( tempTarget );
  1342 		if (aFile.GetInstallType() == CSISInfo::EInstPreInstalledApp)
  1389 		if (aFile.GetInstallType() == CSISInfo::EInstPreInstalledApp)
  1343 		{
  1390 		{
  1344 			LINFO(targetDisplay << L" found for PA installation");
  1391 			LINFO(targetDisplay << L" found for PA installation");
  1345 		}
  1392 		}
  1346 		else
  1393 		else
  1352 	{
  1399 	{
  1353 		// SP can not overwrite a file in the base pkg
  1400 		// SP can not overwrite a file in the base pkg
  1354 		if (isSp)
  1401 		if (isSp)
  1355 		{
  1402 		{
  1356 			std::wostringstream os;
  1403 			std::wostringstream os;
  1357 			os << aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1404 			os << aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1358 			iProblemFiles.append(os.str());
  1405 			iProblemFiles.append(os.str());
  1359 			iError = ECLIPSING_VIOLATION;
  1406 			iError = ECLIPSING_VIOLATION;
  1360 		}
  1407 		}
  1361 	}
  1408 	}
  1362 	else
  1409 	else
  1365 		// PU/SA can not overwrite a file belonging to a different base pkg unless it has been signed by
  1412 		// PU/SA can not overwrite a file belonging to a different base pkg unless it has been signed by
  1366 		// a SU cert
  1413 		// a SU cert
  1367 		if (isSp || (!aSUFlag && (isPu || isSa)))
  1414 		if (isSp || (!aSUFlag && (isPu || isSa)))
  1368 		{
  1415 		{
  1369 			std::wostringstream os;
  1416 			std::wostringstream os;
  1370 			os << aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1417 			os << aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1371 			iProblemFiles.append(os.str());
  1418 			iProblemFiles.append(os.str());
  1372 			iError = ECLIPSING_VIOLATION;
  1419 			iError = ECLIPSING_VIOLATION;
  1373 		}
  1420 		}
  1374 		else
  1421 		else
  1375 		{
  1422 		{
  1376 			LWARN(aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"");
  1423 		    LWARN(aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"");
  1377 		}
  1424 		}
  1378 	}
  1425 	}
  1379 }
  1426 }
  1380 
  1427 
  1381 void Installer::WarnEclipseOverWrite(const SisFile& aFile)
  1428 void Installer::WarnEclipseOverWrite(const SisFile& aFile)
  1391 		for ( ; curr != end; ++curr)
  1438 		for ( ; curr != end; ++curr)
  1392 		{
  1439 		{
  1393 			std::wstring eclipseFile(*curr);
  1440 			std::wstring eclipseFile(*curr);
  1394 
  1441 
  1395 			TUint32 owningUid = 0;
  1442 			TUint32 owningUid = 0;
  1396 			const SisRegistryObject* owningObj = iRegistry.OwningPackage(eclipseFile, owningUid);
  1443 			const SisRegistryObject* owningObj = iRegistry.OwningPackage(eclipseFile.c_str(), owningUid);
  1397 			
  1444 			
  1398 			// always allow orphaned file overwriting
  1445 			// always allow orphaned file overwriting
  1399 			if (owningUid == 0)
  1446 			if (owningUid == 0)
  1400 			{
  1447 			{
  1401 				LWARN(eclipseFile << L" eclipses orphaned file.");
  1448 			    LWARN(eclipseFile.c_str() << L" eclipses orphaned file.");
  1402 			}
  1449 			}
  1403 			else
  1450 			else
  1404 			{
  1451 			{
  1405 				// SP/PU can not overwrite a file belonging to a different base pkg or
  1452 				// SP/PU can not overwrite a file belonging to a different base pkg or
  1406 				// SP/PU can not eclipse a base package which is not in the ROM.
  1453 				// SP/PU can not eclipse a base package which is not in the ROM.
  1407 				std::wostringstream os;
  1454 				std::wostringstream os;
  1408 				os << eclipseFile << L" eclipses file from package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1455 				os << eclipseFile.c_str() << L" eclipses file from package 0x"  << std::hex << owningUid << L" \"" << owningObj->GetPackageName().c_str() << L"\""<< std::endl;
  1409 				iProblemFiles.append(os.str());
  1456 				iProblemFiles.append(os.str());
  1410 				iError = ECLIPSING_VIOLATION;
  1457 				iError = ECLIPSING_VIOLATION;
  1411 				continue;
  1458 				continue;
  1412 			}
  1459 			}
  1413 		}		
  1460 		}		
  1425 	iError = SUCCESS;
  1472 	iError = SUCCESS;
  1426 
  1473 
  1427 	Sids sids;
  1474 	Sids sids;
  1428 	GetSidsFromInstallable(aFiles, sids);
  1475 	GetSidsFromInstallable(aFiles, sids);
  1429 
  1476 
       
  1477 	#ifndef __TOOLS2_LINUX__
  1430 	const std::wstring privatePath = L":\\private\\";
  1478 	const std::wstring privatePath = L":\\private\\";
  1431 	const std::wstring sysPath = L":\\sys\\";
  1479 	const std::wstring sysPath = L":\\sys\\";
  1432 	const std::wstring sysBinPath = L":\\sys\\bin\\";
  1480 	const std::wstring sysBinPath = L":\\sys\\bin\\";
  1433 	const std::wstring resourcePath = L":\\resource\\";
  1481 	const std::wstring resourcePath = L":\\resource\\";
       
  1482 	#else
       
  1483 	const std::wstring privatePath = L":/private/";
       
  1484 	const std::wstring sysPath = L":/sys/";
       
  1485 	const std::wstring sysBinPath = L":/sys/bin/";
       
  1486 	const std::wstring resourcePath = L":/resource/";
       
  1487 	#endif
  1434 	const std::wstring exeType = L".exe";
  1488 	const std::wstring exeType = L".exe";
  1435 
  1489 
  1436     int num_of_files = aFiles.size();
  1490     int num_of_files = aFiles.size();
  1437 	TUint32 pkgUid = aFile.GetPackageUid();
  1491 	TUint32 pkgUid = aFile.GetPackageUid();
  1438 	TUint32 installType = aFile.GetInstallType();
  1492 	TUint32 installType = aFile.GetInstallType();
  1455 	{   
  1509 	{   
  1456 		const InstallableFile* file = aFiles[ ii ];
  1510 		const InstallableFile* file = aFiles[ ii ];
  1457         const CSISFileDescription* sisDescription = file->FileDescription();
  1511         const CSISFileDescription* sisDescription = file->FileDescription();
  1458 
  1512 
  1459 		// file to be installed
  1513 		// file to be installed
  1460 		std::wstring target( file->GetTarget() );
  1514 		std::wstring target( file->GetTarget().c_str() );
  1461 
  1515 
  1462 		if (sisDescription->Operation() == CSISFileDescription::EOpText)
  1516 		if (sisDescription->Operation() == CSISFileDescription::EOpText)
  1463 			break;
  1517 			break;
  1464 		if (sisDescription->Operation() == CSISFileDescription::EOpNull)
  1518 		if (sisDescription->Operation() == CSISFileDescription::EOpNull)
  1465 			{
  1519 			{
  1466 			// a FN file can not remove a file from \sys or \resource
  1520 			// a FN file can not remove a file from \sys or \resource
  1467 			if ((target.find(sysPath,0) != std::wstring::npos) || (target.find(resourcePath,0) != std::wstring::npos))
  1521 			if ((target.find(sysPath,0) != std::wstring::npos) || (target.find(resourcePath,0) != std::wstring::npos))
  1468 				{
  1522 				{
  1469 				// eclipsing problem
  1523 				// eclipsing problem
  1470 				std::wostringstream os;
  1524 				std::wostringstream os;
  1471 				os << L"FN file \"" << target << L"\" can not remove a file from \\sys or \\resource" << std::endl;
  1525 				os << L"FN file \"" << target.c_str() << L"\" can not remove a file from \\sys or \\resource" << std::endl;
  1472 				iProblemFiles.append(os.str());
  1526 				iProblemFiles.append(os.str());
  1473 				iError = DATA_CAGE_VIOLATION;
  1527 				iError = DATA_CAGE_VIOLATION;
  1474 				continue;
  1528 				continue;
  1475 				}
  1529 				}
  1476 			}
  1530 			}
  1477         else 
  1531         else 
  1478             {
  1532             {
  1479 			std::wstring realTarget(file->GetLocalTarget());
  1533 			std::wstring realTarget(file->GetLocalTarget().c_str());
  1480 
  1534 
  1481 		    std::wstring romTarget(target);
  1535 		    std::wstring romTarget(target);
  1482 			romTarget[0] = KRomDriveLetter;
  1536 			romTarget[0] = KRomDriveLetter;
  1483 
  1537 
  1484 			// check to see if we are legally allowed to eclipse a ROM file 
  1538 			// check to see if we are legally allowed to eclipse a ROM file 
  1486 			{
  1540 			{
  1487 				if (!ValidEclipse(aFile, target, *file, suFlag))
  1541 				if (!ValidEclipse(aFile, target, *file, suFlag))
  1488 				{
  1542 				{
  1489 					// eclipsing problem
  1543 					// eclipsing problem
  1490 					std::wostringstream os;
  1544 					std::wostringstream os;
  1491 					os << target << L" eclipses file from ROM" << std::endl;
  1545 					os << target.c_str() << L" eclipses file from ROM" << std::endl;
  1492 					iProblemFiles.append(os.str());
  1546 					iProblemFiles.append(os.str());
       
  1547 
  1493 					iError = ECLIPSING_VIOLATION;
  1548 					iError = ECLIPSING_VIOLATION;
  1494 					continue;
  1549 					continue;
  1495 				}
  1550 				}
  1496 			}
  1551 			}
  1497 			
  1552 			
  1538 						// this package is trying to write to a SID's private directory 
  1593 						// this package is trying to write to a SID's private directory 
  1539 						// which does not belong to this package
  1594 						// which does not belong to this package
  1540 
  1595 
  1541 						const int KUidStringLength = 8;
  1596 						const int KUidStringLength = 8;
  1542 						std::wstring importPath = privatePath;
  1597 						std::wstring importPath = privatePath;
  1543 
  1598 						#ifndef __TOOLS2_LINUX__
  1544 						importPath.append( uidStr.str() + L"\\import" );
  1599 						importPath.append( uidStr.str() + L"\\import" );
       
  1600 						#else
       
  1601 						importPath.append( uidStr.str() + L"/import" );
       
  1602 						#endif
  1545 
  1603 
  1546 						if ((target.find(importPath,0) == std::wstring::npos) && !suFlag)
  1604 						if ((target.find(importPath,0) == std::wstring::npos) && !suFlag)
  1547 						{
  1605 						{
  1548 							// only SA with RU + SU and PU with RU + SU flag can override other private directory
  1606 							// only SA with RU + SU and PU with RU + SU flag can override other private directory
  1549 							std::wostringstream os;
  1607 							std::wostringstream os;
  1550 							os << target << L" cannot be written to a private directory which "
  1608 							os << target.c_str() << L" cannot be written to a private directory which "
  1551 								<< L"does not belong to any exe in this package" << std::endl;
  1609 								<< L"does not belong to any exe in this package" << std::endl;
  1552 							iProblemFiles.append(os.str());
  1610 							iProblemFiles.append(os.str());
  1553 							iError = DATA_CAGE_VIOLATION;
  1611 							iError = DATA_CAGE_VIOLATION;
  1554 							continue;
  1612 							continue;
  1555 						}
  1613 						}
  1615 					
  1673 					
  1616 					if (!allowSidEclipse)
  1674 					if (!allowSidEclipse)
  1617 					{
  1675 					{
  1618 						std::wostringstream os;
  1676 						std::wostringstream os;
  1619 										
  1677 										
  1620 						os << L"The existing file " << owningSidFile << L" already has the SID 0x" << std::hex << sid
  1678 						os << L"The existing file " << owningSidFile.c_str() << L" already has the SID 0x" << std::hex << sid
  1621 						   << std::dec << L", cannot install " << target << std::endl;
  1679 						   << std::dec << L", cannot install " << target.c_str() << std::endl;
  1622 						iProblemFiles.append(os.str());
  1680 						iProblemFiles.append(os.str());
  1623 						iError = DUPLICATE_SID;
  1681 						iError = DUPLICATE_SID;
  1624 						continue;
  1682 						continue;
  1625 					}
  1683 					}
  1626 				}
  1684 				}
  1640 							sisController->InstallBlock().GetFileList(fileDesList);
  1698 							sisController->InstallBlock().GetFileList(fileDesList);
  1641 							for(TFileDescListConstIter iter = fileDesList.begin(); iter != fileDesList.end(); ++iter)
  1699 							for(TFileDescListConstIter iter = fileDesList.begin(); iter != fileDesList.end(); ++iter)
  1642 							{
  1700 							{
  1643 								const CSISFileDescription* fD = *iter;
  1701 								const CSISFileDescription* fD = *iter;
  1644 
  1702 
  1645 								std::wstring romStubTarget(fD->Target().GetString());
  1703 								std::wstring romStubTarget(fD->Target().GetString().c_str());
  1646 
  1704 
  1647 								if (StringUtils::WildcardCompare(romStubTarget,romFileWithDuplicateSid))
  1705 								if (StringUtils::WildcardCompare(romStubTarget,romFileWithDuplicateSid))
  1648 								{
  1706 								{
  1649 									ownedByRomStub = true;
  1707 									ownedByRomStub = true;
  1650 									break;
  1708 									break;
  1661 					if (!allowSidEclipse && !ownedByRomStub)
  1719 					if (!allowSidEclipse && !ownedByRomStub)
  1662 					{
  1720 					{
  1663 						std::wostringstream os;
  1721 						std::wostringstream os;
  1664 											
  1722 											
  1665 						os << L"A ROM file already has the SID 0x" << std::hex << file->Sid()
  1723 						os << L"A ROM file already has the SID 0x" << std::hex << file->Sid()
  1666 						   << std::dec << L", cannot install " << target << std::endl;
  1724 						   << std::dec << L", cannot install " << target.c_str() << std::endl;
  1667 						iProblemFiles.append(os.str());
  1725 						iProblemFiles.append(os.str());
  1668 						iError = DUPLICATE_SID;
  1726 						iError = DUPLICATE_SID;
  1669 						continue;
  1727 						continue;
  1670 					}
  1728 					}
  1671 				}
  1729 				}
  1672 		    }
  1730 		    }
  1673 		    else if (realTarget.find(sysBinPath) != std::wstring::npos)
  1731 		    else if (realTarget.find(sysBinPath) != std::wstring::npos)
  1674 		    {
  1732 		    {
  1675 				std::wostringstream os;
  1733 				std::wostringstream os;
  1676 				os << target << L" cannot be installed to a data caged area" << std::endl;
  1734 				os << target.c_str() << L" cannot be installed to a data caged area" << std::endl;
  1677 				iProblemFiles.append(os.str());
  1735 				iProblemFiles.append(os.str());
  1678 				iError = DATA_CAGE_VIOLATION;
  1736 				iError = DATA_CAGE_VIOLATION;
  1679 				continue;
  1737 				continue;
  1680 		    }
  1738 		    }
  1681         }
  1739         }
  1687 	iEclipsableOverwriteFiles.clear();
  1745 	iEclipsableOverwriteFiles.clear();
  1688 	iEclipsableRomFiles.clear();
  1746 	iEclipsableRomFiles.clear();
  1689 
  1747 
  1690 	if (!iProblemFiles.empty())
  1748 	if (!iProblemFiles.empty())
  1691 	{
  1749 	{
  1692 		std::string x;
  1750 		std::string x = wstring2string(iProblemFiles);
  1693 		throw InvalidSis("", Ucs2ToUtf8(iProblemFiles,x), iError);
  1751 		throw InvalidSis("", x, iError);
  1694 	}
  1752 	}
  1695 }
  1753 }
  1696 
  1754 
  1697 void Installer::SetupExpressionEnvironment(const SisFile& aFile, const SisRegistry& aSisRegistry, RomManager& aRomManager )
  1755 void Installer::SetupExpressionEnvironment(const SisFile& aFile, const SisRegistry& aSisRegistry, RomManager& aRomManager )
  1698 {
  1756 {
  1726 
  1784 
  1727 void Installer::CreateStubSisFile(const InstallSISFile& aInstallSISFile, SisFile& aSis)
  1785 void Installer::CreateStubSisFile(const InstallSISFile& aInstallSISFile, SisFile& aSis)
  1728 {
  1786 {
  1729 	int targetDrive = aInstallSISFile.iTargetDrive;
  1787 	int targetDrive = aInstallSISFile.iTargetDrive;
  1730 	std::wstring drivePath = iConfigManager.GetLocalDrivePath(targetDrive);
  1788 	std::wstring drivePath = iConfigManager.GetLocalDrivePath(targetDrive);
  1731 	
  1789 	#ifndef __TOOLS2_LINUX__
  1732 	drivePath.append(L"\\private\\");
  1790 	drivePath.append(L"\\private\\");
       
  1791 	#else
       
  1792 	drivePath.append(L"/private/");
       
  1793 	#endif
  1733 
  1794 
  1734 	// build SwiDaemon Pathname
  1795 	// build SwiDaemon Pathname
  1735 	std::wstring ctrl = StringUtils::MakePathFromSID(drivePath, KSwiDaemonUid);
  1796 	std::wstring ctrl = StringUtils::MakePathFromSID(drivePath, KSwiDaemonUid);
  1736 
  1797 
  1737 	if ( !MakeDir( ctrl ) )
  1798 	if ( !MakeDir( ctrl ) )
  1741 
  1802 
  1742 	std::wstringstream s;
  1803 	std::wstringstream s;
  1743 	s << std::hex << aSis.GetPackageUid();
  1804 	s << std::hex << aSis.GetPackageUid();
  1744 
  1805 
  1745 	ctrl.append(s.str());
  1806 	ctrl.append(s.str());
  1746 
       
  1747 
  1807 
  1748 	switch(aSis.GetInstallType())
  1808 	switch(aSis.GetInstallType())
  1749     {
  1809     {
  1750 	case CSISInfo::EInstInstallation:
  1810 	case CSISInfo::EInstInstallation:
  1751 	case CSISInfo::EInstPreInstalledApp:
  1811 	case CSISInfo::EInstPreInstalledApp: