3
# -----------------------------------------------------------------------
4
# The default configuration file
5
# -----------------------------------------------------------------------
7
cfgfile="/etc/samhainrc"
9
# -----------------------------------------------------------------------
10
# Be Bourne compatible
11
# -----------------------------------------------------------------------
13
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
16
elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
23
# -----------------------------------------------------------------------
25
# -----------------------------------------------------------------------
29
echo "$programname - update samhain config file after kernel update"
33
echo " -u|--update </path/to/System.map>"
34
echo " Update the configuration file with new"
35
echo " settings as taken from </path/to/System.map>"
37
echo " -c|--config-file </path/to/config-file>"
38
echo " Specify the configuration file to update [${cfgfile}]"
40
echo " -p|--print-only </path/to/System.map>"
41
echo " Print new settings, don't modify anything"
44
echo " Print this help"
47
echo " (ignored, legacy support)"
52
# -----------------------------------------------------------------------
54
# -----------------------------------------------------------------------
61
# -----------------------------------------------------------------------
62
# Get new settings from </path/to/System.map>
63
# -----------------------------------------------------------------------
68
proc_root_inode_operations=
73
if [ -z "$sysmap" ]; then
74
die "No System.map specified"
76
if [ -f "$sysmap" ]; then
77
if [ -r "$sysmap" ]; then
78
system_call=`egrep '[[:alnum:]]{8}[[:space:]]+[[:alpha:]]{1}[[:space:]]+system_call$' ${sysmap} | awk '{ print $1 }'`
79
syscall_table=`egrep '[[:alnum:]]{8}[[:space:]]+[[:alpha:]]{1}[[:space:]]+sys_call_table$' ${sysmap} | awk '{ print $1 }'`
80
proc_root=`egrep '[[:alnum:]]{8}[[:space:]]+[[:alpha:]]{1}[[:space:]]+proc_root$' ${sysmap} | awk '{ print $1 }'`
81
proc_root_inode_operations=`egrep '[[:alnum:]]{8}[[:space:]]+[[:alpha:]]{1}[[:space:]]+proc_root_inode_operations$' ${sysmap} | awk '{ print $1 }'`
82
proc_root_lookup=`egrep '[[:alnum:]]{8}[[:space:]]+[[:alpha:]]{1}[[:space:]]+proc_root_lookup$' ${sysmap} | awk '{ print $1 }'`
84
die "System.map ${sysmap} not readable"
87
die "System.map ${sysmap} not found"
89
test -z "${system_call}" && die "system_call not found in ${cfgfile}"
90
test -z "${syscall_table}" && die "sys_call_table not found in ${cfgfile}"
91
test -z "${proc_root}" && die "proc_root not found in ${cfgfile}"
92
test -z "${proc_root_inode_operations}" && die "proc_root_inode_operations not found in ${cfgfile}"
93
test -z "${proc_root_lookup}" && die "proc_root_lookup not found in ${cfgfile}"
97
# -----------------------------------------------------------------------
99
# -----------------------------------------------------------------------
104
echo "KernelSystemCall = 0x${system_call}"
105
echo "KernelSyscallTable = 0x${syscall_table}"
106
echo "KernelProcRoot = 0x${proc_root}"
107
echo "KernelProcRootIops = 0x${proc_root_inode_operations}"
108
echo "KernelProcRootLookup = 0x${proc_root_lookup}"
112
# -----------------------------------------------------------------------
114
# -----------------------------------------------------------------------
118
# delete current line
120
# single dot == end of insert text
126
ex -s "$cfgfile" <<EOF
128
:/^[[:blank:]]*$1[[:blank:]]*=
137
# -----------------------------------------------------------------------
139
# -----------------------------------------------------------------------
142
# search pattern ([Kernel] section)
144
# single dot == end of insert text
150
ex -s "$cfgfile" <<EOF
152
:/^[[:space:]]*\[Kernel\]
160
# -----------------------------------------------------------------------
161
# Update with new settings
162
# -----------------------------------------------------------------------
168
if [ -z "$cfgfile" ]; then
169
die "No configuration file specified"
171
if [ ! -w "$cfgfile" ]; then
172
die "Configuration file ${cfgfile} not writeable"
174
egrep '^[[:space:]]*\[Kernel\]' "$cfgfile" >/dev/null
175
if [ $? -ne 0 ]; then
176
die "No [Kernel] section in configuration file $cfgfile"
179
cat "$cfgfile" | egrep -i 'KernelProcRootLookup' >/dev/null
180
if [ $? -eq 0 ]; then
181
run_replace 'KernelProcRootLookup' "0x${proc_root_lookup}"
183
run_add 'KernelProcRootLookup' "0x${proc_root_lookup}"
186
cat "$cfgfile" | egrep -i 'KernelProcRootIops' >/dev/null
187
if [ $? -eq 0 ]; then
188
run_replace 'KernelProcRootIops' "0x${proc_root_inode_operations}"
190
run_add 'KernelProcRootIops' "0x${proc_root_inode_operations}"
193
cat "$cfgfile" | egrep -i 'KernelProcRoot[[:space:]]*=' >/dev/null
194
if [ $? -eq 0 ]; then
195
run_replace 'KernelProcRoot' "0x${proc_root}"
197
run_add 'KernelProcRoot' "0x${proc_root}"
200
cat "$cfgfile" | egrep -i 'KernelSyscallTable' >/dev/null
201
if [ $? -eq 0 ]; then
202
run_replace 'KernelSyscallTable' "0x${syscall_table}"
204
run_add 'KernelSyscallTable' "0x${syscall_table}"
207
cat "$cfgfile" | egrep -i 'KernelSystemCall' >/dev/null
208
if [ $? -eq 0 ]; then
209
run_replace 'KernelSystemCall' "0x${system_call}"
211
run_add 'KernelSystemCall' "0x${system_call}"
216
# -----------------------------------------------------------------------
218
# -----------------------------------------------------------------------
226
# If the previous option needs an argument, assign it.
228
if test -n "$opt_prev"; then
229
eval "$opt_prev=\$option"
230
eval export "$opt_prev"
237
optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'`
258
-c=* | --config-file=*)
268
-p=* | --print-only=*)
287
if [ x"$action" = xp ]; then
291
if [ x"$action" = xu ]; then