This file is indexed.

postinst is in postfix 2.11.0-1.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#!/bin/sh -e

# Debian Postfix postinst
# LaMont Jones <lamont@debian.org>
# Based on debconf code by Colin Walters <walters@cis.ohio-state.edu>,
# and John Goerzen <jgoerzen@progenylinux.com>.

# Use debconf.
. /usr/share/debconf/confmodule
CHROOT=/var/spool/postfix
config_directory="/etc/postfix"		# make variable expansion easier...

. /usr/share/postfix/postinst.functions

set_maildrop_perms() {
    MAILDROP=${CHROOT}/maildrop
    SCRIPT=/etc/postfix/postfix-script
    POSTDROP=/usr/sbin/postdrop
    mkdir -p $MAILDROP
    if ! chown postfix:postdrop $MAILDROP 2>/dev/null; then
	addgroup --system postdrop
	chown postfix:postdrop $MAILDROP
    fi
    dpkg-statoverride --remove $POSTDROP >/dev/null 2>&1 || true
    dpkg-statoverride --remove /var/spool/postfix/public >/dev/null 2>&1 || true
    dpkg-statoverride --remove /usr/sbin/postqueue >/dev/null 2>&1 || true
    dpkg-statoverride --update --add root postdrop 02555 $POSTDROP
    dpkg-statoverride --update --add postfix postdrop 02710 /var/spool/postfix/public
    dpkg-statoverride --update --add root postdrop 02555 /usr/sbin/postqueue
    chmod 1730 $MAILDROP
}

fset_all_changed() {
    db_fset postfix/main_mailer_type changed $1
    db_fset postfix/root_address changed $1
    db_fset postfix/destinations changed $1
    db_fset postfix/mailname changed $1
    db_fset postfix/relayhost changed $1
    db_fset postfix/chattr changed $1
    db_fset postfix/mynetworks changed $1
    db_fset postfix/procmail changed $1
    db_fset postfix/mailbox_limit changed $1
    db_fset postfix/recipient_delim changed $1
}

set_postconf() {
    CHANGES=true
    postconf -e "$@"
}

get_postconf() {
    postconf -h "$@"
}

makedir() {
    if [ ! -d $1 ]; then
	mkdir $1
    fi
    chown $2 $1 && chmod $3 $1
}

convert_dbs() {
    # get all of the hash and btree maps.
    maps=$(postconf -h | sed -e 's/[,[:space:]]/\
/g' -e 's/^proxy://' -e '/:/p' | sort -u )
    for i in $maps; do
      case $i in
	hash:*|btree:*)
	    f=${i#*:}.db
	    if [ -f $f ]; then
		echo "attempting conversion of $i"
		echo "  saving old db in ${f}.db3"
		cp $f ${f}.db3
		postmap -u $i
	    fi
	    ;;
      esac
    done
}

fix_master() {
    echoed=""
    # Need to handle some changes in services.
    MASTER=/etc/postfix/master.cf
    if grep -qE '^cleanup[[:space:]]+unix[[:space:]]+-' ${MASTER}; then
	echo "in master.cf:"; echoed=y
	echo "  forcing pickup=unprivileged, cleanup=public, flush=public"
	sed 's/^\(cleanup[[:space:]]*unix[[:space:]]*\)-/\1n/
	     s/^\(flush[[:space:]]*unix[[:space:]]*\)-/\1n/
	     s/^\(pickup[[:space:]]*fifo[[:space:]]*.[[:space:]]*\)n/\1-/
	' ${MASTER} > ${MASTER}.$$
	mv ${MASTER}.$$ ${MASTER}
    fi

    while read line; do
	serv=${line%% *}
	if ! grep -qE "^${serv}[[:space:]]" ${MASTER}; then
	    [ -n "$echoed" ] || echo "in master.cf:"; echoed=y
	    echo "  adding missing entry for ${serv} service"
	    echo "$line" >> ${MASTER}
	fi
    done << @@EOF@@
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
discard   unix  -       -       -       -       -       discard
retry     unix  -       -       -       -       -       error
@@EOF@@

    if ! grep -qE '^relay[[:space:]]' ${MASTER}; then
	[ -n $echoed ] || echo "in master.cf:"; echoed=y
	echo "  adding missing entry for relay service"
	echo "relay     unix  -       -       n       -       -       smtp -o smtp_fallback_relay= " \
	    >> ${MASTER}
	echo "#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5" \
	    >> ${MASTER}
    fi

    if grep -qE '^tlsmgr[[:space:]]*fifo' ${MASTER}; then
	sed '/^tlsmgr/s/fifo/unix/' ${MASTER} > ${MASTER}.$$
	mv ${MASTER}.$$ ${MASTER}
    fi

}

