~ubuntu-branches/ubuntu/hoary/postfix/hoary-security

« back to all changes in this revision

Viewing changes to debian/postinst

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-10-06 11:50:33 UTC
  • Revision ID: james.westby@ubuntu.com-20041006115033-9oky44ylqmhjy7eq
Tags: 2.1.3-1ubuntu17
* Deliver man pages for master.cf services in section 8postfix.
  Remove smtpd.8.gz diversion. Closes: #274777
* Clean up postfix-mysql documentation (created README.Debian files).
  Closes: Warty#2022
* Fix typo in postmap man page.  Closes: #271369

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
 
 
3
# Debian Postfix postinst
 
4
# LaMont Jones <lamont@debian.org>
 
5
# Based on debconf code by Colin Walters <walters@cis.ohio-state.edu>,
 
6
# and John Goerzen <jgoerzen@progenylinux.com>.
 
7
 
 
8
# Use debconf.
 
9
. /usr/share/debconf/confmodule
 
10
CHROOT=/var/spool/postfix
 
11
config_directory="/etc/postfix"         # make variable expansion easier...
 
12
 
 
13
# postinst processing
 
14
 
 
15
. /usr/share/postfix/postinst.functions
 
16
 
 
17
set_maildrop_perms() {
 
18
    MAILDROP=${CHROOT}/maildrop
 
19
    SCRIPT=/etc/postfix/postfix-script
 
20
    POSTDROP=/usr/sbin/postdrop
 
21
    mkdir -p $MAILDROP
 
22
    if ! chown postfix:postdrop $MAILDROP 2>/dev/null; then
 
23
        addgroup --system postdrop
 
24
        chown postfix:postdrop $MAILDROP
 
25
    fi
 
26
    dpkg-statoverride --remove $POSTDROP >/dev/null 2>&1 || true
 
27
    dpkg-statoverride --remove /var/spool/postfix/public >/dev/null 2>&1 || true
 
28
    dpkg-statoverride --remove /usr/sbin/postqueue >/dev/null 2>&1 || true
 
29
    dpkg-statoverride --update --add root postdrop 02555 $POSTDROP
 
30
    dpkg-statoverride --update --add postfix postdrop 02710 /var/spool/postfix/public
 
31
    dpkg-statoverride --update --add root postdrop 02555 /usr/sbin/postqueue
 
32
    chmod 1730 $MAILDROP
 
33
}
 
34
 
 
35
fset_all_changed() {
 
36
    db_fset postfix/main_mailer_type changed $1
 
37
    db_fset postfix/root_address changed $1
 
38
    db_fset postfix/destinations changed $1
 
39
    db_fset postfix/mailname changed $1
 
40
    db_fset postfix/relayhost changed $1
 
41
    db_fset postfix/chattr changed $1
 
42
    db_fset postfix/mynetworks changed $1
 
43
    db_fset postfix/procmail changed $1
 
44
    db_fset postfix/mailbox_limit changed $1
 
45
    db_fset postfix/recipient_delim changed $1
 
46
}
 
47
 
 
48
set_postconf() {
 
49
    CHANGES=true
 
50
    postconf -e "$@"
 
51
}
 
52
 
 
53
get_postconf() {
 
54
    postconf -h "$@"
 
55
}
 
56
 
 
57
makedir() {
 
58
    if [ ! -d $1 ]; then
 
59
        mkdir $1
 
60
    fi
 
61
    chown $2 $1 && chmod $3 $1
 
62
}
 
