Debian Codegraph @

debian/bin/dailyaidecheck

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # Copyright (C) 2000-2005 Mike Markley
4 # Copyright (C) 2006-2023 Marc Haber
5 # Copyright (C) 2010-2021 Hannes von Haugwitz
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20
21 set -e
22 set -C
23
24 shopt -u checkwinsize
25
26 CALLER=""
27 if [scip-shell system . . `[`. -n "$1" ]; then
28 #shellcheck disable=SC2034
29 CALLER="$1"
30 fi
31
32 # trap handler
33
34 FQDN="$(hostnamescip-shell system . . hostname. --fqdn 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.)"
35 if [scip-shell system . . `[`. -z "$FQDN" ]; then
36 FQDN="$(hostnamescip-shell system . . hostname. 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.)"
37 fi
38 if [scip-shell system . . `[`. -z "$FQDN" ]; then
39 echoscip-shell system . . echo. >&2 "error determining FQDN: neither hostname nor hostname --fqdn does give output"
40 hostnamescip-shell system . . hostname. >&2
41 hostnamescip-shell system . . hostname. --fqdn >&2
42 exit 1
43 fi
44
45 traphandlerscip-shell shell shell-project 0.0.0 traphandler().() {
46 trap - INT ERR
47 if [scip-shell system . . `[`. -n "${LOCKED:-}" ]; then
48 # we have the lock,
49 pidofscip-shell system . . pidof. aide | xargsscip-shell system . . xargs. --no-run-if-empty kill -9
50 fi
51 if type -t onexit >/dev/nullscip-shell filesystem . . `/dev/null`.; then
52 onexitscip-shell shell shell-project 0.0.0 onexit(). signal "$1"
53 else
54 echoscip-shell system . . echo. "${MAILHEAD:-}" | foldscip-shell system . . fold. --bytes --width="${MAILWIDTH:-990}" | send_mailscip-shell shell shell-project 0.0.0 send_mail(). "${MAILTO}" "early termination - ${MAILSUBJ}"
55 fi
56 return 0
57 }
58 trap ' traphandler INT; trap - INT ERR' INT
59 trap ' traphandler ERR; trap - INT ERR' ERR
60
61 # bail if no aide binary found
62
63 if ! [scip-shell system . . `[`. -f "/usr/bin/aidescip-shell filesystem . . `/usr/bin/aide`." ] && ! [scip-shell system . . `[`. -f "/usr/sbin/aidescip-shell filesystem . . `/usr/sbin/aide`." ]; then
64 exit 0
65 fi
66
67 # default variables
68
69 PATH="/sbin:/usr/sbin:/bin:/usr/binscip-shell filesystem . . `/sbin:/usr/sbin:/bin:/usr/bin`."
70 LOGDIR="/var/log/aidescip-shell filesystem . . `/var/log/aide`."
71 # LOGFILE: /var/log/aide/aide.log - all logs untruncated (not temp)
72 LOGFILE="$LOGDIR/aide.log"
73 PREFIX="aide"
74 LOCKBASE="/run/aidescip-shell filesystem . . `/run/aide`."
75 LOCKFILE="$LOCKBASE/dailyaidecheck.lock"
76
77 TMPBASE="/var/lib/aidescip-shell filesystem . . `/var/lib/aide`."
78 if ! [scip-shell system . . `[`. -d "${TMPBASE}" ]; then
79 TMPBASE="/run/aidescip-shell filesystem . . `/run/aide`."
80 fi
81 TMPDIRIN="$TMPBASE/dailyaidecheck"
82
83 USE_SAVELOG=""
84 if command -v savelog > /dev/nullscip-shell filesystem . . `/dev/null`.; then
85 USE_SAVELOG="1"
86 fi
87
88 AIDEARGS=""
89 MAILSUBJ="Daily AIDE report for $FQDN"
90
91 BEGINSTAMP="$(datescip-shell system . . date. +"%Y-%m-%d %H:%M:%S")"
92
93 # insist that $LOCKBASE exists
94 if ! [scip-shell system . . `[`. -d "$LOCKBASE" ]; then
95 printfscip-shell system . . printf. "ERR: %s does not exist. It must exist and be only writable for %s\n" "${LOCKBASE}" "${AIDEUSER}"
96 fi
97
98 # have /etc/default/aide override variables
99 if [scip-shell system . . `[`. -f "/etc/default/aidescip-shell filesystem . . `/etc/default/aide`." ]; then
100 #shellcheck disable=1091
101 . "/etc/default/aidescip-shell source . . `/etc/default/aide`."
102 fi
103
104 # from here on, we're going to bail on unbound variables
105
106 set -u
107
108 # umask
109
110 umask 027
111
112 MAILTO="${MAILTO:-root}"
113 eval MAILTO="$MAILTO"
114
115 send_mailscip-shell shell shell-project 0.0.0 send_mail().() {
116 local MAILTO
117 local MAILSUBJ
118 local MAILNAME
119 local S_NAIL_MTA
120 local RET
121 MAILTO="$1"
122 shift
123 MAILSUBJ="$@"
124 RET=""
125 if [scip-shell system . . `[`. -n "${MAILCMD:-}" ]; then
126 eval "${MAILCMD} -s \"${MAILSUBJ}\" \"${MAILTO}\"" || RET=$?
127 elif command -v s-nail >/dev/nullscip-shell filesystem . . `/dev/null`.; then
128 S_NAIL_MTA="smtp://_aide@localhost"
129 if [scip-shell system . . `[`. "${CALLER}" == "--autopkgtest" ]; then
130 S_NAIL_MTA="test:///tmp/dailyaidecheck"
131 fi
132 if echoscip-shell system . . echo. "${MAILTO}" | grepscip-shell system . . grep. -qv @; then
133 # unqualified MAILTO, add /etc/mailname
134 MAILNAME="$(catscip-shell system . . cat. /etc/mailnamescip-shell filesystem . . `/etc/mailname`. 2>/dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.)"
135 MAILTO="${MAILTO}@${MAILNAME:-localhost}"
136 fi
137 s-nail -Smta=${S_NAIL_MTA} -Ssmtp-auth=none -Sv15-compat -Sfrom="AIDE on ${FQDN} <root@${FQDN}>" -s "${MAILSUBJ}" "${MAILTO}" || RET=$?
138 elif command -v mail >/dev/nullscip-shell filesystem . . `/dev/null`.; then
139 if [scip-shell system . . `[`. "${CALLER}" = "--crondaily" ] || [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" -eq 0 ]; then
140 # We are called from cron via capsh or have root and thus
141 # mail(1) is useable, even if sendmail is set-uid-root.
142 mail -s "${MAILSUBJ}" "${MAILTO}" || RET=$?
143 else
144 printfscip-shell system . . printf. >&2 "WARN: it is not possible to use mail(1) unless aide is run as root or as non-root with added capabilities (either via systemd or via capsh). See /usr/share/doc/aide-common/README.Debian.gz for more information.\\n"
145 fi
146 else
147 printfscip-shell system . . printf. >&2 "WARN: mail or s-nail not installed, cannot send mail. See /usr/share/doc/aide-common/README.Debian.gz for more information.\\n"
148 fi
149 if [scip-shell system . . `[`. -n "${RET}" ]; then
150 printfscip-shell system . . printf. >&2 "ERR: dailyaidejob was not able to send mail. The invoked mail command returned a non-zero exit code.\\n"
151 fi
152 }
153
154 # grep aide configuration data from aide config
155
156 DATABASE="$(< "${CONFIG}" grepscip-shell system . . grep. "^database_in[[:space:]]*=[[:space:]]*file:/" | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. --delimiter=: --fields=2)"
157 DATABASE_OUT="$(< "${CONFIG}" grepscip-shell system . . grep. "^database_out[[:space:]]*=[[:space:]]*file:/" | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. --delimiter=: --fields=2)"
158
159 < "${CONFIG}" grepscip-shell system . . grep. -qE "^(report_)?grouped[[:space:]]*=[[:space:]]*(no|false)[[:space:]]*$" && GROUPED="false" || GROUPED="true"
160
161 # default values
162
163 CRON_DAILY_RUN="${CRON_DAILY_RUN:-yes}"
164 MAILWIDTH="${MAILWIDTH:-990}"
165 FIGLET="${FIGLET:-yes}"
166 DATABASE="${DATABASE:-/var/lib/aide/aide.db}"
167 LINES="${LINES:-1000}"
168 COMMAND="${COMMAND:-check}"
169 COPYNEWDB="${COPYNEWDB:-no}"
170 QUIETREPORTS="${QUIETREPORTS:-no}"
171 SILENTREPORTS="${SILENTREPORTS:-no}"
172 TRUNCATEDETAILS="${TRUNCATEDETAILS:-no}"
173 FILTERUPDATES="${FILTERUPDATES:-no}"
174 FILTERINSTALLATIONS="${FILTERINSTALLATIONS:-no}"
175 CRONEXITHOOK="${CRONEXITHOOK:-}"
176 ONEXIT=""
177 AIDEUSER="${AIDEUSER:-$(idscip-shell system . . id. --user --name)}"
178 AIDEUSERUID="$(idscip-shell system . . id. --user "${AIDEUSER}")"
179
180 # silent implies quiet
181 if [scip-shell system . . `[`. "$SILENTREPORTS" = "yes" ]; then
182 QUIETREPORTS="yes"
183 fi
184
185 # Get the database's date
186 DATABASEDATE=""
187 if [scip-shell system . . `[`. -f "$DATABASE" ]; then
188 DATABASEDATE="$(statscip-shell system . . stat. -c %y "$DATABASE" | sedscip-shell system . . sed. -e "s/\\..*//")"
189 fi
190
191 # Force TRUNCATEDETAILS when filter updates/installations
192 if [scip-shell system . . `[`. "$FILTERUPDATES" = "yes" ] || [scip-shell system . . `[`. "$FILTERINSTALLATIONS" = "yes" ] ; then
193 TRUNCATEDETAILS="yes"
194 fi
195
196 # functions
197
198 mytempfilescip-shell shell shell-project 0.0.0 mytempfile().() {
199 NAME="$1"
200 echoscip-shell system . . echo. "$TMPDIR/$NAME"
201 touchscip-shell system . . touch. "$TMPDIR/$NAME"
202 }
203
204 framescip-shell shell shell-project 0.0.0 frame().() {
205 WIDTH=78
206 STARS="*******************************************************************************"
207 SPACES=" "
208 printfscip-shell system . . printf. "%s\\n" "${STARS:1:$WIDTH}"
209 while read -r line ; do
210 HALF="${SPACES:1:$(((WIDTH-${#line})/2))}"
211 LINE="$HALF$line$SPACES"
212 printfscip-shell system . . printf. "*%s*\\n" "${LINE:1:$((WIDTH-2))}"
213 done
214 printfscip-shell system . . printf. "%s\\n" "${STARS:1:$WIDTH}"
215 }
216
217 onexitscip-shell shell shell-project 0.0.0 onexit().() {
218 if [scip-shell system . . `[`. "$ONEXIT" = "running" ]; then
219 return 1
220 fi
221
222 ONEXIT="running"
223
224 local LOGHEAD
225 local MAILHEAD
226 local CRONJOBERR
227
228 CRONEXITHOOKPARM="$1"
229 case "$1" in
230 signal)
231 LOGHEAD="$(printfscip-shell system . . printf. "terminated with signal %s" "$2")"
232 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated with signal %s" "$2")"
233 CRONJOBERR="$2"
234 ;;
235 nodb)
236 LOGHEAD="$(printfscip-shell system . . printf. "database not present.")"
237 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated because no AIDE database is present")"
238 CRONJOBERR="no DB"
239 ;;
240 fatal)
241 LOGHEAD="$(printfscip-shell system . . printf. "terminated by fatal error.")"
242 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated by a fatal error.")"
243 CRONJOBERR="fatal"
244 ;;
245 nolock)
246 LOGHEAD="$(printfscip-shell system . . printf. "terminated because lock %s could not be obtained." "$LOCKFILE")"
247 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated because lock %s could not be obtained." "$LOCKFILE")"
248 CRONJOBERR="no lock"
249 ;;
250 cantmovetmp)
251 LOGHEAD="$(printfscip-shell system . . printf. "terminated: Cannot move away %s." "$TMPDIRIN")"
252 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated: Cannot move away %s." "$TMPDIRIN")"
253 CRONJOBERR="temp dir"
254 ;;
255 nohook)
256 LOGHEAD="$(printfscip-shell system . . printf. "terminated: CRONEXITHOOK set to %s which is not executeable." "$CRONEXITHOOK")"
257 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated: CRONEXITHOOK set to %s which is not executeable." "$CRONEXITHOOK")"
258 CRONJOBERR="no hook"
259 ;;
260 cantcreatetmp)
261 LOGHEAD="$(printfscip-shell system . . printf. "terminated: Cannot create temporary directory %s." "$TMPDIRIN")"
262 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated: Cannot create temporary directory %s." "$TMPDIRIN")"
263 CRONJOBERR="temp dir"
264 ;;
265 cantchmodtmp)
266 LOGHEAD="$(printfscip-shell system . . printf. "terminated: Cannot chmod temporary directory %s." "$TMPDIRIN")"
267 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated: Cannot chmod temporary directory %s." "$TMPDIRIN")"
268 CRONJOBERR="temp dir"
269 ;;
270 tmpnotours)
271 LOGHEAD="$(printfscip-shell system . . printf. "terminated: Temporary directory %s has wrong owner/mode." "$TMPDIRIN")"
272 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated: Temporary directory %s has wrong owner/mode." "$TMPDIRIN")"
273 CRONJOBERR="temp dir"
274 ;;
275 success)
276 ;;
277 *)
278 LOGHEAD="$(printfscip-shell system . . printf. "wrong parameter (\"%s\") to onexit." "$1")"
279 MAILHEAD="$(printfscip-shell system . . printf. "The daily aide check was terminated for unknown reasons, and a wrong parameter (\"%s\")was given to onexit." "$1")"
280 CRONJOBERR="unknown"
281 CRONEXITHOOKPARM="unknown"
282 ;;
283 esac
284
285 if [scip-shell system . . `[`. -z "${TMPDIR:-}" ] || [scip-shell system . . `[`. -z "${MAILFILE:-}" ]; then
286 # we are being called so early that we are not yet fully initialized
287 # LOGHEAD goes to syslog instead of LOGFILE since we do not know
288 # what's up with LOGFILE
289 loggerscip-shell system . . logger. -t dailyaidecheck "$LOGHEAD"
290 if [scip-shell system . . `[`. "$SILENTREPORTS" != "yes" ]; then
291 echoscip-shell system . . echo. "$MAILHEAD" | foldscip-shell system . . fold. --bytes --width="${MAILWIDTH:-990}" | send_mailscip-shell shell shell-project 0.0.0 send_mail(). "${MAILTO}" "premature termination - ${MAILSUBJ}"
292 fi
293 CRONEXITHOOKPARM="early-$CRONEXITHOOKPARM"
294 else
295 # we are being called after the daily aide check was properly set up.
296 # Do the full works.
297
298 if [scip-shell system . . `[`. "$USE_SAVELOG" = "1" ] || [scip-shell system . . `[`. "$USE_SAVELOG" = "yes" ]; then
299 savelogscip-shell system . . savelog. -t -m 640 -c 7 "$LOGFILE" > /dev/nullscip-shell filesystem . . `/dev/null`.
300 else
301 LOGFILEWDATE="${LOGFILE}-$(datescip-shell system . . date. +%Y%m%d-%H%M%S)"
302 lnscip-shell system . . ln. -sf "$LOGFILEWDATE" "$LOGFILE"
303 LOGFILE="${LOGFILEWDATE}"
304 fi
305
306 printfscip-shell system . . printf. >> "$MAILFILE" \
307 "This is an automated report generated by the Advanced Intrusion Detection environment on %s started at %s.\\n\\n" "$FQDN" "$BEGINSTAMP"
308
309 printfscip-shell system . . printf. >> "$LOGFILE" \
310 "aide run on %s started at %s.\\n" "$FQDN" "$BEGINSTAMP"
311
312 if [scip-shell system . . `[`. -n "${LOGHEAD:-}" ]; then
313 printfscip-shell system . . printf. "%s\\n" "$LOGHEAD" | framescip-shell shell shell-project 0.0.0 frame(). >> "$LOGFILE"
314 printfscip-shell system . . printf. "\\n" >> "$LOGFILE"
315 fi
316 if [scip-shell system . . `[`. -n "${MAILHEAD:-}" ]; then
317 printfscip-shell system . . printf. "%s\\n" "$MAILHEAD" | framescip-shell shell shell-project 0.0.0 frame(). >> "$MAILFILE"
318 printfscip-shell system . . printf. "\\n\\n" >> "$MAILFILE"
319 fi
320
321 # report about AIDE's return value
322
323 PRINTED=""
324 FIGLETTEXT=""
325 SCRIPTRETVAL="0"
326 if [scip-shell system . . `[`. -n "${ARETVAL:-}" ]; then
327 ARETEXPL=""
328 ARETERR=""
329 PREFIX="$(printfscip-shell system . . printf. "AIDE returned with exit code %d." "$ARETVAL")"
330 case "$ARETVAL" in
331 -1)
332 PREFIX=""
333 ARETERR="the daily aide check was interrupted before AIDE could return an exit code."
334 FIGLETTEXT="${CRONJOBERR:-interrupt}"
335 SCRIPTRETVAL="1"
336 ;;
337 0)
338 PREFIX="AIDE returned with a zero exit code."
339 ARETEXPL="No changes detected!"
340 FIGLETTEXT="unchanged"
341 ;;
342 1)
343 ARETEXPL="Added entries detected!"
344 FIGLETTEXT="add"
345 ;;
346 2)
347 ARETEXPL="Removed entries detected!"
348 FIGLETTEXT="rem"
349 ;;
350 3)
351 ARETEXPL="Added and removed entries detected!"
352 FIGLETTEXT="add rem"
353 ;;
354 4)
355 ARETEXPL="Changed entries detected!"
356 FIGLETTEXT="chg"
357 ;;
358 5)
359 ARETEXPL="Added and changed entries detected!"
360 FIGLETTEXT="add chg"
361 ;;
362 6)
363 ARETEXPL="Removed and changed entries detected!"
364 FIGLETTEXT="rem chg"
365 ;;
366 7)
367 ARETEXPL="Added, removed and changed entries detected!"
368 FIGLETTEXT="add rem chg"
369 ;;
370 14)
371 ARETERR="Error writing!"
372 FIGLETTEXT="$ARETERR"
373 SCRIPTRETVAL="1"
374 ;;
375 15)
376 ARETERR="Invalid Argument!"
377 FIGLETTEXT="EINVAL"
378 SCRIPTRETVAL="1"
379 ;;
380 16)
381 ARETERR="Unimplemented function!"
382 FIGLETTEXT="unimplemented"
383 SCRIPTRETVAL="1"
384 ;;
385 17|255)
386 ARETERR="Invalid configuration!"
387 FIGLETTEXT="invalid config"
388 SCRIPTRETVAL="1"
389 ;;
390 18)
391 ARETERR="Input/Output error!"
392 FIGLETTEXT="EIO"
393 SCRIPTRETVAL="1"
394 ;;
395 21)
396 ARETERR="cannot obtain lock"
397 FIGLETTEXT="no lock"
398 SCRIPTRETVAL="1"
399 ;;
400 250)
401 ARETERR="executable aide not found"
402 FIGLETTEXT="no executable"
403 SCRIPTRETVAL="1"
404 ;;
405 *)
406 ARETERR="$(printfscip-shell system . . printf. "unknown non-zero exit value %d\\n\\n" "$ARETVAL")"
407 FIGLETTEXT="unknown error"
408 SCRIPTRETVAL="1"
409 ;;
410 esac
411 if [scip-shell system . . `[`. -n "$ARETEXPL" ]; then
412 printfscip-shell system . . printf. "%s %s\\n" "$PREFIX" "$ARETEXPL" >> "$MAILFILE"
413 printfscip-shell system . . printf. "%s %s\\n" "$PREFIX" "$ARETEXPL" >> "$LOGFILE"
414 PRINTED=1
415 fi
416 if [scip-shell system . . `[`. -n "$ARETERR" ]; then
417 printfscip-shell system . . printf. "%s %s\\n" "$PREFIX" "$ARETERR" | framescip-shell shell shell-project 0.0.0 frame(). >> "$MAILFILE"
418 printfscip-shell system . . printf. "%s %s\\n" "$PREFIX" "$ARETERR" | framescip-shell shell shell-project 0.0.0 frame(). >> "$LOGFILE"
419 PRINTED=1
420 fi
421 unset ARETEXPL
422 unset ARETERR
423 unset PREFIX
424 else
425 ARETEXPL="ARETVAL not initialized. daily aide check was aborted prematurely."
426 ARETVAL=255
427 FIGLETTEXT="abort"
428 printfscip-shell system . . printf. "%s\\n" "$ARETEXPL" | framescip-shell shell shell-project 0.0.0 frame(). >> "$MAILFILE"
429 printfscip-shell system . . printf. "%s\\n" "$ARETEXPL" | framescip-shell shell shell-project 0.0.0 frame(). >> "$LOGFILE"
430 PRINTED=1
431 unset ARETEXPL
432 fi
433 if [scip-shell system . . `[`. "${FIGLET}" = "yes" ] && [scip-shell system . . `[`. -x "$(command -v figlet)" ] && [scip-shell system . . `[`. -n "$FIGLETTEXT" ]; then
434 printfscip-shell system . . printf. "\\n%s\\n\\n" "$(figlet $FIGLETTEXT)" >> "$MAILFILE"
435 PRINTED=1
436 fi
437 if [scip-shell system . . `[`. -n "$PRINTED" ]; then
438 printfscip-shell system . . printf. "\\n" >> "$LOGFILE"
439 printfscip-shell system . . printf. "\\n\\n" >> "$MAILFILE"
440 fi
441 unset PRINTED
442
443 # script errors
444
445 if [scip-shell system . . `[`. -n "${ERRORLOG:-}" ] && [scip-shell system . . `[`. -s "$ERRORLOG" ]; then
446 {
447 printfscip-shell system . . printf. "script errors\\n" | framescip-shell shell shell-project 0.0.0 frame().
448 catscip-shell system . . cat. "$ERRORLOG"
449 printfscip-shell system . . printf. "End of script errors\\n\\n"
450 } >> "$MAILFILE"
451
452 {
453 printfscip-shell system . . printf. "script errors\\n" | framescip-shell shell shell-project 0.0.0 frame().
454 catscip-shell system . . cat. "$ERRORLOG"
455 printfscip-shell system . . printf. "End of script errors\\n"
456 } >> "$LOGFILE"
457 fi
458
459 # aide post run information
460
461 if [scip-shell system . . `[`. -n "${POSTRUNLOG:-}" ] && [scip-shell system . . `[`. -s "$POSTRUNLOG" ]; then
462 {
463 printfscip-shell system . . printf. "AIDE post run information\\n"
464 catscip-shell system . . cat. "$POSTRUNLOG"
465 printfscip-shell system . . printf. "End of AIDE post run information\\n\\n"
466 } >> "$MAILFILE"
467
468 {
469 printfscip-shell system . . printf. "AIDE post run information\\n"
470 catscip-shell system . . cat. "$POSTRUNLOG"
471 printfscip-shell system . . printf. "End of AIDE post run information\\n"
472 } >> "$LOGFILE"
473 fi
474
475 # include error log in daily report e-mail
476
477 if [scip-shell system . . `[`. -n "${AERRLOG:-}" ] && [scip-shell system . . `[`. -s "$AERRLOG" ]; then
478 errorlines="$(wcscip-shell system . . wc. -l "$AERRLOG" | awkscip-shell system . . awk. '{ print $1 }')"
479 {
480 if [scip-shell system . . `[`. "$LINES" -gt "0" ] && [scip-shell system . . `[`. "${errorlines:=0}" -gt "$LINES" ]; then
481 printfscip-shell system . . printf. "AIDE has returned many errors.\\nthe error log output has been truncated in this mail\\n" | \
482 frame
483 printfscip-shell system . . printf. "Error output is %d lines, truncated to %d.\\n" "$errorlines" "$LINES"
484 headscip-shell system . . head. -n "$LINES" "$AERRLOG"
485 printfscip-shell system . . printf. "\\nEnd of truncated AIDE error output. The full output can be found in %s.\\n\\n" "$LOGFILE"
486 else
487 printfscip-shell system . . printf. "Errors produced (%d lines):\\n" "$errorlines"
488 catscip-shell system . . cat. "$AERRLOG"
489 printfscip-shell system . . printf. "\\nEnd of AIDE error output.\\n\\n"
490 fi
491 } >> "$MAILFILE"
492 {
493 printfscip-shell system . . printf. "AIDE error output (%d lines):\\n" "$errorlines"
494 catscip-shell system . . cat. "$AERRLOG"
495 printfscip-shell system . . printf. "End of AIDE error output\\n"
496 } >> "$LOGFILE"
497 else
498 printfscip-shell system . . printf. >> "$MAILFILE" "AIDE produced no errors.\\n\\n"
499 printfscip-shell system . . printf. >> "$LOGFILE" "AIDE produced no errors.\\n"
500 fi
501
502 # finish log file
503 {
504 if [scip-shell system . . `[`. -n "${ARUNLOG:-}" ] && [scip-shell system . . `[`. -s "$ARUNLOG" ]; then
505 printfscip-shell system . . printf. "AIDE output (%d lines):\\n" "$(wcscip-shell system . . wc. -l "$ARUNLOG" | awkscip-shell system . . awk. '{ print $1 }')"
506 catscip-shell system . . cat. "$ARUNLOG"
507 printfscip-shell system . . printf. "End of AIDE output.\\n\\n"
508 else
509 printfscip-shell system . . printf. "AIDE detected no changes.\\n\\n"
510 fi
511
512 if [scip-shell system . . `[`. -n "${DBCHECKLOG:-}" ] && [scip-shell system . . `[`. -s "$DBCHECKLOG" ]; then
513 catscip-shell system . . cat. "$DBCHECKLOG"
514 fi
515
516 ENDTIME="$(datescip-shell system . . date. +%s)"
517
518 printfscip-shell system . . printf. "End of AIDE daily aide check at %s, run time %d seconds\\n" "$(datescip-shell system . . date. +"%Y-%m-%d %H:%M" -d@"$ENDTIME")" "$(( ENDTIME - BEGINTIME ))"
519 } >> "$LOGFILE"
520
521 LOGFILE_CHECKSUM="$(sha256sumscip-shell system . . sha256sum. "$LOGFILE")"
522
523 # include de-noised log into mail
524
525 if [scip-shell system . . `[`. -n "${ARUNLOG:-}" ] && [scip-shell system . . `[`. -s "$ARUNLOG" ]; then
526
527 MAIL_MODE=0
528
529 # truncate details
530 if [scip-shell system . . `[`. "$TRUNCATEDETAILS" = "yes" ] ; then
531 case "$ARETVAL" in
532 4|5|6|7)
533 MAILTMP="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). aidemail)"
534 < "$ARUNLOG" sedscip-shell system . . sed. '/^Detailed information about changes:$/,/^The attributes of the (uncompressed) database(s):$/{/^The attributes of the (uncompressed) database(s):$/!d}scip-shell filesystem . . `/^Detailed information about changes:$/,/^The attributes of the (uncompressed) database(s):$/{/^The attributes of the (uncompressed) database(s):$/!d}`.' >> "$MAILTMP"
535 MAIL_MODE=1
536 ;;
537 *)
538 MAILTMP="$ARUNLOG"
539 ;;
540 esac
541
542 # Filter package upgrades/installations
543
544 # Figure out where the dpkg log file is
545 DPKGLOG="$(< /etc/dpkg/dpkg.cfgscip-shell filesystem . . `/etc/dpkg/dpkg.cfg`. grepscip-shell system . . grep. "^log" | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d ' ' -f 2)"
546
547 if { [scip-shell system . . `[`. "$FILTERUPDATES" = "yes" ] || [scip-shell system . . `[`. "$FILTERINSTALLATIONS" = "yes" ] ; } && [scip-shell system . . `[`. -s "$DPKGLOG" ]; then
548
549 # Create a list of files modified by system updates
550 if [scip-shell system . . `[`. "$FILTERUPDATES" = "yes" ] && [scip-shell system . . `[`. "$FILTERINSTALLATIONS" = "yes" ] ; then
551 FILTER="install|upgrade"
552 elif [scip-shell system . . `[`. "$FILTERUPDATES" = "yes" ]; then
553 FILTER="upgrade"
554 else
555 FILTER="install"
556 fi
557 PKG_FILE_LIST="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). pkg_file_list)"
558 REGEX="^([^ ]+ [^ ]+) ($FILTER) ([^ ]+) [^ ]+ [^ ]+$"
559 PKGS=()
560 while read -r line; do
561 if [[ $line =~ $REGEX ]] && [[ "$DATABASEDATE" < ${BASH_REMATCH[1]} ]]; then
562 if dpkg-queryscip-shell system . . dpkg-query. -L "${BASH_REMATCH[3]}" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
563 PKGS+=("${BASH_REMATCH[3]} (${BASH_REMATCH[2]})")
564 dpkg-queryscip-shell system . . dpkg-query. -L "${BASH_REMATCH[3]}" | sedscip-shell system . . sed. -e "/^$/dscip-shell filesystem . . `/^$/d`." -e "/\\/\\./dscip-shell filesystem . . `/\\/\\./d`." >> "$PKG_FILE_LIST"
565 if ! lsscip-shell system . . ls. "/var/lib/dpkg/info/${BASH_REMATCH[3]}."* >> "$PKG_FILE_LIST" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
566 lsscip-shell system . . ls. "/var/lib/dpkg/info/${BASH_REMATCH[3]%:*}."* >> "$PKG_FILE_LIST"
567 fi
568 fi
569 fi
570 done < "$DPKGLOG"
571
572 if [scip-shell system . . `[`. ${#PKGS[@]} -gt 0 ]; then
573 FILTEREDMAIL=$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). filteredmail)
574 MAIL_MODE=$(( MAIL_MODE + 2 ))
575 ADD=0; REM=0; CHG=0
576 N_ADD=0; N_REM=0; N_CHG=0
577 declare -a NF_ADD NF_REM NF_CHG
578 NF_ADD=()
579 NF_REM=()
580 NF_CHG=()
581 REGEX="^(changed|removed|added|[fdLDBFs?!][ :l<>=bpugamcinHAXSEC.+-]{17}): (.*)"
582 BACKUPIFS="$IFS"
583 IFS=""
584 while read -r line; do
585 if [[ $line =~ $REGEX ]] ; then
586 #shellcheck disable=SC2143
587 [scip-shell system . . `[`. -z "$(grepscip-shell system . . grep. -xF "${BASH_REMATCH[2]}" "$PKG_FILE_LIST")" ] && DONTFILTER_FILE=true || DONTFILTER_FILE=false
588 case "${BASH_REMATCH[1]}" in
589 added|[fdLDBFs?]+++++++++++++++++)
590 ((ADD++)) || truescip-shell system . . true.
591 if $DONTFILTER_FILE; then
592 ((N_ADD++)) || truescip-shell system . . true.
593 if $GROUPED; then
594 NF_ADD[${#NF_ADD[*]}]="$line"
595 else
596 NF_CHG[${#NF_CHG[*]}]="$line"
597 fi
598 fi
599 ;;
600 removed|[fdLDBFs?]-----------------)
601 ((REM++)) || truescip-shell system . . true.
602 if $DONTFILTER_FILE; then
603 ((N_REM++)) || truescip-shell system . . true.
604 if $GROUPED; then
605 NF_REM[${#NF_REM[*]}]="$line"
606 else
607 NF_CHG[${#NF_CHG[*]}]="$line"
608 fi
609 fi
610 ;;
611 changed|[fdLDBFs?!]*)
612 ((CHG++)) || truescip-shell system . . true.
613 if $DONTFILTER_FILE; then
614 ((N_CHG++)) || truescip-shell system . . true.
615 NF_CHG[${#NF_CHG[*]}]="$line"
616 fi
617 ;;
618 *)
619 printfscip-shell system . . printf. >> "$FILTEREDMAIL" "error: '%s' could not be matched, mail report is incomplete (full output can be found in %s)!! Please file a bug report against the aide-common package and include this error message.\\n" "${BASH_REMATCH[1]}" "$LOGFILE"
620 ;;
621 esac
622 fi
623 done < "$MAILTMP"
624 IFS=$BACKUPIFS
625 F_ADD=$(( ADD-N_ADD )) || truescip-shell system . . true.
626 F_REM=$(( REM-N_REM )) || truescip-shell system . . true.
627 F_CHG=$(( CHG-N_CHG )) || truescip-shell system . . true.
628 {
629 < "$MAILTMP" sedscip-shell system . . sed. -n '0,/^ Total number of entries:/{p;}'
630 #shellcheck disable=SC2059
631 {
632 SEPERATOR_TEMPLATE="\\n---------------------------------------------------\\n%s entries (filtered: %s):\\n---------------------------------------------------\\n\\n"
633 NUM_FILES_TEMPLATE=" %s entries:\\t\\t%s\\t(filtered: %s)\\n"
634 printfscip-shell system . . printf. "$NUM_FILES_TEMPLATE" "Added" "$N_ADD" "$F_ADD"
635 printfscip-shell system . . printf. "$NUM_FILES_TEMPLATE" "Removed" "$N_REM" "$F_REM"
636 printfscip-shell system . . printf. "$NUM_FILES_TEMPLATE" "Changed" "$N_CHG" "$F_CHG"
637 printfscip-shell system . . printf. "\\nThe following package changes were detected and were filtered from this mail:\\n"
638 printfscip-shell system . . printf. '%s\n' "${PKGS[@]}"
639 if [scip-shell system . . `[`. "$N_ADD" -eq "0" ] && [scip-shell system . . `[`. "$N_REM" -eq "0" ] && [scip-shell system . . `[`. "$N_CHG" -eq "0" ] ; then
640 printfscip-shell system . . printf. "\\nAIDE detected no changes after filtering package changes.\\n\\n"
641 else
642 if [scip-shell system . . `[`. "${#NF_ADD[@]}" -gt "0" ]; then
643 printfscip-shell system . . printf. "$SEPERATOR_TEMPLATE" "Added" "$F_ADD"
644 for ((i=0;i<${#NF_ADD[@]};i++)); do printf "%s\\n" "${NF_ADD[$i]}"; done
645 fi
646 if [scip-shell system . . `[`. "${#NF_REM[@]}" -gt "0" ]; then
647 printfscip-shell system . . printf. "$SEPERATOR_TEMPLATE" "Removed" "$F_REM"
648 for ((i=0;i<${#NF_REM[@]};i++)); do printf "%s\\n" "${NF_REM[$i]}"; done
649 fi
650 if [scip-shell system . . `[`. "${#NF_CHG[@]}" -gt "0" ]; then
651 if $GROUPED; then
652 printfscip-shell system . . printf. "$SEPERATOR_TEMPLATE" "Changed" "$F_CHG"
653 else
654 if [scip-shell system . . `[`. "$N_ADD" -gt "0" ] && [scip-shell system . . `[`. "$N_REM" -gt "0" ] && [scip-shell system . . `[`. "$N_CHG" -gt "0" ]; then
655 HEAD="Added, removed and changed"
656 elif [scip-shell system . . `[`. "$N_ADD" -gt "0" ] && [scip-shell system . . `[`. "$N_REM" -gt "0" ]; then
657 HEAD="Added and removed"
658 elif [scip-shell system . . `[`. "$N_ADD" -gt "0" ] && [scip-shell system . . `[`. "$N_CHG" -gt "0" ]; then
659 HEAD="Added and changed"
660 elif [scip-shell system . . `[`. "$N_REM" -gt "0" ] && [scip-shell system . . `[`. "$N_CHG" -gt "0" ]; then
661 HEAD="Removed and changed"
662 elif [scip-shell system . . `[`. "$N_ADD" -gt "0" ]; then
663 HEAD="Added"
664 elif [scip-shell system . . `[`. "$N_REM" -gt "0" ]; then
665 HEAD="Removed"
666 elif [scip-shell system . . `[`. "$N_CHG" -gt "0" ]; then
667 HEAD="Changed"
668 fi
669 printfscip-shell system . . printf. "$SEPERATOR_TEMPLATE" "$HEAD" "$((F_ADD+F_REM+F_CHG))"
670 fi
671 for ((i=0;i<${#NF_CHG[@]};i++)); do printf "%s\\n" "${NF_CHG[$i]}"; done
672 fi
673 fi
674 }
675 printfscip-shell system . . printf. "\\n---------------------------------------------------\\n"
676 < "$MAILTMP" sedscip-shell system . . sed. -n '/^The attributes of the (uncompressed) database(s):$/,$ {p;}scip-shell filesystem . . `/^The attributes of the (uncompressed) database(s):$/,$ {p;}`.'
677 } >> "$FILTEREDMAIL"
678 MAILTMP="$FILTEREDMAIL"
679 fi
680 fi
681 else
682 MAILTMP="$ARUNLOG"
683 fi
684
685 if [scip-shell system . . `[`. -n "${NOISE:-}" ]; then
686 NOISETMP="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). aidenoise1)"
687 NOISETMP2="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). aidenoise2)"
688 < "$MAILTMP" sedscip-shell system . . sed. -n '1,/^Detailed information about changes:/p' | \
689 grep '^\(changed\|removed\|added\|[fdLDBFs?!][ :l<>=bpugamcinCAXSE.+-]\{16\}\):' | \
690 grep -v "^added: THERE WERE ALSO [0-9]\\+ FILES ADDED UNDER THIS DIRECTORY" >> "$NOISETMP2"
691
692 {
693 if [scip-shell system . . `[`. -n "$NOISE" ]; then
694 ##+# leaning toothpick syndrome, consider grep -E
695 < "$NOISETMP2" grepscip-shell system . . grep. -v "^\\(changed\\|removed\\|added\\|[fdLDBFs?!][ :l<>=bpugamcinCAXSE.+-]\\{16\\}\\): $NOISE" >> "$NOISETMP" || truescip-shell system . . true.
696 printfscip-shell system . . printf. "De-Noised output removes everything matching %s.\\n" "$NOISE"
697 fi
698
699 if [scip-shell system . . `[`. -s "$NOISETMP" ]; then
700 loglines="$(< "$NOISETMP" wcscip-shell system . . wc. -l | awkscip-shell system . . awk. '{ print $1 }')"
701 if [scip-shell system . . `[`. "$LINES" -gt "0" ] && [scip-shell system . . `[`. "${loglines:=0}" -gt "$LINES" ]; then
702 printfscip-shell system . . printf. "AIDE has returned long output which has been truncated in this mail\\n" | \
703 frame
704 printfscip-shell system . . printf. "De-Noised output is %d lines, truncated to %d.\\n" "$loglines" "$LINES"
705 headscip-shell system . . head. -n "$LINES" "$NOISETMP"
706 printfscip-shell system . . printf. "\\nEnd of truncated De-Noised AIDE output. The full output can be found in %s.\\nsha256sum: %s\\n\\n" "$LOGFILE" "$LOGFILE_CHECKSUM"
707 else
708 printfscip-shell system . . printf. "De-Noised output of the daily AIDE check (%d lines):\\n" "$loglines"
709 catscip-shell system . . cat. "$NOISETMP"
710 printfscip-shell system . . printf. "\\nEnd of De-Noised AIDE output.\\n\\n"
711 fi
712 else
713 printfscip-shell system . . printf. "AIDE detected no changes after removing noise.\\n\\n"
714 fi
715 printfscip-shell system . . printf. "============================================================================\\n"
716 }
717 fi
718
719 # include non-de-noised log into mail
720
721 {
722 if [scip-shell system . . `[`. -n "${MAILTMP:-}" ] && [scip-shell system . . `[`. -s "$MAILTMP" ]; then
723 loglines="$(wcscip-shell system . . wc. -l "$MAILTMP" | awkscip-shell system . . awk. '{ print $1 }')"
724 if [scip-shell system . . `[`. "$LINES" -gt "0" ] && [scip-shell system . . `[`. "${loglines:=0}" -gt "$LINES" ]; then
725 printfscip-shell system . . printf. "AIDE has returned long output which has been truncated in this mail\\n" | \
726 frame
727 printfscip-shell system . . printf. "Output is %d lines, truncated to %d.\\n" "$loglines" "$LINES"
728 headscip-shell system . . head. -n "$LINES" "$MAILTMP"
729 printfscip-shell system . . printf. "\\nEnd of truncated AIDE output. The full output can be found in %s.\\nsha256sum: %s\\n\\n" "$LOGFILE" "$LOGFILE_CHECKSUM"
730 else
731 printfscip-shell system . . printf. "Output of the daily AIDE check (%d lines):\\n" "$loglines"
732 catscip-shell system . . cat. "$MAILTMP"
733 if [scip-shell system . . `[`. "$MAIL_MODE" -gt "0" ] ; then
734 case "$MAIL_MODE" in
735 1) AIDE_OUTPUT="truncated" ;;
736 2) AIDE_OUTPUT="filtered" ;;
737 3) AIDE_OUTPUT="truncated and filtered" ;;
738 esac
739 printfscip-shell system . . printf. "\\nEnd of %s AIDE output.\\n\\nThe full output can be found in %s.\\nsha256sum: %s\\n\\n" "$AIDE_OUTPUT" "$LOGFILE" "$LOGFILE_CHECKSUM"
740 else
741 printfscip-shell system . . printf. "\\nEnd of AIDE output.\\n\\n"
742 fi
743 fi
744 else
745 printfscip-shell system . . printf. "AIDE detected no changes.\\n\\n"
746 fi
747 } >> "$MAILFILE"
748 else
749 printfscip-shell system . . printf. >> "$MAILFILE" "funny, AIDE did not leave a log.\\n\\n"
750 printfscip-shell system . . printf. >> "$LOGFILE" "funny, AIDE did not leave a log.\\n"
751 fi
752
753 if [scip-shell system . . `[`. -n "${DBCHECKLOG:-}" ] && [scip-shell system . . `[`. -s "$DBCHECKLOG" ]; then
754 < "$DBCHECKLOG" catscip-shell system . . cat. >> "$MAILFILE"
755 printfscip-shell system . . printf. >> "$MAILFILE" "\\n"
756 fi
757
758 printfscip-shell system . . printf. >> "$MAILFILE" "End of AIDE daily aide check at %s, run time %d seconds\\n" "$(datescip-shell system . . date. +"%Y-%m-%d %H:%M" -d@"$ENDTIME")" "$(( ENDTIME - BEGINTIME ))"
759
760 # send mail if changes or errors were detected or quiet reports not requested
761 if [scip-shell system . . `[`. "$QUIETREPORTS" != "yes" ] || [scip-shell system . . `[`. "$ARETVAL" != "0" ] || [scip-shell system . . `[`. "$(< "$ERRORLOG" wcscip-shell system . . wc. -l)" -ne 0 ]; then
762 # do not send anything (not even error messages) if silence is requested
763 if [scip-shell system . . `[`. "$SILENTREPORTS" != "yes" ]; then
764 < "$MAILFILE" foldscip-shell system . . fold. --bytes --width="${MAILWIDTH:-990}" | send_mailscip-shell shell shell-project 0.0.0 send_mail(). "${MAILTO}" "${MAILSUBJ}"
765 fi
766 fi
767
768 # clean up tmpfiles
769 rmscip-shell system . . rm. -rf "$TMPDIRIN"
770 fi
771
772 if [scip-shell system . . `[`. -n "$CRONEXITHOOK" ] && [scip-shell system . . `[`. -x "$CRONEXITHOOK" ]; then
773 $CRONEXITHOOK $CRONEXITHOOKPARM
774 fi
775
776 # clear lock
777 if [scip-shell system . . `[`. -n "${LOCKED:-}" ] && command -v dotlockfile >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
778 cd "${LOCKBASE}"
779 dotlockfile -u "$LOCKFILE" || truescip-shell system . . true.
780 fi
781 unset LOCKED
782
783 return ${SCRIPTRETVAL}
784 }
785
786 BEGINTIME="$(datescip-shell system . . date. +%s)"
787
788 if [scip-shell system . . `[`. "$CRON_DAILY_RUN" != "yes" ] && ! ttyscip-shell system . . tty. -s; then
789 exit 0
790 fi
791
792 if command -v dotlockfile >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
793 cd "${LOCKBASE}"
794 if ! dotlockfile -p -l "$LOCKFILE"; then
795 onexitscip-shell shell shell-project 0.0.0 onexit(). nolock
796 exit 1
797 fi
798 else
799 PREERRORLOG="no dotlockfile binary in path, not checking for already running daily aide check\\n"
800 fi
801 LOCKED=yes
802
803 # prepare temp dir
804 # We use invariant file names here since our work files need to be
805 # excluded from aide.
806 if [scip-shell system . . `[`. -e "$TMPDIRIN" ]; then
807 # $TMPDIRIN already exists (from an aborted run, maybe?). Move
808 # it away. This does not cause the script to abort, but aide should
809 # have rules to report the new directrory appearing in $TMPBASE.
810 if ! NEWNAME="$(mktempscip-shell system . . mktemp. -d $TMPBASE/dailyaidecheck.old.XXXXXXXXXX)"; then
811 onexitscip-shell shell shell-project 0.0.0 onexit(). cantmovetmp
812 exit 1
813 fi
814 mvscip-shell system . . mv. "$TMPDIRIN" "$NEWNAME"
815 unset NEWNAME
816 fi
817
818 if ! mkdirscip-shell system . . mkdir. -p $TMPDIRIN; then
819 onexitscip-shell shell shell-project 0.0.0 onexit(). cantcreatetmp
820 exit 1
821 fi
822
823 if [scip-shell system . . `[`. "$(statscip-shell system . . stat. --format='%a %u' "${TMPDIRIN}")" != "750 ${AIDEUSERUID}" ]; then
824 onexitscip-shell shell shell-project 0.0.0 onexit(). tmpnotours
825 exit 1
826 fi
827
828 if ! chmodscip-shell system . . chmod. 0700 "${TMPDIRIN}"; then
829 onexitscip-shell shell shell-project 0.0.0 onexit(). cantchmodtmp
830 exit 1
831 fi
832
833 # handle the case that CRONEXITHOOK does not exist or is not executeable
834 if [scip-shell system . . `[`. -n "$CRONEXITHOOK" ]; then
835 if ! [scip-shell system . . `[`. -x "$CRONEXITHOOK" ]; then
836 onexitscip-shell shell shell-project 0.0.0 onexit(). nohook
837 exit 1
838 fi
839 fi
840
841 # we can now directly use file names inside $TMPDIR: It is only
842 # writeable for us (umask 027), so we're safe against symlink attacks.
843 TMPDIR="$TMPDIRIN"
844
845 # now, with $TMPDIR having been created, we can use the full power of onexit.
846
847 # ERRORLOG: Error messages from script. Gets written to $LOGFILE first
848 ERRORLOG="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). errorlog)"
849
850 if [scip-shell system . . `[`. -n "${PREERRORLOG:-}" ]; then
851 printfscip-shell system . . printf. >> "$ERRORLOG" "%s" "$PREERRORLOG"
852 fi
853 unset PREERRORLOG
854
855 # MAILFILE: Contents gets mailed. Built and handled from inside onexit()
856 MAILFILE="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). mailfile)"
857
858 # aide return value
859 ARETVAL=-1
860
861 if [scip-shell system . . `[`. ! -f "$DATABASE" ]; then
862 printfscip-shell system . . printf. >> "$ERRORLOG" "Fatal error: The AIDE database '%s' does not exist!\\n" "$DATABASE"
863 printfscip-shell system . . printf. >> "$ERRORLOG" "This may mean you haven't created it or that the initialization process is still running, or it may mean that someone has removed it.\\n"
864 onexitscip-shell shell shell-project 0.0.0 onexit(). nodb
865 exit 1
866 fi
867
868 # code
869
870 # re-assign current time to be more accurate about aide's real start time
871 BEGINSTAMP="$(datescip-shell system . . date. +"%Y-%m-%d %H:%M:%S")"
872
873 # ARUNLOG: standard output of aide run
874 ARUNLOG="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). arunlog)"
875
876 # AERRLOG: standard error of aide run
877 AERRLOG="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). aerrlog)"
878
879 printfscip-shell system . . printf. "begin timestamp %s\\n" "$BEGINSTAMP" >> "$ARUNLOG"
880
881 # shellcheck disable=SC2086
882 aide --config="${CONFIG}" ${AIDEARGS} "--${COMMAND}" --after="report_url=file:${ARUNLOG}" 2>|"${AERRLOG}" && ARETVAL="$?"
883 ARETVAL="$?"
884
885 # POSTRUNLOG: summary of aide execution and daily aide check log
886 POSTRUNLOG="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). postrunlog)"
887
888 # DBCHECKLOG: Output of the database checksums
889 DBCHECKLOG="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). dbchecklog)"
890
891 # NOISETMP: completely de-noised log
892 # NOISETMP2: pre-filtered ARUNLOG, containing only changed, removed and added lines
893 NOISETMP="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). noisetmp)"
894 NOISETMP2="$(mytempfilescip-shell shell shell-project 0.0.0 mytempfile(). noisetmp2)"
895
896 # find out whether we neeed to copy the new database over the old one
897
898 COPYDB="0"
899 if [scip-shell system . . `[`. "$COPYNEWDB" = "ifnochange" ] && [scip-shell system . . `[`. "$ARETVAL" = "0" ]; then
900 COPYDB="1"
901 printfscip-shell system . . printf. >> "$POSTRUNLOG" "no significant changes detected.\\n"
902 fi
903
904 if [scip-shell system . . `[`. "$COPYNEWDB" = "yes" ]; then
905 COPYDB=1
906 fi
907
908 if [scip-shell system . . `[`. "$COPYDB" = "1" ] && [scip-shell system . . `[`. "$COMMAND" = "update" ]; then
909 cpscip-shell system . . cp. -f "$DATABASE_OUT" "$DATABASE"
910 printfscip-shell system . . printf. >> "$POSTRUNLOG" "output database %s was copied to %s as requested by daily aide check configuration\\n" "$DATABASE_OUT" "$DATABASE"
911 fi
912
913 onexitscip-shell shell shell-project 0.0.0 onexit(). success
914 exit 0
915
916 # vim: tabstop=4 shiftwidth=4 expandtab
917 # end of file