Subject: Collected Debian patches for postsrsd
Author: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

The postsrsd package is maintained in Git rather than maintaining
patches as separate files, and separating the patches isn't worth
the effort.  They are therefore all included in this single Debian
patch.

For full commit history and separated commits, see the packaging Git
repository. The location of the repository can be found in the Vcs-Git
field in debian/control.
--- postsrsd-1.4.orig/init/postsrsd.apparmor.in
+++ postsrsd-1.4/init/postsrsd.apparmor.in
@@ -7,6 +7,6 @@
   capability setuid,
   capability sys_chroot,
   /etc/postsrsd.secret r,
-  @CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ mr,
+  @CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ r,
 }
 
--- postsrsd-1.4.orig/init/postsrsd.default.in
+++ postsrsd-1.4/init/postsrsd.default.in
@@ -35,7 +35,7 @@ SRS_REVERSE_PORT=10002
 # Drop root privileges and run as another user after initialization.
 # This is highly recommended as postsrsd handles untrusted input.
 #
-RUN_AS=nobody
+RUN_AS=postsrsd
 
 # Jail daemon in chroot environment
 CHROOT=@CHROOT_DIR@
--- postsrsd-1.4.orig/init/postsrsd.systemd.in
+++ postsrsd-1.4/init/postsrsd.systemd.in
@@ -1,11 +1,12 @@
 [Unit]
 Description=PostSRSd Daemon
+Documentation=man:postsrsd(8)
 
 [Service]
 Type=simple
-Environment=SRS_DOMAIN=localhost.localdomain
-Environment=SRS_EXCLUDE_DOMAINS=
-EnvironmentFile=@CONFIG_DIR@/@PROJECT_NAME@
+Environment=SRS_DOMAIN=localhost.localdomain SRS_FORWARD_PORT=10001 SRS_REVERSE_PORT=10002 SRS_SECRET=@SYSCONF_DIR@/@PROJECT_NAME@.secret SRS_SEPARATOR==
+Environment=SRS_EXCLUDE_DOMAINS= RUN_AS=postsrsd CHROOT=@CHROOT_DIR@
+EnvironmentFile=-@CONFIG_DIR@/@PROJECT_NAME@
 ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -f "${SRS_FORWARD_PORT}" -r "${SRS_REVERSE_PORT}" -d "${SRS_DOMAIN}" -s "${SRS_SECRET}" -a "${SRS_SEPARATOR}" -u "${RUN_AS}" -c "${CHROOT}" -X"${SRS_EXCLUDE_DOMAINS}"
 Restart=always
 
--- postsrsd-1.4.orig/init/postsrsd.sysv-lsb.in
+++ postsrsd-1.4/init/postsrsd.sysv-lsb.in
@@ -5,11 +5,12 @@
 #
 ### BEGIN INIT INFO
 # Provides:          @PROJECT_NAME@
-# Required-Start:    $syslog $network $local_fs
-# Required-Stop:     $syslog $network $local_fs
+# Required-Start:    $syslog $network $remote_fs
+# Required-Stop:     $syslog $network $remote_fs
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: Start/stop the @PROJECT_NAME@ daemon
+# Description:       postsrsd offers Sender Rewriting Scheme support for Postfix
 ### END INIT INFO
 
 set -e
@@ -29,10 +30,18 @@ test -x $DAEMON || exit 0
 
 # Default configuration
 SRS_DOMAIN=`postconf -h mydomain || true`
-SRS_EXCLUDE_DOMAINS=
-
-# Read config file
-. @CONFIG_DIR@/$NAME
+SRS_FORWARD_PORT=10001
+SRS_REVERSE_PORT=10002
+SRS_SECRET=@SYSCONF_DIR@/@PROJECT_NAME@.secret
+SRS_SEPARATOR==
+RUN_AS=postsrsd
+CHROOT=@CHROOT_DIR@
+
+# Read config file if it is present.
+if [ -r @CONFIG_DIR@/$NAME ]
+then
+    . @CONFIG_DIR@/$NAME
+fi
 
 test -r "$SRS_SECRET" -a -n "$SRS_DOMAIN" || exit 0
 
--- postsrsd-1.4.orig/init/postsrsd.sysv-redhat.in
+++ postsrsd-1.4/init/postsrsd.sysv-redhat.in
@@ -25,10 +25,18 @@ test -x $DAEMON || exit 0
 
 # Default configuration
 SRS_DOMAIN=`postconf -h mydomain || true`
-SRS_EXCLUDE_DOMAINS=
+SRS_FORWARD_PORT=10001
+SRS_REVERSE_PORT=10002
+SRS_SECRET=@SYSCONF_DIR@/@PROJECT_NAME@.secret
+SRS_SEPARATOR==
+RUN_AS=nobody
+CHROOT=@CHROOT_DIR@
 
-# Read config file
-. @CONFIG_DIR@/$NAME
+# Read config file if it is present.
+if [ -r @CONFIG_DIR@/$NAME ]
+then
+    . @CONFIG_DIR@/$NAME
+fi
 
 test -r "$SRS_SECRET" -a -n "$SRS_DOMAIN" || exit 0
 
--- postsrsd-1.4.orig/init/postsrsd.upstart.in
+++ postsrsd-1.4/init/postsrsd.upstart.in
@@ -5,10 +5,20 @@ start on (filesystem and net-device-up)
 stop on runlevel [!2345]
 respawn
 
+env DEFAULTFILE=@CONFIG_DIR@/@PROJECT_NAME@
+
 script
 	SRS_DOMAIN=`postconf -h mydomain || true`
+	SRS_FORWARD_PORT=10001
+	SRS_REVERSE_PORT=10002
+	SRS_SECRET=@SYSCONF_DIR@/@PROJECT_NAME@.secret
+	SRS_SEPARATOR==
 	SRS_EXCLUDE_DOMAINS=
-	. "@CONFIG_DIR@/@PROJECT_NAME@"
+	RUN_AS=postsrsd
+	CHROOT=@CHROOT_DIR@
+	if [ -r "$DEFAULTFILE" ]; then
+		. "$DEFAULTFILE"
+	fi
 	exec @CMAKE_INSTALL_PREFIX@/sbin/@POSTSRSD@ -f "$SRS_FORWARD_PORT" -r "$SRS_REVERSE_PORT" -d "$SRS_DOMAIN" -s "$SRS_SECRET" -a "$SRS_SEPARATOR" -u "$RUN_AS" -c "$CHROOT" -X"$SRS_EXCLUDE_DOMAINS"
 end script
 