63
 
 
64
convert_dbs() {
 
65
    # get all of the hash and btree maps.
 
66
    maps=$(postconf -h | sed -e 's/[,[:space:]]/\
 
67
/g' -e 's/^proxy://' -e '/:/p' | sort -u )
 
68
    for i in $maps; do
 
69
      case $i in
 
70
        hash:*|btree:*)
 
71
            f=${i#*:}.db 
 
72
            if [ -f $f ]; then
 
73
                echo "attempting conversion of $i"
 
74
                echo "  saving old db in ${f}.db3"
 
75
                cp $f ${f}.db3
 
76
                postmap -u $i
 
77
            fi
 
78
            ;;
 
79
      esac
 
80
    done
 
81
}
 
82
 
 
83
fix_master() {
 
84
    echoed=""
 
85
    # Need to handle some changes in services.
 
86
    MASTER=/etc/postfix/master.cf
 
87
    if grep -qE '^cleanup[[:space:]]+unix[[:space:]]+-' ${MASTER}; then
 
88
        echo "in master.cf:"; echoed=y
 
89
        echo "  forcing pickup=unprivileged, cleanup=public, flush=public"
 
90
        sed 's/^\(cleanup[[:space:]]*unix[[:space:]]*\)-/\1n/
 
91
             s/^\(flush[[:space:]]*unix[[:space:]]*\)-/\1n/
 
92
             s/^\(pickup[[:space:]]*fifo[[:space:]]*.[[:space:]]*\)n/\1-/
 
93
        ' ${MASTER} > ${MASTER}.$$
 
94
        mv ${MASTER}.$$ ${MASTER}
 
95
    fi
 
96
 
 
97
    if ! grep -qE '^flush[[:space:]]' ${MASTER}; then
 
98
        [ -n $echoed ] || echo "in master.cf:"; echoed=y
 
99
        echo "  adding missing entry for flush service"
 
100
        echo "flush       unix  n       -       -       1000?   0       flush" \
 
101
            >> ${MASTER}
 
102
    fi
 
103
 
 
104
    if ! grep -qE '^proxymap[[:space:]]' ${MASTER}; then
 
105
        [ -n $echoed ] || echo "in master.cf:"; echoed=y
 
106
        echo "  adding missing entry for proxymap service"
 
107
        echo "proxymap    unix  -       -       n       -       -       proxymap" \
 
108
            >> ${MASTER}
 
109
    fi
 
110
    if ! grep -qE '^trace[[:space:]]' ${MASTER}; then
 
111
        [ -n $echoed ] || echo "in master.cf:"; echoed=y
 
112
        echo "  adding missing entry for trace service"
 
113
        echo "trace       unix  -       -       -       -       0       bounce" \
 
114
            >> ${MASTER}
 
115
    fi
 
116
 
 
117
    if ! grep -qE '^verify[[:space:]]' ${MASTER}; then
 
118
        [ -n $echoed ] || echo "in master.cf:"; echoed=y
 
119
        echo "  adding missing entry for verify service"
 
120
        echo "verify      unix  -       -       -       -       1       verify" \
 
121
            >> ${MASTER}
 
122
    fi
 
123
}
 
124
 
 
125
umask 022
 
126
 
 
127
# postinst processing
 
128
 
 
129
 
 
130
 
 
131
case "$1" in
 
132
    configure)
 
133
        # see below
 
134
        ;;
 
135
 
 
136
    abort-upgrade)
 
137
        fix_master
 
138
        exit 0
 
139
        ;;
 
140
 
 
141
    abort-remove|abort-deconfigure)
 
142
        exit 0
 
143
        ;;
 
144
 
 
145
    *)
 
146
        echo "postinst called with unknown argument \`$1'" >&2
 
147
        exit 1
 
148
        ;;
 
149
esac
 
150
 
 
151
CHANGES=""
 
152
NEWALIASES="y"  # run newaliases at the end of things
 
153
 
 
154
update-rc.d postfix defaults > /dev/null
 
155
update-inetd --disable smtp
 
156
 
 
157
ldconfig
 
158
 
 
159
dpkg-divert --package postfix --remove --rename \
 
160
        --divert /usr/share/man/man8/smtpd.real.8.gz \
 
161
        /usr/share/man/man8/smtpd.8.gz > /dev/null 2>&1
 
162
 
 
163
cd ${CHROOT}
 
164
# make sure that the postfix user exists.  Simplest portable way to check is to
 
165
# chown something, so we'll create the directories that we need here.
 
166
makedir private         root:root 700
 
167
chgrp postfix private 2>/dev/null ||
 
168
    addgroup --system postfix
 
169
chown postfix private 2>/dev/null ||
 
170
    adduser --system --home ${CHROOT} --no-create-home --disabled-password --ingroup postfix postfix
 
171
 
 
172
# need to have postfix in the right group, but old revs do it wrong..
 
173
if [ "$(id -gn postfix)" != "postfix" ]; then
 
174
    usermod -g postfix postfix
 
175
fi
 
176
 
 
177
chown postfix:root private
 
178
 
 
179
db_fget postfix/chattr changed
 
