Update contrib.
1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include <e32std_private.h>
21 #include <e32def_private.h>
25 GLDEF_D RTest test(_L("t_dcnone"));
26 GLDEF_D TTime gTimeNow;
27 LOCAL_D TInt gTheDriveNum;
29 //_LIT(KDefPath, "\\Default\\");
31 const TInt KPathPosition = 2;
32 _LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
35 _LIT(KResourcePath, "?:\\Resource\\");
36 _LIT(KSystemPath, "?:\\Sys\\");
37 _LIT(KPrivatePath, "?:\\Private\\");
38 _LIT(KPrivateFalseID, "?:\\Private\\FFFFFFFF\\");
39 _LIT(KDriveName, "Billy");
40 //_LIT(KVolLable, "Benny");
42 _LIT(KFileSys, "systemfile.txt");
43 //_LIT(KFileSys2, "systemfile.tmp");
44 _LIT(KFileSys3, "sysfile.rna");
46 _LIT(KFilePri, "privatefile.txt");
47 _LIT(KFilePri2, "privatefile.tmp");
48 _LIT(KFilePri3, "prifile.rna");
50 _LIT(KFileRes, "resourcefile.txt");
51 //_LIT(KFileRes2, "resourcefile.tmp");
52 _LIT(KFileRes3, "resfile.rna");
54 _LIT(KMkDirSub,"Subdir\\");
55 _LIT(KOldFile,"?:\\Anyold.txt");
56 //_LIT(KNullPath, "");
57 //_LIT(KLFFSName, "Lffs");
59 _LIT(KWildPath, "Z:\\SYS\\");
62 _LIT(KPrivatePathTest1, "\\Private\\00000001");
63 _LIT(KPrivatePathTest2, "\\Private\\FFFFFFFF");
64 _LIT(KPrivatePathTest3, "\\Private\\FFFFFFFF\\");
67 TBuf<4> driveBuf=_L("?:\\");
80 TBuf<40> theprivatepath;
81 TBuf<40> pritestfalseidname;
89 TBuf<40> shortfilename;
90 TBuf<40> longfilename;
92 TRequestStatus aStat1;
93 TRequestStatus aStat2;
94 TRequestStatus aStat3;
95 TRequestStatus aStat4;
98 // TDriveInfo adriveInfo;
100 TBuf<40> systestfile;
101 TBuf<40> pritestfile;
102 TBuf<40> restestfile;
103 TBuf<40> systestfile1;
104 TBuf<40> pritestfile1;
105 TBuf<40> restestfile1;
115 LOCAL_C void TestPathCheck()
117 // This test case is brought in by INC054580
118 // (NTT Renaming sys ¨Cfolder on C -drive on H2 allows user to access sys -files)
121 TInt r = TheFs.Rename(_L("\\sys"), _L("\\sysbad"));
122 test(r == KErrPermissionDenied);
123 r = TheFs.Rename(_L("\\resource"), _L("\\resourcebad"));
124 test(r == KErrPermissionDenied);
125 r = TheFs.Rename(_L("\\private"), _L("\\privatebad"));
126 test(r == KErrPermissionDenied);
129 LOCAL_C void systemRFstest()
134 systestname=KSystemPath;
135 systestname[0]=(TText)('A' + gTheDriveNum);
138 mkdirname.Append(systestname);
139 mkdirname.Append(KMkDirSub);
140 r=TheFs.MkDirAll(mkdirname);
141 test(r==KErrPermissionDenied);
143 r=TheFs.RmDir(mkdirname);
144 test(r==KErrPermissionDenied);
146 r=TheFs.SetSubst(systestname,EDriveP);
147 test(r==KErrPermissionDenied);
149 r=TheFs.SetSessionPath(systestname);
150 test(r==KErrPermissionDenied);
152 TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
153 test(aStat1==KErrPermissionDenied);
155 systestfile=KSystemPath;
156 systestfile[0]=(TText)('A' + gTheDriveNum);
157 systestfile1=systestfile;
158 systestfile.Append(KFileSys);
159 systestfile1.Append(KFileSys3);
162 oldName[0]=(TText)gDriveToTest;
164 r=TheFs.GetShortName(systestfile, shortfilename);
165 test(r==KErrPermissionDenied);
167 r=TheFs.GetLongName(systestfile1, longfilename);
168 test(r==KErrPermissionDenied);
170 r=file1.Create(TheFs,oldName,EFileWrite);
171 test(r==KErrNone || r==KErrAlreadyExists);
174 r=TheFs.Replace(oldName,systestfile);
175 test(r==KErrPermissionDenied);
177 r=TheFs.Rename(systestfile,systestfile1);
178 test(r==KErrPermissionDenied);
180 // check that the entry for the system directory itself can be retrieved with no error
181 // - with or without a slash
182 TPtrC restrictedDir(systestname.Ptr(), systestname.Length());
183 r=TheFs.Entry(restrictedDir, entry);
184 test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
186 test (entry.iAtt & KEntryAttDir);
188 TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
189 r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
190 test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
193 r=TheFs.Entry(systestfile1,entry);
194 test(r==KErrPermissionDenied);
196 r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
197 test(r==KErrPermissionDenied);
199 r=TheFs.Delete(systestfile1);
200 test(r==KErrPermissionDenied);
205 LOCAL_C void resourceRFstest()
211 restestname=KResourcePath;
212 restestname[0]=(TText)('A' + gTheDriveNum);
215 mkdirname.Append(restestname);
216 mkdirname.Append(KMkDirSub);
217 r=TheFs.MkDirAll(mkdirname);
218 test(r==KErrPermissionDenied);
220 TheFs.RmDir(mkdirname);
221 test(r==KErrPermissionDenied);
223 r=TheFs.SetSubst(restestname,EDriveP);
224 test(r==KErrPermissionDenied);
226 r=TheFs.RealName(_L("P:\\File.XXX"),realName);
229 r=TheFs.SetSessionPath(restestname);
232 TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
233 test(aStat4==KRequestPending);
236 restestfile=KResourcePath;
237 restestfile[0]=(TText)('A' + gTheDriveNum);
238 restestfile1=restestfile;
239 restestfile.Append(KFileRes);
240 restestfile1.Append(KFileRes3);
243 oldName[0]=(TText)gDriveToTest;
245 r=TheFs.GetShortName(restestfile, shortfilename);
246 test(r==KErrNone || KErrPathNotFound);
248 r=TheFs.GetLongName(restestfile1, longfilename);
249 test(r==KErrNone || KErrPathNotFound);
251 r=file1.Create(TheFs,oldName,EFileWrite);
252 test(r==KErrNone || r==KErrAlreadyExists);
255 r=TheFs.Replace(oldName,restestfile);
256 test(r==KErrPermissionDenied);
258 r=TheFs.Rename(restestfile,restestfile1);
259 test(r==KErrPermissionDenied);
261 // check that the entry for the resource directory itself can be retrieved with no error
262 // - with or without a slash
263 TPtrC restrictedDir(restestname.Ptr(), restestname.Length());
264 r=TheFs.Entry(restrictedDir, entry);
265 test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
267 test (entry.iAtt & KEntryAttDir);
269 TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
270 r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
271 test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
274 r=TheFs.Entry(restestfile1,entry);
275 test(r==KErrNone || r==KErrNotFound);
277 r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
278 test(r==KErrPermissionDenied);
280 r=TheFs.Delete(restestfile1);
281 test(r==KErrPermissionDenied);
286 LOCAL_C void privatefalseIDRFstest()
291 pritestfalseidname=KPrivateFalseID;
292 pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
295 mkdirname.Append(pritestfalseidname);
296 mkdirname.Append(KMkDirSub);
298 r=TheFs.MkDirAll(mkdirname);
299 test(r==KErrPermissionDenied);
301 r=TheFs.RmDir(mkdirname);
302 test(r==KErrPermissionDenied);
304 r=TheFs.SetSubst(pritestfalseidname,EDriveP);
305 test(r==KErrPermissionDenied);
307 TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
308 test(aStat2==KErrPermissionDenied);
311 pritestfile=KPrivateFalseID;
312 pritestfile[0]=(TText)('A' + gTheDriveNum);
313 pritestfile1=pritestfile;
314 pritestfile.Append(KFilePri2);
315 pritestfile1.Append(KFilePri3);
318 oldName[0]=(TText)gDriveToTest;
320 r=TheFs.GetShortName(pritestfile, shortfilename);
321 test(r==KErrPermissionDenied);
323 r=TheFs.GetLongName(pritestfile1, longfilename);
324 test(r==KErrPermissionDenied);
326 r=file1.Create(TheFs,oldName,EFileWrite);
327 test(r==KErrNone || r==KErrAlreadyExists);
330 r=TheFs.Replace(oldName,pritestfile);
331 test(r==KErrPermissionDenied);
333 r=TheFs.Rename(pritestfile,pritestfile1);
334 test(r==KErrPermissionDenied);
336 r=TheFs.Entry(pritestfile1,entry);
337 test(r==KErrPermissionDenied);
339 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
340 test(r==KErrPermissionDenied);
342 r=TheFs.Delete(pritestfile1);
343 test(r==KErrPermissionDenied);
349 LOCAL_C void privateRFstest()
354 pritestname=KPrivatePath;
355 pritestname[0]=(TText)('A' + gTheDriveNum);
358 mkdirname.Append(pritestname);
359 mkdirname.Append(KMkDirSub);
361 r=TheFs.MkDirAll(mkdirname);
362 test(r==KErrPermissionDenied);
364 r=TheFs.RmDir(mkdirname);
365 test(r==KErrPermissionDenied);
367 r=TheFs.SetSubst(pritestname,EDriveP);
368 test(r==KErrPermissionDenied);
370 TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
371 test(aStat2==KErrPermissionDenied);
374 pritestfile=KPrivatePath;
375 pritestfile[0]=(TText)('A' + gTheDriveNum);
376 pritestfile1=pritestfile;
377 pritestfile.Append(KFilePri2);
378 pritestfile1.Append(KFilePri3);
381 oldName[0]=(TText)gDriveToTest;
383 r=TheFs.GetShortName(pritestfile, shortfilename);
384 test(r==KErrPermissionDenied);
386 r=TheFs.GetLongName(pritestfile1, longfilename);
387 test(r==KErrPermissionDenied);
389 r=file1.Create(TheFs,oldName,EFileWrite);
390 test(r==KErrNone || r==KErrAlreadyExists);
393 r=TheFs.Replace(oldName,pritestfile);
394 test(r==KErrPermissionDenied);
396 r=TheFs.Rename(pritestfile,pritestfile1);
397 test(r==KErrPermissionDenied);
399 r=TheFs.Entry(pritestfile1,entry);
400 test(r==KErrPermissionDenied);
402 // check that the entry for the private directory itself can be retrieved with no error
403 // - with or without a slash
404 TPtrC restrictedDir(pritestname.Ptr(), pritestname.Length());
405 r=TheFs.Entry(restrictedDir, entry);
406 test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
408 test (entry.iAtt & KEntryAttDir);
410 TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
411 r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
412 test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
415 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
416 test(r==KErrPermissionDenied);
418 r=TheFs.Delete(pritestfile1);
419 test(r==KErrPermissionDenied);
424 LOCAL_C void privateSIDRFstest()
429 theprivatepath[0]=(TText)gDriveToTest;
430 test.Printf(_L("the Private Path = %S"),&theprivatepath);
433 mkdirname.Append(theprivatepath);
434 mkdirname.Append(KMkDirSub);
435 r=TheFs.MkDirAll(mkdirname);
438 r=TheFs.RmDir(mkdirname);
441 r=TheFs.SetSubst(theprivatepath,EDriveP);
442 test(r==KErrPermissionDenied);
444 r=TheFs.RealName(_L("P:\\File.XXX"),realName);
447 r=TheFs.SetSessionPath(theprivatepath);
450 TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
451 test(aStat3==KRequestPending);
454 pritestfile=theprivatepath;
455 pritestfile[0]=(TText)('A' + gTheDriveNum);
456 pritestfile1=pritestfile;
457 pritestfile.Append(KFilePri2);
458 pritestfile1.Append(KFilePri3);
461 oldName[0]=(TText)gDriveToTest;
463 r=TheFs.GetShortName(pritestfile, shortfilename);
464 test(r==KErrNone || KErrPathNotFound);
466 r=TheFs.GetLongName(pritestfile1, longfilename);
467 test(r==KErrNone || KErrPathNotFound);
469 r=file1.Create(TheFs,oldName,EFileWrite);
470 test(r==KErrNone || r==KErrAlreadyExists);
473 r=TheFs.Replace(oldName,pritestfile);
476 r=TheFs.Rename(pritestfile,pritestfile1);
477 test(r==KErrNone || r==KErrAlreadyExists);
479 r=TheFs.Entry(pritestfile1,entry);
482 //Test Entry with correct SID
483 r=TheFs.Entry(theprivatepath,entry);
486 //Test Entry with correct SID and without "//" appended
487 r=TheFs.Entry(KPrivatePathTest1,entry);
490 //Test Entry with invalid SID, without // appended
491 r=TheFs.Entry(KPrivatePathTest2,entry);
492 test(r==KErrPermissionDenied);
494 //Test Entry with invalid SID
495 r=TheFs.Entry(KPrivatePathTest3,entry);
496 test(r==KErrPermissionDenied);
498 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
501 r=TheFs.Delete(pritestfile1);
507 LOCAL_C void systemRFiletest()
512 r=TheFs.SetSessionPath(systestname);
513 test(r==KErrPermissionDenied);
515 r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
516 test(r==KErrPermissionDenied);
519 TBuf<25> sysfilename;
520 sysfilename.Append(systestname);
521 sysfilename.Append(KFileSys);
523 r=file1.Create(TheFs,sysfilename,EFileWrite);
524 test(r==KErrPermissionDenied);
526 r=file1.Open(TheFs,sysfilename,EFileWrite);
527 test(r==KErrPermissionDenied);
529 r=file1.Open(TheFs,sysfilename,EFileRead);
530 test(r==KErrPermissionDenied);
532 r=file1.Replace(TheFs,sysfilename,EFileWrite);
533 test(r==KErrPermissionDenied);
535 TFindFile finder(TheFs);
537 r=finder.FindWildByDir(KWildFile, KWildPath, dir);
538 if (!(r==KErrPermissionDenied))
539 test.Printf(_L("T_DCNONE: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r);
540 test(r==KErrPermissionDenied);
544 LOCAL_C void resourceRFiletest()
549 r=TheFs.SetSessionPath(restestname);
552 r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
553 test(r==KErrPermissionDenied);
556 r=file1.Create(TheFs,KFileRes,EFileWrite);
557 test(r==KErrPermissionDenied);
560 r=file1.Open(TheFs,KFileRes,EFileWrite);
561 test(r==KErrPermissionDenied);
564 r=file1.Open(TheFs,KFileRes,EFileRead|EFileShareReadersOnly);
565 test(r==KErrNone || r==KErrPathNotFound);
568 r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileRead);
569 test(r==KErrNone || r==KErrPathNotFound);
572 r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileWrite);
573 test(r==KErrPermissionDenied);
576 r=file1.Open(TheFs,KFileRes,EFileShareReadersOnly);
577 test(r==KErrNone || r==KErrPathNotFound);
579 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
580 test(r==KErrNone || r==KErrPathNotFound);
582 //this operation is prevented as you can not open a file for write access in the resource directory
583 r=file1.Rename(KFileRes3);
584 test(r==KErrPermissionDenied || r==KErrAccessDenied);
588 r=file1.Replace(TheFs,KFileRes,EFileWrite);
589 test(r==KErrPermissionDenied);
595 LOCAL_C void privatefalseIDRFiletest()
601 r=TheFs.SetSessionPath(pritestfalseidname);
602 test(r==KErrPermissionDenied);
604 r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
605 test(r==KErrPermissionDenied);
607 TBuf<25> prifilename;
608 prifilename.Append(pritestname);
609 prifilename.Append(KFileSys);
611 r=file1.Create(TheFs,prifilename,EFileWrite);
612 test(r==KErrPermissionDenied);
615 r=file1.Open(TheFs,prifilename,EFileWrite);
616 test(r==KErrPermissionDenied);
618 r=file1.Open(TheFs,prifilename,EFileRead);
619 test(r==KErrPermissionDenied);
622 r=file1.Replace(TheFs,prifilename,EFileWrite);
623 test(r==KErrPermissionDenied);
629 LOCAL_C void privateRFiletest()
635 r=TheFs.SetSessionPath(pritestname);
636 test(r==KErrPermissionDenied);
638 r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
639 test(r==KErrPermissionDenied);
641 TBuf<25> prifilename;
642 prifilename.Append(pritestname);
643 prifilename.Append(KFileSys);
645 r=file1.Create(TheFs,prifilename,EFileWrite);
646 test(r==KErrPermissionDenied);
649 r=file1.Open(TheFs,prifilename,EFileWrite);
650 test(r==KErrPermissionDenied);
653 r=file1.Open(TheFs,prifilename,EFileRead);
654 test(r==KErrPermissionDenied);
657 r=file1.Replace(TheFs,prifilename,EFileWrite);
658 test(r==KErrPermissionDenied);
662 LOCAL_C void privateSIDRFiletest()
668 r=TheFs.SetSessionToPrivate(gTheDriveNum);
671 r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
674 r=file1.Create(TheFs,KFilePri,EFileWrite);
675 test(r==KErrNone || r==KErrAlreadyExists);
677 r=file1.Open(TheFs,KFilePri,EFileWrite);
680 r=file1.Open(TheFs,KFilePri,EFileRead);
683 r=file1.Replace(TheFs,KFilePri,EFileWrite);
685 r=file1.Rename(KFilePri3);
686 test(r==KErrNone || r==KErrAlreadyExists);
692 LOCAL_C void RDirtest()
699 TBuf<30> dirNameBuf(KSystemPath);
700 dirNameBuf[0]=(TText)gDriveToTest;
701 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
702 test(r==KErrPermissionDenied);
704 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
705 test(r==KErrPermissionDenied);
709 dirNameBuf=KPrivateFalseID;
710 dirNameBuf[0]=(TText)gDriveToTest;
711 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
712 test(r==KErrPermissionDenied);
714 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
715 test(r==KErrPermissionDenied);
720 dirNameBuf=KPrivatePath;
721 dirNameBuf[0]=(TText)gDriveToTest;
722 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
723 test(r==KErrPermissionDenied);
725 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
726 test(r==KErrPermissionDenied);
730 TheFs.PrivatePath(dirNameBuf);
731 dirNameBuf.Insert(0,_L("?:"));
732 dirNameBuf[0]=(TText)gDriveToTest;
733 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
736 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
741 dirNameBuf=KResourcePath;
742 dirNameBuf[0]=(TText)gDriveToTest;
743 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
745 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
752 LOCAL_C void TestNoCaps()
754 // test APIs with no capabilities
757 r=TheFs.FileSystemName(fsname,gTheDriveNum);
759 r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
760 test(r==KErrPermissionDenied);
761 // r=TheFs.RemoveFileSystem(fsname); //can not test due to bug elsewhere fix exists
762 // test(r==KErrPermissionDenied);
763 // r=TheFs.AddFileSystem(fsname);
764 // test(r==KErrPermissionDenied);
765 r = MountFileSystem(TheFs, fsname, gTheDriveNum);
766 test(r==KErrPermissionDenied);
767 r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
768 test(r==KErrPermissionDenied);
769 // r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum); //broken on wins C:
770 // test(r==KErrPermissionDenied);
776 privatefalseIDRFstest();
781 privateSIDRFiletest();
782 privatefalseIDRFiletest();
783 //disk changes to sys and pri paths should have completed these
784 test(aStat4 == KRequestPending);
785 TheFs.NotifyChangeCancel(aStat4);
786 test(aStat4==KErrCancel);
789 User::WaitForRequest(aStat3);
790 test(aStat1==KErrPermissionDenied);
791 test(aStat2==KErrPermissionDenied);
792 test(aStat3==KErrNone);
794 r=TheFs.SetSessionPath(systestname);
795 test(r==KErrPermissionDenied);
798 //Test RRawDisk class
799 r=rawdisk.Open(TheFs,gTheDriveNum);
800 test(r==KErrPermissionDenied);
803 r=format.Open(TheFs,driveBuf,EHighDensity,count);
804 test(r==KErrPermissionDenied);
808 driveBuf[0]=(TText)gDriveToTest;
809 r=TheFs.ScanDrive(driveBuf);
810 test(r==KErrPermissionDenied);
811 r=TheFs.CheckDisk(driveBuf);
812 test(r==KErrPermissionDenied);
815 LOCAL_C void TestCaps()
817 // test format etc that require certain capabilities
820 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
821 const char myDiagMsg[]="Capability Check Failure";
822 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
823 r=RProcess().HasCapability(ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
825 r=RProcess().HasCapability(ECapabilityTCB, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
827 r=RProcess().HasCapability(ECapabilityDiskAdmin, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
829 r=RProcess().HasCapability(ECapability_None, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
832 driveBuf[0]=(TText)gDriveToTest;
833 r=TheFs.SessionPath(temp);
836 r=TheFs.CreatePrivatePath(gTheDriveNum);
837 test(r==KErrNone || r== KErrAlreadyExists);
840 r=TheFs.PrivatePath(tempPri);
842 theprivatepath = _L("?:");
843 theprivatepath.Append(tempPri);
847 TFileName thesessionpath;
848 r=TheFs.SetSessionToPrivate(gTheDriveNum);
850 r=TheFs.SessionPath(thesessionpath);
853 test(thesessionpath == theprivatepath);
858 LOCAL_C void MakeDirs()
860 // Create system and private directories for scan with and without DC
864 r = TheFs.MkDir(_L("\\normal\\"));
865 test(r == KErrNone || r == KErrAlreadyExists);
866 r = TheFs.MkDir(_L("\\normal\\one\\"));
867 test(r == KErrNone || r == KErrAlreadyExists);
868 r = TheFs.MkDir(_L("\\normal\\two\\"));
869 test(r == KErrNone || r == KErrAlreadyExists);
870 r = TheFs.MkDir(_L("\\sys\\"));
871 test(r == KErrPermissionDenied);
872 r = TheFs.MkDir(_L("\\sys\\one\\"));
873 test(r == KErrPermissionDenied);
874 r = TheFs.MkDir(_L("\\sys\\two\\"));
875 test(r == KErrPermissionDenied);
876 r = TheFs.MkDir(_L("\\private\\"));
877 test(r == KErrPermissionDenied);
878 r = TheFs.MkDir(_L("\\private\\one\\"));
879 test(r == KErrPermissionDenied);
880 r = TheFs.MkDir(_L("\\private\\two\\"));
881 test(r == KErrPermissionDenied);
882 r = TheFs.MkDir(_L("\\ZZZZZZ\\"));
883 test(r == KErrNone || r == KErrAlreadyExists);
888 LOCAL_C void ScanDir(const TDesC& aName, CDirScan::TScanDirection aDirection, TInt aError)
890 CDirScan* scanner = NULL;
891 TRAP(r, scanner = CDirScan::NewL(TheFs));
892 test(r == KErrNone && scanner);
894 TRAP(r, scanner->SetScanDataL(aName,KEntryAttDir,ESortByName|EAscending,aDirection));
897 CDir *entryList=NULL;
900 TRAP(r, scanner->NextL(entryList));
904 TInt count=entryList->Count();
907 TEntry data=(*entryList)[count];
908 TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
910 dirName.Append(data.iName);
911 test.Printf(_L(" %S\n"),&dirName);
922 The following test, tests CFileMan and CDirScan API on folders private and sys
923 to confirm that any operation on these folders for any app with incorrect capability
924 returns KErrPermissionDenied. This test step was added as a result of DEF051428
925 ("PlatSec: Incorrect errors returned by f32")
927 LOCAL_C void TestCaging()
929 CFileMan* fMan=CFileMan::NewL(TheFs);
934 // Checking the private path
935 TBuf<30> privatepath;
936 r=TheFs.PrivatePath(privatepath);
937 test.Printf(_L("Private Path is=%S"),&privatepath);
939 r = TheFs.MkDir(_L("\\Caged\\"));
940 test(r==KErrNone || r==KErrAlreadyExists);
942 CDir* entryCount=NULL;
943 r=TheFs.GetDir(_L("\\*.*"),KEntryAttNormal,ESortNone,entryCount);
945 TInt rootCount= entryCount->Count();
952 CDir* entryCount2=NULL;
953 r=fMan->Copy(_L("\\sys\\"),_L("\\Caged\\"));
954 test(r == KErrPermissionDenied);
955 r=fMan->Copy(_L("\\*"),_L("\\Caged\\"));
958 r=TheFs.GetDir(_L("\\Caged\\*.*"),KEntryAttNormal,ESortNone,entryCount2);
960 TInt cagedCount= entryCount2->Count();
962 test(cagedCount==rootCount);
967 // Check if both copied sys and private are empty (no information is exposed)
968 CDir* entryCount3=NULL;
969 r=TheFs.GetDir(_L("\\Caged\\private\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount3);
970 test(r==KErrPathNotFound);
974 CDir* entryCount4=NULL;
975 r=TheFs.GetDir(_L("\\Caged\\sys\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount4);
976 test(r==KErrPathNotFound);
981 r=fMan->Copy(_L("\\private\\two\\moo"),_L("\\private\\two\\mew"));
982 test(r == KErrPermissionDenied);
984 // Create a test file
986 r = testFile.Replace(TheFs, _L("\\capTest"),EFileWrite);
987 test(r==KErrNone || r==KErrAlreadyExists);
992 name.Append(_L("privateFile.tst"));
994 r = privateFile.Replace(TheFs, name,EFileWrite);
995 test(r==KErrNone || r==KErrAlreadyExists);
999 r=fMan->Copy(_L("\\capTest"),_L("\\private\\two\\moo"));
1000 test(r == KErrPermissionDenied);
1001 r=fMan->Copy(_L("\\capTest"),_L("\\sys\\bin\\moo"));
1002 test(r == KErrPermissionDenied);
1003 r=fMan->Copy(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo"));
1004 test(r == KErrPermissionDenied);
1005 r=fMan->Copy(_L("\\sys\\*"),_L("\\"));
1006 test (r==KErrPermissionDenied);
1007 r=fMan->Copy(name,_L("\\sys\\"));
1008 test(r==KErrPermissionDenied);
1011 r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo"));
1012 test(r == KErrPermissionDenied);
1013 r=fMan->Move(_L("\\private\\two\\moo.."),_L("\\private\\one\\moo"));
1014 test(r == KErrPermissionDenied);
1015 r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo.."));
1016 test(r == KErrPermissionDenied);
1017 r=fMan->Move(name,_L("\\privateFile.tst"));
1018 test(r == KErrNone);
1019 r=fMan->Move(_L("\\privateFile.tst"),name);
1020 test(r == KErrNone);
1021 r=fMan->Move(_L("\\capTest"),_L("\\private\\two\\moo"));
1022 test(r == KErrPermissionDenied);
1023 r=fMan->Move(_L("\\capTest"),_L("\\sys\\bin\\moo"));
1024 test(r == KErrPermissionDenied);
1025 r=fMan->Move(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo"));
1026 test(r == KErrPermissionDenied);
1027 r=fMan->Move(_L("\\sys\\*"),_L("\\"));
1028 test (r==KErrPermissionDenied);
1029 r=fMan->Move(name,_L("\\sys\\"));
1030 test(r==KErrPermissionDenied);
1034 r=fMan->Attribs(_L("\\private\\two\\moo"),KEntryAttReadOnly,0,TTime(0));
1035 test(r == KErrPermissionDenied);
1036 r=fMan->Attribs(_L("\\private\\moo"),KEntryAttReadOnly,0,TTime(0));
1037 test(r == KErrPermissionDenied);
1038 r=fMan->Attribs(name,KEntryAttReadOnly,0,TTime(0));
1039 test(r == KErrNone);
1040 r=fMan->Attribs(name,0,KEntryAttReadOnly,TTime(0));
1041 test(r == KErrNone);
1045 r=fMan->RmDir(_L("\\private\\"));
1046 test(r == KErrPermissionDenied);
1047 r=fMan->RmDir(_L("\\private\\two\\"));
1048 test(r == KErrPermissionDenied);
1049 r=fMan->RmDir(_L("\\private\\tw?\\"));
1050 test(r == KErrPermissionDenied);
1051 r=fMan->RmDir(_L("\\sys\\"));
1052 test(r == KErrPermissionDenied);
1056 r=fMan->Rename(_L("\\private\\two\\moo"),_L("\\private\\two\\mew"));
1057 test(r == KErrPermissionDenied);
1060 r=fMan->Delete(_L("\\private\\two\\test"));
1061 test(r == KErrPermissionDenied);
1062 r=fMan->Delete(_L("\\private\\moo"));
1063 test(r == KErrPermissionDenied);
1064 r=fMan->Delete(_L("\\sys\\moo"));
1065 test(r == KErrPermissionDenied);
1068 //Something that actually exists in Private
1069 r=fMan->Rename(name,_L("\\private\\00000001\\moo"));
1070 test(r == KErrNone);
1071 r=fMan->Rename(_L("\\private\\00000001\\moo"),name);
1072 test(r == KErrNone);
1073 r=fMan->Copy(name,_L("\\private\\00000001\\moo"));
1074 test(r == KErrNone);
1075 r=fMan->Delete(_L("\\private\\00000001\\moo"));
1076 test(r == KErrNone);
1078 // Clean up the test data
1079 r=fMan->RmDir(_L("\\Caged\\"));
1080 test(r == KErrNone);
1081 r=fMan->Delete(_L("\\capTest"));
1082 test(r == KErrNone);
1083 r=fMan->Delete(name);
1084 test(r == KErrNone);
1089 ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone);
1090 ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone);
1091 ScanDir(_L("\\private\\"), CDirScan::EScanDownTree, KErrPermissionDenied);
1092 ScanDir(_L("\\private\\"), CDirScan::EScanUpTree, KErrPermissionDenied);
1094 LOCAL_C void CleanDirs()
1096 // Remove system and private directories for scan with and without DC
1097 // (note that the \Private directory may not be able to be removed at this
1098 // point if it contains other directories, so failing with "in use" is
1099 // permitted in this case).
1103 r = TheFs.RmDir(_L("\\normal\\one\\"));
1104 test(r == KErrNone);
1105 r = TheFs.RmDir(_L("\\normal\\two\\"));
1106 test(r == KErrNone);
1107 r = TheFs.RmDir(_L("\\normal\\"));
1108 test(r == KErrNone);
1109 r = TheFs.RmDir(_L("\\sys\\one\\"));
1110 test(r == KErrPermissionDenied);
1111 r = TheFs.RmDir(_L("\\sys\\two\\"));
1112 test(r == KErrPermissionDenied);
1113 r = TheFs.RmDir(_L("\\sys\\"));
1114 test(r == KErrPermissionDenied);
1115 r = TheFs.RmDir(_L("\\private\\one\\"));
1116 test(r == KErrPermissionDenied);
1117 r = TheFs.RmDir(_L("\\private\\two\\"));
1118 test(r == KErrPermissionDenied);
1119 r = TheFs.RmDir(_L("\\private\\"));
1120 test(r == KErrPermissionDenied);
1121 r = TheFs.RmDir(_L("\\ZZZZZZ\\"));
1122 test(r == KErrNone);
1125 TFileName gDirList[100];
1128 LOCAL_C void ListDirs()
1130 // List the directories and files on the disk, without DC (so we
1131 // find all of them), saving them in gDirList[] apart from
1132 // members of the System and Private ones.
1135 CDirScan* scanner = NULL;
1137 TRAP(r, scanner = CDirScan::NewL(TheFs));
1138 test(r == KErrNone && scanner);
1140 TheFs.Parse(_L("\\"),dirName);
1141 TRAP(r, scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName|EAscending));
1142 test(r == KErrNone);
1144 test.Printf(_L("------ ALL DIRECTORIES ------\n"));
1147 scanner->NextL(entryList);
1148 if (entryList==NULL)
1150 TInt count=entryList->Count();
1153 TEntry data=(*entryList)[count];
1154 TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
1155 gDirList[gDirNum] = path;
1156 gDirList[gDirNum].Append(data.iName);
1157 test.Printf(_L(" %S\n"),&gDirList[gDirNum]);
1166 LOCAL_C void TestDirs()
1168 // Scan directories and files with DC on, so only the root \Private
1169 // and \System directories should be found (no contents).
1176 CDirScan* scanner = NULL;
1178 TRAP(r, scanner = CDirScan::NewL(TheFs));
1179 test(r == KErrNone && scanner);
1181 TheFs.Parse(_L("\\"),dirName);
1182 TRAP(r, scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName|EAscending));
1183 test(r == KErrNone);
1184 CDir *entryList = NULL;
1186 test.Printf(_L("------ ACCESSIBLE DIRECTORIES ------\n"));
1189 TRAP(r, scanner->NextL(entryList));
1192 test.Printf(_L("*** ERROR %d doing NextL()\n"), r);
1195 if (entryList==NULL)
1197 TInt count=entryList->Count();
1200 TEntry data=(*entryList)[count];
1201 TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
1202 path.Append(data.iName);
1203 if (path == gDirList[num])
1205 test.Printf(_L("%S\n"),&path);
1210 test.Printf(_L("%S *** NOT FOUND ***\n"),&path);
1218 test(r == KErrNone);
1221 test.Printf(_L("Directory not as expected (%d found < %d expected\n"), num, gDirNum);
1224 test.Printf(_L("------------------------------------\n"));
1228 void TestSystemDrive()
1230 test.Next(_L("TestSystemDrive"));
1231 TDriveNumber drive = RFs::GetSystemDrive();
1232 test.Printf(_L("System Drive is %c:\n"), 'A'+drive);
1233 for(TInt i=EDriveA; i<=EDriveZ; i++)
1235 test(TheFs.SetSystemDrive((TDriveNumber)i) == KErrPermissionDenied);
1237 TChar drvchar = RFs::GetSystemDriveChar();
1238 test(drvchar == (TChar)('A' + drive));
1241 LOCAL_C void CleanupL()
1246 test.Next(_L("Delete test directory"));
1247 CFileMan* fMan=CFileMan::NewL(TheFs);
1248 TInt r=fMan->RmDir(gSessionPath);
1253 GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
1258 if( !PlatSec::IsCapabilityEnforced(ECapabilityTCB) ||
1259 !PlatSec::IsCapabilityEnforced(ECapabilityAllFiles) ||
1260 !PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin))
1262 test.Printf(_L("Insufficient capabilities enabled - leaving t_dcnone"));
1263 test.Printf(_L("\n")); // Prevent overwrite by next print
1266 TurnAllocFailureOff();
1267 TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
1270 sesspath=_L("?:\\");
1271 sesspath[0] = (TText)gDriveToTest;
1273 TInt r= TheFs.SetSessionPath(sesspath);
1278 cmd[0] = (TText)gDriveToTest;
1280 r=tp.Create(_L("clean_prepdc.exe"),sesspath);
1287 User::WaitForRequest(ps);
1290 //check double mode ie that Defpath still works
1296 r=fs1.SessionPath(sesspath);
1298 test.Printf(_L("session1 Path=%S"),&sesspath);
1300 TBuf<30> privatepath;
1301 r=fs1.SetSessionToPrivate(gTheDriveNum);
1303 r=fs1.PrivatePath(privatepath);
1305 r=privatepath.Compare(KExpectedPrivatePath());
1307 r=fs1.SessionPath(sesspath);
1309 r=privatepath.Compare(sesspath.Mid(KPathPosition));
1311 r=fs1.CreatePrivatePath(gTheDriveNum);
1317 r=fs2.SessionPath(sesspath);
1319 test.Printf(_L("session2 Path=%S"),&sesspath);
1328 test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());