Bug#945280: configurable config file name

2019-11-25 Thread Harald Dunkel

PS: One important aspect is that /etc/default/opensmtpd is *not* included
in the Debian package. If it would be included, then I would get conflicts
again.


Regards
Harri



Bug#945280: configurable config file name

2019-11-25 Thread Harald Dunkel

Hi Ryan,

On 2019-11-23 18:07, Ryan Kavanagh wrote:


I'm trying to understand the rationale for having a separate smtpd.conf.
/etc/smtpd.conf is listed in conffiles, so package upgrades will never
clobber the changes you have made to it. During upgrades, if a package
has a new version of /etc/smtpd.conf and you have local changes, then
dpkg will prompt you to figure out how to handle the differences.



Thats the point. If you have 300+ hosts you want to avoid this interactive
step during an upgrade. The idea is to provide /etc/default/opensmtpd and
/etc/nullclient.smtpd.conf in a dedicated config package, ignoring the
config files in the opensmtpd package completly.

dpkg-divert is not an option, because this tool is a mess. I am using
dpkg-divert exactly for this nullclient case at the moment.


If you want to always keep the old/local version (and have dpkg not
prompt you during upgrades), you can pass --force-confold and
--force-confdef to dpkg. See this writeup[0] by Raphaël Hertzog for more
details.



Raphaël keeps focus on upgrading a single package using dpkg. Problem here
is you might want these options for opensmtpd during "apt upgrade", but not
for other packages. You simply do not know in advance.


Does this solve the issues you've been encountering? If not, I'll apply
the patch. Please let me know.



That would be very nice. I tried to make the suggested patch as transparent
as possible.


Regards
Harri



Bug#945280: configurable config file name

2019-11-23 Thread Ryan Kavanagh
Control: tags -1 + moreinfo

On Fri, Nov 22, 2019 at 12:12:04PM +0100, Harald Dunkel wrote:
> Would it be possible to make the opensmtpd config file configurable?

Sure, I can apply the patch, though the defaults file will be
/etc/default/opensmtpd to match the init script name (see §5.10 of the
maintainer's guide and the suggestion in policy §9.3.2).

> That would allow me to run a private "/etc/smarthost.smtpd.conf" (just
> as an example) without conflict to the default config file provided in
> the package.

I'm trying to understand the rationale for having a separate smtpd.conf.
/etc/smtpd.conf is listed in conffiles, so package upgrades will never
clobber the changes you have made to it. During upgrades, if a package
has a new version of /etc/smtpd.conf and you have local changes, then
dpkg will prompt you to figure out how to handle the differences.

If you want to always keep the old/local version (and have dpkg not
prompt you during upgrades), you can pass --force-confold and
--force-confdef to dpkg. See this writeup[0] by Raphaël Hertzog for more
details.

Does this solve the issues you've been encountering? If not, I'll apply
the patch. Please let me know.

Best,
Ryan

[0] 
https://raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/
-- 
|)|/  Ryan Kavanagh  | GPG: 4E46 9519 ED67 7734 268F
|\|\  https://rak.ac |  BD95 8F7B F8FC 4A11 C97A


signature.asc
Description: PGP signature


Bug#945280: configurable config file name

2019-11-23 Thread Harald Dunkel

Attached is a better version, introducing /etc/default/opensmtpd.conf.

Regards
Harri
#!/bin/sh
# /etc/init.d/opensmtpd
#
# Written by Daniel Walrond 
#and Ryan Kavanagh 

### BEGIN INIT INFO
# Provides:  opensmtpd mail-transport-agent
# Required-Start:$local_fs $remote_fs $syslog $network
# Required-Stop: $local_fs $remote_fs $syslog $network
# Should-Start:  postgresql mysql dovecot
# Default-Start: 2 3 4 5
# Default-Stop:  0 1 6
# Short-Description: opensmtpd Mail Transport Agent
# Description:   OpenSMTPD
### END INIT INFO

# Do not "set -e"; /lib/lsb/init-functions included below may fail if "set -e"
# is in effect and echoing status messages to the console fails.
set -u

DEFAULT=/etc/default/opensmtpd.conf

DAEMON="/usr/sbin/smtpd"
CONFIG="/etc/smtpd.conf"
PIDFILE="/run/smtpd.pid"
CONTROL="/usr/sbin/smtpctl"
DESC="opensmtpd"
test -f "${DEFAULT}" && source "${DEFAULT}"

test -x "${DAEMON}" || exit 0

. /lib/lsb/init-functions

smtpd_start()
{
  if start-stop-daemon \
  --start \
  --pidfile "${PIDFILE}" \
  --exec "${DAEMON}" \
  -- -f "${CONFIG}"; then
log_progress_msg "opensmtpd"
return 0
  else
log_progress_msg "opensmtpd"
return 1
  fi
}

smtpd_stop()
{
  if start-stop-daemon --stop --pidfile "${PIDFILE}" -- -f "${CONFIG}"; then
log_progress_msg "opensmtpd"
return 0
  else
log_progress_msg "opensmtpd"
return 1
  fi
}

smtpd_config_check()
{
# ${DAEMON} -n checks the config file's validity
if "${DAEMON}" -f "${CONFIG}" -n >/dev/null 2>&1; then
  return 0
else
  log_end_msg 1
  "${DAEMON}" -f "${CONFIG}" -n
  return 1
fi
}

case "$1" in
start)
  log_daemon_msg "Starting MTA"
  # Although smtpd checks the config automatically on startup,
  # check it manually ourselves so that error messages are
  # printed after our "failed!" instead of between it and
  # "Starting MTA"
  if smtpd_config_check; then