add_root_alias() {
    db_get postfix/root_address && root_addr="$RET"
    ret=$(echo $RET | tr 'A-Z' 'a-z')
    if [ "$ret" != "none" ] && [ -n "$ret" ] ; then
	echo "adding root: $RET alias"
	echo "root:	$RET" >> /etc/aliases
    fi
}

umask 022

# postinst processing

# Automatically added by dh_makeshlibs
if [ "$1" = "configure" ]; then
	ldconfig
fi
# End automatically added section


case "$1" in
    configure)
	OLDVERSION="$2"
	# see below
	;;

    abort-upgrade)
	fix_master
	exit 0
	;;

    abort-remove|abort-deconfigure)
	exit 0
	;;

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

CHANGES=""
NEWALIASES="y"

update-rc.d postfix defaults > /dev/null

ldconfig

dpkg-divert --package postfix --remove --rename \
	--divert /usr/share/man/man8/smtpd.real.8.gz \
	/usr/share/man/man8/smtpd.8.gz > /dev/null 2>&1

# handle sasl-smtp[d] -> smtp[d] change.  oops..
if [ -d /etc/postfix/sasl ]; then
    cd /etc/postfix/sasl
    for file in smtp smtpd; do
       if [ -r sasl-${file}.conf ] && [ ! -r ${file}.conf ]; then
	    ln -s sasl-${file}.conf ${file}.conf
       fi
    done
fi

cd ${CHROOT}
# make sure that the postfix user exists.  Simplest portable way to check is to
# chown something, so we'll create the directories that we need here.
makedir private		root:root 700
chgrp postfix private 2>/dev/null ||
    addgroup --system postfix
chown postfix private 2>/dev/null ||
    adduser --system --home ${CHROOT} --no-create-home --disabled-password --ingroup postfix postfix

# need to have postfix in the right group, but old revs do it wrong..
if [ "$(id -gn postfix)" != "postfix" ]; then
    usermod -g postfix postfix
fi

chown postfix:root private

db_fget postfix/chattr changed
if [ "$RET" = "true" ]; then
    db_get postfix/chattr && chat="$RET"
    echo "setting synchronous mail queue updates: $chat"
    if [ "$chat" = "true" ]; then
	chat="+S"
    else
	chat="-S"
    fi
fi

makedir pid root:root 755
makedir public postfix:root 755
for dir in incoming active bounce defer deferred flush saved corrupt; do
    makedir ${dir} postfix:root 700
    if [ -n "$chat" ]; then
	chattr $chat $dir 2>/dev/null || true
    fi
done

cd /etc/postfix

if [ ! -f dynamicmaps.cf ]; then
    echo "Creating /etc/postfix/dynamicmaps.cf"
    # only need tcp and sqlite, since they are provided by the postfix
    # package.  Everything else gets added by its own package.
    cat << EOF > dynamicmaps.cf
# Postfix dynamic maps configuration file.
#
#type	location of .so file			open function	(mkmap func)
#====	================================	=============	============
EOF
    addmap tcp
    addmap sqlite
else
    # add sqlite if we were told we could in preinst.
    if [ -f /var/spool/postfix/sqlite_addition ]; then
	addmap sqlite
	rm -f /var/spool/postfix/sqlite_addition
    fi
fi

db_get postfix/main_mailer_type && mailer="$RET"

[ -f master.cf ] || cp /usr/share/postfix/master.cf.dist master.cf

