From fa49784af22dab2e40203cae7fd269043ef653c8 Mon Sep 17 00:00:00 2001 From: janneke Date: Wed, 28 Jan 2004 21:02:12 +0000 Subject: [PATCH] * input/no-notation/safe-include.ly: * input/no-notation/safe-guile.ly: * input/no-notation/safe-ps.ly: * input/no-notation/safe-tex.ly: New file. * scripts/lilypond.py (global_latex_preamble): Add \nofiles for safe mode Add -s,--safe-mode option. Use -S,--set for setting options now. (run_lilypond): When in --safe-mode, pass option to lilypond-bin. When in --safe-mode, set environment openout_any=p[aranoid]. * tex/ltest.tex: * tex/lilyponddefs.tex: Add \nofiles. * Documentation/topdocs/NEWS.texi: Add note about safe mode. --- ChangeLog | 17 +++++++++ Documentation/topdocs/NEWS.texi | 8 +++-- input/no-notation/safe-guile.ly | 14 ++++++++ input/no-notation/safe-include.ly | 13 +++++++ input/no-notation/safe-ps.ly | 11 ++++++ input/no-notation/safe-tex.ly | 16 +++++++++ scripts/lilypond.py | 57 ++++++++++++++++++++++--------- tex/lilyponddefs.tex | 1 + tex/ltest.tex | 1 + 9 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 input/no-notation/safe-guile.ly create mode 100644 input/no-notation/safe-include.ly create mode 100644 input/no-notation/safe-ps.ly create mode 100644 input/no-notation/safe-tex.ly diff --git a/ChangeLog b/ChangeLog index 378ec3eef8..8dcb7b0eda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,22 @@ 2004-01-28 Jan Nieuwenhuizen + * input/no-notation/safe-include.ly: + * input/no-notation/safe-guile.ly: + * input/no-notation/safe-ps.ly: + * input/no-notation/safe-tex.ly: New file. + + * scripts/lilypond.py (global_latex_preamble): Add \nofiles for + safe mode Add -s,--safe-mode option. Use -S,--set for setting + options now. + (run_lilypond): When in --safe-mode, pass option to lilypond-bin. + When in --safe-mode, set environment openout_any=p[aranoid]. + + * tex/ltest.tex: + * tex/lilyponddefs.tex: Add \nofiles. + + * python/lilylib.py (get_bbox, make_ps_images): Add -dSAFER to gs + options. + * Documentation/topdocs/NEWS.texi: Add note about safe mode. * mf/GNUmakefile (FETA_LIST_FILES): Install feta*list.lys too. diff --git a/Documentation/topdocs/NEWS.texi b/Documentation/topdocs/NEWS.texi index 5c19902c47..030a9077bf 100644 --- a/Documentation/topdocs/NEWS.texi +++ b/Documentation/topdocs/NEWS.texi @@ -18,9 +18,11 @@ Version 2.1.13 @itemize @bullet -@item Safe mode has been reinstated for lilypond-bin. When lilypond-bin -is invoked with @code{--safe-mode}, the user's Guile expressions are -evaluated in a safe environment and file inclusion is not allowed. +@item Safe mode has been reinstated for lilypond. +When lilypond is invoked with @{--safe-mode}, @TeX{} and PostScript +file output is disallowed, and lilypond-bin is invoked with +@code{--safe-mode}, the user's Guile expressions are evaluated in a +safe environment and file inclusion is not allowed. (This feature is still experimental.) @item There is now a Scheme macro for defining markup diff --git a/input/no-notation/safe-guile.ly b/input/no-notation/safe-guile.ly new file mode 100644 index 0000000000..a9a97ca662 --- /dev/null +++ b/input/no-notation/safe-guile.ly @@ -0,0 +1,14 @@ +\version "2.1.16" + +\header{ + + texidoc = "This should not survive lilypond --safe-mode, and + certainly not write /tmp/safe-guile.scm" + +} + +#(write "hallo" (open-file "/tmp/safe-guile.scm" "w")) + +\score{ + \notes c'' +} \ No newline at end of file diff --git a/input/no-notation/safe-include.ly b/input/no-notation/safe-include.ly new file mode 100644 index 0000000000..08cdfceab1 --- /dev/null +++ b/input/no-notation/safe-include.ly @@ -0,0 +1,13 @@ +\version "2.1.16" + +\header{ + + texidoc = "This should not survive lilypond --safe-mode" + +} + +\include "safe-ps.ly" + +\score{ + \notes c'' +} \ No newline at end of file diff --git a/input/no-notation/safe-ps.ly b/input/no-notation/safe-ps.ly new file mode 100644 index 0000000000..aeee4ae654 --- /dev/null +++ b/input/no-notation/safe-ps.ly @@ -0,0 +1,11 @@ +\version "2.1.16" + +\header{ + texidoc = "This should not survive lilypond run, and certainly not + write /tmp/safe-ps.ps" +} + +\score{ + \notes c''-"\\embeddedps{ (/tmp/safe-ps.ps) (w) file (hallo) writestring }" + +} diff --git a/input/no-notation/safe-tex.ly b/input/no-notation/safe-tex.ly new file mode 100644 index 0000000000..a407512113 --- /dev/null +++ b/input/no-notation/safe-tex.ly @@ -0,0 +1,16 @@ +\version "2.1.16" + +\header{ + + texidoc = "This should not survive lilypond --safe-mode --no-pdf --png + run, and certainly not write /tmp/safe-tex.tex" + + % beware + % openout_any=y lilypond --keep --safe-mode -S latexoptions=']{article} + % \let\nofiles\relax%' input/no-notation/safe-tex.ly + +} + +\score{ + \notes c''-"\\newwrite\\barf\\immediate\\openout\\barf=/tmp/safe-tex.tex\\immediate\\write\\barf{hallo}" +} diff --git a/scripts/lilypond.py b/scripts/lilypond.py index 15af60e526..96dd3b4cd0 100644 --- a/scripts/lilypond.py +++ b/scripts/lilypond.py @@ -126,30 +126,33 @@ option_definitions = [ _ ("write Makefile dependencies for every input file")), ('', 'h', 'help', _ ("print this help")), ('', '', 'debug', _ ("print even more output")), + (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")), + ('','', 'html', _("make HTML file with links to all output")), (_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")), ('', 'k', 'keep', _ ("keep all output, output to directory %s.dir") % program_name), ('', '', 'no-lily', _ ("don't run LilyPond")), ('', 'm', 'no-paper', _ ("produce MIDI output only")), (_ ("FILE"), 'o', 'output', _ ("write output to FILE")), - (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")), (_ ('RES'), '', 'preview-resolution', _ ("set the resolution of the preview to RES")), + ('', '', 'no-pdf', _ ("do not generate PDF output")), + ('', '', 'no-ps', _ ("do not generate PostScript outpug")), + ('', 'p', 'pdf', _ ("generate PDF output")), ('', 'P', 'postscript', _ ("generate PostScript output")), - ('', '', 'png', _("generate PNG page images")), - ('', '', 'psgz', _("generate PS.GZ")), - # separate options for PDF / PS / DVI ? ('', '', 'pdftex', _ ("use pdflatex to generate a PDF output")), - # FIXME: preview, picture; to indicate creation of a PNG? + ('', '', 'png', _("generate PNG page images")), ('', '', 'preview', _ ("make a picture of the first system")), - ('','', 'html', _("make HTML file with links to all output")), - (_ ("KEY=VAL"), 's', 'set', _ ("change global setting KEY to VAL")), + ('', '', 'psgz', _ ("generate PS.GZ")), + ('', 's', 'safe-mode', _ ("run in safe-mode")), + (_ ("KEY=VAL"), 'S', 'set', _ ("change global setting KEY to VAL")), ('', 'V', 'verbose', _ ("be verbose")), ('', 'v', 'version', _ ("print version number")), ('', 'w', 'warranty', _ ("show warranty and copyright")), ] # other globals +safe_mode_p = 0 preview_p = 0 page_images_p = 0 lilypond_error_p = 0 @@ -253,6 +256,9 @@ def run_lilypond (files, dep_prefix): if pdftex_p: opts = opts + ' -f pdftex' + if safe_mode_p: + opts = opts + ' --safe-mode' + if track_dependencies_p: opts = opts + " --dependencies" if dep_prefix: @@ -395,15 +401,17 @@ def global_latex_preamble (extra): options = '' - if extra['latexoptions']: options = options + ',' + extra['latexoptions'][-1] s = s + '\\documentclass[%s]{article}\n' % options - if extra['language']: - s = s + r'\usepackage[%s]{babel}' % extra['language'][-1] + '\n' + if safe_mode_p: + s = s + '\\nofiles\n' + if extra['language']: + s = s + r'\usepackage[%s]{babel}' \ + % extra['language'][-1] + '\n' s = s + '\\usepackage{%s}\n' \ % string.join (extra['latexpackages'], ',') @@ -704,10 +712,21 @@ for opt in options: elif o == '--include' or o == '-I': include_path.append (a) elif o == '--postscript' or o == '-P': - targets.append ('PS') + if 'PDF' in targets: + targets.remove ('PDF') + if 'PS' not in targets: + targets.append ('PS') + elif o == '--pdf' or o == '-p': + if 'PDF' not in targets: + targets.append ('PDF') + elif o == '--no-pdf': + if 'PDF' in targets: + targets.remove ('PDF') elif o == '--no-ps': - targets.remove ('PS') - targets.remove ('PDF') + if 'PS' in targets: + targets.remove ('PS') + if 'PDF' in targets: + targets.remove ('PDF') elif o == '--keep' or o == '-k': keep_temp_dir_p = 1 elif o == '--debug': @@ -726,7 +745,9 @@ for opt in options: paper_p = 0 elif o == '--output' or o == '-o': output_name = a - elif o == '--set' or o == '-s': + elif o == '--safe-mode' or o == '-s': + safe_mode_p = 1 + elif o == '--set' or o == '-S': ss = string.split (a, '=') set_setting (extra_init, ss[0], ss[1]) elif o == '--dependencies' or o == '-d': @@ -738,8 +759,8 @@ for opt in options: sys.exit (0) elif o == '--pdftex': latex_cmd = 'pdflatex' - targets.remove('DVI') - targets.append('PDFTEX') + targets.remove ('DVI') + targets.append ('PDFTEX') pdftex_p = 1 tex_extension = '.pdftex' elif o == '--warranty' or o == '-w': @@ -755,6 +776,8 @@ for opt in options: targets.append ('PNG') elif o == '--psgz': targets.append ('PS.GZ') + if 'PS' not in targets: + targets.append ('PS') else: unimplemented_option () # signal programming error @@ -830,6 +853,8 @@ if 1: tmpdir = ly.setup_temp () ly.setup_environment () + if safe_mode_p: + os.environ['openout_any'] = 'p' # to be sure, add tmpdir *in front* of inclusion path. #os.environ['TEXINPUTS'] = tmpdir + ':' + os.environ['TEXINPUTS'] diff --git a/tex/lilyponddefs.tex b/tex/lilyponddefs.tex index 515e8811ec..5cc6d4ffcf 100644 --- a/tex/lilyponddefs.tex +++ b/tex/lilyponddefs.tex @@ -55,6 +55,7 @@ \endgroup \def\lilyponddocument{} \documentclass[a4paper]{article} + \nofiles \pagestyle{empty} % \begin is defined as \outer in texinfo, thus we use \csname \csname begin\endcsname{document} diff --git a/tex/ltest.tex b/tex/ltest.tex index ce39b7c222..0425d88072 100644 --- a/tex/ltest.tex +++ b/tex/ltest.tex @@ -1,5 +1,6 @@ % Mats Bengtsson \documentclass[a4paper, 10pt]{article} +\nofiles % Allow for 8-bit characters: \usepackage[latin1]{inputenc} -- 2.39.5