Debian Codegraph @

debian/aideinit

raw symbols SCIP
1 #!/bin/sh
2 #
3 # Copyright (C) 2003-2005 Mike Markley <[email protected]>
4 # Copyright (C) 2005-2022 Marc Haber
5 # Copyright (C) 2010 Hannes von Haugwitz
6 #
7 # This script is free for any purpose whatseoever so long as the above
8 # copyright notice remains in place.
9
10 if [ -f /etc/default/aide ]; then
11 . /etc/default/aide
12 fi
13
14 # Defaults
15 MAILTO="${MAILTO:-root}"
16 CONFIG="${CONFIG:-/etc/aide/aide.conf}"
17
18 # Options
19 opt_f=0
20 opt_y=0
21 opt_c=0
22 opt_b=0
23
24 if ! [ -f "/usr/bin/aide" ] && ! [ -f "/usr/sbin/aide" ]; then
25 printf >&2 "no /usr/bin/aide found, check your dependencies\\n"
26 exit 1
27 fi
28
29 aideinit_usage() {
30 printf >&2 "Usage: %s [options] -- [aide options]\\n" "$0"
31 printf >&2 " -y|--yes Overwrite output file\\n"
32 printf >&2 " -f|--force Force overwrite of database\\n"
33 printf >&2 " -c|--config Specify alternate config file\\n"
34 printf >&2 " -o|--output Specify alternate output file\\n"
35 printf >&2 " -d|--database Specify alternate database file\\n"
36 printf >&2 " -b|--background Run in the background\\n"
37 }
38
39 while [ -n "$1" ]; do
40 case "$1" in
41 -h|--help)
42 aideinit_usage
43 exit 0
44 ;;
45 -f|--force)
46 opt_f=1
47 shift
48 ;;
49 -y|--yes)
50 opt_y=1
51 shift
52 ;;
53 -b|--background)
54 opt_b=1
55 shift
56 ;;
57 -o|--output)
58 shift
59 [ -z "$1" ] && aideinit_usage && exit 1
60 outfile=$1
61 shift
62 ;;
63 -d|--database)
64 shift
65 [ -z "$1" ] && aideinit_usage && exit 1
66 dbfile=$1
67 shift
68 ;;
69 -c|--config)
70 opt_c=1
71 shift
72 [ -z "$1" ] && aideinit_usage && exit 1
73 config=$1
74 shift
75 ;;
76 --)
77 shift
78 break 2
79 ;;
80 *)
81 printf >&2 "Unknown option %s (use -- to delimit aideinit and aide options)\\n" "$1"
82 exit
83 ;;
84 esac
85 done
86
87
88 config=${config:-$CONFIG}
89
90 if [ ! -f "$config" ]; then
91 printf >&2 "%s: %s: file not found\\n" "$0" "${config}"
92 exit 1
93 fi
94
95 if [ -z "${outfile}" ]; then
96 outfile=$(grep -E "^[[:space:]]*database_out=file:" "${config}" | cut -d: -f2)
97 [ -z "${outfile}" ] && outfile="/var/lib/aide/aide.db.new"
98 fi
99 if [ -z "${dbfile}" ]; then
100 dbfile=$(grep -E "^[[:space:]]*database_in=file:" "${config}" | cut -d: -f2)
101 [ -z "${dbfile}" ] && dbfile="/var/lib/aide/aide.db"
102 fi
103
104 if [ -f "${outfile}" ]; then
105 if [ $opt_y -eq 0 ]; then
106 printf "Overwrite existing %s [Yn]? " "${outfile}"
107 read yn
108 case "$yn" in
109 [Nn]*)
110 exit 0
111 ;;
112 esac
113 fi
114 fi
115
116 extraflags=""
117
118 run_aideinit() {
119 if command -v capsh >/dev/null; then
120 capsh --caps="cap_dac_read_search,cap_audit_write+eip cap_setpcap,cap_setuid,cap_setgid+ep" --keep=1 --user=_aide --addamb=cap_dac_read_search,cap_audit_write -- \
121 -c "aide --config=${config} --init $extraflags $@ >/var/log/aide/aideinit.log 2>/var/log/aide/aideinit.errors"
122 RET=$?
123 else
124 aide --config="${config}" --init ${extraflags} $@ >/var/log/aide/aideinit.log 2>/var/log/aide/aideinit.errors
125 RET=$?
126 fi
127 printf "AIDE --init return code %d\\n" "${RET}" >> /var/log/aide/aideinit.log
128 if [ "$RET" != "0" ]; then
129 printf "AIDE --init return code %d\\n" "${RET}" >> /var/log/aide/aideinit.errors
130 fi
131 return $RET
132 }
133
134 aideinit_background() {
135 printf "running aide --init in background. See /var/log/aide/aideinit.* for log and errors\\n"
136 touch /var/log/aide/adeinit.still-running
137 run_aideinit
138 RET=$?
139 rm -f /var/log/aide/adeinit.still-running
140 if [ -f "${dbfile}" ] && [ "${opt_f}" -eq 0 ]; then
141 printf >&2 "%s exists and -f was not specified\\n" "${dbfile}" >> /var/log/aide/aideinit.errors
142 fi
143 if [ "$(< /var/log/aide/aideinit.errors wc -l)" -gt 0 ]; then
144 (printf "AIDE init errors:\\n"; cat /var/log/aide/aideinit.errors) | /usr/bin/mail -s "AIDE initialization problem" "${MAILTO}"
145 else
146 cp -f "${outfile}" "${dbfile}"
147 fi
148 return "${RET}"
149 }
150
151 if [ "${opt_b}" -eq 1 ]; then
152 aideinit_background &
153 exit 0
154 fi
155
156 # this is only reached if we run in foreground
157 printf >&2 "Running aide --init...\\n"
158 run_aideinit
159 RET=$?
160
161 if [ "$RET" != "0" ]; then
162 printf >&2 "AIDE --init return code %s\\n" "${RET}"
163 exit $RET
164 fi
165
166 if [ -f "$dbfile" ] && [ "${opt_f}" -eq 0 ]; then
167 printf "Overwrite %s [yN]? " "${dbfile}"
168 read yn
169 case "$yn" in
170 [yY]*)
171 cp -f "${outfile}" "${dbfile}"
172 ;;
173 esac
174 else
175 cp -f "${outfile}" "${dbfile}"
176 fi
177
178 # vim: tabstop=4 shiftwidth=4 expandtab
179 # end of file
180