0
|
1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// f32test\server\t_sysbin.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#define __E32TEST_EXTENSION__
|
|
19 |
#include <e32test.h>
|
|
20 |
#include <f32file.h>
|
|
21 |
|
|
22 |
_LIT(KCheckFailed,"Check failed %d != %d\n");
|
|
23 |
|
|
24 |
#define CHECK_EQ(a,b) { if(a!=b) { test.Printf(KCheckFailed,a,b); test(0); } }
|
|
25 |
|
|
26 |
RTest test(_L("T_SYSBIN"));
|
|
27 |
|
|
28 |
TBool SysBinEnforced = 0;
|
|
29 |
TBool RunningFromROM;
|
|
30 |
|
|
31 |
RFs TheFs;
|
|
32 |
CFileMan* TheFileMan;
|
|
33 |
|
|
34 |
void CheckFileName(RProcess aProcess, const TDesC& aFileName)
|
|
35 |
{
|
|
36 |
TFileName fileName = aProcess.FileName();
|
|
37 |
test(fileName.MatchF(aFileName)==0);
|
|
38 |
}
|
|
39 |
|
|
40 |
_LIT(KExeAInSysBin,"z:\\sys\\bin\\t_sysbina.exe");
|
|
41 |
_LIT(KExeBInSystemPrograms,"z:\\system\\programs\\t_sysbinb.exe");
|
|
42 |
_LIT(KDllAInSysBin,"z:\\sys\\bin\\t_sysbin_dlla.dll");
|
|
43 |
_LIT(KDllBInSystemLibs,"z:\\system\\libs\\t_sysbin_dllb.dll");
|
|
44 |
#ifndef __WINS__
|
|
45 |
_LIT(KExeBInSysBin,"z:\\sys\\bin\\t_sysbinb.exe");
|
|
46 |
_LIT(KDllBInSysBin,"z:\\sys\\bin\\t_sysbin_dllb.dll");
|
|
47 |
#endif
|
|
48 |
_LIT(KRamDll,"z:\\sys\\bin\\t_sysbin_dll_ram.dll");
|
|
49 |
_LIT(KDllCInCTest,"c:\\sysbin_test\\t_sysbin_dllc.dll");
|
|
50 |
_LIT(KDllC,"t_sysbin_dllc.dll");
|
|
51 |
_LIT(KDllDInCSysBinTest,"c:\\sys\\bin\\test\\t_sysbin_dlld.dll");
|
|
52 |
_LIT(KDllD,"t_sysbin_dlld.dll");
|
|
53 |
|
|
54 |
|
|
55 |
void CheckFileName(RLibrary aLibrary, const TDesC& aFileName)
|
|
56 |
{
|
|
57 |
TFileName fileName = aLibrary.FileName();
|
|
58 |
test(fileName.MatchF(aFileName)==0);
|
|
59 |
}
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
void TestExeB(const TDesC& aFileName)
|
|
64 |
{
|
|
65 |
RProcess p;
|
|
66 |
TInt r = p.Create(aFileName,KNullDesC);
|
|
67 |
if(SysBinEnforced)
|
|
68 |
{
|
|
69 |
#ifdef __WINS__
|
|
70 |
CHECK_EQ(r,KErrNotFound)
|
|
71 |
#else
|
|
72 |
CHECK_EQ(r,KErrNone)
|
|
73 |
CheckFileName(p,KExeBInSysBin);
|
|
74 |
p.Terminate(0);
|
|
75 |
p.Close();
|
|
76 |
#endif
|
|
77 |
}
|
|
78 |
else
|
|
79 |
{
|
|
80 |
CHECK_EQ(r,KErrNone)
|
|
81 |
CheckFileName(p,KExeBInSystemPrograms);
|
|
82 |
p.Terminate(0);
|
|
83 |
p.Close();
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
void TestDllB(const TDesC& aFileName)
|
|
90 |
{
|
|
91 |
RLibrary l;
|
|
92 |
TInt r = l.Load(aFileName);
|
|
93 |
if(SysBinEnforced)
|
|
94 |
{
|
|
95 |
#ifdef __WINS__
|
|
96 |
CHECK_EQ(r,KErrNotFound)
|
|
97 |
#else
|
|
98 |
CHECK_EQ(r,KErrNone)
|
|
99 |
CheckFileName(l,KDllBInSysBin);
|
|
100 |
l.Close();
|
|
101 |
#endif
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
CHECK_EQ(r,KErrNone)
|
|
106 |
CheckFileName(l,KDllBInSystemLibs);
|
|
107 |
l.Close();
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
void TestDllC(const TDesC& aFileName,const TDesC& aPath)
|
|
114 |
{
|
|
115 |
RLibrary l;
|
|
116 |
test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
|
|
117 |
TInt r = l.Load(aFileName,aPath);
|
|
118 |
if(SysBinEnforced)
|
|
119 |
CHECK_EQ(r,KErrNotFound)
|
|
120 |
else
|
|
121 |
{
|
|
122 |
CHECK_EQ(r,KErrNone)
|
|
123 |
CheckFileName(l,KDllCInCTest);
|
|
124 |
l.Close();
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
void TestDllD(const TDesC& aFileName,const TDesC& aPath)
|
|
131 |
{
|
|
132 |
RLibrary l;
|
|
133 |
test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
|
|
134 |
TInt r = l.Load(aFileName,aPath);
|
|
135 |
CHECK_EQ(r,KErrNone)
|
|
136 |
CheckFileName(l,KDllDInCSysBinTest);
|
|
137 |
l.Close();
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
GLDEF_C TInt E32Main()
|
|
143 |
{
|
|
144 |
SysBinEnforced=PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin);
|
|
145 |
|
|
146 |
TInt r;
|
|
147 |
RProcess p;
|
|
148 |
RLibrary l;
|
|
149 |
|
|
150 |
test.Title();
|
|
151 |
|
|
152 |
test( KErrNone == TheFs.Connect() );
|
|
153 |
RunningFromROM = TheFs.IsFileInRom(RProcess().FileName())!=0;
|
|
154 |
|
|
155 |
// Turn off evil lazy dll unloading
|
|
156 |
{
|
|
157 |
RLoader l;
|
|
158 |
test_KErrNone(l.Connect());
|
|
159 |
test_KErrNone(l.CancelLazyDllUnload());
|
|
160 |
l.Close();
|
|
161 |
}
|
|
162 |
|
|
163 |
CTrapCleanup* ct = CTrapCleanup::New();
|
|
164 |
test_NotNull(ct);
|
|
165 |
TRAP(r, TheFileMan=CFileMan::NewL(TheFs));
|
|
166 |
test_KErrNone(r);
|
|
167 |
|
|
168 |
test.Start(_L("Check loading an EXE which lives in \\SYS\\BIN"));
|
|
169 |
|
|
170 |
test.Start(_L("Load without path or ext"));
|
|
171 |
r = p.Create(_L("T_SYSBINa"),KNullDesC);
|
|
172 |
CHECK_EQ(r,KErrNone)
|
|
173 |
CheckFileName(p,KExeAInSysBin);
|
|
174 |
p.Terminate(0);
|
|
175 |
p.Close();
|
|
176 |
|
|
177 |
test.Next(_L("Load without path"));
|
|
178 |
r = p.Create(_L("T_SYSBINa.EXE"),KNullDesC);
|
|
179 |
CHECK_EQ(r,KErrNone)
|
|
180 |
CheckFileName(p,KExeAInSysBin);
|
|
181 |
p.Terminate(0);
|
|
182 |
p.Close();
|
|
183 |
|
|
184 |
test.Next(_L("Load with path but without ext"));
|
|
185 |
r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa"),KNullDesC);
|
|
186 |
CHECK_EQ(r,KErrNone)
|
|
187 |
CheckFileName(p,KExeAInSysBin);
|
|
188 |
p.Terminate(0);
|
|
189 |
p.Close();
|
|
190 |
|
|
191 |
test.Next(_L("Load with path and ext"));
|
|
192 |
r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa.EXE"),KNullDesC);
|
|
193 |
CHECK_EQ(r,KErrNone)
|
|
194 |
CheckFileName(p,KExeAInSysBin);
|
|
195 |
p.Terminate(0);
|
|
196 |
p.Close();
|
|
197 |
|
|
198 |
test.Next(_L("Load with SYSTEM\\PROGRAMS path and without ext"));
|
|
199 |
r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa"),KNullDesC);
|
|
200 |
if(!SysBinEnforced)
|
|
201 |
CHECK_EQ(r,KErrNotFound)
|
|
202 |
else
|
|
203 |
{
|
|
204 |
CHECK_EQ(r,KErrNone)
|
|
205 |
CheckFileName(p,KExeAInSysBin);
|
|
206 |
p.Terminate(0);
|
|
207 |
p.Close();
|
|
208 |
}
|
|
209 |
|
|
210 |
test.Next(_L("Load with SYSTEM\\PROGRAMS path and with ext"));
|
|
211 |
r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa.EXE"),KNullDesC);
|
|
212 |
if(!SysBinEnforced)
|
|
213 |
CHECK_EQ(r,KErrNotFound)
|
|
214 |
else
|
|
215 |
{
|
|
216 |
CHECK_EQ(r,KErrNone)
|
|
217 |
CheckFileName(p,KExeAInSysBin);
|
|
218 |
p.Terminate(0);
|
|
219 |
p.Close();
|
|
220 |
}
|
|
221 |
|
|
222 |
test.End();
|
|
223 |
|
|
224 |
test.Next(_L("Check loading an EXE which lives in \\SYSTEM\\PROGRAMS"));
|
|
225 |
|
|
226 |
if(!RunningFromROM)
|
|
227 |
{
|
|
228 |
test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
|
|
229 |
}
|
|
230 |
else
|
|
231 |
{
|
|
232 |
test.Start(_L("Load without path or ext"));
|
|
233 |
TestExeB(_L("T_SYSBINb"));
|
|
234 |
|
|
235 |
test.Next(_L("Load without path"));
|
|
236 |
TestExeB(_L("T_SYSBINb.EXE"));
|
|
237 |
|
|
238 |
test.Next(_L("Load with path but without ext"));
|
|
239 |
TestExeB(_L("\\System\\programs\\T_SYSBINb"));
|
|
240 |
|
|
241 |
test.Next(_L("Load with path and ext"));
|
|
242 |
TestExeB(_L("\\System\\programs\\T_SYSBINb.EXE"));
|
|
243 |
|
|
244 |
test.End();
|
|
245 |
}
|
|
246 |
|
|
247 |
test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN"));
|
|
248 |
|
|
249 |
test.Start(_L("Load without path or ext"));
|
|
250 |
r = l.Load(_L("T_SYSBIN_DLLa"));
|
|
251 |
CHECK_EQ(r,KErrNone)
|
|
252 |
CheckFileName(l,KDllAInSysBin);
|
|
253 |
l.Close();
|
|
254 |
|
|
255 |
test.Next(_L("Load without path"));
|
|
256 |
r = l.Load(_L("T_SYSBIN_DLLa.DLL"));
|
|
257 |
CHECK_EQ(r,KErrNone)
|
|
258 |
CheckFileName(l,KDllAInSysBin);
|
|
259 |
l.Close();
|
|
260 |
|
|
261 |
test.Next(_L("Load with path but without ext"));
|
|
262 |
r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa"));
|
|
263 |
CHECK_EQ(r,KErrNone)
|
|
264 |
CheckFileName(l,KDllAInSysBin);
|
|
265 |
l.Close();
|
|
266 |
|
|
267 |
test.Next(_L("Load with path and ext"));
|
|
268 |
r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa.DLL"));
|
|
269 |
CHECK_EQ(r,KErrNone)
|
|
270 |
CheckFileName(l,KDllAInSysBin);
|
|
271 |
l.Close();
|
|
272 |
|
|
273 |
test.Next(_L("Load with SYSTEM\\LIBS path and without ext"));
|
|
274 |
r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa"));
|
|
275 |
if(!SysBinEnforced)
|
|
276 |
CHECK_EQ(r,KErrNotFound)
|
|
277 |
else
|
|
278 |
{
|
|
279 |
CHECK_EQ(r,KErrNone)
|
|
280 |
CheckFileName(l,KDllAInSysBin);
|
|
281 |
l.Close();
|
|
282 |
}
|
|
283 |
|
|
284 |
test.Next(_L("Load with SYSTEM\\LIBS path and with ext"));
|
|
285 |
r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa.DLL"));
|
|
286 |
if(!SysBinEnforced)
|
|
287 |
CHECK_EQ(r,KErrNotFound)
|
|
288 |
else
|
|
289 |
{
|
|
290 |
CHECK_EQ(r,KErrNone)
|
|
291 |
CheckFileName(l,KDllAInSysBin);
|
|
292 |
l.Close();
|
|
293 |
}
|
|
294 |
|
|
295 |
test.End();
|
|
296 |
|
|
297 |
test.Next(_L("Check loading an DLL which lives in \\SYSTEM\\LIBS"));
|
|
298 |
|
|
299 |
if(!RunningFromROM)
|
|
300 |
{
|
|
301 |
test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
|
|
302 |
}
|
|
303 |
else
|
|
304 |
{
|
|
305 |
test.Start(_L("Load without path or ext"));
|
|
306 |
TestDllB(_L("T_SYSBIN_DLLb"));
|
|
307 |
|
|
308 |
test.Next(_L("Load without path"));
|
|
309 |
TestDllB(_L("T_SYSBIN_DLLb.DLL"));
|
|
310 |
|
|
311 |
test.Next(_L("Load with path but without ext"));
|
|
312 |
TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb"));
|
|
313 |
|
|
314 |
test.Next(_L("Load with path and ext"));
|
|
315 |
TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb.DLL"));
|
|
316 |
|
|
317 |
test.End();
|
|
318 |
}
|
|
319 |
|
|
320 |
test.Next(_L("Check loading an DLL which lives in \\SYSBIN_TEST"));
|
|
321 |
|
|
322 |
r = TheFileMan->Copy(KRamDll,KDllCInCTest,CFileMan::ERecurse);
|
|
323 |
test_KErrNone(r);
|
|
324 |
|
|
325 |
test.Start(_L("Load using full path+name"));
|
|
326 |
TestDllC(KDllCInCTest,KNullDesC);
|
|
327 |
|
|
328 |
test.Next(_L("Load using separate search path"));
|
|
329 |
TestDllC(KDllC,_L("\\sysbin_test\\"));
|
|
330 |
#ifndef __WINS__
|
|
331 |
TestDllC(KDllC,_L("\\sysbin_test"));
|
|
332 |
TestDllC(KDllC,_L("sysbin_test\\"));
|
|
333 |
TestDllC(KDllC,_L("sysbin_test"));
|
|
334 |
#endif
|
|
335 |
|
|
336 |
TestDllC(KDllC,_L("c:\\sysbin_test\\"));
|
|
337 |
#ifndef __WINS__
|
|
338 |
TestDllC(KDllC,_L("c:\\sysbin_test"));
|
|
339 |
TestDllC(KDllC,_L("c:sysbin_test\\"));
|
|
340 |
TestDllC(KDllC,_L("c:sysbin_test"));
|
|
341 |
#endif
|
|
342 |
|
|
343 |
test.End();
|
|
344 |
|
|
345 |
_LIT(KCTestPath,"c:\\sysbin_test\\");
|
|
346 |
r = TheFileMan->RmDir(KCTestPath);
|
|
347 |
test_KErrNone(r);
|
|
348 |
|
|
349 |
test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN\\TEST"));
|
|
350 |
|
|
351 |
r = TheFileMan->Copy(KRamDll,KDllDInCSysBinTest,CFileMan::ERecurse);
|
|
352 |
test_KErrNone(r);
|
|
353 |
|
|
354 |
test.Start(_L("Load using full path+name"));
|
|
355 |
TestDllD(KDllDInCSysBinTest,KNullDesC);
|
|
356 |
|
|
357 |
test.Next(_L("Load using separate search path"));
|
|
358 |
TestDllD(KDllD,_L("\\sys\\bin\\test\\"));
|
|
359 |
#ifndef __WINS__
|
|
360 |
TestDllD(KDllD,_L("\\sys\\bin\\test"));
|
|
361 |
TestDllD(KDllD,_L("sys\\bin\\test"));
|
|
362 |
TestDllD(KDllD,_L("sys\\bin\\test\\"));
|
|
363 |
#endif
|
|
364 |
|
|
365 |
TestDllD(KDllD,_L("c:\\sys\\bin\\test\\"));
|
|
366 |
#ifndef __WINS__
|
|
367 |
TestDllD(KDllD,_L("c:\\sys\\bin\\test"));
|
|
368 |
TestDllD(KDllD,_L("c:sys\\bin\\test\\"));
|
|
369 |
TestDllD(KDllD,_L("c:sys\\bin\\test"));
|
|
370 |
#endif
|
|
371 |
|
|
372 |
TestDllD(KDllD,_L("\\dummy;\\sys\\bin\\test\\"));
|
|
373 |
TestDllD(KDllD,_L("\\sys\\bin\\test\\;\\dummy2"));
|
|
374 |
TestDllD(KDllD,_L("\\dummy1;\\sys\\bin\\test2;\\sys\\bin\\test\\"));
|
|
375 |
|
|
376 |
TestDllD(KDllD,_L("c:\\dummy;c:\\sys\\bin\\test\\"));
|
|
377 |
TestDllD(KDllD,_L("c:\\sys\\bin\\test\\;c:\\dummy2"));
|
|
378 |
TestDllD(KDllD,_L("c:\\dummy1;c:\\sys\\bin\\test2;c:\\sys\\bin\\test\\"));
|
|
379 |
|
|
380 |
test.End();
|
|
381 |
|
|
382 |
_LIT(KCTestPath2,"c:\\sys\\bin\\test\\");
|
|
383 |
r = TheFileMan->RmDir(KCTestPath2);
|
|
384 |
test_KErrNone(r);
|
|
385 |
|
|
386 |
test.End();
|
|
387 |
return(0);
|
|
388 |
}
|