if [ "$mailer" != "No configuration" ]; then	# [
    if [ -f main.cf ]; then
	NEWCONF=""
    else
	cp /usr/share/postfix/main.cf.debian main.cf
	if [ -f /etc/ssl/private/ssl-cert-snakeoil.key ]; then
	    cat /usr/share/postfix/main.cf.tls >> main.cf
	fi
	postconf -e "smtpd_relay_restrictions=permit_mynetworks permit_sasl_authenticated defer_unauth_destination"
	NEWCONF=yes
    fi

    # This is the braindead local-only master.cf from elsewhen
    # we now deal with this in main.cf, so mark the mailer_type changed.
    md5sum=$(md5sum /etc/postfix/master.cf)
    if [ "${md5sum%% *}" = "fadb677a071ea2851cc2b8a12345823d" ]; then
	cp /usr/share/postfix/master.cf.dist master.cf
	db_fset postfix/main_mailer_type changed true
    fi
fi	# !No configuration ]

# cleanup from braindamage.
if [ -d /etc/postfix/maildrop ]; then
    rmdir /etc/postfix/maildrop 2>/dev/null
fi

set_maildrop_perms postdrop
if [ -f /var/spool/postfix/db-upgrade ]; then
    rm /var/spool/postfix/db-upgrade
    db_get postfix/db_upgrade_warning && convert="$RET"
    if [ "$convert" = "true" ]; then
	convert_dbs
    else
	echo "DB files not converted, Postfix restart may fail."
    fi
fi

