1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_dcnone.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1331 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <f32file.h>
1.20 +#include <e32test.h>
1.21 +#include <e32std.h>
1.22 +#include <e32std_private.h>
1.23 +#include <e32def.h>
1.24 +#include <e32def_private.h>
1.25 +#include <e32svr.h>
1.26 +#include "t_server.h"
1.27 +
1.28 +GLDEF_D RTest test(_L("t_dcnone"));
1.29 +GLDEF_D TTime gTimeNow;
1.30 +LOCAL_D TInt gTheDriveNum;
1.31 +
1.32 +//_LIT(KDefPath, "\\Default\\");
1.33 +
1.34 +const TInt KPathPosition = 2;
1.35 +_LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
1.36 +
1.37 +
1.38 +_LIT(KResourcePath, "?:\\Resource\\");
1.39 +_LIT(KSystemPath, "?:\\Sys\\");
1.40 +_LIT(KPrivatePath, "?:\\Private\\");
1.41 +_LIT(KPrivateFalseID, "?:\\Private\\FFFFFFFF\\");
1.42 +_LIT(KDriveName, "Billy");
1.43 +//_LIT(KVolLable, "Benny");
1.44 +
1.45 +_LIT(KFileSys, "systemfile.txt");
1.46 +//_LIT(KFileSys2, "systemfile.tmp");
1.47 +_LIT(KFileSys3, "sysfile.rna");
1.48 +
1.49 +_LIT(KFilePri, "privatefile.txt");
1.50 +_LIT(KFilePri2, "privatefile.tmp");
1.51 +_LIT(KFilePri3, "prifile.rna");
1.52 +
1.53 +_LIT(KFileRes, "resourcefile.txt");
1.54 +//_LIT(KFileRes2, "resourcefile.tmp");
1.55 +_LIT(KFileRes3, "resfile.rna");
1.56 +
1.57 +_LIT(KMkDirSub,"Subdir\\");
1.58 +_LIT(KOldFile,"?:\\Anyold.txt");
1.59 +//_LIT(KNullPath, "");
1.60 +//_LIT(KLFFSName, "Lffs");
1.61 +
1.62 +_LIT(KWildPath, "Z:\\SYS\\");
1.63 +_LIT(KWildFile, "*");
1.64 +
1.65 +_LIT(KPrivatePathTest1, "\\Private\\00000001");
1.66 +_LIT(KPrivatePathTest2, "\\Private\\FFFFFFFF");
1.67 +_LIT(KPrivatePathTest3, "\\Private\\FFFFFFFF\\");
1.68 +TInt theDrive=0;
1.69 +TCapability TheCaps;
1.70 +TBuf<4> driveBuf=_L("?:\\");
1.71 +RFormat format;
1.72 +TInt count;
1.73 +RRawDisk rawdisk;
1.74 +RFile file1;
1.75 +RFile file2;
1.76 +RDir dir;
1.77 +CDir* dirEntries;
1.78 +TInt r;
1.79 +TBuf<40> fsname;
1.80 +TBuf<40> systestname;
1.81 +TBuf<40> pritestname;
1.82 +TBuf<40> restestname;
1.83 +TBuf<40> theprivatepath;
1.84 +TBuf<40> pritestfalseidname;
1.85 +TBuf<40> mkdirname;
1.86 +TFileName fromTemp;
1.87 +
1.88 +
1.89 +TBuf<25> prifilename;
1.90 +TBuf<25> sysfilename;
1.91 +TBuf<30> realName;
1.92 +TBuf<40> shortfilename;
1.93 +TBuf<40> longfilename;
1.94 +
1.95 +TRequestStatus aStat1;
1.96 +TRequestStatus aStat2;
1.97 +TRequestStatus aStat3;
1.98 +TRequestStatus aStat4;
1.99 +
1.100 +TVolumeInfo aVolInfo;
1.101 +// TDriveInfo adriveInfo;
1.102 +
1.103 +TBuf<40> systestfile;
1.104 +TBuf<40> pritestfile;
1.105 +TBuf<40> restestfile;
1.106 +TBuf<40> systestfile1;
1.107 +TBuf<40> pritestfile1;
1.108 +TBuf<40> restestfile1;
1.109 +
1.110 +TTime testtime;
1.111 +TBuf<20> oldName;
1.112 +TBuf<25> temp;
1.113 +TEntry entry;
1.114 +
1.115 +
1.116 +
1.117 +
1.118 +LOCAL_C void TestPathCheck()
1.119 +//
1.120 +// This test case is brought in by INC054580
1.121 +// (NTT Renaming sys ¨Cfolder on C -drive on H2 allows user to access sys -files)
1.122 +//
1.123 + {
1.124 + TInt r = TheFs.Rename(_L("\\sys"), _L("\\sysbad"));
1.125 + test(r == KErrPermissionDenied);
1.126 + r = TheFs.Rename(_L("\\resource"), _L("\\resourcebad"));
1.127 + test(r == KErrPermissionDenied);
1.128 + r = TheFs.Rename(_L("\\private"), _L("\\privatebad"));
1.129 + test(r == KErrPermissionDenied);
1.130 + }
1.131 +
1.132 +LOCAL_C void systemRFstest()
1.133 +//
1.134 +//
1.135 +//
1.136 + {
1.137 + systestname=KSystemPath;
1.138 + systestname[0]=(TText)('A' + gTheDriveNum);
1.139 +
1.140 + mkdirname.Zero();
1.141 + mkdirname.Append(systestname);
1.142 + mkdirname.Append(KMkDirSub);
1.143 + r=TheFs.MkDirAll(mkdirname);
1.144 + test(r==KErrPermissionDenied);
1.145 +
1.146 + r=TheFs.RmDir(mkdirname);
1.147 + test(r==KErrPermissionDenied);
1.148 +
1.149 + r=TheFs.SetSubst(systestname,EDriveP);
1.150 + test(r==KErrPermissionDenied);
1.151 +
1.152 + r=TheFs.SetSessionPath(systestname);
1.153 + test(r==KErrPermissionDenied);
1.154 +
1.155 + TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
1.156 + test(aStat1==KErrPermissionDenied);
1.157 +
1.158 + systestfile=KSystemPath;
1.159 + systestfile[0]=(TText)('A' + gTheDriveNum);
1.160 + systestfile1=systestfile;
1.161 + systestfile.Append(KFileSys);
1.162 + systestfile1.Append(KFileSys3);
1.163 +
1.164 + oldName=KOldFile;
1.165 + oldName[0]=(TText)gDriveToTest;
1.166 +
1.167 + r=TheFs.GetShortName(systestfile, shortfilename);
1.168 + test(r==KErrPermissionDenied);
1.169 +
1.170 + r=TheFs.GetLongName(systestfile1, longfilename);
1.171 + test(r==KErrPermissionDenied);
1.172 +
1.173 + r=file1.Create(TheFs,oldName,EFileWrite);
1.174 + test(r==KErrNone || r==KErrAlreadyExists);
1.175 + file1.Close();
1.176 +
1.177 + r=TheFs.Replace(oldName,systestfile);
1.178 + test(r==KErrPermissionDenied);
1.179 +
1.180 + r=TheFs.Rename(systestfile,systestfile1);
1.181 + test(r==KErrPermissionDenied);
1.182 +
1.183 + // check that the entry for the system directory itself can be retrieved with no error
1.184 + // - with or without a slash
1.185 + TPtrC restrictedDir(systestname.Ptr(), systestname.Length());
1.186 + r=TheFs.Entry(restrictedDir, entry);
1.187 + test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
1.188 + test(r==KErrNone);
1.189 + test (entry.iAtt & KEntryAttDir);
1.190 +
1.191 + TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
1.192 + r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
1.193 + test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
1.194 + test(r==KErrNone);
1.195 +
1.196 + r=TheFs.Entry(systestfile1,entry);
1.197 + test(r==KErrPermissionDenied);
1.198 +
1.199 + r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
1.200 + test(r==KErrPermissionDenied);
1.201 +
1.202 + r=TheFs.Delete(systestfile1);
1.203 + test(r==KErrPermissionDenied);
1.204 +
1.205 + }
1.206 +
1.207 +
1.208 +LOCAL_C void resourceRFstest()
1.209 +//
1.210 +//
1.211 +//
1.212 + {
1.213 +
1.214 + restestname=KResourcePath;
1.215 + restestname[0]=(TText)('A' + gTheDriveNum);
1.216 +
1.217 + mkdirname.Zero();
1.218 + mkdirname.Append(restestname);
1.219 + mkdirname.Append(KMkDirSub);
1.220 + r=TheFs.MkDirAll(mkdirname);
1.221 + test(r==KErrPermissionDenied);
1.222 +
1.223 + TheFs.RmDir(mkdirname);
1.224 + test(r==KErrPermissionDenied);
1.225 +
1.226 + r=TheFs.SetSubst(restestname,EDriveP);
1.227 + test(r==KErrPermissionDenied);
1.228 +
1.229 + r=TheFs.RealName(_L("P:\\File.XXX"),realName);
1.230 + test(r==KErrNone);
1.231 +
1.232 + r=TheFs.SetSessionPath(restestname);
1.233 + test(r==KErrNone);
1.234 +
1.235 + TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
1.236 + test(aStat4==KRequestPending);
1.237 +
1.238 +
1.239 + restestfile=KResourcePath;
1.240 + restestfile[0]=(TText)('A' + gTheDriveNum);
1.241 + restestfile1=restestfile;
1.242 + restestfile.Append(KFileRes);
1.243 + restestfile1.Append(KFileRes3);
1.244 +
1.245 + oldName=KOldFile;
1.246 + oldName[0]=(TText)gDriveToTest;
1.247 +
1.248 + r=TheFs.GetShortName(restestfile, shortfilename);
1.249 + test(r==KErrNone || KErrPathNotFound);
1.250 +
1.251 + r=TheFs.GetLongName(restestfile1, longfilename);
1.252 + test(r==KErrNone || KErrPathNotFound);
1.253 +
1.254 + r=file1.Create(TheFs,oldName,EFileWrite);
1.255 + test(r==KErrNone || r==KErrAlreadyExists);
1.256 + file1.Close();
1.257 +
1.258 + r=TheFs.Replace(oldName,restestfile);
1.259 + test(r==KErrPermissionDenied);
1.260 +
1.261 + r=TheFs.Rename(restestfile,restestfile1);
1.262 + test(r==KErrPermissionDenied);
1.263 +
1.264 + // check that the entry for the resource directory itself can be retrieved with no error
1.265 + // - with or without a slash
1.266 + TPtrC restrictedDir(restestname.Ptr(), restestname.Length());
1.267 + r=TheFs.Entry(restrictedDir, entry);
1.268 + test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
1.269 + test(r==KErrNone);
1.270 + test (entry.iAtt & KEntryAttDir);
1.271 +
1.272 + TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
1.273 + r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
1.274 + test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
1.275 + test(r==KErrNone);
1.276 +
1.277 + r=TheFs.Entry(restestfile1,entry);
1.278 + test(r==KErrNone || r==KErrNotFound);
1.279 +
1.280 + r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
1.281 + test(r==KErrPermissionDenied);
1.282 +
1.283 + r=TheFs.Delete(restestfile1);
1.284 + test(r==KErrPermissionDenied);
1.285 +
1.286 + }
1.287 +
1.288 +
1.289 +LOCAL_C void privatefalseIDRFstest()
1.290 +//
1.291 +//
1.292 +//
1.293 + {
1.294 + pritestfalseidname=KPrivateFalseID;
1.295 + pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
1.296 +
1.297 + mkdirname.Zero();
1.298 + mkdirname.Append(pritestfalseidname);
1.299 + mkdirname.Append(KMkDirSub);
1.300 +
1.301 + r=TheFs.MkDirAll(mkdirname);
1.302 + test(r==KErrPermissionDenied);
1.303 +
1.304 + r=TheFs.RmDir(mkdirname);
1.305 + test(r==KErrPermissionDenied);
1.306 +
1.307 + r=TheFs.SetSubst(pritestfalseidname,EDriveP);
1.308 + test(r==KErrPermissionDenied);
1.309 +
1.310 + TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
1.311 + test(aStat2==KErrPermissionDenied);
1.312 +
1.313 +
1.314 + pritestfile=KPrivateFalseID;
1.315 + pritestfile[0]=(TText)('A' + gTheDriveNum);
1.316 + pritestfile1=pritestfile;
1.317 + pritestfile.Append(KFilePri2);
1.318 + pritestfile1.Append(KFilePri3);
1.319 +
1.320 + oldName=KOldFile;
1.321 + oldName[0]=(TText)gDriveToTest;
1.322 +
1.323 + r=TheFs.GetShortName(pritestfile, shortfilename);
1.324 + test(r==KErrPermissionDenied);
1.325 +
1.326 + r=TheFs.GetLongName(pritestfile1, longfilename);
1.327 + test(r==KErrPermissionDenied);
1.328 +
1.329 + r=file1.Create(TheFs,oldName,EFileWrite);
1.330 + test(r==KErrNone || r==KErrAlreadyExists);
1.331 + file1.Close();
1.332 +
1.333 + r=TheFs.Replace(oldName,pritestfile);
1.334 + test(r==KErrPermissionDenied);
1.335 +
1.336 + r=TheFs.Rename(pritestfile,pritestfile1);
1.337 + test(r==KErrPermissionDenied);
1.338 +
1.339 + r=TheFs.Entry(pritestfile1,entry);
1.340 + test(r==KErrPermissionDenied);
1.341 +
1.342 + r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
1.343 + test(r==KErrPermissionDenied);
1.344 +
1.345 + r=TheFs.Delete(pritestfile1);
1.346 + test(r==KErrPermissionDenied);
1.347 +
1.348 + }
1.349 +
1.350 +
1.351 +
1.352 +LOCAL_C void privateRFstest()
1.353 +//
1.354 +//
1.355 +//
1.356 + {
1.357 + pritestname=KPrivatePath;
1.358 + pritestname[0]=(TText)('A' + gTheDriveNum);
1.359 +
1.360 + mkdirname.Zero();
1.361 + mkdirname.Append(pritestname);
1.362 + mkdirname.Append(KMkDirSub);
1.363 +
1.364 + r=TheFs.MkDirAll(mkdirname);
1.365 + test(r==KErrPermissionDenied);
1.366 +
1.367 + r=TheFs.RmDir(mkdirname);
1.368 + test(r==KErrPermissionDenied);
1.369 +
1.370 + r=TheFs.SetSubst(pritestname,EDriveP);
1.371 + test(r==KErrPermissionDenied);
1.372 +
1.373 + TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
1.374 + test(aStat2==KErrPermissionDenied);
1.375 +
1.376 +
1.377 + pritestfile=KPrivatePath;
1.378 + pritestfile[0]=(TText)('A' + gTheDriveNum);
1.379 + pritestfile1=pritestfile;
1.380 + pritestfile.Append(KFilePri2);
1.381 + pritestfile1.Append(KFilePri3);
1.382 +
1.383 + oldName=KOldFile;
1.384 + oldName[0]=(TText)gDriveToTest;
1.385 +
1.386 + r=TheFs.GetShortName(pritestfile, shortfilename);
1.387 + test(r==KErrPermissionDenied);
1.388 +
1.389 + r=TheFs.GetLongName(pritestfile1, longfilename);
1.390 + test(r==KErrPermissionDenied);
1.391 +
1.392 + r=file1.Create(TheFs,oldName,EFileWrite);
1.393 + test(r==KErrNone || r==KErrAlreadyExists);
1.394 + file1.Close();
1.395 +
1.396 + r=TheFs.Replace(oldName,pritestfile);
1.397 + test(r==KErrPermissionDenied);
1.398 +
1.399 + r=TheFs.Rename(pritestfile,pritestfile1);
1.400 + test(r==KErrPermissionDenied);
1.401 +
1.402 + r=TheFs.Entry(pritestfile1,entry);
1.403 + test(r==KErrPermissionDenied);
1.404 +
1.405 + // check that the entry for the private directory itself can be retrieved with no error
1.406 + // - with or without a slash
1.407 + TPtrC restrictedDir(pritestname.Ptr(), pritestname.Length());
1.408 + r=TheFs.Entry(restrictedDir, entry);
1.409 + test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
1.410 + test(r==KErrNone);
1.411 + test (entry.iAtt & KEntryAttDir);
1.412 +
1.413 + TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
1.414 + r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
1.415 + test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
1.416 + test(r==KErrNone);
1.417 +
1.418 + r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
1.419 + test(r==KErrPermissionDenied);
1.420 +
1.421 + r=TheFs.Delete(pritestfile1);
1.422 + test(r==KErrPermissionDenied);
1.423 +
1.424 + }
1.425 +
1.426 +
1.427 +LOCAL_C void privateSIDRFstest()
1.428 +//
1.429 +//
1.430 +//
1.431 + {
1.432 + theprivatepath[0]=(TText)gDriveToTest;
1.433 + test.Printf(_L("the Private Path = %S"),&theprivatepath);
1.434 +
1.435 + mkdirname.Zero();
1.436 + mkdirname.Append(theprivatepath);
1.437 + mkdirname.Append(KMkDirSub);
1.438 + r=TheFs.MkDirAll(mkdirname);
1.439 + test(r==KErrNone);
1.440 +
1.441 + r=TheFs.RmDir(mkdirname);
1.442 + test(r==KErrNone);
1.443 +
1.444 + r=TheFs.SetSubst(theprivatepath,EDriveP);
1.445 + test(r==KErrPermissionDenied);
1.446 +
1.447 + r=TheFs.RealName(_L("P:\\File.XXX"),realName);
1.448 + test(r==KErrNone);
1.449 +
1.450 + r=TheFs.SetSessionPath(theprivatepath);
1.451 + test(r==KErrNone);
1.452 +
1.453 + TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
1.454 + test(aStat3==KRequestPending);
1.455 +
1.456 +
1.457 + pritestfile=theprivatepath;
1.458 + pritestfile[0]=(TText)('A' + gTheDriveNum);
1.459 + pritestfile1=pritestfile;
1.460 + pritestfile.Append(KFilePri2);
1.461 + pritestfile1.Append(KFilePri3);
1.462 +
1.463 + oldName=KOldFile;
1.464 + oldName[0]=(TText)gDriveToTest;
1.465 +
1.466 + r=TheFs.GetShortName(pritestfile, shortfilename);
1.467 + test(r==KErrNone || KErrPathNotFound);
1.468 +
1.469 + r=TheFs.GetLongName(pritestfile1, longfilename);
1.470 + test(r==KErrNone || KErrPathNotFound);
1.471 +
1.472 + r=file1.Create(TheFs,oldName,EFileWrite);
1.473 + test(r==KErrNone || r==KErrAlreadyExists);
1.474 + file1.Close();
1.475 +
1.476 + r=TheFs.Replace(oldName,pritestfile);
1.477 + test(r==KErrNone);
1.478 +
1.479 + r=TheFs.Rename(pritestfile,pritestfile1);
1.480 + test(r==KErrNone || r==KErrAlreadyExists);
1.481 +
1.482 + r=TheFs.Entry(pritestfile1,entry);
1.483 + test(r==KErrNone);
1.484 +
1.485 + //Test Entry with correct SID
1.486 + r=TheFs.Entry(theprivatepath,entry);
1.487 + test(r==KErrNone);
1.488 +
1.489 + //Test Entry with correct SID and without "//" appended
1.490 + r=TheFs.Entry(KPrivatePathTest1,entry);
1.491 + test(r==KErrNone);
1.492 +
1.493 + //Test Entry with invalid SID, without // appended
1.494 + r=TheFs.Entry(KPrivatePathTest2,entry);
1.495 + test(r==KErrPermissionDenied);
1.496 +
1.497 + //Test Entry with invalid SID
1.498 + r=TheFs.Entry(KPrivatePathTest3,entry);
1.499 + test(r==KErrPermissionDenied);
1.500 +
1.501 + r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
1.502 + test(r==KErrNone);
1.503 +
1.504 + r=TheFs.Delete(pritestfile1);
1.505 + test(r==KErrNone);
1.506 +
1.507 + }
1.508 +
1.509 +
1.510 +LOCAL_C void systemRFiletest()
1.511 +//
1.512 +//
1.513 +//
1.514 + {
1.515 + r=TheFs.SetSessionPath(systestname);
1.516 + test(r==KErrPermissionDenied);
1.517 +
1.518 + r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
1.519 + test(r==KErrPermissionDenied);
1.520 +
1.521 +
1.522 + TBuf<25> sysfilename;
1.523 + sysfilename.Append(systestname);
1.524 + sysfilename.Append(KFileSys);
1.525 +
1.526 + r=file1.Create(TheFs,sysfilename,EFileWrite);
1.527 + test(r==KErrPermissionDenied);
1.528 +
1.529 + r=file1.Open(TheFs,sysfilename,EFileWrite);
1.530 + test(r==KErrPermissionDenied);
1.531 +
1.532 + r=file1.Open(TheFs,sysfilename,EFileRead);
1.533 + test(r==KErrPermissionDenied);
1.534 +
1.535 + r=file1.Replace(TheFs,sysfilename,EFileWrite);
1.536 + test(r==KErrPermissionDenied);
1.537 +
1.538 + TFindFile finder(TheFs);
1.539 + CDir* dir = NULL;
1.540 + r=finder.FindWildByDir(KWildFile, KWildPath, dir);
1.541 + if (!(r==KErrPermissionDenied))
1.542 + test.Printf(_L("T_DCNONE: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r);
1.543 + test(r==KErrPermissionDenied);
1.544 + delete dir;
1.545 + }
1.546 +
1.547 +LOCAL_C void resourceRFiletest()
1.548 +//
1.549 +//
1.550 +//
1.551 + {
1.552 + r=TheFs.SetSessionPath(restestname);
1.553 + test(r==KErrNone);
1.554 +
1.555 + r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
1.556 + test(r==KErrPermissionDenied);
1.557 + file1.Close();
1.558 +
1.559 + r=file1.Create(TheFs,KFileRes,EFileWrite);
1.560 + test(r==KErrPermissionDenied);
1.561 + file1.Close();
1.562 +
1.563 + r=file1.Open(TheFs,KFileRes,EFileWrite);
1.564 + test(r==KErrPermissionDenied);
1.565 + file1.Close();
1.566 +
1.567 + r=file1.Open(TheFs,KFileRes,EFileRead|EFileShareReadersOnly);
1.568 + test(r==KErrNone || r==KErrPathNotFound);
1.569 + file1.Close();
1.570 +
1.571 + r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileRead);
1.572 + test(r==KErrNone || r==KErrPathNotFound);
1.573 + file1.Close();
1.574 +
1.575 + r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileWrite);
1.576 + test(r==KErrPermissionDenied);
1.577 + file1.Close();
1.578 +
1.579 + r=file1.Open(TheFs,KFileRes,EFileShareReadersOnly);
1.580 + test(r==KErrNone || r==KErrPathNotFound);
1.581 +
1.582 + r=file1.ChangeMode(EFileShareExclusive); //this is not illegal though will prevent shared access to resource which is nit my fault but may be desirable to prevent
1.583 + test(r==KErrNone || r==KErrPathNotFound);
1.584 +
1.585 + //this operation is prevented as you can not open a file for write access in the resource directory
1.586 + r=file1.Rename(KFileRes3);
1.587 + test(r==KErrPermissionDenied || r==KErrAccessDenied);
1.588 +
1.589 + file1.Close();
1.590 +
1.591 + r=file1.Replace(TheFs,KFileRes,EFileWrite);
1.592 + test(r==KErrPermissionDenied);
1.593 + file1.Close();
1.594 +
1.595 + }
1.596 +
1.597 +
1.598 +LOCAL_C void privatefalseIDRFiletest()
1.599 +//
1.600 +//
1.601 +//
1.602 + {
1.603 +
1.604 + r=TheFs.SetSessionPath(pritestfalseidname);
1.605 + test(r==KErrPermissionDenied);
1.606 +
1.607 + r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
1.608 + test(r==KErrPermissionDenied);
1.609 +
1.610 + TBuf<25> prifilename;
1.611 + prifilename.Append(pritestname);
1.612 + prifilename.Append(KFileSys);
1.613 +
1.614 + r=file1.Create(TheFs,prifilename,EFileWrite);
1.615 + test(r==KErrPermissionDenied);
1.616 +
1.617 +
1.618 + r=file1.Open(TheFs,prifilename,EFileWrite);
1.619 + test(r==KErrPermissionDenied);
1.620 +
1.621 + r=file1.Open(TheFs,prifilename,EFileRead);
1.622 + test(r==KErrPermissionDenied);
1.623 +
1.624 +
1.625 + r=file1.Replace(TheFs,prifilename,EFileWrite);
1.626 + test(r==KErrPermissionDenied);
1.627 +
1.628 + }
1.629 +
1.630 +
1.631 +
1.632 +LOCAL_C void privateRFiletest()
1.633 +//
1.634 +//
1.635 +//
1.636 + {
1.637 +
1.638 + r=TheFs.SetSessionPath(pritestname);
1.639 + test(r==KErrPermissionDenied);
1.640 +
1.641 + r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
1.642 + test(r==KErrPermissionDenied);
1.643 +
1.644 + TBuf<25> prifilename;
1.645 + prifilename.Append(pritestname);
1.646 + prifilename.Append(KFileSys);
1.647 +
1.648 + r=file1.Create(TheFs,prifilename,EFileWrite);
1.649 + test(r==KErrPermissionDenied);
1.650 +
1.651 +
1.652 + r=file1.Open(TheFs,prifilename,EFileWrite);
1.653 + test(r==KErrPermissionDenied);
1.654 +
1.655 +
1.656 + r=file1.Open(TheFs,prifilename,EFileRead);
1.657 + test(r==KErrPermissionDenied);
1.658 +
1.659 +
1.660 + r=file1.Replace(TheFs,prifilename,EFileWrite);
1.661 + test(r==KErrPermissionDenied);
1.662 +
1.663 + }
1.664 +
1.665 +LOCAL_C void privateSIDRFiletest()
1.666 +//
1.667 +//
1.668 +//
1.669 + {
1.670 +
1.671 + r=TheFs.SetSessionToPrivate(gTheDriveNum);
1.672 + test(r==KErrNone);
1.673 +
1.674 + r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
1.675 + test(r==KErrNone);
1.676 + file1.Close();
1.677 + r=file1.Create(TheFs,KFilePri,EFileWrite);
1.678 + test(r==KErrNone || r==KErrAlreadyExists);
1.679 + file1.Close();
1.680 + r=file1.Open(TheFs,KFilePri,EFileWrite);
1.681 + test(r==KErrNone);
1.682 + file1.Close();
1.683 + r=file1.Open(TheFs,KFilePri,EFileRead);
1.684 + test(r==KErrNone);
1.685 + file1.Close();
1.686 + r=file1.Replace(TheFs,KFilePri,EFileWrite);
1.687 + test(r==KErrNone);
1.688 + r=file1.Rename(KFilePri3);
1.689 + test(r==KErrNone || r==KErrAlreadyExists);
1.690 + file1.Close();
1.691 +
1.692 + }
1.693 +
1.694 +
1.695 +LOCAL_C void RDirtest()
1.696 +//
1.697 +//
1.698 +//
1.699 + {
1.700 + //system
1.701 +
1.702 + TBuf<30> dirNameBuf(KSystemPath);
1.703 + dirNameBuf[0]=(TText)gDriveToTest;
1.704 + r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
1.705 + test(r==KErrPermissionDenied);
1.706 + dir.Close();
1.707 + r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
1.708 + test(r==KErrPermissionDenied);
1.709 + dirNameBuf.Zero();
1.710 + delete dirEntries;
1.711 +
1.712 + dirNameBuf=KPrivateFalseID;
1.713 + dirNameBuf[0]=(TText)gDriveToTest;
1.714 + r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
1.715 + test(r==KErrPermissionDenied);
1.716 + dir.Close();
1.717 + r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
1.718 + test(r==KErrPermissionDenied);
1.719 + dirNameBuf.Zero();
1.720 + delete dirEntries;
1.721 +
1.722 + //Private
1.723 + dirNameBuf=KPrivatePath;
1.724 + dirNameBuf[0]=(TText)gDriveToTest;
1.725 + r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
1.726 + test(r==KErrPermissionDenied);
1.727 + dir.Close();
1.728 + r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
1.729 + test(r==KErrPermissionDenied);
1.730 + dirNameBuf.Zero();
1.731 + delete dirEntries;
1.732 + //Private/uid
1.733 + TheFs.PrivatePath(dirNameBuf);
1.734 + dirNameBuf.Insert(0,_L("?:"));
1.735 + dirNameBuf[0]=(TText)gDriveToTest;
1.736 + r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
1.737 + test(r==KErrNone);
1.738 + dir.Close();
1.739 + r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
1.740 + test(r==KErrNone);
1.741 + dirNameBuf.Zero();
1.742 + delete dirEntries;
1.743 + //Resource
1.744 + dirNameBuf=KResourcePath;
1.745 + dirNameBuf[0]=(TText)gDriveToTest;
1.746 + r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
1.747 + test(r==KErrNone);
1.748 + r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
1.749 + test(r==KErrNone);
1.750 + dir.Close();
1.751 + delete dirEntries;
1.752 + }
1.753 +
1.754 +
1.755 +LOCAL_C void TestNoCaps()
1.756 +//
1.757 +// test APIs with no capabilities
1.758 +//
1.759 + {
1.760 + r=TheFs.FileSystemName(fsname,gTheDriveNum);
1.761 + test(r==KErrNone);
1.762 + r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
1.763 + test(r==KErrPermissionDenied);
1.764 +// r=TheFs.RemoveFileSystem(fsname); //can not test due to bug elsewhere fix exists
1.765 +// test(r==KErrPermissionDenied);
1.766 +// r=TheFs.AddFileSystem(fsname);
1.767 +// test(r==KErrPermissionDenied);
1.768 + r = MountFileSystem(TheFs, fsname, gTheDriveNum);
1.769 + test(r==KErrPermissionDenied);
1.770 + r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
1.771 + test(r==KErrPermissionDenied);
1.772 +// r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum); //broken on wins C:
1.773 +// test(r==KErrPermissionDenied);
1.774 +
1.775 + systemRFstest();
1.776 + resourceRFstest();
1.777 + privateRFstest();
1.778 + privateSIDRFstest();
1.779 + privatefalseIDRFstest();
1.780 +
1.781 + systemRFiletest();
1.782 + resourceRFiletest();
1.783 + privateRFiletest();
1.784 + privateSIDRFiletest();
1.785 + privatefalseIDRFiletest();
1.786 + //disk changes to sys and pri paths should have completed these
1.787 + test(aStat4 == KRequestPending);
1.788 + TheFs.NotifyChangeCancel(aStat4);
1.789 + test(aStat4==KErrCancel);
1.790 +
1.791 +
1.792 + User::WaitForRequest(aStat3);
1.793 + test(aStat1==KErrPermissionDenied);
1.794 + test(aStat2==KErrPermissionDenied);
1.795 + test(aStat3==KErrNone);
1.796 +
1.797 + r=TheFs.SetSessionPath(systestname);
1.798 + test(r==KErrPermissionDenied);
1.799 +
1.800 +
1.801 +//Test RRawDisk class
1.802 + r=rawdisk.Open(TheFs,gTheDriveNum);
1.803 + test(r==KErrPermissionDenied);
1.804 +// rawdisk.Close();
1.805 +
1.806 + r=format.Open(TheFs,driveBuf,EHighDensity,count);
1.807 + test(r==KErrPermissionDenied);
1.808 +
1.809 + RDirtest();
1.810 +
1.811 + driveBuf[0]=(TText)gDriveToTest;
1.812 + r=TheFs.ScanDrive(driveBuf);
1.813 + test(r==KErrPermissionDenied);
1.814 + r=TheFs.CheckDisk(driveBuf);
1.815 + test(r==KErrPermissionDenied);
1.816 + }
1.817 +
1.818 +LOCAL_C void TestCaps()
1.819 +//
1.820 +// test format etc that require certain capabilities
1.821 +//
1.822 + {
1.823 +#ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
1.824 + const char myDiagMsg[]="Capability Check Failure";
1.825 +#endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
1.826 + r=RProcess().HasCapability(ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
1.827 + test(!r);
1.828 + r=RProcess().HasCapability(ECapabilityTCB, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
1.829 + test(!r);
1.830 + r=RProcess().HasCapability(ECapabilityDiskAdmin, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
1.831 + test(!r);
1.832 + r=RProcess().HasCapability(ECapability_None, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
1.833 + test(r);
1.834 +
1.835 + driveBuf[0]=(TText)gDriveToTest;
1.836 + r=TheFs.SessionPath(temp);
1.837 + test(r==KErrNone);
1.838 +
1.839 + r=TheFs.CreatePrivatePath(gTheDriveNum);
1.840 + test(r==KErrNone || r== KErrAlreadyExists);
1.841 +
1.842 + TBuf<18> tempPri;
1.843 + r=TheFs.PrivatePath(tempPri);
1.844 + test(r==KErrNone);
1.845 + theprivatepath = _L("?:");
1.846 + theprivatepath.Append(tempPri);
1.847 +
1.848 + TestNoCaps();
1.849 +
1.850 + TFileName thesessionpath;
1.851 + r=TheFs.SetSessionToPrivate(gTheDriveNum);
1.852 + test(r==KErrNone);
1.853 + r=TheFs.SessionPath(thesessionpath);
1.854 + test(r==KErrNone);
1.855 +
1.856 + test(thesessionpath == theprivatepath);
1.857 +
1.858 + }
1.859 +
1.860 +
1.861 +LOCAL_C void MakeDirs()
1.862 +//
1.863 +// Create system and private directories for scan with and without DC
1.864 +//
1.865 + {
1.866 + TInt r;
1.867 + r = TheFs.MkDir(_L("\\normal\\"));
1.868 + test(r == KErrNone || r == KErrAlreadyExists);
1.869 + r = TheFs.MkDir(_L("\\normal\\one\\"));
1.870 + test(r == KErrNone || r == KErrAlreadyExists);
1.871 + r = TheFs.MkDir(_L("\\normal\\two\\"));
1.872 + test(r == KErrNone || r == KErrAlreadyExists);
1.873 + r = TheFs.MkDir(_L("\\sys\\"));
1.874 + test(r == KErrPermissionDenied);
1.875 + r = TheFs.MkDir(_L("\\sys\\one\\"));
1.876 + test(r == KErrPermissionDenied);
1.877 + r = TheFs.MkDir(_L("\\sys\\two\\"));
1.878 + test(r == KErrPermissionDenied);
1.879 + r = TheFs.MkDir(_L("\\private\\"));
1.880 + test(r == KErrPermissionDenied);
1.881 + r = TheFs.MkDir(_L("\\private\\one\\"));
1.882 + test(r == KErrPermissionDenied);
1.883 + r = TheFs.MkDir(_L("\\private\\two\\"));
1.884 + test(r == KErrPermissionDenied);
1.885 + r = TheFs.MkDir(_L("\\ZZZZZZ\\"));
1.886 + test(r == KErrNone || r == KErrAlreadyExists);
1.887 + }
1.888 +
1.889 +TFileName dirName;
1.890 +
1.891 +LOCAL_C void ScanDir(const TDesC& aName, CDirScan::TScanDirection aDirection, TInt aError)
1.892 + {
1.893 + CDirScan* scanner = NULL;
1.894 + TRAP(r, scanner = CDirScan::NewL(TheFs));
1.895 + test(r == KErrNone && scanner);
1.896 +
1.897 + TRAP(r, scanner->SetScanDataL(aName,KEntryAttDir,ESortByName|EAscending,aDirection));
1.898 + test(r == KErrNone);
1.899 +
1.900 + CDir *entryList=NULL;
1.901 + for (;;)
1.902 + {
1.903 + TRAP(r, scanner->NextL(entryList));
1.904 + test(r == aError);
1.905 + if (entryList==NULL)
1.906 + break;
1.907 + TInt count=entryList->Count();
1.908 + while (count--)
1.909 + {
1.910 + TEntry data=(*entryList)[count];
1.911 + TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
1.912 + dirName = path;
1.913 + dirName.Append(data.iName);
1.914 + test.Printf(_L(" %S\n"),&dirName);
1.915 +
1.916 + }
1.917 + delete entryList;
1.918 + entryList=NULL;
1.919 + }
1.920 + delete scanner;
1.921 +
1.922 + }
1.923 +
1.924 +/**
1.925 +The following test, tests CFileMan and CDirScan API on folders private and sys
1.926 +to confirm that any operation on these folders for any app with incorrect capability
1.927 +returns KErrPermissionDenied. This test step was added as a result of DEF051428
1.928 +("PlatSec: Incorrect errors returned by f32")
1.929 +*/
1.930 +LOCAL_C void TestCaging()
1.931 + {
1.932 + CFileMan* fMan=CFileMan::NewL(TheFs);
1.933 + TInt r;
1.934 + if(fMan!=NULL)
1.935 + {
1.936 +
1.937 + // Checking the private path
1.938 + TBuf<30> privatepath;
1.939 + r=TheFs.PrivatePath(privatepath);
1.940 + test.Printf(_L("Private Path is=%S"),&privatepath);
1.941 +
1.942 + r = TheFs.MkDir(_L("\\Caged\\"));
1.943 + test(r==KErrNone || r==KErrAlreadyExists);
1.944 +
1.945 + CDir* entryCount=NULL;
1.946 + r=TheFs.GetDir(_L("\\*.*"),KEntryAttNormal,ESortNone,entryCount);
1.947 + test(r==KErrNone);
1.948 + TInt rootCount= entryCount->Count();
1.949 +
1.950 + delete entryCount;
1.951 + entryCount=NULL;
1.952 +
1.953 +
1.954 + //Testing Copy
1.955 + CDir* entryCount2=NULL;
1.956 + r=fMan->Copy(_L("\\sys\\"),_L("\\Caged\\"));
1.957 + test(r == KErrPermissionDenied);
1.958 + r=fMan->Copy(_L("\\*"),_L("\\Caged\\"));
1.959 + test(r == KErrNone);
1.960 +
1.961 + r=TheFs.GetDir(_L("\\Caged\\*.*"),KEntryAttNormal,ESortNone,entryCount2);
1.962 + test(r==KErrNone);
1.963 + TInt cagedCount= entryCount2->Count();
1.964 +
1.965 + test(cagedCount==rootCount);
1.966 +
1.967 + delete entryCount2;
1.968 + entryCount2=NULL;
1.969 +
1.970 + // Check if both copied sys and private are empty (no information is exposed)
1.971 + CDir* entryCount3=NULL;
1.972 + r=TheFs.GetDir(_L("\\Caged\\private\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount3);
1.973 + test(r==KErrPathNotFound);
1.974 + delete entryCount3;
1.975 + entryCount3=NULL;
1.976 +
1.977 + CDir* entryCount4=NULL;
1.978 + r=TheFs.GetDir(_L("\\Caged\\sys\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount4);
1.979 + test(r==KErrPathNotFound);
1.980 + delete entryCount4;
1.981 + entryCount4=NULL;
1.982 +
1.983 +
1.984 + r=fMan->Copy(_L("\\private\\two\\moo"),_L("\\private\\two\\mew"));
1.985 + test(r == KErrPermissionDenied);
1.986 +
1.987 + // Create a test file
1.988 + RFile testFile;
1.989 + r = testFile.Replace(TheFs, _L("\\capTest"),EFileWrite);
1.990 + test(r==KErrNone || r==KErrAlreadyExists);
1.991 + testFile.Close();
1.992 +
1.993 + TFileName name;
1.994 + name = privatepath;
1.995 + name.Append(_L("privateFile.tst"));
1.996 + RFile privateFile;
1.997 + r = privateFile.Replace(TheFs, name,EFileWrite);
1.998 + test(r==KErrNone || r==KErrAlreadyExists);
1.999 + privateFile.Close();
1.1000 +
1.1001 +
1.1002 + r=fMan->Copy(_L("\\capTest"),_L("\\private\\two\\moo"));
1.1003 + test(r == KErrPermissionDenied);
1.1004 + r=fMan->Copy(_L("\\capTest"),_L("\\sys\\bin\\moo"));
1.1005 + test(r == KErrPermissionDenied);
1.1006 + r=fMan->Copy(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo"));
1.1007 + test(r == KErrPermissionDenied);
1.1008 + r=fMan->Copy(_L("\\sys\\*"),_L("\\"));
1.1009 + test (r==KErrPermissionDenied);
1.1010 + r=fMan->Copy(name,_L("\\sys\\"));
1.1011 + test(r==KErrPermissionDenied);
1.1012 +
1.1013 + // Testing Move
1.1014 + r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo"));
1.1015 + test(r == KErrPermissionDenied);
1.1016 + r=fMan->Move(_L("\\private\\two\\moo.."),_L("\\private\\one\\moo"));
1.1017 + test(r == KErrPermissionDenied);
1.1018 + r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo.."));
1.1019 + test(r == KErrPermissionDenied);
1.1020 + r=fMan->Move(name,_L("\\privateFile.tst"));
1.1021 + test(r == KErrNone);
1.1022 + r=fMan->Move(_L("\\privateFile.tst"),name);
1.1023 + test(r == KErrNone);
1.1024 + r=fMan->Move(_L("\\capTest"),_L("\\private\\two\\moo"));
1.1025 + test(r == KErrPermissionDenied);
1.1026 + r=fMan->Move(_L("\\capTest"),_L("\\sys\\bin\\moo"));
1.1027 + test(r == KErrPermissionDenied);
1.1028 + r=fMan->Move(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo"));
1.1029 + test(r == KErrPermissionDenied);
1.1030 + r=fMan->Move(_L("\\sys\\*"),_L("\\"));
1.1031 + test (r==KErrPermissionDenied);
1.1032 + r=fMan->Move(name,_L("\\sys\\"));
1.1033 + test(r==KErrPermissionDenied);
1.1034 +
1.1035 +
1.1036 + // Testing Attribs
1.1037 + r=fMan->Attribs(_L("\\private\\two\\moo"),KEntryAttReadOnly,0,TTime(0));
1.1038 + test(r == KErrPermissionDenied);
1.1039 + r=fMan->Attribs(_L("\\private\\moo"),KEntryAttReadOnly,0,TTime(0));
1.1040 + test(r == KErrPermissionDenied);
1.1041 + r=fMan->Attribs(name,KEntryAttReadOnly,0,TTime(0));
1.1042 + test(r == KErrNone);
1.1043 + r=fMan->Attribs(name,0,KEntryAttReadOnly,TTime(0));
1.1044 + test(r == KErrNone);
1.1045 +
1.1046 +
1.1047 + // Testing RmDir
1.1048 + r=fMan->RmDir(_L("\\private\\"));
1.1049 + test(r == KErrPermissionDenied);
1.1050 + r=fMan->RmDir(_L("\\private\\two\\"));
1.1051 + test(r == KErrPermissionDenied);
1.1052 + r=fMan->RmDir(_L("\\private\\tw?\\"));
1.1053 + test(r == KErrPermissionDenied);
1.1054 + r=fMan->RmDir(_L("\\sys\\"));
1.1055 + test(r == KErrPermissionDenied);
1.1056 +
1.1057 +
1.1058 + // Testing Rename
1.1059 + r=fMan->Rename(_L("\\private\\two\\moo"),_L("\\private\\two\\mew"));
1.1060 + test(r == KErrPermissionDenied);
1.1061 +
1.1062 + // Testing Delete
1.1063 + r=fMan->Delete(_L("\\private\\two\\test"));
1.1064 + test(r == KErrPermissionDenied);
1.1065 + r=fMan->Delete(_L("\\private\\moo"));
1.1066 + test(r == KErrPermissionDenied);
1.1067 + r=fMan->Delete(_L("\\sys\\moo"));
1.1068 + test(r == KErrPermissionDenied);
1.1069 +
1.1070 +
1.1071 + //Something that actually exists in Private
1.1072 + r=fMan->Rename(name,_L("\\private\\00000001\\moo"));
1.1073 + test(r == KErrNone);
1.1074 + r=fMan->Rename(_L("\\private\\00000001\\moo"),name);
1.1075 + test(r == KErrNone);
1.1076 + r=fMan->Copy(name,_L("\\private\\00000001\\moo"));
1.1077 + test(r == KErrNone);
1.1078 + r=fMan->Delete(_L("\\private\\00000001\\moo"));
1.1079 + test(r == KErrNone);
1.1080 +
1.1081 + // Clean up the test data
1.1082 + r=fMan->RmDir(_L("\\Caged\\"));
1.1083 + test(r == KErrNone);
1.1084 + r=fMan->Delete(_L("\\capTest"));
1.1085 + test(r == KErrNone);
1.1086 + r=fMan->Delete(name);
1.1087 + test(r == KErrNone);
1.1088 + delete(fMan);
1.1089 + }
1.1090 +
1.1091 + // CDirScan tests
1.1092 + ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone);
1.1093 + ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone);
1.1094 + ScanDir(_L("\\private\\"), CDirScan::EScanDownTree, KErrPermissionDenied);
1.1095 + ScanDir(_L("\\private\\"), CDirScan::EScanUpTree, KErrPermissionDenied);
1.1096 + }
1.1097 +LOCAL_C void CleanDirs()
1.1098 +//
1.1099 +// Remove system and private directories for scan with and without DC
1.1100 +// (note that the \Private directory may not be able to be removed at this
1.1101 +// point if it contains other directories, so failing with "in use" is
1.1102 +// permitted in this case).
1.1103 +//
1.1104 + {
1.1105 + TInt r;
1.1106 + r = TheFs.RmDir(_L("\\normal\\one\\"));
1.1107 + test(r == KErrNone);
1.1108 + r = TheFs.RmDir(_L("\\normal\\two\\"));
1.1109 + test(r == KErrNone);
1.1110 + r = TheFs.RmDir(_L("\\normal\\"));
1.1111 + test(r == KErrNone);
1.1112 + r = TheFs.RmDir(_L("\\sys\\one\\"));
1.1113 + test(r == KErrPermissionDenied);
1.1114 + r = TheFs.RmDir(_L("\\sys\\two\\"));
1.1115 + test(r == KErrPermissionDenied);
1.1116 + r = TheFs.RmDir(_L("\\sys\\"));
1.1117 + test(r == KErrPermissionDenied);
1.1118 + r = TheFs.RmDir(_L("\\private\\one\\"));
1.1119 + test(r == KErrPermissionDenied);
1.1120 + r = TheFs.RmDir(_L("\\private\\two\\"));
1.1121 + test(r == KErrPermissionDenied);
1.1122 + r = TheFs.RmDir(_L("\\private\\"));
1.1123 + test(r == KErrPermissionDenied);
1.1124 + r = TheFs.RmDir(_L("\\ZZZZZZ\\"));
1.1125 + test(r == KErrNone);
1.1126 + }
1.1127 +
1.1128 +TFileName gDirList[100];
1.1129 +TInt gDirNum = 0;
1.1130 +
1.1131 +LOCAL_C void ListDirs()
1.1132 +//
1.1133 +// List the directories and files on the disk, without DC (so we
1.1134 +// find all of them), saving them in gDirList[] apart from
1.1135 +// members of the System and Private ones.
1.1136 +//
1.1137 + {
1.1138 + CDirScan* scanner = NULL;
1.1139 + TInt r;
1.1140 + TRAP(r, scanner = CDirScan::NewL(TheFs));
1.1141 + test(r == KErrNone && scanner);
1.1142 + TParse dirName;
1.1143 + TheFs.Parse(_L("\\"),dirName);
1.1144 + TRAP(r, scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName|EAscending));
1.1145 + test(r == KErrNone);
1.1146 + CDir *entryList;
1.1147 + test.Printf(_L("------ ALL DIRECTORIES ------\n"));
1.1148 + for (;;)
1.1149 + {
1.1150 + scanner->NextL(entryList);
1.1151 + if (entryList==NULL)
1.1152 + break;
1.1153 + TInt count=entryList->Count();
1.1154 + while (count--)
1.1155 + {
1.1156 + TEntry data=(*entryList)[count];
1.1157 + TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
1.1158 + gDirList[gDirNum] = path;
1.1159 + gDirList[gDirNum].Append(data.iName);
1.1160 + test.Printf(_L(" %S\n"),&gDirList[gDirNum]);
1.1161 + gDirNum++;
1.1162 + }
1.1163 + delete entryList;
1.1164 + entryList=NULL;
1.1165 + }
1.1166 + delete scanner;
1.1167 + }
1.1168 +
1.1169 +LOCAL_C void TestDirs()
1.1170 +//
1.1171 +// Scan directories and files with DC on, so only the root \Private
1.1172 +// and \System directories should be found (no contents).
1.1173 +//
1.1174 + {
1.1175 +
1.1176 + MakeDirs();
1.1177 + ListDirs();
1.1178 +
1.1179 + CDirScan* scanner = NULL;
1.1180 + TInt r;
1.1181 + TRAP(r, scanner = CDirScan::NewL(TheFs));
1.1182 + test(r == KErrNone && scanner);
1.1183 + TParse dirName;
1.1184 + TheFs.Parse(_L("\\"),dirName);
1.1185 + TRAP(r, scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName|EAscending));
1.1186 + test(r == KErrNone);
1.1187 + CDir *entryList = NULL;
1.1188 + TInt num = 0;
1.1189 + test.Printf(_L("------ ACCESSIBLE DIRECTORIES ------\n"));
1.1190 + for (;;)
1.1191 + {
1.1192 + TRAP(r, scanner->NextL(entryList));
1.1193 + if (r != KErrNone)
1.1194 + {
1.1195 + test.Printf(_L("*** ERROR %d doing NextL()\n"), r);
1.1196 + break;
1.1197 + }
1.1198 + if (entryList==NULL)
1.1199 + break;
1.1200 + TInt count=entryList->Count();
1.1201 + while (count--)
1.1202 + {
1.1203 + TEntry data=(*entryList)[count];
1.1204 + TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
1.1205 + path.Append(data.iName);
1.1206 + if (path == gDirList[num])
1.1207 + {
1.1208 + test.Printf(_L("%S\n"),&path);
1.1209 + num++;
1.1210 + }
1.1211 + else
1.1212 + {
1.1213 + test.Printf(_L("%S *** NOT FOUND ***\n"),&path);
1.1214 + }
1.1215 + }
1.1216 + delete entryList;
1.1217 + entryList=NULL;
1.1218 + }
1.1219 + delete scanner;
1.1220 + CleanDirs();
1.1221 + test(r == KErrNone);
1.1222 + if (num < gDirNum)
1.1223 + {
1.1224 + test.Printf(_L("Directory not as expected (%d found < %d expected\n"), num, gDirNum);
1.1225 + test(0);
1.1226 + }
1.1227 + test.Printf(_L("------------------------------------\n"));
1.1228 +
1.1229 + }
1.1230 +
1.1231 +void TestSystemDrive()
1.1232 + {
1.1233 + test.Next(_L("TestSystemDrive"));
1.1234 + TDriveNumber drive = RFs::GetSystemDrive();
1.1235 + test.Printf(_L("System Drive is %c:\n"), 'A'+drive);
1.1236 + for(TInt i=EDriveA; i<=EDriveZ; i++)
1.1237 + {
1.1238 + test(TheFs.SetSystemDrive((TDriveNumber)i) == KErrPermissionDenied);
1.1239 + }
1.1240 + TChar drvchar = RFs::GetSystemDriveChar();
1.1241 + test(drvchar == (TChar)('A' + drive));
1.1242 + }
1.1243 +
1.1244 +LOCAL_C void CleanupL()
1.1245 +//
1.1246 +// Clean up tests
1.1247 +//
1.1248 + {
1.1249 + test.Next(_L("Delete test directory"));
1.1250 + CFileMan* fMan=CFileMan::NewL(TheFs);
1.1251 + TInt r=fMan->RmDir(gSessionPath);
1.1252 + test(r==KErrNone);
1.1253 + delete fMan;
1.1254 + }
1.1255 +
1.1256 +GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
1.1257 +//
1.1258 +// Do all tests
1.1259 +//
1.1260 + {
1.1261 + if( !PlatSec::IsCapabilityEnforced(ECapabilityTCB) ||
1.1262 + !PlatSec::IsCapabilityEnforced(ECapabilityAllFiles) ||
1.1263 + !PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin))
1.1264 + {
1.1265 + test.Printf(_L("Insufficient capabilities enabled - leaving t_dcnone"));
1.1266 + test.Printf(_L("\n")); // Prevent overwrite by next print
1.1267 + return;
1.1268 + }
1.1269 + TurnAllocFailureOff();
1.1270 + TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
1.1271 +
1.1272 + TBuf<30> sesspath;
1.1273 + sesspath=_L("?:\\");
1.1274 + sesspath[0] = (TText)gDriveToTest;
1.1275 +
1.1276 + TInt r= TheFs.SetSessionPath(sesspath);
1.1277 + test(r==KErrNone);
1.1278 +
1.1279 + TBuf<2> cmd;
1.1280 + cmd.SetLength(1);
1.1281 + cmd[0] = (TText)gDriveToTest;
1.1282 + RProcess tp;
1.1283 + r=tp.Create(_L("clean_prepdc.exe"),sesspath);
1.1284 + test(r==KErrNone);
1.1285 + {
1.1286 + TRequestStatus ps;
1.1287 + tp.Logon(ps);
1.1288 + tp.Resume();
1.1289 + tp.Close();
1.1290 + User::WaitForRequest(ps);
1.1291 + }
1.1292 +
1.1293 + //check double mode ie that Defpath still works
1.1294 + RFs fs1;
1.1295 + RFs fs2;
1.1296 +
1.1297 + r=fs1.Connect();
1.1298 + test(r==KErrNone);
1.1299 + r=fs1.SessionPath(sesspath);
1.1300 + test(r==KErrNone);
1.1301 + test.Printf(_L("session1 Path=%S"),&sesspath);
1.1302 +
1.1303 + TBuf<30> privatepath;
1.1304 + r=fs1.SetSessionToPrivate(gTheDriveNum);
1.1305 + test(r==KErrNone);
1.1306 + r=fs1.PrivatePath(privatepath);
1.1307 + test(r==KErrNone);
1.1308 + r=privatepath.Compare(KExpectedPrivatePath());
1.1309 + test(r==0);
1.1310 + r=fs1.SessionPath(sesspath);
1.1311 + test(r==KErrNone);
1.1312 + r=privatepath.Compare(sesspath.Mid(KPathPosition));
1.1313 + test(r==0);
1.1314 + r=fs1.CreatePrivatePath(gTheDriveNum);
1.1315 + test(r==KErrNone);
1.1316 + fs1.Close();
1.1317 +
1.1318 + r=fs2.Connect();
1.1319 + test(r==KErrNone);
1.1320 + r=fs2.SessionPath(sesspath);
1.1321 + test(r==KErrNone);
1.1322 + test.Printf(_L("session2 Path=%S"),&sesspath);
1.1323 + fs2.Close();
1.1324 +
1.1325 + TestCaps();
1.1326 + TestCaging();
1.1327 + TestDirs();
1.1328 + TestPathCheck();
1.1329 + TestSystemDrive();
1.1330 +
1.1331 + test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());
1.1332 +
1.1333 + CleanupL();
1.1334 + }