20925
|
1 |
(* Title: Pure/General/secure.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Makarius
|
|
4 |
|
|
5 |
Secure critical operations.
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature SECURE =
|
|
9 |
sig
|
20977
|
10 |
val set_secure: unit -> unit
|
20925
|
11 |
val is_secure: unit -> bool
|
|
12 |
val deny_secure: string -> unit
|
21770
|
13 |
val use_text: (string -> unit) * (string -> 'a) -> bool -> string -> unit
|
|
14 |
val use_file: (string -> unit) * (string -> 'a) -> bool -> string -> unit
|
20925
|
15 |
val use: string -> unit
|
|
16 |
val commit: unit -> unit
|
20992
|
17 |
val execute: string -> string
|
|
18 |
val system: string -> int
|
20925
|
19 |
end;
|
|
20 |
|
|
21 |
structure Secure: SECURE =
|
|
22 |
struct
|
|
23 |
|
20992
|
24 |
(** secure flag **)
|
20925
|
25 |
|
|
26 |
val secure = ref false;
|
|
27 |
|
20977
|
28 |
fun set_secure () = secure := true;
|
20925
|
29 |
fun is_secure () = ! secure;
|
|
30 |
|
|
31 |
fun deny_secure msg = deny (is_secure ()) msg;
|
|
32 |
|
|
33 |
|
20992
|
34 |
(** critical operations **)
|
|
35 |
|
|
36 |
(* ML evaluation *)
|
20925
|
37 |
|
|
38 |
fun secure_mltext () = deny_secure "Cannot evaluate ML source in secure mode";
|
|
39 |
|
|
40 |
val orig_use_text = use_text;
|
21770
|
41 |
val orig_use_file = use_file;
|
20925
|
42 |
|
|
43 |
fun use_text pr verbose txt = (secure_mltext (); orig_use_text pr verbose txt);
|
21770
|
44 |
fun use_file pr verbose name = (secure_mltext (); orig_use_file pr verbose name);
|
|
45 |
val use = use_file Output.ml_output true;
|
20925
|
46 |
|
|
47 |
(*commit is dynamically bound!*)
|
|
48 |
fun commit () = orig_use_text Output.ml_output false "commit();";
|
|
49 |
|
20992
|
50 |
|
|
51 |
(* shell commands *)
|
|
52 |
|
|
53 |
fun secure_shell () = deny_secure "Cannot execute shell commands in secure mode";
|
|
54 |
|
|
55 |
val orig_execute = execute;
|
|
56 |
val orig_system = system;
|
|
57 |
|
|
58 |
fun execute s = (secure_shell (); orig_execute s);
|
|
59 |
fun system s = (secure_shell (); orig_system s);
|
|
60 |
|
20925
|
61 |
end;
|
|
62 |
|
21770
|
63 |
val use_text = Secure.use_text;
|
|
64 |
val use_file = Secure.use_file;
|
20925
|
65 |
val use = Secure.use;
|
20992
|
66 |
val execute = Secure.execute;
|
|
67 |
val system = Secure.system;
|