blob: dae9c4d557dc74a2663a1d1bc89472ff13535f6b (
plain) (
blame)
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
|
#!/sbin/openrc-run
description="Start/stop the s6 services for netqmail"
depend()
{
after net
after localmount
}
makesmtpd()
{
set -e
ip="$1"
usetls="$2"
if "$usetls" ; then
s="s"
port=25
else
s=
port=465
fi
if s6-tcpserver6-socketbinder -dBb0 -- "$ip" "$port" true 2>/dev/null ; then
ipv=6
relayfor="$smtprelay6"
elif s6-tcpserver4-socketbinder -dBb0 -- "$ip" "$port" true 2>/dev/null ; then
ipv=4
relayfor="$smtprelay4"
else
return 1
fi
service="smtp${s}d-$ip"
sdir=/run/services/"$service"
logdir=/var/log/"smtp${s}d-$ip"
mkdir -p -m 0755 "$logdir"
chown qmaill:qmaill "$logdir"
chmod 2700 "$logdir"
rm -rf "$sdir"
cp -a /etc/qmail/services/smtp"${s}"d"${ipv}"-skeleton "$sdir"
echo "$ip" > "$sdir"/env/IP
if "$usetls" ; then
echo "$SMTPSD_KEYFILE" > "$sdir"/env/KEYFILE
echo "$SMTPSD_CERTFILE" > "$sdir"/env/CERTFILE
fi
for j in $relayfor ; do
mkdir -p -m 0755 "$sdir/data/rules/ip${ipv}/$j/env"
touch "$sdir/data/rules/ip${ipv}/$j/allow"
echo > "$sdir/data/rules/ip${ipv}/$j/env/RELAYCLIENT"
done
return 0
}
stop()
{
set -e
. /etc/conf.d/netqmail
ebegin "Stopping SMTP and SMTPS listeners"
dirs=""
logs=""
for i in ${SMTPD_IPS} ; do
rm -f "/run/service/smtpd-$i"
s6-svc -d "/run/services/smtpd-$i"
dirs="$dirs /run/services/smtpd-$i"
logs="$logs /run/services/smtpd-$i/log"
done
if test -r "$SMTPSD_KEYFILE" && test -r "$SMTPSD_CERTFILE" ; then
for i in ${SMTPSD_IPS} ; do
rm -f "/run/service/smtpsd-$i"
s6-svc -d "/run/services/smtpsd-$i"
dirs="$dirs /run/services/smtpsd-$i"
logs="$logs /run/services/smtpsd-$i/log"
done
fi
s6-svwait -D $dirs
eend $?
ebegin "Stopping the qmail-send service (this may take some time)"
rm -f /run/service/qmail
logs="$logs /var/qmail/services/qmail/log"
s6-svc -dwD /var/qmail/services/qmail
eend $?
ebegin "Stopping loggers and cleaning up qmail services"
for i in $logs ; do
s6-svc -d "$i"
done
s6-svwait -D $logs
s6-svscanctl -aN /run/service
rm -rf $dirs
eend $?
}
start()
{
set -e
. /etc/conf.d/netqmail
ebegin "Parsing the relay subnets"
smtprelay4=
smtprelay6=
for i in ${RELAY_SUBNETS} ; do
j=`echo "$i" | tr / _`
if echo "$i" | grep -qF : ; then
smtprelay6="$smtprelay6 $j"
elif echo "$i" | grep -qF . ; then
smtprelay4="$smtprelay4 $j"
else
false
break
fi
done
eend $?
ebegin "Starting the qmail-send service"
ln -nsf ../../var/qmail/services/qmail /run/service/qmail
s6-svscanctl -a /run/service
s6-svwait -U /var/qmail/services/qmail
eend $?
for i in ${SMTPD_IPS} ; do
ebegin "Creating a service directory for a SMTP listener on $i"
makesmtpd "$i" false
eend $?
done
if test -r "$SMTPSD_KEYFILE" && test -r "$SMTPSD_CERTFILE" ; then
for i in ${SMTPSD_IPS} ; do
ebegin "Creating a service directory for a SMTPS listener on $i"
makesmtpd "$i" true
eend $?
done
fi
dirs=""
ebegin "Starting SMTP/S listeners"
for i in ${SMTPD_IPS} ; do
ln -nsf "../services/smtpd-$i" "/run/service/smtpd-$i"
dirs="$dirs /run/service/smtpd-$i"
done
if test -r "$SMTPSD_KEYFILE" && test -r "$SMTPSD_CERTFILE" ; then
for i in ${SMTPSD_IPS} ; do
ln -nsf "../services/smtpsd-$i" "/run/service/smtpsd-$i"
dirs="$dirs /run/service/smtpsd-$i"
done
fi
s6-svscanctl -aN /run/service
s6-svwait -U $dirs
eend $?
}
|