packages/net/clamav/files/clamav.init
W. Michael Petullo 54016ddaf4 clamav: allow configuration to use TCP socket
Something having to do with passing a file descriptor over spamd's
Unix socket causes the ClamAV milter to fail. The milter says "ERROR:
Unknown reply from clamd," and running strace on spamd reveals "No file
descriptor received. ERROR."

Some work by others can be found on the Internet that suggests using
a TCP socket for the communication between the milter and spamd fixes
this. Lucian Cristian confirmed this on OpenWrt.

I am not sure why the Unix socket does not work. I suspect it is something
related to musl, but I have not yet found evidence of this.

This merge request adds the option to configure spamd to use a TCP
socket, and it uses this as the default. The merge request also adds an
init script for clamav-milter.

Signed-off-by: W. Michael Petullo <mike@flyn.org>
2021-01-09 18:29:46 -06:00

129 lines
3.3 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org
START=90
STOP=10
USE_PROCD=1
PROG=/usr/sbin/clamd
CLAMD_CONFIGFILE="/tmp/clamav/clamd.conf"
validate_clamav_section() {
uci_load_validate clamav clamav "$1" "$2" \
'clamd_config_file:string' \
'LogFile:string' \
'LogFileMaxSize:string' \
'LogVerbose:string' \
'ExtendedDetectionInfo:string' \
'LogTime:string' \
'OfficialDatabaseOnly:string' \
'StreamMinPort:uinteger' \
'StreamMaxPort:uinteger' \
'MaxThreads:uinteger' \
'ReadTimeout:uinteger' \
'CommandReadTimeout:uinteger' \
'MaxDirectoryRecursion:uinteger' \
'FollowDirectorySymlinks:string' \
'FollowFileSymlinks:string' \
'SelfCheck:uinteger' \
'DetectPUA:string' \
'ScanPE:string' \
'DisableCertCheck:string' \
'ScanELF:string' \
'AlertBrokenExecutables:string' \
'ScanOLE2:string' \
'ScanPDF:string' \
'ScanSWF:string' \
'ScanMail:string' \
'ScanPartialMessages:string' \
'ScanArchive:string' \
'TemporaryDirectory:string' \
'AlertEncrypted:string' \
'MaxFileSize:string' \
'LocalSocket:string' \
'TCPSocket:port' \
'TCPAddr:ipaddr' \
'User:string' \
'ExitOnOOM:string' \
'DatabaseDirectory:string'
}
start_clamav_instance() {
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
mkdir -p "$DatabaseDirectory"
mkdir -p /etc/clamav/
mkdir -p /var/run/clamav/
chmod a+rw /var/run/clamav
mkdir -p "$(dirname $CLAMD_CONFIGFILE)"
ln -sf "$clamd_config_file" "$CLAMD_CONFIGFILE"
{
echo "LogFile " "$LogFile"
echo "LogFileMaxSize " "$LogFileMaxSize"
echo "LogVerbose " "$LogVerbose"
echo "ExtendedDetectionInfo " "$ExtendedDetectionInfo"
echo "LogTime " "$LogTime"
echo "OfficialDatabaseOnly " "$OfficialDatabaseOnly"
echo "StreamMinPort " "$StreamMinPort"
echo "StreamMaxPort " "$StreamMaxPort"
echo "MaxThreads " "$MaxThreads"
echo "ReadTimeout " "$ReadTimeout"
echo "CommandReadTimeout " "$CommandReadTimeout"
echo "MaxDirectoryRecursion " "$MaxDirectoryRecursion"
echo "FollowDirectorySymlinks " "$FollowDirectorySymlinks"
echo "FollowFileSymlinks " "$FollowFileSymlinks"
echo "SelfCheck " "$SelfCheck"
echo "DetectPUA " "$DetectPUA"
echo "ScanPE " "$ScanPE"
echo "DisableCertCheck " "$DisableCertCheck"
echo "ScanELF " "$ScanELF"
echo "AlertBrokenExecutables " "$AlertBrokenExecutables"
echo "ScanOLE2 " "$ScanOLE2"
echo "ScanPDF " "$ScanPDF"
echo "ScanSWF " "$ScanSWF"
echo "ScanMail " "$ScanMail"
echo "ScanPartialMessages " "$ScanPartialMessages"
echo "ScanArchive " "$ScanArchive"
echo "TemporaryDirectory " "$TemporaryDirectory"
echo "AlertEncrypted " "$AlertEncrypted"
echo "MaxFileSize " "$MaxFileSize"
echo "User " "$User"
echo "ExitOnOOM " "$ExitOnOOM"
echo "DatabaseDirectory " "$DatabaseDirectory"
} > "$CLAMD_CONFIGFILE"
if [ -n "$LocalSocket" ]; then
echo "LocalSocket " "$LocalSocket" >>"$CLAMD_CONFIGFILE"
fi
if [ -n "$TCPSocket" ]; then
echo "TCPAddr" "$TCPAddr" >>"$CLAMD_CONFIGFILE"
echo "TCPSocket " "$TCPSocket" >>"$CLAMD_CONFIGFILE"
fi
procd_open_instance
procd_set_param command $PROG -c $CLAMD_CONFIGFILE
procd_set_param file $CLAMD_CONFIGFILE
procd_close_instance
}
start_service()
{
validate_clamav_section clamav start_clamav_instance
}
stop_service()
{
service_stop $PROG
}
service_triggers()
{
procd_add_reload_trigger "clamav"
procd_add_validation validate_clamav_section
}