if [ "$mailer" != "No configuration" ]; then	# [
    myhostname=$(hostname --fqdn 2>/dev/null || echo "")
    if [ -z "$myhostname" ]; then
	if [ -r /etc/hostname ];then
	    myhostname=$(cat /etc/hostname)
	    if [ $myhostname = ${myhostname%.*} -a -f /etc/resolv.conf ]; then
		# The resolver uses the last one found, and ignores the rest
		mydom=$(awk '/^(search|domain)/ {x=$2;} END {print x}' \
			/etc/resolv.conf)
		myhostname="$myhostname${mydom:+.$mydom}"
	    fi
	else
	    myhostname="UNKNOWN"
	fi
    fi
    mydomain=${myhostname#*.}

    if [ -n "$NEWCONF" ]; then
	fset_all_changed true
	alias_maps=hash:/etc/aliases
	nis_status=$(dpkg -l nis 2>/dev/null | sed -n '$p')
	if [ "X$nis_status" != "X${nis_status#i}" ] && [ -x /usr/bin/ypcat ] &&
		/usr/bin/ypcat mail.aliases >/dev/null 2>&1; then
	    alias_maps="hash:/etc/aliases, nis:mail.aliases"
	    cat << EOF
It appears that you have an NIS map for mail aliases; using that in
addition to /etc/aliases.

EOF
	fi
	if [ -n "$myhostname" ]; then
	    echo "setting myhostname: $myhostname"
	    set_postconf "myhostname=$myhostname"
	fi
	echo "setting alias maps"
	set_postconf "alias_maps=$alias_maps"
	echo "setting alias database"
	set_postconf "alias_database=hash:/etc/aliases"
    else
	if [ -f /var/spool/postfix/mydomain-upgrade ]; then
	  rm -f /var/spool/postfix/mydomain-upgrade
	  db_get postfix/mydomain_upgrade && upgrade="$RET"
	  if [ "$upgrade" = "true" ]; then
	    echo "setting mydomain=$mydomain"
	    set_postconf "mydomain=$mydomain"
	  fi
	fi
    fi

    db_fget postfix/mailname changed
    if [ "$RET" = "true" ]; then
	db_get postfix/mailname && mailname="$RET"
	lcmailname="$(echo $RET| tr 'A-Z' 'a-z')"
	if [ "X$lcmailname" = "X==default==" ]; then
	    mailname=$(hostname --fqdn 2>/dev/null || echo localdomain)
	fi
	lcmailname="$(echo $mailname| tr 'A-Z' 'a-z')"
	if [ -f /etc/mailname ] && [ "X$(tr 'A-Z' 'a-z' < /etc/mailname)" = "X$lcmailname" ]; then
	    MAILNAME=""
	else
	    MAILNAME=yes
	fi
	if [ "X${lcmailname}" = Xubuntu.com ] || [ "X${lcmailname}" = Xdebian.org ]; then
	    echo "refusing to set mailname to ${mailname}."
	elif [ "X${mailname%.*}" != "X${mailname}" ]; then
	    if [ -n "$MAILNAME" ]; then
		echo "changing /etc/mailname to $mailname"
		echo $mailname > /etc/mailname
	    fi
	    echo "setting myorigin"
	    set_postconf "myorigin=/etc/mailname"
	else
	    echo "mailname is not a fully qualified domain name.  Not changing /etc/mailname."
	fi
    fi
    db_fget postfix/destinations changed
    if [ "$RET" = "true" ]; then
	db_get postfix/destinations && destinations="$RET"
	echo "setting destinations: $destinations"
	set_postconf "mydestination=$destinations"
    fi
    db_fget postfix/relayhost changed
    if [ "$RET" = "true" ]; then
	db_get postfix/relayhost && relayhost="$RET"
	echo "setting relayhost: $relayhost"
	set_postconf "relayhost=$relayhost"
    fi
    db_fget postfix/mynetworks changed
    if [ "$RET" = "true" ]; then
	db_get postfix/mynetworks && mynetworks="$RET"
	if [ -z "$RET" ]; then
	    echo "deleting mynetworks"
	    if grep -q '^mynetworks[[:space:]]*=' main.cf; then
		# need to remove it, get postconf to do the hard part.
		postconf -e 'mynetworks=127.0.0.0/8'
		perl -i -ne 'print unless /^mynetworks\s*=/' main.cf
	    fi
	else
	    echo "setting mynetworks: $mynetworks"
	    set_postconf "mynetworks=$mynetworks"
	fi
    fi
    db_fget postfix/procmail changed
    if [ "$RET" = "true" ]; then
	db_get postfix/procmail && useprocmail="$RET"
	if [ "x$useprocmail" = "xtrue" ]; then
	    echo "setting mailbox_command"
	    set_postconf 'mailbox_command=procmail -a "$EXTENSION"'
	else
	    if grep -q ^mailbox_command /etc/postfix/main.cf; then
		echo "clearing mailbox_command"
		set_postconf "mailbox_command="
	    fi
	fi
    fi
    db_fget postfix/mailbox_limit changed
    if [ "$RET" = "true" ]; then
	db_get postfix/mailbox_limit && mailbox_limit="$RET"
	echo "setting mailbox_size_limit: $mailbox_limit"
	set_postconf "mailbox_size_limit=$mailbox_limit"
    fi

    db_fget postfix/recipient_delim changed
    if [ "$RET" = "true" ]; then
	db_get postfix/recipient_delim && recip="$RET"
	echo "setting recipient_delimiter: $recip"
	set_postconf "recipient_delimiter=$recip"
    fi

    db_fget postfix/main_mailer_type changed
    if [ "$RET" = "true" ]; then
	dtrans=smtp
	# already have mailer
	case "$mailer" in
	    "Local only")	val=loopback-only; dtrans=error;;
	    "Satellite system")	val=loopback-only;;
	    *)			val=all;;
	esac
	echo "setting inet_interfaces: $val"
	set_postconf "inet_interfaces=$val"

	if [ $(postconf -h default_transport) != $dtrans ]; then
	    echo "setting default_transport: $dtrans"
	    set_postconf "default_transport=$dtrans"
	    echo "setting relay_transport: $dtrans"
	    set_postconf "relay_transport=$dtrans"
	fi
    fi

    db_fget postfix/protocols changed
    if [ "$RET" = "true" ]; then
	db_get postfix/protocols && protocols="$RET"
	echo "setting inet_protocols: $protocols"
	set_postconf "inet_protocols=$protocols"
    fi

    # 2.10 upgrade requires us to copy the smtpd_recipient_restrictions
    # into smtpd_relay_restrictions  Only present for upgrades from before
    # 2.10.0-2 
    if [ -f /var/spool/postfix/set_relay_restrictions ]; then
	# early 2.10.0 was special...  see #702374
	# if we got here with 2.10.0 in OLDVERSION, then there is no value for
	# smtpd_relay_restrictions specified in main.cf, and
	# smtpd_recipient_restrictions is either null (default for 2.10) or
	# else it is some non-default value that we should copy to relay.
	VALUE="$(postconf -h smtpd_recipient_restrictions)"
	if [ -z "$VALUE" ] && dpkg --compare-versions $OLDVERSION ge 2.10.0; then
	    # null, so use the correct default
	    VALUE="permit_mynetworks, reject_unauth_destination"
	fi
	echo "setting smtpd_relay_restrictions: $VALUE"
	set_postconf "smtpd_relay_restrictions=$VALUE"
	rm -f /var/spool/postfix/set_relay_restrictions
    fi

    if [ -z "$CHANGES" ]; then
	MSG="configuration was not changed"
    else if [ -n "$NEWCONF" ]; then
	    MSG="is now set up with a default configuration"
	else
	    MSG="is now set up with the changes above"
	fi
    fi