180
if [ "$RET" = "true" ]; then
 
181
    db_get postfix/chattr && chat="$RET"
 
182
    echo "setting synchronous mail queue updates: $chat"    
 
183
    if [ "$chat" = "true" ]; then
 
184
        chat="+S"
 
185
    else
 
186
        chat="-S"
 
187
    fi
 
188
fi
 
189
 
 
190
for dir in pid public; do
 
191
    makedir ${dir} postfix:root 755
 
192
done
 
193
for dir in incoming active bounce defer deferred flush saved corrupt; do
 
194
    makedir ${dir} postfix:root 700
 
195
    if [ -n "$chat" ]; then
 
196
        chattr $chat $dir 2>/dev/null || true
 
197
    fi
 
198
done
 
199
 
 
200
cd /etc/postfix
 
201
 
 
202
if [ ! -f dynamicmaps.cf ]; then
 
203
    echo "Creating /etc/postfix/dynamicmaps.cf"
 
204
    cat << EOF > dynamicmaps.cf
 
205
# Postfix dynamic maps configuration file.
 
206
#
 
207
# The first match found is the one that is used.  Wildcards are not supported
 
208
# as of postfix 2.0.2
 
209
#
 
210
#type   location of .so file                    open function   (mkmap func)
 
211
#====   ================================        =============   ============
 
212
EOF
 
213
    addmap tcp
 
214
else
 
215
    # handle dynamicmaps.cf upgrade - we checked with the user in preinst.
 
216
    if [ -f /var/spool/postfix/dynamicmaps_upgrade ]; then
 
217
      (
 
218
        if ! grep -qi 'wildcards are not supported' dynamicmaps.cf; then
 
219
            echo '# *** Wildcards are not supported as of postfix 2.0.2 ***'
 
220
            echo '#'
 
221
        fi
 
222
        sed '/^\*[[:space:]]/d' dynamicmaps.cf
 
223
      ) > dynamicmaps.cf.$$
 
224
      mv dynamicmaps.cf.$$ dynamicmaps.cf
 
225
      # Need to add all of them, since we may need them to configure... sigh.
 
226
      addmap tcp
 
227
      addmap ldap
 
228
      addmap pcre
 
229
      addmap mysql
 
230
      addmap pgsql
 
231
      addmap sdbm mkmap_sdbm_open
 
232
    fi
 
233
fi
 
234
 
 
235
db_fget postfix/main_mailer_type changed && mailer_changed="$RET"
 
236
db_get postfix/main_mailer_type && mailer="$RET"
 
237
 
 
238
if [ ! -f master.cf ]; then
 
239
    case "$mailer" in
 
240
    "Local only"|"Satellite system")
 
241
        cp /usr/share/postfix/master.cf.local master.cf
 
242
        ;;
 
243
    *)
 
244
        cp /usr/share/postfix/master.cf.dist master.cf
 
245
        ;;
 
246
    esac
 
247
fi
 
248
 
 
249
if [ "$mailer" != "No configuration" ]; then    # [
 
250
    if [ -f main.cf ]; then
 
251
        NEWCONF=""
 
252
    else
 
253
        cp /usr/share/postfix/main.cf.debian main.cf
 
254
        NEWCONF=yes
 
255
    fi
 
256
fi      # !No configuration ]
 
257
 
 
258
# cleanup from braindamage.
 
259
if [ -d /etc/postfix/maildrop ]; then
 
260
    rmdir /etc/postfix/maildrop 2>/dev/null
 
261
fi
 
262
 
 
263
set_maildrop_perms postdrop
 
264
if [ -f /var/spool/postfix/db-upgrade ]; then
 
265
    rm /var/spool/postfix/db-upgrade
 
266
    db_get postfix/db_upgrade_warning && convert="$RET"
 
267
    if [ "$convert" = "true" ]; then
 
268
        convert_dbs
 
269
    else
 
270
        echo "DB files not converted, Postfix restart may fail."
 
271
    fi
 
272
fi
 
273
 
 
274
if [ "$mailer" != "No configuration" ]; then    # [
 
275
    myhostname=$(hostname --fqdn 2>/dev/null || echo "")
 
276
    if [ -z "$myhostname" ]; then
 
277
        if [ -r /etc/hostname ];then
 
