summaryrefslogtreecommitdiffstats
path: root/debian/postfix.preinst
blob: c0edce25c20621e1666324c935e36bd51de3962f (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/bin/sh -e

# Debian Postfix preinst
# LaMont Jones <lamont@debian.org>
# Modified to use debconf by Colin Walters <levanti@verbum.org>

# do we have debconf?
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
    DEBCONF=true
else
    DEBCONF=
fi

dpkg_vers=$(dpkg --status dpkg | sed -n '/Version: /s/^Version: //p')
CONFIG=/etc/postfix/main.cf
MASTER=/etc/postfix/master.cf
POSTDROP=/usr/sbin/postdrop

compat_conversion_warning() {
    if [ -n "$DEBCONF" ]; then
	db_input medium postfix/compat_conversion_warning || true
	db_go || true
	db_get postfix/compat_conversion_warning
	if [ "$RET" = "false" ]; then
	    echo "aborting postfix install"
	    exit 1
	fi
    else
    	cat << EOF
This upgrade of postfix changes some default values in the configuration. As
part of this upgrade, the following will be changed: (1) chrooted components
will be changed from '-' to 'y' in master.cf, and (2) myhostname will be set
to a fully-qualified domain name if it is not already such.  The install will
be aborted if you do not allow the change.
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	echo "aborting postfix install"
			exit 1;;
	    *)		;;
	esac
    fi
}

lmtp_retired_warning() {
    if [ -n "$DEBCONF" ]; then
	db_input medium postfix/lmtp_retired_warning || true
	db_go || true
	db_get postfix/lmtp_retired_warning
	if [ "$RET" = "false" ]; then
	    echo "aborting postfix install"
	    exit 1
	fi
    else
	cat << EOF
This upgrade of postfix drops the "lmtp" symlink, and your configuration
(master.cf) refers to it: lmtp was merged into smtp long ago.  The install
will be aborted if you do not allow the change.
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	echo "aborting postfix install"
			exit 1;;
	    *)		;;
	esac
    fi
}

main_cf_conversion_warning() {
    if [ -n "$DEBCONF" ]; then
	db_input medium postfix/main_cf_conversion_warning || true
	db_go || true
	db_get postfix/main_cf_conversion_warning
	if [ "$RET" = "false" ]; then
	    echo "aborting postfix install"
	    exit 1
	fi
    else
    	cat << EOF
This upgrade of postfix changes where daemons are located, and your postfix
configuration explicitly specifies the old location.  The install will be
aborted if you do not allow the change.
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	echo "aborting postfix install"
			exit 1;;
	    *)		;;
	esac
    fi
}

dynamicmaps_conversion_warning() {
    if [ -n "$DEBCONF" ]; then
	db_input medium postfix/dynamicmaps_conversion_warning || true
	db_go || true
	db_get postfix/dynamicmaps_conversion_warning
	if [ "$RET" != "false" ]; then
	    touch /var/spool/postfix/dynamicmaps_3.0_transition
	fi
    else
    	cat << EOF
Postfix version 3.0 changes how dynamic maps are delivered, and your
dynamicmaps.cf does not reflect that.  Accept this option to convert
dynamicmaps.cf to the version required for 3.0.
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	;;
	    *)		touch /var/spool/postfix/dynamicmaps_3.0_transition;;
	esac
    fi
}

relay_restrictions_warning() {
    if [ -n "$DEBCONF" ]; then
	db_input medium postfix/relay_restrictions_warning || true
	db_go || true
	db_get postfix/relay_restrictions_warning
	if [ "$RET" != "false" ]; then
	    touch /var/spool/postfix/set_relay_restrictions
	fi
    else
    	cat << EOF
Postfix version 2.10 adds smtpd_relay_restrictions, to separate relaying
restrictions from recipient restrictions, and you have a non-default value
for smtpd_recipient_restrictions.

Failure to do this may result in deferred or bounced mail after the
upgrade.  Accept this option to set smtpd_relay_restrictions to
smtpd_recipient_restrictions.
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	;;
	    *)		touch /var/spool/postfix/set_relay_restrictions;;
	esac
    fi
}