else	# ] No configuration [
    if [ -f main.cf ]; then
	MSG="configuration was untouched"
    else
	MSG="was not set up.  Start with
  cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
"
	# make sure that we don't try anything stupid below.
	NEWALIASES=""
	rm -f /var/spool/postfix/restart /var/spool/postfix/reload
    fi
fi	# not 'No configuration' ]

if [ ! -f /etc/aliases ]; then	# no /etc/aliases [
    echo "/etc/aliases does not exist, creating it."
    cat << EOF > /etc/aliases
# See man 5 aliases for format
postmaster:    root
EOF
    if [ "$mailer" != "No configuration" ]; then	# [
	db_fget postfix/root_address changed
	if [ "$RET" = "true" ]; then
	    add_root_alias
	    NEWALIASES=y
	fi
    fi	# not 'No configuration' ]
fi # ] no /etc/aliases

if [ "X$OLDVERSION" = "X" ]; then
    # On fresh installs, push a root alias into the file.
    if ! grep -q ^root: /etc/aliases && ! [ -f ~root/.forward ]; then
	add_root_alias
	NEWALIASES=y
    fi
    # And update the doc dirs if postfix-doc is already unpacked
    if [ -f /etc/postfix/main.cf ] && \
       [ -f /usr/share/doc/postfix-doc/changelog.Debian.gz ]; then
	postconf -e	readme_directory=/usr/share/doc/postfix \
    			html_directory=/usr/share/doc/postfix/html
    fi
fi

db_fget postfix/root_address changed
if [ "$RET" = "true" ] && ! grep -q ^root: /etc/aliases; then
  echo "WARNING: /etc/aliases exists, but does not have a root alias."
fi

fset_all_changed false

fold -s << EOF

Postfix $MSG.  If you need to make changes, edit
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
values, see postconf(1).

After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.

EOF

# all done with debconf here.
db_stop

fix_master

# Fix old permissions
chown postfix:postfix /var/lib/postfix
if [ -f /var/lib/postfix/prng_exch ]; then
    chown postfix:postfix /var/lib/postfix/prng_exch
fi

if [ "X$OLDVERSION" = "X" ] && [ ! -f /etc/aliases.db ]; then
    NEWALIASES=y
fi

if [ -x /usr/sbin/update-inetd ]; then
    update-inetd --disable smtp </dev/null >/dev/null 2>&1 || true
fi

if [ "$mailer" != "No configuration" ] || [ -f /etc/postfix/main.cf ]; then
    if [ -n "$NEWALIASES" ]; then
	echo "Running newaliases"
	rm -f /etc/aliases.db	# handle the roll to db2.0
	# newaliases chokes if hostname not set
	# newaliases is equivalent to postalias $(postconf -h alias_database)
	# and in debootstrap, newaliases == /bin/true...
	if [ -z "$(postconf -h myhostname||true)" ]; then
	   cp -a main.cf main.cf.dpkg.$$
	   postconf -e 'myhostname=debian'
	   newaliases
	   mv main.cf.dpkg.$$ main.cf
	else
	   newaliases
	fi
    fi

    [ -x /usr/sbin/invoke-rc.d ] && \
	    INIT="invoke-rc.d postfix" || \
	    INIT="/etc/init.d/postfix"
    # start postfix
    if [ -f /var/spool/postfix/restart ]; then
	rm -f /var/spool/postfix/restart
	${INIT} restart
    else
	# or maybe just restart postfix
	if [ -f /var/spool/postfix/reload ]; then
	    rm -f /var/spool/postfix/reload
	    ${INIT} restart
	fi
    fi
fi