diff options
-rw-r--r-- | Resource/Init/gs_init.ps | 58 | ||||
-rw-r--r-- | psi/int.mak | 2 | ||||
-rw-r--r-- | psi/zfile.c | 31 |
3 files changed, 54 insertions, 37 deletions
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps index 0fb46790e..c8ce399ef 100644 --- a/Resource/Init/gs_init.ps +++ b/Resource/Init/gs_init.ps @@ -2004,15 +2004,30 @@ systemdict /EPSBoundingBoxInit known { EPSBoundingBoxInit } if .currentglobal //true .setglobal /SAFETY 2 dict dup /safe //false put - dup /tempfiles 10 dict readonly put + dup /tempfiles 10 dict noaccess put readonly def .setglobal +/tempfilepaths +[ + (TMPDIR) getenv not + { + (TEMP) getenv not + { + (TMP) getenv not + { + (/temp) (/tmp) + } if + } if + } if +] def + /.locksafe_userparams { SAFETY /safe get not { << /PermitFileReading [ currentuserparams /PermitFileReading get aload pop + //tempfilepaths aload pop /FONTPATH .systemvar (*) .generate_dir_list_templates % Library files : /LIBPATH .systemvar (*) .generate_dir_list_templates @@ -2030,16 +2045,11 @@ readonly def ] /PermitFileWriting [ currentuserparams /PermitFileWriting get aload pop - (TMPDIR) getenv not - { - (TEMP) getenv not - { - (TMP) getenv not - { - (/temp) (/tmp) - } if - } if - } if + //tempfilepaths aload pop + ] + /PermitFileControl [ + currentuserparams /PermitFileControl get aload pop + //tempfilepaths aload pop ] /LockFilePermissions //true >> setuserparams @@ -2047,6 +2057,8 @@ readonly def if } bind def +currentdict /tempfilepaths undef + /.locksafe { .locksafe_userparams systemdict /getenv {pop //false} .forceput @@ -2108,30 +2120,6 @@ readonly def .locksafeglobal } bind executeonly odef -/deletefile { - dup { deletefile } stopped { - pop //deletefile $error /errorname get signalerror - } { - % deletefile succeeded. Remove from tempfile list if present - //SAFETY /tempfiles get exch cvn 2 copy known { - .forceundef - } { - pop pop - } - ifelse - } - ifelse -} .bind executeonly odef - -% If a file is opened with .tempfile with SAFER not (yet) set, -% the file can be deleted later, even if SAFER is set. -/.tempfile { - .tempfile % filename file - //SAFETY /safe get not { % only add the filename if we're not yet safe - //SAFETY /tempfiles get 2 .argindex //true .forceput - } if -} .bind executeonly odef - % If we are running in SAFER mode, lock things down SAFER { .setsafeglobal } if diff --git a/psi/int.mak b/psi/int.mak index 7080c5396..5d9b3d519 100644 --- a/psi/int.mak +++ b/psi/int.mak @@ -335,7 +335,7 @@ $(PSOBJ)zfile.$(OBJ) : $(PSSRC)zfile.c $(OP)\ $(memory__h) $(string__h) $(unistd__h) $(stat__h) $(gp_h) $(gpmisc_h)\ $(gscdefs_h) $(gsfname_h) $(gsstruct_h) $(gsutil_h) $(gxalloc_h) $(gxiodev_h)\ $(dstack_h) $(estack_h) $(files_h)\ - $(ialloc_h) $(idict_h) $(ilevel_h) $(iname_h) $(iutil_h)\ + $(ialloc_h) $(idict_h) $(iddict_h) $(ilevel_h) $(iname_h) $(iutil_h)\ $(isave_h) $(main_h) $(sfilter_h) $(stream_h) $(strimpl_h) $(store_h)\ $(zfile_h) $(INT_MAK) $(MAKEDIRS) $(PSCC) $(PSO_)zfile.$(OBJ) $(C_) $(PSSRC)zfile.c diff --git a/psi/zfile.c b/psi/zfile.c index 19996b09c..b30784029 100644 --- a/psi/zfile.c +++ b/psi/zfile.c @@ -35,6 +35,7 @@ #include "iname.h" #include "isave.h" /* for restore */ #include "idict.h" +#include "iddict.h" #include "iutil.h" #include "stream.h" #include "strimpl.h" @@ -312,6 +313,28 @@ file_is_tempfile(i_ctx_t *i_ctx_p, const uchar *fname, int len) return true; } +static int +record_file_is_tempfile(i_ctx_t *i_ctx_p, const uchar *fname, int len, bool add) +{ + ref *SAFETY; + ref *tempfiles; + ref kname, bref; + int code = 0; + + if (dict_find_string(systemdict, "SAFETY", &SAFETY) <= 0 || + dict_find_string(SAFETY, "tempfiles", &tempfiles) <= 0) { + return 0; + } + if ((code = name_ref(imemory, fname, len, &kname, 1)) < 0) { + return code; + } + make_bool(&bref, true); + if (add) + return idict_put(tempfiles, &kname, &bref); + else + return idict_undef(tempfiles, &kname); +} + /* ------ Level 2 extensions ------ */ /* <string> deletefile - */ @@ -321,17 +344,22 @@ zdeletefile(i_ctx_t *i_ctx_p) os_ptr op = osp; gs_parsed_file_name_t pname; int code = parse_real_file_name(op, &pname, imemory, "deletefile"); + bool is_temp = false; if (code < 0) return code; if (pname.iodev == iodev_default(imemory)) { if ((code = check_file_permissions(i_ctx_p, pname.fname, pname.len, pname.iodev, "PermitFileControl")) < 0 && - !file_is_tempfile(i_ctx_p, op->value.bytes, r_size(op))) { + !(is_temp = file_is_tempfile(i_ctx_p, op->value.bytes, r_size(op)))) { return code; } } code = (*pname.iodev->procs.delete_file)(pname.iodev, pname.fname); + + if (code >= 0 && is_temp) + code = record_file_is_tempfile(i_ctx_p, (unsigned char *)pname.fname, strlen(pname.fname), false); + gs_free_file_name(&pname, "deletefile"); if (code < 0) return code; @@ -797,6 +825,7 @@ ztempfile(i_ctx_t *i_ctx_p) } make_string(op - 1, a_readonly | icurrent_space, fnlen, sbody); make_stream_file(op, s, fmode); + code = record_file_is_tempfile(i_ctx_p, (unsigned char *)fname, fnlen, true); done: if (prefix) |