From 0abb5731679eb677e345b1fe975325b4971d698f Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Tue, 25 Jun 2019 17:53:05 +0000 Subject: [PATCH] Implement simple access control for reading and writing files that are accessable from within DOSBox. Overlay not yet tested, hence not part of this commit. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4245 --- src/dos/dos_programs.cpp | 8 ++++---- src/dos/drive_fat.cpp | 2 +- src/dos/drive_local.cpp | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/dos/dos_programs.cpp b/src/dos/dos_programs.cpp index 034e5605..621b9bfc 100644 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -607,9 +607,9 @@ private: //File not found on mounted filesystem. Try regular filesystem std::string filename_s(filename); Cross::ResolveHomedir(filename_s); - tmpfile = fopen(filename_s.c_str(),"rb+"); + tmpfile = fopen_wrap(filename_s.c_str(),"rb+"); if(!tmpfile) { - if( (tmpfile = fopen(filename_s.c_str(),"rb")) ) { + if( (tmpfile = fopen_wrap(filename_s.c_str(),"rb")) ) { //File exists; So can't be opened in correct mode => error 2 // fclose(tmpfile); // if(tryload) error = 2; @@ -1301,7 +1301,7 @@ public: if(fstype=="fat") { if (imgsizedetect) { - FILE * diskfile = fopen(temp_line.c_str(), "rb+"); + FILE * diskfile = fopen_wrap(temp_line.c_str(), "rb+"); if (!diskfile) { WriteOut(MSG_Get("PROGRAM_IMGMOUNT_INVALID_IMAGE")); return; @@ -1448,7 +1448,7 @@ public: WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_2"), drive, tmp.c_str()); } else { - FILE *newDisk = fopen(temp_line.c_str(), "rb+"); + FILE *newDisk = fopen_wrap(temp_line.c_str(), "rb+"); if (!newDisk) { WriteOut(MSG_Get("PROGRAM_IMGMOUNT_INVALID_IMAGE")); return; diff --git a/src/dos/drive_fat.cpp b/src/dos/drive_fat.cpp index 63bfc155..e7ffdb70 100644 --- a/src/dos/drive_fat.cpp +++ b/src/dos/drive_fat.cpp @@ -705,7 +705,7 @@ fatDrive::fatDrive(const char *sysFilename, Bit32u bytesector, Bit32u cylsector, imgDTA = new DOS_DTA(imgDTAPtr); } - diskfile = fopen(sysFilename, "rb+"); + diskfile = fopen_wrap(sysFilename, "rb+"); if(!diskfile) {created_successfully = false;return;} fseek(diskfile, 0L, SEEK_END); filesize = (Bit32u)ftell(diskfile) / 1024L; diff --git a/src/dos/drive_local.cpp b/src/dos/drive_local.cpp index da8d6e59..4b9013b2 100644 --- a/src/dos/drive_local.cpp +++ b/src/dos/drive_local.cpp @@ -39,16 +39,16 @@ bool localDrive::FileCreate(DOS_File * * file,char * name,Bit16u /*attributes*/) CROSS_FILENAME(newname); char* temp_name = dirCache.GetExpandName(newname); //Can only be used in till a new drive_cache action is preformed */ /* Test if file exists (so we need to truncate it). don't add to dirCache then */ - bool existing_file=false; + bool existing_file = false; - FILE * test=fopen(temp_name,"rb+"); + FILE * test = fopen_wrap(temp_name,"rb+"); if(test) { fclose(test); existing_file=true; } - FILE * hand=fopen(temp_name,"wb+"); + FILE * hand = fopen_wrap(temp_name,"wb+"); if (!hand){ LOG_MSG("Warning: file creation failed: %s",newname); return false; @@ -95,11 +95,11 @@ bool localDrive::FileOpen(DOS_File * * file,char * name,Bit32u flags) { } } - FILE * hand=fopen(newname,type); + FILE * hand = fopen_wrap(newname,type); // Bit32u err=errno; if (!hand) { if((flags&0xf) != OPEN_READ) { - FILE * hmm=fopen(newname,"rb"); + FILE * hmm = fopen_wrap(newname,"rb"); if (hmm) { fclose(hmm); LOG_MSG("Warning: file %s exists and failed to open in write mode.\nPlease Remove write-protection",newname); @@ -122,7 +122,7 @@ FILE * localDrive::GetSystemFilePtr(char const * const name, char const * const CROSS_FILENAME(newname); dirCache.ExpandName(newname); - return fopen(newname,type); + return fopen_wrap(newname,type); } bool localDrive::GetSystemFilename(char *sysName, char const * const dosName) { @@ -145,7 +145,7 @@ bool localDrive::FileUnlink(char * name) { struct stat buffer; if(stat(fullname,&buffer)) return false; // File not found. - FILE* file_writable = fopen(fullname,"rb+"); + FILE* file_writable = fopen_wrap(fullname,"rb+"); if(!file_writable) return false; //No acces ? ERROR MESSAGE NOT SET. FIXME ? fclose(file_writable);