kentpeacock / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone
Petr Šabata 81d24c
commit 0e22b79bfde45a7cf7a2e51a68ec11c4285f3b31
Petr Šabata 81d24c
Author: Jakub Jelen <jjelen@redhat.com>
Petr Šabata 81d24c
Date:   Mon Nov 21 15:04:06 2016 +0100
Petr Šabata 81d24c
Petr Šabata 81d24c
    systemd stuff
Petr Šabata 81d24c
Petr Šabata 81d24c
diff --git a/configure.ac b/configure.ac
Petr Šabata 81d24c
index 2ffc369..162ce92 100644
Petr Šabata 81d24c
--- a/configure.ac
Petr Šabata 81d24c
+++ b/configure.ac
Petr Šabata 81d24c
@@ -4265,6 +4265,30 @@ AC_ARG_WITH([kerberos5],
Petr Šabata 81d24c
 AC_SUBST([GSSLIBS])
Petr Šabata 81d24c
 AC_SUBST([K5LIBS])
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+# Check whether user wants systemd support
Petr Šabata 81d24c
+SYSTEMD_MSG="no"
Petr Šabata 81d24c
+AC_ARG_WITH(systemd,
Petr Šabata 81d24c
+	[  --with-systemd          Enable systemd support],
Petr Šabata 81d24c
+	[ if test "x$withval" != "xno" ; then
Petr Šabata 81d24c
+		AC_PATH_TOOL([PKGCONFIG], [pkg-config], [no])
Petr Šabata 81d24c
+		if test "$PKGCONFIG" != "no"; then
Petr Šabata 81d24c
+			AC_MSG_CHECKING([for libsystemd])
Petr Šabata 81d24c
+			if $PKGCONFIG --exists libsystemd; then
Petr Šabata 81d24c
+				SYSTEMD_CFLAGS=`$PKGCONFIG --cflags libsystemd`
Petr Šabata 81d24c
+				SYSTEMD_LIBS=`$PKGCONFIG --libs libsystemd`
Petr Šabata 81d24c
+				CPPFLAGS="$CPPFLAGS $SYSTEMD_CFLAGS"
Petr Šabata 81d24c
+				SSHDLIBS="$SSHDLIBS $SYSTEMD_LIBS"
Petr Šabata 81d24c
+				AC_MSG_RESULT([yes])
Petr Šabata 81d24c
+				AC_DEFINE(HAVE_SYSTEMD, 1, [Define if you want systemd support.])
Petr Šabata 81d24c
+				SYSTEMD_MSG="yes"
Petr Šabata 81d24c
+			else
Petr Šabata 81d24c
+				AC_MSG_RESULT([no])
Petr Šabata 81d24c
+			fi
Petr Šabata 81d24c
+		fi
Petr Šabata 81d24c
+	fi ]
Petr Šabata 81d24c
+)
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 # Looking for programs, paths and files
Petr Šabata 81d24c
 
Petr Šabata 81d24c
 PRIVSEP_PATH=/var/empty
Petr Šabata 81d24c
@@ -5097,6 +5121,7 @@ echo "                   libedit support: $LIBEDIT_MSG"
Petr Šabata 81d24c
 echo "  Solaris process contract support: $SPC_MSG"
Petr Šabata 81d24c
 echo "           Solaris project support: $SP_MSG"
Petr Šabata 81d24c
 echo "         Solaris privilege support: $SPP_MSG"
Petr Šabata 81d24c
+echo "                   systemd support: $SYSTEMD_MSG"
Petr Šabata 81d24c
 echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
Petr Šabata 81d24c
 echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
Petr Šabata 81d24c
 echo "                  BSD Auth support: $BSD_AUTH_MSG"
Petr Šabata 81d24c
diff --git a/contrib/sshd.service b/contrib/sshd.service
Petr Šabata 81d24c
new file mode 100644
Petr Šabata 81d24c
index 0000000..e0d4923
Petr Šabata 81d24c
--- /dev/null
Petr Šabata 81d24c
+++ b/contrib/sshd.service
Petr Šabata 81d24c
@@ -0,0 +1,16 @@
Petr Šabata 81d24c
+[Unit]
Petr Šabata 81d24c
+Description=OpenSSH server daemon
Petr Šabata 81d24c
+Documentation=man:sshd(8) man:sshd_config(5)
Petr Šabata 81d24c
+After=network.target
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+[Service]
Petr Šabata 81d24c
+Type=notify
Petr Šabata 81d24c
+ExecStart=/usr/sbin/sshd -D $OPTIONS
Petr Šabata 81d24c
+ExecReload=/bin/kill -HUP $MAINPID
Petr Šabata 81d24c
+KillMode=process
Petr Šabata 81d24c
+Restart=on-failure
Petr Šabata 81d24c
+RestartPreventExitStatus=255
Petr Šabata 81d24c
+
Petr Šabata 81d24c
+[Install]
Petr Šabata 81d24c
+WantedBy=multi-user.target
Petr Šabata 81d24c
+
Petr Šabata 81d24c
diff --git a/sshd.c b/sshd.c
Petr Šabata 81d24c
index 816611c..b8b9d13 100644
Petr Šabata 81d24c
--- a/sshd.c
Petr Šabata 81d24c
+++ b/sshd.c
Petr Šabata 81d24c
@@ -85,6 +85,10 @@
Petr Šabata 81d24c
 #include <prot.h>
Petr Šabata 81d24c
 #endif
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+#ifdef HAVE_SYSTEMD
Petr Šabata 81d24c
+#include <systemd/sd-daemon.h>
Petr Šabata 81d24c
+#endif
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 #include "xmalloc.h"
Petr Šabata 81d24c
 #include "ssh.h"
Petr Šabata 81d24c
 #include "ssh2.h"
Petr Šabata 81d24c
@@ -1888,6 +1892,11 @@ main(int ac, char **av)
Petr Šabata 81d24c
 			}
Petr Šabata 81d24c
 		}
Petr Šabata 81d24c
 
Petr Šabata 81d24c
+#ifdef HAVE_SYSTEMD
Petr Šabata 81d24c
+		/* Signal systemd that we are ready to accept connections */
Petr Šabata 81d24c
+		sd_notify(0, "READY=1");
Petr Šabata 81d24c
+#endif
Petr Šabata 81d24c
+
Petr Šabata 81d24c
 		/* Accept a connection and return in a forked child */
Petr Šabata 81d24c
 		server_accept_loop(&sock_in, &sock_out,
Petr Šabata 81d24c
 		    &newsock, config_s);