Skip to content

Commit

Permalink
tweaks to dongleguard
Browse files Browse the repository at this point in the history
  • Loading branch information
israpps authored Feb 21, 2024
1 parent 60a4819 commit f4a8934
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/filer.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,14 @@ void pad_psu_header(psu_header *psu)
///dongleguard
/// checks if the file about to be touched is a security dongle boot file.
/// if it is, prompts the user to confirm the operation before proceeding.
/// returns 0 if user wants to proceed. returns nonzero if user does not want to proceed or the file is not a boot file
/// returns 1 if user wants to proceed. returns 0 if user does not want to proceed or the file is not a boot file
int dongleguard(char *filepath) {
if (!strcmp(filepath, "mc0:boot.bin")) {
if (ynDialog("you're about to delete/rename/move the security dongle boot file\ndont do this if you don't know what it is\n\nContinue?") > 0) {
return 0; // is a dongle bootfile, and we want to delete
} else {return 2; /*is a dongle bootfile and we dont want to delete*/}
} else {return 1; /*not a dongle boot file*/}
DPRINTF("%s(%s)\n", __FUNCTION__, filepath);
if (!strcmp(filepath, "mc0:/boot.bin")) {
return (ynDialog("you're about to remove/modify the security dongle boot file\n"
"dont do this if you don't know what it is\n\nContinue?")>0);
}
return -1;
}
#endif
//--------------------------------------------------------------
Expand Down Expand Up @@ -524,6 +525,7 @@ int ynDialog(const char *message)
drawScr();
drawSprite(setting->color[COLOR_BACKGR], dx, dy, dx + dw + 1, (dy + dh) + 1);
drawScr();
DPRINTF("%s:%d\n", __func__, ret);
return ret;
}
//------------------------------
Expand Down Expand Up @@ -2163,7 +2165,7 @@ void make_title_cfg(const char *path, const FILEINFO *file, char **_msg0)
//------------------------------
//endfunc make_title_cfg
//--------------------------------------------------------------
int delete (const char *path, const FILEINFO *file)
int delete(const char *path, const FILEINFO *file)
{
FILEINFO files[MAX_ENTRY];
char party[MAX_NAME], dir[MAX_PATH], hdddir[MAX_PATH];
Expand All @@ -2187,7 +2189,7 @@ int delete (const char *path, const FILEINFO *file)
sprintf(dir, "%s%s", path, file->name);
genLimObjName(dir, 0);
#ifdef SUPPORT_SYSTEM_2X6
if (dongleguard(dir) != 0)
if (!dongleguard(dir))
return 0;
#endif
#ifdef ETH
Expand All @@ -2198,7 +2200,7 @@ int delete (const char *path, const FILEINFO *file)
strcat(dir, "/");
nfiles = getDir(dir, files);
for (i = 0; i < nfiles; i++) {
ret = delete (dir, &files[i]); //recursively delete contents of folder
ret = delete(dir, &files[i]); //recursively delete contents of folder
if (ret < 0)
return -1;
}
Expand Down Expand Up @@ -2269,8 +2271,8 @@ int Rename(const char *path, const FILEINFO *file, const char *name)
sprintf(oldPath, "%s%s", path, file->name);
sprintf(newPath, "%s%s", path, name);
#ifdef SUPPORT_SYSTEM_2X6
if (dongleguard(oldPath) != 0)
return 0;
if (!dongleguard(oldPath)>0)
return 0;
#endif
if ((test = fileXioDopen(newPath)) >= 0) { //Does folder of same name exist ?
fileXioDclose(test);
Expand Down Expand Up @@ -2464,6 +2466,11 @@ int copy(char *outPath, const char *inPath, FILEINFO file, int recurses)
} else
sprintf(out, "%s%s", outPath, newfile.name);

#ifdef SUPPORT_SYSTEM_2X6
if (!dongleguard(out)>0)
return 0;
#endif

if (!strcmp(in, out))
return 0; //if in and out are identical our work is done.

Expand Down Expand Up @@ -2585,7 +2592,7 @@ int copy(char *outPath, const char *inPath, FILEINFO file, int recurses)
if (ynDialog(progress) < 0)
return -1;
if ((PasteMode == PM_MC_BACKUP) || (PasteMode == PM_MC_RESTORE) || (PasteMode == PM_PSU_RESTORE)) {
ret = delete (outPath, &newfile); //Attempt recursive delete
ret = delete(outPath, &newfile); //Attempt recursive delete
if (ret < 0)
return -1;
if (newdir(outPath, newfile.name) < 0)
Expand Down Expand Up @@ -4054,7 +4061,7 @@ int getFilePath(char *out, int cnfmode)
sprintf(tmp1, " %s", LNG(deleting));
strcat(tmp, tmp1);
drawMsg(tmp);
ret = delete (path, &files[browser_sel]);
ret = delete(path, &files[browser_sel]);
} else {
for (i = 0; i < browser_nfiles; i++) {
if (marks[i]) {
Expand All @@ -4066,7 +4073,7 @@ int getFilePath(char *out, int cnfmode)
sprintf(tmp1, " %s", LNG(deleting));
strcat(tmp, tmp1);
drawMsg(tmp);
ret = delete (path, &files[i]);
ret = delete(path, &files[i]);
if (ret < 0)
break;
}
Expand Down Expand Up @@ -4701,7 +4708,7 @@ void subfunc_Paste(char *mess, char *path)
if (ret < 0)
break;
if (browser_cut) {
ret = delete (clipPath, &clipFiles[i]);
ret = delete(clipPath, &clipFiles[i]);
if (ret < 0)
break;
}
Expand Down

0 comments on commit f4a8934

Please sign in to comment.