sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\t_sysbin.cpp sl@0: // sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: _LIT(KCheckFailed,"Check failed %d != %d\n"); sl@0: sl@0: #define CHECK_EQ(a,b) { if(a!=b) { test.Printf(KCheckFailed,a,b); test(0); } } sl@0: sl@0: RTest test(_L("T_SYSBIN")); sl@0: sl@0: TBool SysBinEnforced = 0; sl@0: TBool RunningFromROM; sl@0: sl@0: RFs TheFs; sl@0: CFileMan* TheFileMan; sl@0: sl@0: void CheckFileName(RProcess aProcess, const TDesC& aFileName) sl@0: { sl@0: TFileName fileName = aProcess.FileName(); sl@0: test(fileName.MatchF(aFileName)==0); sl@0: } sl@0: sl@0: _LIT(KExeAInSysBin,"z:\\sys\\bin\\t_sysbina.exe"); sl@0: _LIT(KExeBInSystemPrograms,"z:\\system\\programs\\t_sysbinb.exe"); sl@0: _LIT(KDllAInSysBin,"z:\\sys\\bin\\t_sysbin_dlla.dll"); sl@0: _LIT(KDllBInSystemLibs,"z:\\system\\libs\\t_sysbin_dllb.dll"); sl@0: #ifndef __WINS__ sl@0: _LIT(KExeBInSysBin,"z:\\sys\\bin\\t_sysbinb.exe"); sl@0: _LIT(KDllBInSysBin,"z:\\sys\\bin\\t_sysbin_dllb.dll"); sl@0: #endif sl@0: _LIT(KRamDll,"z:\\sys\\bin\\t_sysbin_dll_ram.dll"); sl@0: _LIT(KDllCInCTest,"c:\\sysbin_test\\t_sysbin_dllc.dll"); sl@0: _LIT(KDllC,"t_sysbin_dllc.dll"); sl@0: _LIT(KDllDInCSysBinTest,"c:\\sys\\bin\\test\\t_sysbin_dlld.dll"); sl@0: _LIT(KDllD,"t_sysbin_dlld.dll"); sl@0: sl@0: sl@0: void CheckFileName(RLibrary aLibrary, const TDesC& aFileName) sl@0: { sl@0: TFileName fileName = aLibrary.FileName(); sl@0: test(fileName.MatchF(aFileName)==0); sl@0: } sl@0: sl@0: sl@0: sl@0: void TestExeB(const TDesC& aFileName) sl@0: { sl@0: RProcess p; sl@0: TInt r = p.Create(aFileName,KNullDesC); sl@0: if(SysBinEnforced) sl@0: { sl@0: #ifdef __WINS__ sl@0: CHECK_EQ(r,KErrNotFound) sl@0: #else sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeBInSysBin); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: #endif sl@0: } sl@0: else sl@0: { sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeBInSystemPrograms); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: void TestDllB(const TDesC& aFileName) sl@0: { sl@0: RLibrary l; sl@0: TInt r = l.Load(aFileName); sl@0: if(SysBinEnforced) sl@0: { sl@0: #ifdef __WINS__ sl@0: CHECK_EQ(r,KErrNotFound) sl@0: #else sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllBInSysBin); sl@0: l.Close(); sl@0: #endif sl@0: } sl@0: else sl@0: { sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllBInSystemLibs); sl@0: l.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: void TestDllC(const TDesC& aFileName,const TDesC& aPath) sl@0: { sl@0: RLibrary l; sl@0: test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath); sl@0: TInt r = l.Load(aFileName,aPath); sl@0: if(SysBinEnforced) sl@0: CHECK_EQ(r,KErrNotFound) sl@0: else sl@0: { sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllCInCTest); sl@0: l.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: void TestDllD(const TDesC& aFileName,const TDesC& aPath) sl@0: { sl@0: RLibrary l; sl@0: test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath); sl@0: TInt r = l.Load(aFileName,aPath); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllDInCSysBinTest); sl@0: l.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: SysBinEnforced=PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin); sl@0: sl@0: TInt r; sl@0: RProcess p; sl@0: RLibrary l; sl@0: sl@0: test.Title(); sl@0: sl@0: test( KErrNone == TheFs.Connect() ); sl@0: RunningFromROM = TheFs.IsFileInRom(RProcess().FileName())!=0; sl@0: sl@0: // Turn off evil lazy dll unloading sl@0: { sl@0: RLoader l; sl@0: test_KErrNone(l.Connect()); sl@0: test_KErrNone(l.CancelLazyDllUnload()); sl@0: l.Close(); sl@0: } sl@0: sl@0: CTrapCleanup* ct = CTrapCleanup::New(); sl@0: test_NotNull(ct); sl@0: TRAP(r, TheFileMan=CFileMan::NewL(TheFs)); sl@0: test_KErrNone(r); sl@0: sl@0: test.Start(_L("Check loading an EXE which lives in \\SYS\\BIN")); sl@0: sl@0: test.Start(_L("Load without path or ext")); sl@0: r = p.Create(_L("T_SYSBINa"),KNullDesC); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeAInSysBin); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: sl@0: test.Next(_L("Load without path")); sl@0: r = p.Create(_L("T_SYSBINa.EXE"),KNullDesC); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeAInSysBin); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: sl@0: test.Next(_L("Load with path but without ext")); sl@0: r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa"),KNullDesC); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeAInSysBin); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: sl@0: test.Next(_L("Load with path and ext")); sl@0: r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa.EXE"),KNullDesC); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeAInSysBin); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: sl@0: test.Next(_L("Load with SYSTEM\\PROGRAMS path and without ext")); sl@0: r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa"),KNullDesC); sl@0: if(!SysBinEnforced) sl@0: CHECK_EQ(r,KErrNotFound) sl@0: else sl@0: { sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeAInSysBin); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: } sl@0: sl@0: test.Next(_L("Load with SYSTEM\\PROGRAMS path and with ext")); sl@0: r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa.EXE"),KNullDesC); sl@0: if(!SysBinEnforced) sl@0: CHECK_EQ(r,KErrNotFound) sl@0: else sl@0: { sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(p,KExeAInSysBin); sl@0: p.Terminate(0); sl@0: p.Close(); sl@0: } sl@0: sl@0: test.End(); sl@0: sl@0: test.Next(_L("Check loading an EXE which lives in \\SYSTEM\\PROGRAMS")); sl@0: sl@0: if(!RunningFromROM) sl@0: { sl@0: test.Printf(_L("TESTS NOT RUN - Not running from ROM")); sl@0: } sl@0: else sl@0: { sl@0: test.Start(_L("Load without path or ext")); sl@0: TestExeB(_L("T_SYSBINb")); sl@0: sl@0: test.Next(_L("Load without path")); sl@0: TestExeB(_L("T_SYSBINb.EXE")); sl@0: sl@0: test.Next(_L("Load with path but without ext")); sl@0: TestExeB(_L("\\System\\programs\\T_SYSBINb")); sl@0: sl@0: test.Next(_L("Load with path and ext")); sl@0: TestExeB(_L("\\System\\programs\\T_SYSBINb.EXE")); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN")); sl@0: sl@0: test.Start(_L("Load without path or ext")); sl@0: r = l.Load(_L("T_SYSBIN_DLLa")); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllAInSysBin); sl@0: l.Close(); sl@0: sl@0: test.Next(_L("Load without path")); sl@0: r = l.Load(_L("T_SYSBIN_DLLa.DLL")); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllAInSysBin); sl@0: l.Close(); sl@0: sl@0: test.Next(_L("Load with path but without ext")); sl@0: r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa")); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllAInSysBin); sl@0: l.Close(); sl@0: sl@0: test.Next(_L("Load with path and ext")); sl@0: r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa.DLL")); sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllAInSysBin); sl@0: l.Close(); sl@0: sl@0: test.Next(_L("Load with SYSTEM\\LIBS path and without ext")); sl@0: r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa")); sl@0: if(!SysBinEnforced) sl@0: CHECK_EQ(r,KErrNotFound) sl@0: else sl@0: { sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllAInSysBin); sl@0: l.Close(); sl@0: } sl@0: sl@0: test.Next(_L("Load with SYSTEM\\LIBS path and with ext")); sl@0: r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa.DLL")); sl@0: if(!SysBinEnforced) sl@0: CHECK_EQ(r,KErrNotFound) sl@0: else sl@0: { sl@0: CHECK_EQ(r,KErrNone) sl@0: CheckFileName(l,KDllAInSysBin); sl@0: l.Close(); sl@0: } sl@0: sl@0: test.End(); sl@0: sl@0: test.Next(_L("Check loading an DLL which lives in \\SYSTEM\\LIBS")); sl@0: sl@0: if(!RunningFromROM) sl@0: { sl@0: test.Printf(_L("TESTS NOT RUN - Not running from ROM")); sl@0: } sl@0: else sl@0: { sl@0: test.Start(_L("Load without path or ext")); sl@0: TestDllB(_L("T_SYSBIN_DLLb")); sl@0: sl@0: test.Next(_L("Load without path")); sl@0: TestDllB(_L("T_SYSBIN_DLLb.DLL")); sl@0: sl@0: test.Next(_L("Load with path but without ext")); sl@0: TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb")); sl@0: sl@0: test.Next(_L("Load with path and ext")); sl@0: TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb.DLL")); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: test.Next(_L("Check loading an DLL which lives in \\SYSBIN_TEST")); sl@0: sl@0: r = TheFileMan->Copy(KRamDll,KDllCInCTest,CFileMan::ERecurse); sl@0: test_KErrNone(r); sl@0: sl@0: test.Start(_L("Load using full path+name")); sl@0: TestDllC(KDllCInCTest,KNullDesC); sl@0: sl@0: test.Next(_L("Load using separate search path")); sl@0: TestDllC(KDllC,_L("\\sysbin_test\\")); sl@0: #ifndef __WINS__ sl@0: TestDllC(KDllC,_L("\\sysbin_test")); sl@0: TestDllC(KDllC,_L("sysbin_test\\")); sl@0: TestDllC(KDllC,_L("sysbin_test")); sl@0: #endif sl@0: sl@0: TestDllC(KDllC,_L("c:\\sysbin_test\\")); sl@0: #ifndef __WINS__ sl@0: TestDllC(KDllC,_L("c:\\sysbin_test")); sl@0: TestDllC(KDllC,_L("c:sysbin_test\\")); sl@0: TestDllC(KDllC,_L("c:sysbin_test")); sl@0: #endif sl@0: sl@0: test.End(); sl@0: sl@0: _LIT(KCTestPath,"c:\\sysbin_test\\"); sl@0: r = TheFileMan->RmDir(KCTestPath); sl@0: test_KErrNone(r); sl@0: sl@0: test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN\\TEST")); sl@0: sl@0: r = TheFileMan->Copy(KRamDll,KDllDInCSysBinTest,CFileMan::ERecurse); sl@0: test_KErrNone(r); sl@0: sl@0: test.Start(_L("Load using full path+name")); sl@0: TestDllD(KDllDInCSysBinTest,KNullDesC); sl@0: sl@0: test.Next(_L("Load using separate search path")); sl@0: TestDllD(KDllD,_L("\\sys\\bin\\test\\")); sl@0: #ifndef __WINS__ sl@0: TestDllD(KDllD,_L("\\sys\\bin\\test")); sl@0: TestDllD(KDllD,_L("sys\\bin\\test")); sl@0: TestDllD(KDllD,_L("sys\\bin\\test\\")); sl@0: #endif sl@0: sl@0: TestDllD(KDllD,_L("c:\\sys\\bin\\test\\")); sl@0: #ifndef __WINS__ sl@0: TestDllD(KDllD,_L("c:\\sys\\bin\\test")); sl@0: TestDllD(KDllD,_L("c:sys\\bin\\test\\")); sl@0: TestDllD(KDllD,_L("c:sys\\bin\\test")); sl@0: #endif sl@0: sl@0: TestDllD(KDllD,_L("\\dummy;\\sys\\bin\\test\\")); sl@0: TestDllD(KDllD,_L("\\sys\\bin\\test\\;\\dummy2")); sl@0: TestDllD(KDllD,_L("\\dummy1;\\sys\\bin\\test2;\\sys\\bin\\test\\")); sl@0: sl@0: TestDllD(KDllD,_L("c:\\dummy;c:\\sys\\bin\\test\\")); sl@0: TestDllD(KDllD,_L("c:\\sys\\bin\\test\\;c:\\dummy2")); sl@0: TestDllD(KDllD,_L("c:\\dummy1;c:\\sys\\bin\\test2;c:\\sys\\bin\\test\\")); sl@0: sl@0: test.End(); sl@0: sl@0: _LIT(KCTestPath2,"c:\\sys\\bin\\test\\"); sl@0: r = TheFileMan->RmDir(KCTestPath2); sl@0: test_KErrNone(r); sl@0: sl@0: test.End(); sl@0: return(0); sl@0: }