postfix: fix uid/gid conflicts, general cleanup

Fix uid/gid conflict with package icecast (uid=87, gid=87) and
package pianod (uid=88, gid=88) by claiming uid/gid 25 for postfix
instead of 87 and uid/gid 26 for postconf instead of 88.

Remove main.cf.default that is not used by any Postfix module.
The default configuration parameters are hardcoded into postconf
and they are available via "postconf -d <parameter>".
main.cf.default is therefore unnecessary.

"mydomain" parameter should be deduced from the domain configuration
setting in /e/c/dhcp rather than from "hostname" in /e/c/system
which is often just a hostname without the domain name component.

"mynetworks" parameter is unnecessary where "mynetworks_style" is
defined.

The change of the location of data_directory, queue_directory and
mail_spool_directory from /var/lib/postfix, /var/spool/postfix and
/var/mail to /data/postfix/lib, /data/postfix/spool and
/data/postfix/mail has been postponed until the author of this
commit and the maintainer of this package has had a meaningful
opportunity to consult with LEDE/OpenWrt developers on the preferred
mount point for the persistent data storage device.

Change the criteria for executing the post-installation script.
Invoke postinst() where the value of "myhostname" parameter in main.cf
is not defined rather than where "$config_directory"/opkg_postinst is
present with the value of "$config_directory" hardcoded to
"$IPKG_INSTROOT"/etc/postfix in /etc/init.d/postfix.

Enable PCRE support by default.

Remove the code making entries in /etc/sysupgrade.conf and instead
define configuration files to be saved during a sysupgrade in
Makefile's Package/postfix/conffiles section.

Move the creation of mail_spool_directory from host to target in
order to enable change of directory ownership to 'postfix' when
postinit() is executed on the target.

Avoid postfix restart in postinst script that results in an
error message during opkg install process.

Enable Postfix autostart by creating a link in /etc/rc.d/ on
installation.

Make the code less verbose.

