-
Notifications
You must be signed in to change notification settings - Fork 0
/
config
100 lines (87 loc) · 1.96 KB
/
config
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
declare -ri max_file_size=200*1048576
declare -r base_dir="/etc/preloader"
declare -ra exclude_ext=(
avi mpg mpeg mp? m?v m?a og? flac vob mkv wav riff mov h26?
nef raw
gz bz2 xz 7z lzma tar zip rar cab
lock lck log
'~*'
)
declare -ra exclude=(
'^/(boot|proc|sys|dev|run|tmp)/'
'incomplete|\.!|~'
'/Cache'
'\.tmp$'
'~$'
'^\./'
'/etc/(passwd|shadow|group)'
'xauth'
'/(lock|LOCK)$'
)
################################################################################
if [ -e "${base_dir}/config" ]; then
source "${base_dir}/config"
fi
declare list_dir="${base_dir}/lists"
if ! [ -e "${base_dir}" ]; then
sudo mkdir -p "${base_dir}"
sudo mkdir -p "${list_dir}"
fi
# Security problem: any user could add a massive load of data to the preload
# list, causing the preloader to trigger an OOM. We could add a
# "max_payload_size" config var to get around this.
if ! [ -w "${list_dir}" -a -r "${list_dir}" -a -x "${list_dir}" ]; then
sudo chmod -R 777 "${list_dir}"
fi
function join_array {
# Delim cannot contain '%'
local delim="$1"
shift
if (( $# == 0 )); then
return
fi
printf -- "%s" "$1"
shift
printf -- "${delim}%s" "$@"
}
function get_filter_rx {
local rx=''
rx+="$(join_array '|' "${exclude_ext[@]}" | sed -e 's/?/./g;s/\*/.*/g'; printf '$')"
rx+="|$(join_array '|' "${exclude[@]}")"
printf -- "%s" "${rx}" | sed -e 's/\//\\\//g'
}
declare -r exclude_rx="$(get_filter_rx)"
function glue_prog {
cat <<EOF
use strict;
use warnings;
use feature qw(say);
my \$rx = qr/${exclude_rx}/;
EOF
cat <<'EOF'
while (<>) {
if (/open\(\s*"([^"]+)"(?:\s*,\s*([\w|]+)(?:\s*,\s*(\d+)?)?)\s*\)\s*=\s*(-?\d+)/) {
my $path = $1;
my $mode = $2 // "<unspecified>";
my $permission = $3 // "<unspecified>";
my $res = $4;
say $path if ($res >= 1 and $path !~ $rx);
}
}
EOF
}
function is_excluded {
echo "$@" | perl <(
cat <<EOF
use strict;
use warnings;
my \$rx = qr/${exclude_rx}/;
EOF
cat <<'EOF'
while (<>) {
exit(0) if ($_ =~ $rx);
}
exit(1);
EOF
)
}