summaryrefslogtreecommitdiffstats
path: root/net/clamav/files/clamav.init
blob: 4d24b9a1d5fb4459eceff189927321b33dbf8b75 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/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' \
		'LogVerbose:string' \
		'LogTime:string' \
		'Debug:string' \
		'LogSyslog:string' \
		'LogFacility:string' \
		'ExtendedDetectionInfo: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"

	{
	[ -n "$LogVerbose" ]				&& echo "LogVerbose " "$LogVerbose"
	[ -n "$LogTime" ]					&& echo "LogTime " "$LogTime"
	[ -n "$Debug" ]						&& echo "Debug " "$Debug"
	[ -n "$LogSyslog" ]					&& echo "LogSyslog " "$LogSyslog"
	[ -n "$LogFacility" ]				&& echo "LogFacility " "$LogFacility"
	[ -n "$ExtendedDetectionInfo" ]		&& echo "ExtendedDetectionInfo " "$ExtendedDetectionInfo"
	[ -n "$OfficialDatabaseOnly" ]		&& echo "OfficialDatabaseOnly " "$OfficialDatabaseOnly"
	[ -n "$StreamMinPort" ]				&& echo "StreamMinPort " "$StreamMinPort"
	[ -n "$StreamMaxPort" ]				&& echo "StreamMaxPort " "$StreamMaxPort"
	[ -n "$MaxThreads" ]				&& echo "MaxThreads " "$MaxThreads"
	[ -n "$ReadTimeout" ]				&& echo "ReadTimeout " "$ReadTimeout"
	[ -n "$CommandReadTimeout" ]		&& echo "CommandReadTimeout " "$CommandReadTimeout"
	[ -n "$MaxDirectoryRecursion" ]		&& echo "MaxDirectoryRecursion " "$MaxDirectoryRecursion"
	[ -n "$FollowDirectorySymlinks" ]	&& echo "FollowDirectorySymlinks " "$FollowDirectorySymlinks"
	[ -n "$FollowFileSymlinks" ]		&& echo "FollowFileSymlinks " "$FollowFileSymlinks"
	[ -n "$SelfCheck" ]					&& echo "SelfCheck " "$SelfCheck"
	[ -n "$DetectPUA" ]					&& echo "DetectPUA " "$DetectPUA"
	[ -n "$ScanPE" ]					&& echo "ScanPE " "$ScanPE"
	[ -n "$DisableCertCheck" ]			&& echo "DisableCertCheck " "$DisableCertCheck"
	[ -n "$ScanELF" ]					&& echo "ScanELF " "$ScanELF"
	[ -n "$AlertBrokenExecutables" ]	&& echo "AlertBrokenExecutables " "$AlertBrokenExecutables"
	[ -n "$ScanOLE2" ]					&& echo "ScanOLE2 " "$ScanOLE2"
	[ -n "$ScanPDF" ]					&& echo "ScanPDF " "$ScanPDF"
	[ -n "$ScanSWF" ]					&& echo "ScanSWF " "$ScanSWF"
	[ -n "$ScanMail" ]					&& echo "ScanMail " "$ScanMail"
	[ -n "$ScanPartialMessages" ]		&& echo "ScanPartialMessages " "$ScanPartialMessages"
	[ -n "$ScanArchive" ]				&& echo "ScanArchive " "$ScanArchive"
	[ -n "$TemporaryDirectory" ]		&& echo "TemporaryDirectory " "$TemporaryDirectory"
	[ -n "$AlertEncrypted" ]			&& echo "AlertEncrypted " "$AlertEncrypted"
	[ -n "$MaxFileSize" ]				&& echo "MaxFileSize " "$MaxFileSize"
	[ -n "$User" ]						&& echo "User " "$User"
	[ -n "$ExitOnOOM" ]					&& echo "ExitOnOOM " "$ExitOnOOM"
	[ -n "$DatabaseDirectory" ]			&& 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
}