mydomain_warning() {
    if [ -n "$DEBCONF" ]; then
	db_fset postfix/mydomain_warning seen false
	db_input medium postfix/mydomain_warning || true
	db_go || true
	db_get postfix/mydomain_warning
	if [ "$RET" = "false" ]; then
	    echo "aborting postfix install"
	    exit 1
	fi
    else
	# no debconf, fall back
	cat << EOF
Postfix version 2.3.3-2 and later require changes in main.cf.
Specifically, mydomain must be specified, since hostname(2) is not
an FQDN.
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	echo "aborting postfix install"
			exit 1
			;;
	esac
    fi
}

retry_warning() {
    if [ -n "$DEBCONF" ]; then
	db_fset postfix/retry_upgrade_warning seen false
	db_input medium postfix/retry_upgrade_warning || true
	db_go || true
	db_get postfix/retry_upgrade_warning
	if [ "$RET" = "false" ]; then
	    echo "aborting postfix install"
	    exit 1
	fi
    else
	# no debconf, fall back
	cat << EOF
Postfix version 2.4 requires that the retry service be added to master.cf
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	echo "aborting postfix install"
			exit 1
			;;
	esac
    fi
}

tlsmgr_warning() {
    if [ -n "$DEBCONF" ]; then
	db_fset postfix/tlsmgr_upgrade_warning seen false
	db_input medium postfix/tlsmgr_upgrade_warning || true
	db_go || true
	db_get postfix/tlsmgr_upgrade_warning
	if [ "$RET" = "false" ]; then
	    echo "aborting postfix install"
	    exit 1
	fi
    else
	# no debconf, fall back
	cat << EOF
Postfix version 2.2 has changed the invocation of tlsmgr.
EOF
	echo -n "Shall I make the change? "
	read line
	case ${line} in
	    [nN]*)	echo "aborting postfix install"
			exit 1
			;;
	esac
    fi
}

kernel_version_warning() {
    if [ -n "$DEBCONF" ]; then
	db_fset postfix/kernel_version_warning seen false
	db_input low postfix/kernel_version_warning || true
	db_go || true
	db_get postfix/kernel_version_warning
    else
	cat << EOF
Postfix uses features that are not found in kernels prior to 2.6.  If you
proceeed with the installation, Postfix will not run.
EOF
	RET=false
    fi
    if [ "$RET" = "false" ]; then
	echo "Aborting postfix install"
	exit 1
    fi
}

(umask 022; mkdir -p /var/spool/postfix)

