| author | hoelzl | 
| Thu, 26 Aug 2010 18:41:54 +0200 | |
| changeset 39083 | e46acc0ea1fe | 
| parent 37977 | 3ceccd415145 | 
| child 38799 | 712cb964d113 | 
| permissions | -rw-r--r-- | 
| 20925 | 1 | (* Title: Pure/General/secure.ML | 
| 2 | Author: Makarius | |
| 3 | ||
| 4 | Secure critical operations. | |
| 5 | *) | |
| 6 | ||
| 7 | signature SECURE = | |
| 8 | sig | |
| 20977 | 9 | val set_secure: unit -> unit | 
| 20925 | 10 | val is_secure: unit -> bool | 
| 26080 | 11 | val deny_secure: string -> unit | 
| 31330 | 12 | val secure_mltext: unit -> unit | 
| 30672 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 13 | val use_text: use_context -> int * string -> bool -> string -> unit | 
| 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 14 | val use_file: use_context -> bool -> string -> unit | 
| 30625 
d53d1a16d5ee
replaced install_pp/make_pp by more general toplevel_pp based on use_text;
 wenzelm parents: 
29606diff
changeset | 15 | val toplevel_pp: string list -> string -> unit | 
| 37239 | 16 | val Isar_setup: unit -> unit | 
| 17 | val PG_setup: unit -> unit | |
| 20925 | 18 | val commit: unit -> unit | 
| 35010 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 19 | val bash_output: string -> string * int | 
| 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 20 | val bash: string -> int | 
| 20925 | 21 | end; | 
| 22 | ||
| 23 | structure Secure: SECURE = | |
| 24 | struct | |
| 25 | ||
| 20992 | 26 | (** secure flag **) | 
| 20925 | 27 | |
| 32738 | 28 | val secure = Unsynchronized.ref false; | 
| 20925 | 29 | |
| 20977 | 30 | fun set_secure () = secure := true; | 
| 20925 | 31 | fun is_secure () = ! secure; | 
| 32 | ||
| 22567 
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
 wenzelm parents: 
22144diff
changeset | 33 | fun deny_secure msg = if is_secure () then error msg else (); | 
| 20925 | 34 | |
| 35 | ||
| 25753 | 36 | |
| 20992 | 37 | (** critical operations **) | 
| 38 | ||
| 39 | (* ML evaluation *) | |
| 20925 | 40 | |
| 41 | fun secure_mltext () = deny_secure "Cannot evaluate ML source in secure mode"; | |
| 42 | ||
| 30672 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 43 | val raw_use_text = use_text; | 
| 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 44 | val raw_use_file = use_file; | 
| 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 45 | val raw_toplevel_pp = toplevel_pp; | 
| 20925 | 46 | |
| 30672 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 47 | fun use_text context pos verbose txt = (secure_mltext (); raw_use_text context pos verbose txt); | 
| 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 48 | fun use_file context verbose name = (secure_mltext (); raw_use_file context verbose name); | 
| 23922 
707639e9497d
marked some CRITICAL sections (for multithreading);
 wenzelm parents: 
22567diff
changeset | 49 | |
| 30672 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 50 | fun toplevel_pp path pp = (secure_mltext (); raw_toplevel_pp ML_Parse.global_context path pp); | 
| 30625 
d53d1a16d5ee
replaced install_pp/make_pp by more general toplevel_pp based on use_text;
 wenzelm parents: 
29606diff
changeset | 51 | |
| 32739 | 52 | |
| 53 | (* global evaluation *) | |
| 54 | ||
| 55 | val use_global = raw_use_text ML_Parse.global_context (0, "") false; | |
| 56 | ||
| 57 | fun commit () = use_global "commit();"; (*commit is dynamically bound!*) | |
| 37239 | 58 | |
| 59 | fun Isar_setup () = use_global "open Unsynchronized;"; | |
| 37977 
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
 wenzelm parents: 
37239diff
changeset | 60 | fun PG_setup () = use_global "structure ThyLoad = ProofGeneral.ThyLoad;"; | 
| 20925 | 61 | |
| 20992 | 62 | |
| 63 | (* shell commands *) | |
| 64 | ||
| 65 | fun secure_shell () = deny_secure "Cannot execute shell commands in secure mode"; | |
| 66 | ||
| 35010 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 67 | val orig_bash_output = bash_output; | 
| 20992 | 68 | |
| 35010 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 69 | fun bash_output s = (secure_shell (); orig_bash_output s); | 
| 26332 | 70 | |
| 35010 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 71 | fun bash s = | 
| 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 72 | (case bash_output s of | 
| 26332 | 73 |     ("", rc) => rc
 | 
| 74 | | (out, rc) => (writeln (perhaps (try (unsuffix "\n")) out); rc)); | |
| 20992 | 75 | |
| 20925 | 76 | end; | 
| 77 | ||
| 23978 | 78 | (*override previous toplevel bindings!*) | 
| 21770 | 79 | val use_text = Secure.use_text; | 
| 80 | val use_file = Secure.use_file; | |
| 30672 
beaadd5af500
more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
 wenzelm parents: 
30625diff
changeset | 81 | fun use s = Secure.use_file ML_Parse.global_context true s | 
| 31473 | 82 | handle ERROR msg => (writeln msg; error "ML error"); | 
| 30625 
d53d1a16d5ee
replaced install_pp/make_pp by more general toplevel_pp based on use_text;
 wenzelm parents: 
29606diff
changeset | 83 | val toplevel_pp = Secure.toplevel_pp; | 
| 35010 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 84 | val bash_output = Secure.bash_output; | 
| 
d6e492cea6e4
renamed system/system_out to bash/bash_output -- to emphasized that this is really GNU bash, not some undefined POSIX sh;
 wenzelm parents: 
32739diff
changeset | 85 | val bash = Secure.bash; |