blob: b76e48e522637c7040a7bdf591328e1aa339ac85 (
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#!/bin/sh
# PROVIDE: milter-batv
# REQUIRE: DAEMON
# BEFORE: mail
# KEYWORD: shutdown
# Define these milterbatv_* variables in one of these files:
# /etc/rc.conf
# /etc/rc.conf.local
# /etc/rc.conf.d/milterbatv
#
# milterbatv_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable batv-milter
# milterbatv_uid (str): Set username to run milter.
# milterbatv_profiles (list): Set to "" by default.
# Define your profiles here.
# milterbatv_cfgfile (str): Configuration file.
#
# milterbatv_${profile}_* : Variables per profile.
# Sockets must be different from each other.
#
# all parameters below can be set in batv-filter.conf(5).
# milterbatv_socket (str): Path to the milter socket.
# milterbatv_domain (str): Domainpart of From: in mails to sign.
# milterbatv_allowlist (str): Path to the allow list file.
# milterbatv_key (str): Path to the private key file to sign with.
# milterbatv_flags (str): Flags passed to start command.
. /etc/rc.subr
name="milterbatv"
rcvar=milterbatv_enable
start_precmd="batv_prepcmd"
stop_postcmd="batv_postcmd"
command="%%PREFIX%%/bin/batv-filter"
_piddir="/var/run/milterbatv"
pidfile="${_piddir}/pid"
load_rc_config $name
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#
: ${milterbatv_enable="NO"}
: ${milterbatv_uid="mailnull"}
: ${milterbatv_cfgfile="%%PREFIX%%/etc/mail/batv-filter.conf"}
# Options other than above can be set with $milterbatv_flags.
# see batv-milter documentation for detail.
if [ -n "$2" ]; then
profile="$2"
if [ "x${milterbatv_profiles}" != "x" ]; then
pidfile="${_piddir}/${profile}.pid"
eval milterbatv_enable="\${milterbatv_${profile}_enable:-${milterbatv_enable}}"
eval milterbatv_socket="\${milterbatv_${profile}_socket:-}"
if [ "x${milterbatv_socket}" = "x" ];then
echo "You must define a socket (milterbatv_${profile}_socket)"
exit 1
fi
eval milterbatv_cfgfile="\${milterbatv_${profile}_cfgfile:-${milterbatv_cfgfile}}"
eval milterbatv_domain="\${milterbatv_${profile}_domain:-${milterbatv_domain}}"
eval milterbatv_allowlist="\${milterbatv_${profile}_allowlist:-${milterbatv_allowlist}}"
eval milterbatv_key="\${milterbatv_${profile}_key:-${milterbatv_key}}"
eval milterbatv_flags="\${milterbatv_${profile}_flags:-${milterbatv_flags}}"
if [ -f "${milterbatv_cfgfile}" ];then
milterbatv_cfgfile="-x ${milterbatv_cfgfile}"
else
milterbatv_cfgfile=""
fi
if [ "x${milterbatv_socket}" != "x" ];then
_socket_prefix="-p"
fi
if [ "x${milterbatv_uid}" != "x" ];then
_uid_prefix="-u"
fi
if [ "x${milterbatv_domain}" != "x" ];then
milterbatv_domain="-d ${milterbatv_domain}"
fi
if [ "x${milterbatv_allowlist}" != "x" ];then
milterbatv_allowlist="-a ${milterbatv_allowlist}"
fi
if [ "x${milterbatv_key}" != "x" ];then
milterbatv_key="-k ${milterbatv_key}"
fi
command_args="-l ${_socket_prefix} ${milterbatv_socket} ${_uid_prefix} ${milterbatv_uid} -P ${pidfile} ${milterbatv_cfgfile} ${milterbatv_domain} ${milterbatv_allowlist} ${milterbatv_key}"
else
echo "$0: extra argument ignored"
fi
else
if [ "x${milterbatv_profiles}" != "x" -a "x$1" != "x" ]; then
if [ "x$1" != "xrestart" ]; then
for profile in ${milterbatv_profiles}; do
echo "===> milterbatv profile: ${profile}"
%%RC_SCRIPT%% $1 ${profile}
retcode="$?"
if [ "0${retcode}" -ne 0 ]; then
failed="${profile} (${retcode}) ${failed:-}"
else
success="${profile} ${success:-}"
fi
done
exit 0
else
restart_precmd=""
fi
else
if [ -f "${milterbatv_cfgfile}" ];then
milterbatv_cfgfile="-x ${milterbatv_cfgfile}"
else
milterbatv_cfgfile=""
fi
if [ "x${milterbatv_socket}" != "x" ];then
_socket_prefix="-p"
fi
if [ "x${milterbatv_uid}" != "x" ];then
_uid_prefix="-u"
fi
if [ "x${milterbatv_domain}" != "x" ];then
milterbatv_domain="-d ${milterbatv_domain}"
fi
if [ "x${milterbatv_allowlist}" != "x" ];then
milterbatv_allowlist="-a ${milterbatv_allowlist}"
fi
if [ "x${milterbatv_key}" != "x" ];then
milterbatv_key="-k ${milterbatv_key}"
fi
command_args="-l ${_socket_prefix} ${milterbatv_socket} ${_uid_prefix} ${milterbatv_uid} -P ${pidfile} ${milterbatv_cfgfile} ${milterbatv_domain} ${milterbatv_allowlist} ${milterbatv_key}"
fi
fi
batv_prepcmd ()
{
if [ -S ${milterbatv_socket##local:} ] ; then
rm -f ${milterbatv_socket##local:}
elif [ -S ${milterbatv_socket##unix:} ] ; then
rm -f ${milterbatv_socket##unix:}
fi
if [ ! -d ${_piddir} ] ; then
mkdir -p ${_piddir}
fi
if [ -n "${milterbatv_uid}" ] ; then
chown ${milterbatv_uid} ${_piddir}
fi
}
batv_postcmd()
{
if [ -S ${milterbatv_socket##local:} ] ; then
rm -f ${milterbatv_socket##local:}
elif [ -S ${milterbatv_socket##unix:} ] ; then
rm -f ${milterbatv_socket##unix:}
fi
# just if the directory is empty
rmdir ${_piddir} > /dev/null 2>&1
}
run_rc_command "$1"
|