smtpd_start
log_end_msg $?
  fi
  ;;
stop)
  log_daemon_msg "Stopping MTA"
  smtpd_stop
  log_end_msg $?
  ;;
restart)
  log_daemon_msg "Stopping MTA for restart"
  # If the check fails, the log_end_msg in smtpd_config_check
  # will output "failed!" for us.
  if smtpd_config_check; then
smtpd_stop
log_end_msg $?
log_daemon_msg "Restarting MTA"
smtpd_start
log_end_msg $?
  fi
  ;;
force-reload)
  log_daemon_msg "Stopping MTA for reload"
  smtpd_stop
  log_end_msg $?
  log_daemon_msg "Restarting MTA"
  smtpd_start
  log_end_msg $?
  ;;
check)
  log_daemon_msg "Checking MTA configuration"
  if smtpd_config_check; then
log_progress_msg "success"
log_end_msg $?
  fi
  ;;
status)
  status_of_proc "${DAEMON}" "MTA ${DESC}"
  ;;
*)
  echo "Usage: $0 {start|stop|restart|force-reload|status|check}"
  exit 1
  ;;
esac

exit 0

# vim:set sw=2:


Bug#945280: configurable config file name

2019-11-22 Thread Harald Dunkel

Package: opensmtpd
Version: 6.6.1p1-1
Severity: wishlist

Would it be possible to make the opensmtpd config file configurable?
Some code in the init file like


test -f /etc/default/opensmtpd.conf && source 
/etc/default/opensmtpd.conf
: ${CONFIG:="/etc/smtpd.conf"}

:
start-stop-daemon --start -p "${PIDFILE}" --exec ${DAEMON} -- -f 
"${CONFIG}"
:

would do. See attachment.

That would allow me to run a private "/etc/smarthost.smtpd.conf" (just as an
example) without conflict to the default config file provided in the
package.


Thanx in advance
Harri
#!/bin/sh
# /etc/init.d/opensmtpd
#
# Written by Daniel Walrond 
#and Ryan Kavanagh 

### BEGIN INIT INFO
# Provides:  opensmtpd mail-transport-agent
# Required-Start:$local_fs $remote_fs $syslog $network
# Required-Stop: $local_fs $remote_fs $syslog $network
# Should-Start:  postgresql mysql dovecot
# Default-Start: 2 3 4 5
# Default-Stop:  0 1 6
# Short-Description: opensmtpd Mail Transport Agent
# Description:   OpenSMTPD
### END INIT INFO

# Do not "set -e"; /lib/lsb/init-functions included below may fail if "set -e"
# is in effect and echoing status messages to the console fails.
set -u

BASE="smtpd"
DAEMON="/usr/sbin/smtpd"
CONTROL="/usr/sbin/smtpctl"
PIDFILE="/run/${BASE}.pid"
DESC="opensmtpd"

test -f /etc/default/opensmtpd.conf && source /etc/default/opensmtpd.conf

: ${CONFIG:="/etc/smtpd.conf"}

test -x /usr/sbin/smtpd || exit 0

. /lib/lsb/init-functions

smtpd_start()
{
  if start-stop-daemon \
  --start \
  --pidfile "${PIDFILE}" \
  --exec "${DAEMON}" \
  -- -f "${CONFIG}"; then
log_progress_msg "opensmtpd"
return 0
  else
log_progress_msg "opensmtpd"
return 1
  fi
}

smtpd_stop()
{
  if start-stop-daemon --stop --pidfile "${PIDFILE}" -- -f "${CONFIG}"; then
log_progress_msg "opensmtpd"
return 0
  else
log_progress_msg "opensmtpd"
return 1
  fi
}

smtpd_config_check()
{
# ${DAEMON} -n checks the config file's validity
if "${DAEMON}" -f "${CONFIG}" -n >/dev/null 2>&1; then
  return 0
else
  log_end_msg 1
  "${DAEMON}" -f "${CONFIG}" -n
  return 1
fi
}

case "$1" in
start)
  log_daemon_msg "Starting MTA"
  # Although smtpd checks the config automatically on startup,
  # check it manually ourselves so that error messages are
  # printed after our "failed!" instead of between it and
  # "Starting MTA"
  if smtpd_config_check; then
smtpd_start
log_end_msg $?
  fi
  ;;
stop)
  log_daemon_msg "Stopping MTA"
  smtpd_stop
  log_end_msg $?
  ;;
restart)
  log_daemon_msg "Stopping MTA for restart"
  # If the check fails, the log_end_msg in smtpd_config_check
  # will output "failed!" for us.
  if smtpd_config_check; then
smtpd_stop
log_end_msg $?
log_daemon_msg "Restarting MTA"
smtpd_start
log_end_msg $?
  fi
  ;;
force-reload)
  log_daemon_msg "Stopping MTA for reload"
  smtpd_stop
  log_end_msg $?
  log_daemon_msg "Restarting MTA"
  smtpd_start
  log_end_msg $?
  ;;
check)
  log_daemon_msg "Checking MTA configuration"
  if smtpd_config_check; then
log_progress_msg "success"
log_end_msg $?
  fi
  ;;
status)
  status_of_proc "${DAEMON}" "MTA ${DESC}"
  ;;
*)
  echo "Usage: $0 {start|stop|restart|force-reload|status|check}"
  exit 1
  ;;
esac

exit 0

# vim:set sw=2: