forked from SeattleTestbed/seattlelib_v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivate_hideprivate_layer.repy
57 lines (47 loc) · 1.85 KB
/
private_hideprivate_layer.repy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Author: Steven Portzer
Started: June 13, 2011
Description:
A security layer that prevents user programs from accessing files starting with
'private_'.
"""
# Checks to make sure the file isn't private before opening it
def secure_open(filename, mode='r'):
if filename.startswith("private_"):
raise ValueError("User is not allowed to use file names starting with 'private_'")
return open(filename, mode)
# Filters out private files from the returned file list
def secure_listdir():
filelist = []
for filename in listdir():
if not filename.startswith("private_"):
filelist.append(filename)
return filelist
# Checks to make sure the file isn't private before removing it
def secure_removefile(filename):
if filename.startswith("private_"):
raise ValueError("User is not allowed to use file names starting with 'private_'")
removefile(filename)
# Define open
CHILD_CONTEXT_DEF["open"] = {"type":"func",
"args":(str,(str, None)),
"return":"any",
"exceptions":"any",
"target":secure_open
}
# Define listdir
CHILD_CONTEXT_DEF["listdir"] = {"type":"func",
"args":None,
"return":list,
"exceptions":"any",
"target":secure_listdir
}
# Define removefile
CHILD_CONTEXT_DEF["removefile"] = {"type":"func",
"args":(str,),
"return":None,
"exceptions":"any",
"target":secure_removefile
}
# Dispatch the next module
secure_dispatch_module()