278
            myhostname=$(cat /etc/hostname)
 
279
            if [ $hostname = ${hostname%.*} -a -f /etc/resolv.conf ]; then
 
280
                mydom=$(awk '/^(search|domain)/ { print $2;quit;}' \
 
281
                        /etc/resolv.conf)
 
282
                myhostname="$myhostname${mydom:+.$mydom}"
 
283
            fi
 
284
        else
 
285
            myhostname="UNKNOWN"
 
286
        fi
 
287
    fi
 
288
    mydomain=${myhostname#*.}
 
289
 
 
290
    if [ -n "$NEWCONF" ]; then
 
291
        fset_all_changed true
 
292
        alias_maps=hash:/etc/aliases
 
293
        nis_status=$(dpkg -l nis 2>/dev/null | sed -n '$p')
 
294
        if [ "X$nis_status" != "X${nis_status#i}" ] && [ -x /usr/bin/ypcat ] &&
 
295
                /usr/bin/ypcat mail.aliases >/dev/null 2>&1; then
 
296
            alias_maps="hash:/etc/aliases, nis:mail.aliases"
 
297
            cat << EOF
 
298
It appears that you have an NIS map for mail aliases; using that in
 
299
addition to /etc/aliases.
 
300
 
 
301
EOF
 
302
        fi
 
303
        if [ -n "$myhostname" ]; then
 
304
            echo "setting myhostname: $myhostname"
 
305
            set_postconf "myhostname=$myhostname"
 
306
        fi
 
307
        echo "setting alias maps"
 
308
        set_postconf "alias_maps=$alias_maps"
 
309
        echo "setting alias database"
 
310
        set_postconf "alias_database=hash:/etc/aliases"
 
311
    fi
 
312
 
 
313
    db_fget postfix/mailname changed
 
314
    if [ "$RET" = "true" ]; then
 
315
        db_get postfix/mailname && mailname="$RET"
 
316
        if [ -f /etc/mailname ] && [ "X$(cat /etc/mailname)" = "X$mailname" ]; then
 
317
            MAILNAME=""
 
318
        else
 
319
            MAILNAME=yes
 
320
        fi
 
321
        if [ "X${mailname%.*}" != "X${mailname}" ]; then
 
322
            if [ -n "$MAILNAME" ]; then
 
323
                echo "changing /etc/mailname"
 
324
                echo $mailname > /etc/mailname
 
325
            fi
 
326
            echo "setting myorigin"
 
327
            set_postconf "myorigin=/etc/mailname"
 
328
        else
 
329
            echo "mailname is not a fully qualified domain name.  Not changing /etc/mailname."
 
330
        fi
 
331
    fi
 
332
    db_fget postfix/destinations changed
 
333
    if [ "$RET" = "true" ]; then
 
334
        db_get postfix/destinations && destinations="$RET"
 
335
        echo "setting destinations: $destinations"
 
336
        set_postconf "mydestination=$destinations"
 
337
    fi
 
338
    db_fget postfix/relayhost changed
 
339
    if [ "$RET" = "true" ]; then
 
340
        db_get postfix/relayhost && relayhost="$RET"
 
341
        echo "setting relayhost: $relayhost"    
 
342
        set_postconf "relayhost=$relayhost"
 
343
    fi
 
344
    db_fget postfix/mynetworks changed
 
345
    if [ "$RET" = "true" ]; then
 
346
        db_get postfix/mynetworks && mynetworks="$RET"
 
347
        if [ -z "$RET" ]; then
 
348
            echo "deleting mynetworks"    
 
349
            if grep -q '^mynetworks[[:space:]]*=' main.cf; then
 
350
                # need to remove it, get postconf to do the hard part.
 
351
                postconf -e 'mynetworks=127.0.0.0/8'
 
352
                perl -i -ne 'print unless /^mynetworks\s*=/' main.cf
 
353
            fi
 
354
        else
 
355
            echo "setting mynetworks: $mynetworks"    
 
356
            set_postconf "mynetworks=$mynetworks"
 
357
        fi
 
358
    fi
 
359
    db_fget postfix/procmail changed
 
360
    if [ "$RET" = "true" ]; then
 
361
        db_get postfix/procmail && useprocmail="$RET"
 
362
        if [ "x$useprocmail" = "xtrue" ]; then
 
363
            echo "setting mailbox_command"        
 
364
            set_postconf 'mailbox_command=procmail -a "$EXTENSION"'
 
365
        else
 
366
            echo "clearing mailbox_command"        
 
367
            set_postconf "mailbox_command="
 
368
        fi
 
369
    fi
 
370
    db_fget postfix/mailbox_limit changed
 
371
    if [ "$RET" = "true" ]; then
 
372
        db_get postfix/mailbox_limit && mailbox_limit="$RET"
 
373
        echo "setting mailbox_size_limit: $mailbox_limit"    
 
374
        set_postconf "mailbox_size_limit=$mailbox_limit"
 
375
    fi
 
376
 
 
377
    db_fget postfix/recipient_delim changed
 
378
    if [ "$RET" = "true" ]; then
 
379
        db_get postfix/recipient_delim && recip="$RET"
 
380
        echo "setting recipient_delimiter: $recip"    
 
381
        set_postconf "recipient_delimiter=$recip"
 
382
    fi
 
383
 
 
384
    if [ -z "$CHANGES" ]; then
 
385
        MSG="configuration was not changed"
 
386
    else if [ -n "$NEWCONF" ]; then
 
387
            MSG="is now set up with a default configuration"
 
388
        else
 
389
            MSG="is now set up with the changes above"
 
390
        fi
 
391
    fi
 
392
else    # ] No configuration [
 
393
    if [ -f main.cf ]; then
 
394
        MSG="configuration was untouched"
 
395
    else
 
396
        MSG="was not set up.  Start with 
 
397
  cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
 
398
"
 
399
        # make sure that we don't try anything stupid below.
 
400
        NEWALIASES=""
 
401
        rm -f /var/spool/postfix/restart /var/spool/postfix/reload
 
402
    fi
 
403
fi      # not 'No configuration' ]
 
404
 
 
405
if [ ! -f /etc/aliases ]; then  # no /etc/aliases [
 
406
    echo "/etc/aliases does not exist, creating it."
 
407
    cat << EOF > /etc/aliases
 
408
# See man 5 aliases for format
 
409
postmaster:    root
 
410
EOF
 
411
    if [ "$mailer" != "No configuration" ]; then        # [
 
412
        db_fget postfix/root_address changed
 
413
        if [ "$RET" = "true" ]; then
 
414
            db_get postfix/root_address && root_addr="$RET"
 
415
            ret=$(echo $RET | tr '[A-Z]' '[a-z]')
 
416
            if [ "$ret" != "none" ]; then
 
417
                echo "root:     $RET" >> /etc/aliases
 
418
            fi
 
419
        fi
 
420
    fi  # not 'No configuration' ]
 
421
fi # ] no /etc/aliases
 
422
 
 
423
fset_all_changed false
 
424
 
 
425
fold -s << EOF
 
426
 
 
427
Postfix $MSG.  If you need to make changes, edit
 
428
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
 
429
values, see postconf(1).
 
430
 
 
431
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
 
432
 
 
433
EOF
 
434
 
 
435
# all done with debconf here.
 
436
db_stop
 
437
 
 
438
fix_master
 
439
 
 
440
if [ -n "$NEWALIASES" ]; then
 
441
    echo "Running newaliases"
 
442
    rm -f /etc/aliases.db       # handle the roll to db2.0
 
443
 
 
444
    # newaliases chokes if hostname not set
 
445
    if [ -z "$(postconf -h myhostname||true)" ]; then
 
446
        cp -a main.cf main.cf.dpkg.$$
 
447
        postconf -e 'myhostname=ubuntu'
 
448
        newaliases
 
449
        mv main.cf.dpkg.$$ main.cf
 
450
    else
 
451
        newaliases
 
452
    fi
 
453
fi
 
454
 
 
455
rm -f /var/spool/postfix/root_address
 
456
 
 
457
# start postfix
 
458
if [ -f /var/spool/postfix/restart ]; then
 
459
    rm -f /var/spool/postfix/restart
 
460
    /etc/init.d/postfix start
 
461
else
 
462
    # or maybe just restart postfix
 
463
    if [ -f /var/spool/postfix/reload ]; then
 
464
        rm -f /var/spool/postfix/reload
 
465
        /etc/init.d/postfix restart
 
466
    fi
 
467
fi