Subject: Re: Upgrading removes sendmail, breaks system config
To: None <current-users@NetBSD.org, tech-userlevel@NetBSD.org>
From: Pavel Cahyna <pavel@NetBSD.org>
List: current-users
Date: 08/25/2007 14:30:15
--pf9I7BMVVzbSWLtt
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Wed, Jul 11, 2007 at 02:30:46PM +0200, Pavel Cahyna wrote:
> On Wed, Jul 11, 2007 at 01:00:11PM +0100, Matthias Scheler wrote:
> > I would actually argue that the update should automatically add
> > "postfix=NO" to "/etc/rc.conf" unless it was previously enabled
> > with "postfix=YES".
> > 
> > Imagine a NetBSD 3.x system which uses Exim as the MTA. The "/etc/rc.conf"
> > could look like this:
> > 
> > sendmail=NO
> > smmsp=NO
> > exim=YES
> > 
> > With NetBSD 4.x this might not work anymore because it will suddently
> > try to start Postfix.
> 
> Good point, I haven't thought of that. A similar issue arised with
> sendmail when it became a daemon and atatat solved it with some magic in
> the rc script.

Here is a patch to do that. It also prints a warning if mailer.conf points
to the old, removed sendmail.

I also plan to add a postinstall item (disabled by default) which would
update mailer.conf.

And sysinst should detect this condition (old mailer.conf) and ask if you
want to automatically transition to postfix or do nothing and fix the
issue manually.

Pavel

--pf9I7BMVVzbSWLtt
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="postfix.diff"

? postfix.diff
Index: defaults/rc.conf
===================================================================
RCS file: /cvsroot/src/etc/defaults/rc.conf,v
retrieving revision 1.88
diff -u -p -r1.88 rc.conf
--- defaults/rc.conf	14 Jul 2007 21:20:32 -0000	1.88
+++ defaults/rc.conf	25 Aug 2007 12:29:31 -0000
@@ -193,7 +193,14 @@ cron=YES
 named=NO		named_flags=""		# see below for named_chrootdir
 timed=NO		timed_flags=""
 ntpd=NO			ntpd_flags=""		# see below for ntpd_chrootdir
-postfix=YES
+# The default setting for postfix here is YES, but gets re-examined by
+# the rc.d/postfix startup script when it runs.  The script sets
+# _rc_d_postfix to "check", and then causes all rc.conf settings to
+# be re-evaluated.  If the value of $postfix after this is "check",
+# the script then checks to see if /etc/mailer.conf selects the system
+# postfix. If not, it does print a warning and does not start postfix 
+# to avoid conflict with a different MTA.
+postfix=${_rc_d_postfix:-YES}
 lpd=NO			lpd_flags="-s"		# -s "secure" unix domain only
 sshd=NO			sshd_flags=""
 ssh_keygen_flags="-b 1024"	# generate 1024 bit keys if host keys missing
Index: rc.d/postfix
===================================================================
RCS file: /cvsroot/src/etc/rc.d/postfix,v
retrieving revision 1.13
diff -u -p -r1.13 postfix
--- rc.d/postfix	7 Sep 2006 15:26:08 -0000	1.13
+++ rc.d/postfix	25 Aug 2007 12:29:31 -0000
@@ -69,5 +69,31 @@ postfix_op()
 	${postfix_command} ${rc_arg}
 }
 
+check_use_postfix()
+{
+	_mta_path=$(awk '/^sendmail[ \t]/{print$2}' /etc/mailer.conf)
+	_postfix_path="/usr/libexec/postfix/sendmail"
+	_sendmail_path="/usr/libexec/sendmail/sendmail"
+
+	if [ "${postfix}" != "check" ]; then
+	    echo "${postfix}"
+	elif [ "${_mta_path}" = "${_postfix_path}" ]; then
+	    echo YES
+	else
+	    echo "WARNING: default postfix not used as not selected in mailer.conf" >&2
+	    if [ "${_mta_path}" = "${_sendmail_path}" -a \
+		! -x "${_mta_path}" ]; then
+		echo "WARNING: mailer.conf points to the removed sendmail" >&2
+		echo "update /etc/mailer.conf to get a working mailer configuration" >&2
+	    fi
+	    echo NO
+	fi
+}
+
+# force re-evaluation of /etc/rc.conf and resetting of $sendmail
+_rc_conf_loaded=false
+_rc_d_postfix=check
 load_rc_config $name
+unset _rc_d_postfix
+postfix=$(check_use_postfix)
 run_rc_command "$1"

--pf9I7BMVVzbSWLtt--