1 package io.jawk.jrt;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.io.IOException;
26 import java.io.PrintStream;
27 import java.util.Locale;
28 import io.jawk.AwkSandboxException;
29
30
31
32
33
34 public class SandboxedJRT extends JRT {
35
36
37
38
39
40
41
42
43
44 public SandboxedJRT(VariableManager vm, Locale locale, AwkSink awkSink, PrintStream error) {
45 super(vm, locale, awkSink, error);
46 }
47
48 @Override
49 protected AwkSink getFileAwkSink(String filename, boolean append) {
50 return sandboxViolation("Output redirection is disabled in sandbox mode");
51 }
52
53 @Override
54 protected AwkSink getPipeAwkSink(String cmd) {
55 return sandboxViolation("Command execution through pipelines is disabled in sandbox mode");
56 }
57
58 @Override
59 public PrintStream jrtGetPrintStream(String filename, boolean append) {
60 return sandboxViolation("Output redirection is disabled in sandbox mode");
61 }
62
63 @Override
64 public PrintStream jrtSpawnForOutput(String cmd) {
65 return sandboxViolation("Command execution through pipelines is disabled in sandbox mode");
66 }
67
68 @Override
69 public boolean jrtConsumeFileInput(String filename) throws IOException {
70 return sandboxViolation("Input redirection is disabled in sandbox mode");
71 }
72
73 @Override
74 public boolean jrtConsumeCommandInput(String cmd) throws IOException {
75 return sandboxViolation("Command execution through pipelines is disabled in sandbox mode");
76 }
77
78 @Override
79 public Integer jrtSystem(String cmd) {
80 return sandboxViolation("system() is disabled in sandbox mode");
81 }
82
83 private static <T> T sandboxViolation(String message) {
84 throw new AwkSandboxException(message);
85 }
86 }