Signed-off-by: Val Kulkov <val.kulkov@gmail.com>
This commit is contained in:
Val Kulkov
2017-11-14 21:42:55 -05:00
parent ebbd1a2d88
commit ed3d8020bc
3 changed files with 80 additions and 1002 deletions
+62 -109
View File
@@ -1,4 +1,4 @@
#
#
# Copyright (C) 2014-2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
@@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=postfix
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_VERSION:=3.2.3
PKG_SOURCE_URL:= \
https://cdn.postfix.johnriley.me/mirrors/postfix-release/official/ \
@@ -37,6 +37,9 @@ define Package/postfix
SECTION:=mail
CATEGORY:=Mail
TITLE:=Postfix Mail Transmit Agent
USERID:= \
postfix=25:postfix=25 \
postdrop=26:postdrop=26
URL:=http://www.postfix.org/
DEPENDS:=+POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +POSTFIX_SQLITE:libsqlite3 +POSTFIX_PGSQL:libpq +POSTFIX_EAI:icu +POSTFIX_PCRE:libpcre
endef
@@ -66,7 +69,7 @@ define Package/postfix/config
bool "BerkeleyDB support"
default n
help
Implements support for btree files using Berkeley DB. Note that hash files support is not compiled into Berkeley DB OpenWRT distribution
Implements support for btree and hash files using Berkeley DB.
config POSTFIX_CDB
bool "CDB support"
default y
@@ -84,7 +87,7 @@ define Package/postfix/config
Implement support for PostgreSQL
config POSTFIX_PCRE
bool "PCRE support"
default n
default y
help
Implement support for Perl Compatible Regular Expressions
config POSTFIX_EAI
@@ -102,7 +105,6 @@ endef
CCARGS=-DNO_NIS
AUXLIBS=-L$(STAGING_DIR)/usr/lib
default_database_type=cdb
ifdef CONFIG_POSTFIX_TLS
CCARGS+=-DUSE_TLS
@@ -122,12 +124,15 @@ endif
ifdef CONFIG_POSTFIX_CDB
CCARGS+=-DHAS_CDB
AUXLIBS+=-lcdb
ifndef default_database_type
default_database_type=cdb
endif
endif
ifdef CONFIG_POSTFIX_DB
AUXLIBS+=-ldb
CCARGS+=-DHAS_DB
ifndef CONFIG_POSTFIX_CDB
ifndef default_database_type
default_database_type=btree
endif
else
@@ -162,13 +167,12 @@ endif
CCARGS+=-DDEF_DB_TYPE=\"$(default_database_type)\"
config_directory=/etc/postfix# also add this to postfix init file
# prevent postfix-install from executing postconf at build time
# by explicitly providing the default values to postfix-install
config_directory=/etc/postfix
sample_directory=/etc/postfix
command_directory=/usr/sbin
daemon_directory=/usr/libexec/postfix
data_directory=/usr/var/lib/postfix
queue_directory=/usr/var/spool/postfix
mail_spool_directory=/usr/var/mail
html_directory=no
manpage_directory=no
readme_directory=no
@@ -177,66 +181,38 @@ newaliases_path=/usr/bin/newaliases
mailq_path=/usr/bin/mailq
shlib_directory=/usr/lib/postfix
meta_directory=/etc/postfix
data_directory=/usr/var/lib/postfix
queue_directory=/usr/var/spool/postfix
mail_spool_directory=/usr/var/mail
ln_suffix=.postfix
ln_old_suffix=.old
ln_suffix_pre_pf=.pre-postfix
ln_suffix_legacy=.old
define Package/postfix/conffiles
$(config_directory)/main.cf
$(config_directory)/master.cf
$(config_directory)/aliases
$(config_directory)/virtual
$(config_directory)
endef
define Build/Configure
if [ "$(CONFIG_POSTFIX_DB)" = "" -a "$(CONFIG_POSTFIX_CDB)" = "" ]; then\
echo "Build error: You must select at least one of the DB types";\
exit 1;\
if [ "$(default_database_type)" = "" ]; then \
echo "Build error: CDB or BerkeleyDB support must be enabled."; \
exit 1; \
fi
cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
endef
# Steps to regenerate files/main.cf.default:
#
# 1. Compile the package with current file
# 2. Execute the following command on target device:
# postconf -d > /tmp/main.cf.new
# 3. Transfer /tmp/main.cf.new file to the build system
# 4. Execute the following command:
# cat /tmp/main.cf.new | ( echo '# DO NOT EDIT THIS FILE. EDIT THE MAIN.CF FILE INSTEAD. THE'; echo '# TEXT HERE JUST SHOWS DEFAULT SETTINGS BUILT INTO POSTFIX.'; echo '#'; grep -v ^alias_maps\ = |grep -v ^alias_database\ = |grep -v ^command_directory\ = |grep -v ^config_directory\ = |grep -v ^daemon_directory\ = |grep -v ^data_directory\ = |grep -v ^default_database_type\ = |grep -v ^html_directory\ = |grep -v ^mail_spool_directory\ = |grep -v ^mailq_path\ = |grep -v ^manpage_directory\ = |grep -v ^meta_directory\ = |grep -v ^mydomain\ = |grep -v ^myhostname\ = |grep -v ^mynetworks\ = |grep -v ^mynetworks_style\ = |grep -v ^newaliases_path\ = |grep -v ^queue_directory\ = |grep -v ^readme_directory\ = |grep -v ^sample_directory\ = |grep -v ^sendmail_path\ = |grep -v ^shlib_directory\ = |grep -v ^smtputf8_enable\ = |grep -v ^virtual_maps\ = |grep -v ^process_id\ = ) > files/main.cf.default
# 5. Done. Now you can rebuild the package with new main.cf.default.
#
define Build/Compile
# Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC as a workaround
cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
cp ./files/main.cf.default $(PKG_BUILD_DIR)/conf/main.cf.default
echo "default_database_type = $(default_database_type)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "alias_database = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "alias_maps = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "virtual_maps = $(default_database_type):$(config_directory)/virtual" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "shlib_directory = $(shlib_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "meta_directory = $(meta_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
echo "smtputf8_enable = $(smtputf8_conf)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
$(foreach p, \
default_database_type config_directory command_directory daemon_directory \
shlib_directory manpage_directory data_directory queue_directory \
mail_spool_directory, \
echo "$(p) = $($(p))" >> $(PKG_BUILD_DIR)/conf/main.cf;)
endef
define Package/postfix/install
cd $(PKG_BUILD_DIR); $(MAKE) install_root=$(1) command_directory=$(command_directory) daemon_directory=$(daemon_directory) data_directory=$(data_directory) html_directory=$(html_directory) mail_owner=postfix mailq_path=$(mailq_path)$(ln_suffix) manpage_directory=$(manpage_directory) newaliases_path=$(newaliases_path)$(ln_suffix) queue_directory=$(queue_directory) readme_directory=$(readme_directory) sendmail_path=$(sendmail_path)$(ln_suffix) setgid_group=postdrop sample_directory=$(sample_directory) config_directory=$(config_directory) shlib_directory=$(shlib_directory) meta_directory=$(meta_directory) mail_version=$(PKG_VERSION) non-interactive-package
$(INSTALL_DIR) $(1)$(mail_spool_directory)
$(INSTALL_DIR) $(1)/etc/init.d/
$(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
endef
@@ -244,69 +220,46 @@ endef
define Package/postfix/postinst
#!/bin/sh
if [ -f "$${IPKG_INSTROOT}$(sendmail_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
mv "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) saved as $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
fi
if [ ! -f "$${IPKG_INSTROOT}$(sendmail_path)" ]; then
ln -s "$(sendmail_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
fi
for syml in $(sendmail_path) $(newaliases_path) $(mailq_path); do
file=$${IPKG_INSTROOT}$${syml}
if [ -f "$${file}$(ln_suffix_legacy)" ]; then
# update files saved by legacy versions of Postfix postinst script
mv "$${file}$(ln_suffix_legacy)" "$${file}$(ln_suffix_pre_pf)"
fi
if [ -f "$${file}" ]; then
linktarget=$$(basename $$(readlink "$${file}"))
postfixf=$$(basename "$${syml}")$(ln_suffix)
if [ $${linktarget} != $${postfixf} ]; then
mv "$${file}" "$${file}$(ln_suffix_pre_pf)"
echo "Info: $${file} saved as $${file}$(ln_suffix_pre_pf)"
fi
fi
if [ ! -f "$${file}" ]; then
ln -s "$${syml}$(ln_suffix)" "$${file}"
fi
done
# fix file/dir ownership in data_directory and queue_directory
if [ -z "$${IPKG_INSTROOT}" ]; then
postfix set-permissions
fi
if [ -f "$${IPKG_INSTROOT}$(newaliases_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
mv "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) saved as $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
fi
if [ ! -f "$${IPKG_INSTROOT}$(newaliases_path)" ]; then
ln -s "$(newaliases_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
fi
if [ -f "$${IPKG_INSTROOT}$(mailq_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
mv "$${IPKG_INSTROOT}$(mailq_path)" "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
echo "Warning: $${IPKG_INSTROOT}$(mailq_path) saved as $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
fi
if [ ! -f "$(mailq_path)" ]; then
ln -s "$(mailq_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
fi
grep -qc main\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/main.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
grep -qc master\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/master.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
grep -qc aliases "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/aliases" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
grep -qc virtual "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/virtual" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
touch "$${IPKG_INSTROOT}$(config_directory)"/opkg_postinst
if [ -z "$${IPKG_INSTROOT}" ]; then
ps | grep "postfix/master" | grep -cvq grep >/dev/null && /etc/init.d/postfix restart
fi
endef
define Package/postfix/prerm
#!/bin/sh
ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix stop
/etc/init.d/postfix disable
endef
define Package/postfix/postrm
#!/bin/sh
rm -f $${IPKG_INSTROOT}$(config_directory)/aliases.cdb $${IPKG_INSTROOT}$(config_directory)/aliases.db $${IPKG_INSTROOT}$(data_directory)/master.lock
rm -f "$(sendmail_path)" "$(newaliases_path)" "$(mailq_path)"
rm -f $${IPKG_INSTROOT}$(config_directory)/virtual.cdb $${IPKG_INSTROOT}$(config_directory)/virtual.db
rm -f "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(mailq_path)"
if [ -f "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" ]; then
mv "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) restored from $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
fi
if [ -f "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" ]; then
mv "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) restored from $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
fi
if [ -f "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" ]; then
mv "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
echo "Warning: $${IPKG_INSTROOT}$(mailq_path) restored from $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
fi
for syml in "$(sendmail_path)" "$(newaliases_path)" "$(mailq_path)"; do
file=$${IPKG_INSTROOT}$${syml}
if [ -f "$${file}$(ln_suffix_legacy)" ]; then
# update files saved by legacy versions of Postfix postinst script
mv "$${file}$(ln_suffix_legacy)" "$${file}$(ln_suffix_pre_pf)"
fi
if [ -f "$${syml}$(ln_suffix_pre_pf)" ]; then
mv "$${syml}$(ln_suffix_pre_pf)" "$${syml}"
echo "Info: $${syml}$(ln_suffix_pre_pf) restored as $${syml}"
fi
done
endef
$(eval $(call BuildPackage,postfix))