postfix-mysql package upgrade results in server configuration error

Bug #1791139 reported by LGB [Gábor Lénárt]
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
postfix (Debian)
Fix Released
Unknown
postfix (Ubuntu)
Fix Released
Medium
Karl Stenerud
Bionic
Fix Released
Undecided
Andreas Hasenack

Bug Description

[Impact]

If a user's /etc/postfix/main.conf has an empty alias_database setting, postfix-mysql.postinst fails when upgrading.

[Test Case]

Install the previous postfix and postfix-mysql:

# apt install -y postfix=3.3.0-1 postfix-mysql=3.3.0-1
 * Install type: Local Only
 * System mail name: anything

Clear the alias settings in /etc/postfix/main.cf, then upgrade to the latest:

# sed -i 's/\(alias_.* =\).*/\1/g' /etc/postfix/main.cf
# service postfix reload
# apt upgrade -y

You'll get the following error:
    Adding mysql map entry to /etc/postfix/dynamicmaps.cf
    /var/lib/dpkg/info/postfix-mysql.postinst: 33: [: =: unexpected operator

[Regression Potential]

The fix only affects the package installation scripts.

[Original Description]

I wanted to upgrade my bionic system. Some postfix related packages has been upgraded:

# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  base-files postfix postfix-ldap postfix-mysql postfix-pcre
  python3-problem-report qemu-guest-agent
7 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

# ls /var/cache/apt/archives/postfix*deb
/var/cache/apt/archives/postfix_3.3.0-1ubuntu0.1_amd64.deb /var/cache/apt/archives/postfix-ldap_3.3.0-1ubuntu0.1_amd64.deb /var/cache/apt/archives/postfix-pcre_3.3.0-1ubuntu0.1_amd64.deb
/var/cache/apt/archives/postfix-cdb_3.3.0-1ubuntu0.1_amd64.deb /var/cache/apt/archives/postfix-mysql_3.3.0-1ubuntu0.1_amd64.deb

After the installation, I saw this error message:

Setting up postfix-mysql (3.3.0-1ubuntu0.1) ...
Adding mysql map entry to /etc/postfix/dynamicmaps.cf
/var/lib/dpkg/info/postfix-mysql.postinst: 33: [: =: unexpected operator

But anyway, installation seemed to be succeeded. However, I noticed, that according to my mail logs, all mysql based postfix tables does not work at all with "unsupported map type". Just noticed, that even with ldap tables, not only mysql tables ...

restarting postfix seems to cured the problem, but I think, it shouldn't work this way ...

What I found: in /var/lib/dpkg/info/postfix-mysql.postinst the corresponding context, where the problem is (line 33):

    configure)
        addmap mysql
       if [ $(postconf |grep alias_database | awk '{print $3}'|awk -F \: \
           '{print $1}') = 'mysql' ]; then
           runnewaliases
       fi
    ;;

I guess, the problem is the following: I have the main.cf with empty alias_database directive, since I don't use aliases at all, so in main.cf, I have:

# grep ^alias /etc/postfix/main.cf
alias_maps =
alias_database =
# postconf |grep alias_database
alias_database =
# postconf |grep alias_database | awk '{print $3}'|awk -F \: '{print $1}'
#

So you see, because of my config, I get empty string ... And it seems the postinst script is not prepared to have this, as the empty string is represented in the script this way then:

if [ = 'mysql' ]; then

So it is understandable now, that I get this error:

/var/lib/dpkg/info/postfix-mysql.postinst: 33: [: =: unexpected operator

Because of the postinst script runs with "set -e", this error is "fatal". Surely, I guess the same issue happens with postfix-ldap package as well, I guess, maybe with others, I am not sure (postfix-pcre, etc?).

I think, this should be fixed, since it can break things for everyone using empty value for alias_database directive in main.cf

Though I am still not sure, why postfix thought these are unsupported map types after the upgrade, and postfix restart cured the problem, shouldn't the upgrade restart postfix anyway?

As a workaround, I put an empty hash map file into main.cf for with option, now there is no error message in postinst script, but still, it's a strange situation ...

Also, the logic in the script to "extract" table type is a bit complicated I guess, I would use something like this:

if [ "$(postconf -h alias_database | cut -f1 -d:)" = "mysql" ]; then
....

Maybe there are better solutions than mine above, still, it's just a quick idea (rather than multiple awk's and a grep) ....

Thanks for your attention.

Related branches

Revision history for this message
LGB [Gábor Lénárt] (lgb) wrote :

Btw, maybe an even better solution for that "if":

if postconf -h alias_database | grep -q '^mysql:' ; then

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Ack to the case
Ack to the analysis
Ack to the fix being better escaping so that this isn't an issue anymore

tags: added: bitesize
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

This bug is present in Debian too. So it would be best fixed in Debian, and then Ubuntu will pick it up on the next merge.

Being the original reporter would you mind also filing a bug with Debian please?
If you do so report here the bug number so we can link both together.

tags: added: needs-upstream-report
Revision history for this message
LGB [Gábor Lénárt] (lgb) wrote :

I don't know too much about Debian bug reporting, but anyway I've tried here:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=908221

Revision history for this message
LGB [Gábor Lénárt] (lgb) wrote :

By the way, I still have the suspect that something other is problematic here as well!!

Now, I tried to upgrade a test server, where those alias maps are NOT empty, by will. So no error messages shown with the postinst script of the package or anything, everything seems to be ok.

Still, after upgrade postfix reports "Server configuration error" for SMTP peers, and its log file is full of "unsupported map type" ldap or mysql ... Again, stopping postfix then restarting cures the problem then without any further action. But I have never seen a problem like this.

Since my reported problem here is mainly about that "if" statement in the postinst script, what hasn't affected my second test here, and still problem, I have the suspect that there should be another problem here as well ......

Revision history for this message
LGB [Gábor Lénárt] (lgb) wrote :

Maybe it's something to do with dynamicmaps.cf, since it seems that file always changes throughout the upgrade of postfix related packages?

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

That construct from the broken "if" statement is used everywhere indeed:

$ grep -E "\(postconf \|grep" debian/*.postinst
debian/postfix-cdb.postinst: if [ $(postconf |grep alias_database | awk '{print $3}'|awk -F \: \
debian/postfix-ldap.postinst: if [ $(postconf |grep alias_database | awk '{print $3}'|awk -F \: \
debian/postfix-lmdb.postinst: if [ $(postconf |grep alias_database | awk '{print $3}'|awk -F \: \
debian/postfix-mysql.postinst: if [ $(postconf |grep alias_database | awk '{print $3}'|awk -F \: \
debian/postfix-pcre.postinst: if [ $(postconf |grep alias_database | awk '{print $3}'|awk -F \: \
debian/postfix-pgsql.postinst: if [ $(postconf |grep alias_database | awk '{print $3}'|awk -F \: \
debian/postfix.postinst: aliastype=$(postconf |grep alias_database | awk '{print $3}' | \

Changed in postfix (Ubuntu):
status: New → Triaged
importance: Undecided → Medium
description: updated
Changed in postfix (Ubuntu):
assignee: nobody → Karl Stenerud (kstenerud)
status: Triaged → In Progress
Changed in postfix (Debian):
status: Unknown → New
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package postfix - 3.3.0-1ubuntu2

---------------
postfix (3.3.0-1ubuntu2) cosmic; urgency=medium

   Handle empty alias_database field in main.cf (LP: #1791139 Closes: #908221)

 -- Karl Stenerud <email address hidden> Wed, 12 Sep 2018 06:06:30 +0000

Changed in postfix (Ubuntu):
status: In Progress → Fix Released
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Karl, can you please check if the only remaining affected release is bionic? I thought I had checked, but couldn't find a comment in the bug about that.

Changed in postfix (Ubuntu Bionic):
assignee: nobody → Karl Stenerud (kstenerud)
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

I confirmed it, xenial is fine, so just bionic still needs fixing.

Changed in postfix (Ubuntu Bionic):
assignee: Karl Stenerud (kstenerud) → Andreas Hasenack (ahasenack)
status: New → In Progress
Revision history for this message
Brian Murray (brian-murray) wrote : Please test proposed package

Hello LGB, or anyone else affected,

Accepted postfix into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/postfix/3.3.0-1ubuntu0.2 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in postfix (Ubuntu Bionic):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-bionic
Revision history for this message
Andreas Hasenack (ahasenack) wrote :
Download full text (4.6 KiB)

Bionic Verification
===================

First, reproducing the bug. Since the postinst of other postfix-* packages was also changed, I'm installing them as well, and not just postfix-mysql:

ubuntu@bionic-postfix-1791139:~$ sudo apt install postfix postfix-mysql postfix-cdb postfix-ldap postfix-lmdb postfix-pcre postfix-pgsql -y
(...)

ubuntu@bionic-postfix-1791139:~$ apt-cache policy postfix
postfix:
  Installed: 3.3.0-1ubuntu0.1
  Candidate: 3.3.0-1ubuntu0.1
  Version table:
 *** 3.3.0-1ubuntu0.1 500
        500 http://br.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages

# Creating condition for the bug:
ubuntu@bionic-postfix-1791139:~$ sudo sed -i 's/\(alias_.* =\).*/\1/g' /etc/postfix/main.cf
ubuntu@bionic-postfix-1791139:~$ sudo service postfix reload
ubuntu@bionic-postfix-1791139:~$

# reinstalling the same packages, showing the failures, one per package:

ubuntu@bionic-postfix-1791139:~$ sudo apt install postfix postfix-mysql postfix-cdb postfix-ldap postfix-lmdb postfix-pcre postfix-pgsql -y --reinstall
(...)
Setting up postfix-pcre (3.3.0-1ubuntu0.1) ...
Adding pcre map entry to /etc/postfix/dynamicmaps.cf
/var/lib/dpkg/info/postfix-pcre.postinst: 33: [: =: unexpected operator
Setting up postfix-mysql (3.3.0-1ubuntu0.1) ...
Adding mysql map entry to /etc/postfix/dynamicmaps.cf
/var/lib/dpkg/info/postfix-mysql.postinst: 33: [: =: unexpected operator
Setting up postfix-lmdb (3.3.0-1ubuntu0.1) ...
Adding lmdb map entry to /etc/postfix/dynamicmaps.cf
/var/lib/dpkg/info/postfix-lmdb.postinst: 34: [: =: unexpected operator
Setting up postfix-ldap (3.3.0-1ubuntu0.1) ...
Adding ldap map entry to /etc/postfix/dynamicmaps.cf
/var/lib/dpkg/info/postfix-ldap.postinst: 33: [: =: unexpected operator
Setting up postfix-pgsql (3.3.0-1ubuntu0.1) ...
Adding pgsql map entry to /etc/postfix/dynamicmaps.cf
/var/lib/dpkg/info/postfix-pgsql.postinst: 33: [: =: unexpected operator
Setting up postfix-cdb (3.3.0-1ubuntu0.1) ...
Adding cdb map entry to /etc/postfix/dynamicmaps.cf
/var/lib/dpkg/info/postfix-cdb.postinst: 33: [: =: unexpected operator
Processing triggers for libc-bin (2.27-3ubuntu1) ...

a) upgrading to the fixed packages
# Installing the fixed packages on top (I enabled universe for bionic-proposed because of lmdb):
ubuntu@bionic-postfix-1791139:~$ sudo apt install postfix postfix-mysql postfix-cdb postfix-ldap postfix-lmdb postfix-pcre postfix-pgsql -y
(...)
Setting up postfix-pcre (3.3.0-1ubuntu0.2) ...
Adding pcre map entry to /etc/postfix/dynamicmaps.cf
Setting up postfix-mysql (3.3.0-1ubuntu0.2) ...
Adding mysql map entry to /etc/postfix/dynamicmaps.cf
Setting up postfix-lmdb (3.3.0-1ubuntu0.2) ...
Adding lmdb map entry to /etc/postfix/dynamicmaps.cf
Setting up postfix-ldap (3.3.0-1ubuntu0.2) ...
Adding ldap map entry to /etc/postfix/dynamicmaps.cf
Setting up postfix-pgsql (3.3.0-1ubuntu0.2) ...
Adding pgsql map entry to /etc/postfix/dynamicmaps.cf
Setting up postfix-cdb (3.3.0-1ubuntu0.2) ...
Adding cdb map entry to /etc/postfix/dynamicmaps.cf
Processing triggers for libc-bin (2.27-3ubuntu1) ...
ubuntu@bionic-postfix-1791139:~$

Worked just fine.

b) fresh install scenario with the fixed packages
ubuntu@bionic-postfix-17...

Read more...

tags: added: verification-done-bionic
removed: verification-needed-bionic
Changed in postfix (Debian):
status: New → Fix Released
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

The only dep8 failure now is sbuild on i386, and it's because of https://bugs.launchpad.net/ubuntu/+source/sbuild/+bug/1806388

That can only be fixed via an SRU of sbuild itself.

Revision history for this message
Łukasz Zemczak (sil2100) wrote : Update Released

The verification of the Stable Release Update for postfix has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package postfix - 3.3.0-1ubuntu0.2

---------------
postfix (3.3.0-1ubuntu0.2) bionic; urgency=medium

  [ Karl Stenerud ]
  * d/postfix-{cdb,ldap,lmdb,mysql,pcre,pgsql}.postinst, d/postfix.postinst:
    Handle empty alias_database field in main.cf (LP: #1791139 Closes: #908221)

 -- Andreas Hasenack <email address hidden> Thu, 11 Oct 2018 17:15:25 -0300

Changed in postfix (Ubuntu Bionic):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.