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
|
|
13 |
val use: string -> unit
|
|
14 |
val use_text: (string -> unit) * (string -> 'a) -> bool -> string -> unit
|
|
15 |
val commit: unit -> unit
|
20992
|
16 |
val execute: string -> string
|
|
17 |
val system: string -> int
|
20925
|
18 |
end;
|
|
19 |
|
|
20 |
structure Secure: SECURE =
|
|
21 |
struct
|
|
22 |
|
20992
|
23 |
(** secure flag **)
|
20925
|
24 |
|
|
25 |
val secure = ref false;
|
|
26 |
|
20977
|
27 |
fun set_secure () = secure := true;
|
20925
|
28 |
fun is_secure () = ! secure;
|
|
29 |
|
|
30 |
fun deny_secure msg = deny (is_secure ()) msg;
|
|
31 |
|
|
32 |
|
20992
|
33 |
(** critical operations **)
|
|
34 |
|
|
35 |
(* ML evaluation *)
|
20925
|
36 |
|
|
37 |
fun secure_mltext () = deny_secure "Cannot evaluate ML source in secure mode";
|
|
38 |
|
|
39 |
val orig_use = use;
|
|
40 |
val orig_use_text = use_text;
|
|
41 |
|
|
42 |
fun use file = (secure_mltext (); orig_use file);
|
|
43 |
fun use_text pr verbose txt = (secure_mltext (); orig_use_text pr verbose txt);
|
|
44 |
|
|
45 |
(*commit is dynamically bound!*)
|
|
46 |
fun commit () = orig_use_text Output.ml_output false "commit();";
|
|
47 |
|
20992
|
48 |
|
|
49 |
(* shell commands *)
|
|
50 |
|
|
51 |
fun secure_shell () = deny_secure "Cannot execute shell commands in secure mode";
|
|
52 |
|
|
53 |
val orig_execute = execute;
|
|
54 |
val orig_system = system;
|
|
55 |
|
|
56 |
fun execute s = (secure_shell (); orig_execute s);
|
|
57 |
fun system s = (secure_shell (); orig_system s);
|
|
58 |
|
20925
|
59 |
end;
|
|
60 |
|
|
61 |
val use = Secure.use;
|
|
62 |
val use_text = Secure.use_text;
|
20992
|
63 |
val execute = Secure.execute;
|
|
64 |
val system = Secure.system;
|