case "$1" in
    install)
	rm -f /var/spool/postfix/restart /var/spool/postfix/reload
	# workaround sendmail not unregistering itself...
	if [ -e /etc/suid.conf ] && [ -x /usr/sbin/suidunregister ]; then
	    if grep -q sendmail /etc/suid.conf; then
		/usr/sbin/suidunregister -s postfix /usr/sbin/sendmail
	    fi
	fi

	if [ -L /etc/postfix/postfix-script ]; then
		rm -f /etc/postfix/postfix-script
	fi

	;;

    upgrade)
	version=$2
	if [ -d /var/spool/postfix ] && [ -f /etc/postfix/main.cf ]; then
	    touch /var/spool/postfix/restart
	fi
	export LANG=C	# for the comparison of mail version...

	if [ -L /etc/postfix/postfix-script ]; then
		rm -f /etc/postfix/postfix-script
	fi

	# If user has not modified master/main.proto, move aside so new version
	# is installed (#991513)
        cmp -s /usr/share/postfix/main.cf.dist /etc/postfix/main.cf.proto && \
	    mv /etc/postfix/main.cf.proto /etc/postfix/main.cf.proto.old \
	    || echo "/etc/postfix/main.cf.proto modified, not updating."
        cmp -s /usr/share/postfix/master.cf.dist /etc/postfix/master.cf.proto && \
	    mv /etc/postfix/master.cf.proto /etc/postfix/master.cf.proto.old \
	    || echo "/etc/postfix/master.cf.proto modified, not updating."

	if grep -q '^tlsmgr[[:space:]]*fifo' $MASTER; then
	  tlsmgr_warning
	fi

	if dpkg --compare-versions $version lt 3.1.0-1; then
	    # check on compatibility warning issues and warn as appropriate.
	    # even default myhostname needs to be checked to make sure it has a '.'.
	    for dir in /etc/postfix $(postconf -hxn multi_instance_directories 2>/dev/null || true); do
		if [ ! -f "${dir}/main.cf" ] || dpkg --compare-versions $version lt 2.11; then
		    # Just assume that there are issues with the chroot status,
		    # since postconf -F didn't exist before 2.11
		    compat_conversion_warning
		    break
		fi
		SRV=$(postconf -c "$dir" -F '*/*/chroot'| sed -n '/ = -$/s/ =.*$//p')
		if [ -n "$SRV" ] || \
			postconf -c "$dir" -hx myhostname | grep -qv '\.'; then
		    compat_conversion_warning
		    break
		fi
	    done
	fi
	if [ -f /etc/postfix/main.cf ] && dpkg --compare-versions $version lt 3.0.4-5; then
	    # if daemon_directory is specifically set, and wrong, then we need
            # to fix it.
	    for dir in /etc/postfix $(postconf -hxn multi_instance_directories); do
		DD=$(postconf -c "$dir" -hxn daemon_directory)
		if [ "X${DD}" = X/usr/lib/postfix ]; then
		    main_cf_conversion_warning
		    break
		fi
	    done
	fi

	if dpkg --compare-versions $version lt 3.0.3-2; then
	    # If we still think that it's dict_tcp.so, then we need to convert.
	    DM=/etc/postfix/dynamicmaps.cf
	    if [ ! -f ${DM} ] || grep -q "/usr/lib/postfix/dict_tcp.so" ${DM}; then
		dynamicmaps_conversion_warning
	    fi
	fi

	if dpkg --compare-versions $version lt 2.10.0-2; then
	  RECIP=$(postconf -hx smtpd_recipient_restrictions 2>/dev/null || true)
	  DEFAULT="permit_mynetworks, reject_unauth_destination"
	  if [ "$RECIP" != "$DEFAULT" ]; then
	    # 2.10.0-1 is special because it was broken.  If they haven't fixed
	    # it themselves, deal with it.
	    if dpkg --compare-versions $version ge 2.10.0-1; then
	      if [ -n "$RECIP" ] && [ -z "$(postconf -n smtpd_relay_restrictions)" ]; then
		relay_restrictions_warning
	      fi
	    else
	      # if they have the default recipient_restrictions then no need to ask.
	      relay_restrictions_warning
	    fi
	  fi
	fi

	if ! grep -q '^retry[[:space:]]' $MASTER; then
	  retry_warning
	fi
	invoke-rc.d --quiet postfix stop || true
	;;

    abort-upgrade)
	if [ -f /etc/postfix/main.cf.proto.old ]; then
	  mv /etc/postfix/main.cf.proto.old /etc/postfix/main.cf.proto
	  echo "Restoring old /etc/postfix/main.cf.proto on failed upgrade."
	fi
	if [ -f /etc/postfix/master.cf.proto.old ]; then
	  mv /etc/postfix/master.cf.proto.old /etc/postfix/master.cf.proto
	  echo "Restoring old /etc/postfix/master.cf.proto on failed upgrade."
	fi
	;;

    *)
	echo "preinst called with unknown argument \`$1'" >&2
	exit 1
	;;
esac

if [ install = "$1" -o upgrade = "$1" ]; then
    # cleanup after past mistakes.
    rm -f /usr/sbin/postconf.postfix
    dpkg-divert --package postfix-tls --remove \
	 --divert /usr/sbin/postconf.postfix \
		  /usr/sbin/postconf >/dev/null 2>/dev/null
fi

#DEBHELPER#