From eb16e4a078f75914cb6a44b887ba3713911f9c12 Mon Sep 17 00:00:00 2001 From: Nash Kaminski Date: Fri, 8 Mar 2024 23:17:57 +0000 Subject: [PATCH] systemd user + system services management for Debian and derivatives as well --- Makefile | 5 +- rpm/SOURCES/cntlm-user => cntlm-user.in | 2 +- debian/changelog | 2 +- debian/cntlm.default | 3 +- debian/cntlm.init | 87 ------------------------- debian/cntlm.service | 13 ++++ debian/cntlm.user.service | 12 ++++ debian/postinst | 11 ---- debian/postrm | 6 -- debian/prerm | 10 --- debian/rules | 3 +- rpm/SPECS/cntlm.spec | 4 +- 12 files changed, 35 insertions(+), 123 deletions(-) rename rpm/SOURCES/cntlm-user => cntlm-user.in (88%) delete mode 100644 debian/cntlm.init create mode 100644 debian/cntlm.service create mode 100644 debian/cntlm.user.service diff --git a/Makefile b/Makefile index c043bdf..8b15c6f 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ DESTDIR := PREFIX := /usr/local SYSCONFDIR := $(DESTDIR)/etc BINDIR := $(DESTDIR)$(PREFIX)/sbin +LIBEXECDIR := $(DESTDIR)$(PREFIX)/libexec MANDIR := $(DESTDIR)$(PREFIX)/share/man STAMP := configure-stamp @@ -153,6 +154,8 @@ install: $(NAME) install -m 600 doc/$(NAME).conf $(SYSCONFDIR)/$(NAME).conf; \ else \ install -D -m 755 $(STRIP) $(NAME) $(BINDIR)/$(NAME); \ + sed "s#%BINDIR%#$(BINDIR)#g" cntlm-user.in > cntlm-user; \ + install -D -m 755 $(NAME)-user $(LIBEXECDIR)/$(NAME)-user; \ install -D -m 644 doc/$(NAME).1 $(MANDIR)/man1/$(NAME).1; \ [ -f $(SYSCONFDIR)/$(NAME).conf -o -z "$(SYSCONFDIR)" ] \ || install -D -m 600 doc/$(NAME).conf $(SYSCONFDIR)/$(NAME).conf; \ @@ -238,7 +241,7 @@ uninstall: clean: @rm -f config/endian config/gethostname config/socklen_t config/strdup config/arc4random_buf config/strlcat config/strlcpy config/memset_s config/gss config/*.exe - @rm -f *.o cntlm cntlm.exe configure-stamp build-stamp config/config.h + @rm -f *.o cntlm cntlm.exe configure-stamp build-stamp config/config.h cntlm-user @rm -f $(patsubst %, win/%, $(CYGWIN_REQS) cntlm.exe cntlm.ini LICENSE.txt resources.o setup.iss cntlm_manual.pdf) distclean: clean diff --git a/rpm/SOURCES/cntlm-user b/cntlm-user.in similarity index 88% rename from rpm/SOURCES/cntlm-user rename to cntlm-user.in index 4ba70fb..433ab20 100644 --- a/rpm/SOURCES/cntlm-user +++ b/cntlm-user.in @@ -10,4 +10,4 @@ if [ ! -e "${CNTLM_CONFIG_LOC}" ] ; then exit 0 fi -exec /usr/sbin/cntlm -f -c "${CNTLM_CONFIG_LOC}" "$@" \ No newline at end of file +exec %BINDIR%/cntlm -f -c "${CNTLM_CONFIG_LOC}" "$@" \ No newline at end of file diff --git a/debian/changelog b/debian/changelog index 775078a..8a840de 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -cntlm (0.94beta1) unstable; urgency=low +cntlm (0.95.0beta1) unstable; urgency=low * Ad-hoc source build, not a Debian maintained package! diff --git a/debian/cntlm.default b/debian/cntlm.default index 6f94a49..523fe03 100644 --- a/debian/cntlm.default +++ b/debian/cntlm.default @@ -1,3 +1,2 @@ # Additional options that are passed to the Daemon. -TIMEOUT=1 -RUNAS=cntlm +OPTARGS="" diff --git a/debian/cntlm.init b/debian/cntlm.init deleted file mode 100644 index 04871a8..0000000 --- a/debian/cntlm.init +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/sh -# -### BEGIN INIT INFO -# Provides: cntlm -# Required-Start: $syslog $time -# Required-Stop: $syslog $time -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Authenticating HTTP accelerator for NTLM secured proxies -# Description: Cntlm is meant to be given your proxy address and becomming -# the primary proxy then, listening on a selected local port. -# You point all your proxy-aware programs to it and don't ever -# have to deal with proxy authentication again. -### END INIT INFO -# -# DAEMON Location of the binary -# PIDFILE Make sure that you or, if used, -U uid can create/write it -# TIMEOUT How long to wait for active connections to finish before -# forcing cntlm to stop with a second signal -# RUNAS Name or number of the non-privileged account to run as -# - -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=/usr/sbin/cntlm -NAME=cntlm -DESC="CNTLM Authentication Proxy" - -# Set default values -PIDFILE=/var/run/cntlm/cntlm.pid -TIMEOUT=1 -RUNAS=cntlm - -test -x $DAEMON || exit 0 - -# Include custom values if available -if [ -f /etc/default/cntlm ] ; then - . /etc/default/cntlm -fi - -DAEMON_OPTS="$DAEMON_OPTS -U $RUNAS -P $PIDFILE" -PIDDIR=`dirname $PIDFILE 2>/dev/null` - -start() { - echo -n "Starting $DESC: " - - if [ -n "$PIDDIR" -a ! -d "$PIDDIR" ]; then - mkdir -p "$PIDDIR" 2>/dev/null - chown "$RUNAS" "$PIDDIR" 2>/dev/null - chmod 755 "$PIDDIR" 2>/dev/null - fi - - start-stop-daemon --oknodo --quiet --start --pidfile $PIDFILE --name $NAME --startas $DAEMON -- $DAEMON_OPTS 2>/dev/null - if [ $? -eq 0 ]; then - echo "$NAME." - else - echo "failed!" - fi -} - -stop() { - echo -n "Stopping $DESC: " - start-stop-daemon --oknodo --quiet --stop --retry -HUP/$TIMEOUT/-KILL/2 --pidfile $PIDFILE --name $NAME 2>/dev/null - if [ $? -eq 0 ]; then - echo "$NAME." - else - echo "failed!" - fi -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|reload|force-reload) - stop - start - ;; - *) - echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2 - exit 2 - ;; -esac - -exit 0 diff --git a/debian/cntlm.service b/debian/cntlm.service new file mode 100644 index 0000000..5567a00 --- /dev/null +++ b/debian/cntlm.service @@ -0,0 +1,13 @@ +[Unit] +Description=cNTLM authentication proxy +After=network.target + +[Service] +Type=simple +Environment="RUNAS=cntlm" +EnvironmentFile=-/etc/default/cntlm +ExecStart=/usr/sbin/cntlm -f -U $RUNAS -c /etc/cntlm.conf $OPTARGS +Restart=on-failure + +[Install] +WantedBy=default.target diff --git a/debian/cntlm.user.service b/debian/cntlm.user.service new file mode 100644 index 0000000..27c49d1 --- /dev/null +++ b/debian/cntlm.user.service @@ -0,0 +1,12 @@ +[Unit] +Description=cNTLM authentication proxy - per user instance +After=network.target + +[Service] +Type=simple +EnvironmentFile=-/etc/default/cntlm +ExecStart=/usr/libexec/cntlm-user $OPTARGS +Restart=on-failure + +[Install] +WantedBy=default.target diff --git a/debian/postinst b/debian/postinst index d1c780d..23729bf 100644 --- a/debian/postinst +++ b/debian/postinst @@ -20,14 +20,3 @@ if ! [ -d $HOME ]; then fi #DEBHELPER# - -# Automatically added by dh_installinit -if [ -x "/etc/init.d/cntlm" ]; then - update-rc.d cntlm defaults >/dev/null - if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then - invoke-rc.d cntlm start || exit $? - else - /etc/init.d/cntlm start || exit $? - fi -fi -# End automatically added section diff --git a/debian/postrm b/debian/postrm index 3ec0f03..703191c 100644 --- a/debian/postrm +++ b/debian/postrm @@ -24,9 +24,3 @@ if [ "$1" = "purge" ]; then fi #DEBHELPER# - -# Automatically added by dh_installinit -if [ "$1" = "purge" ] ; then - update-rc.d cntlm remove >/dev/null || exit $? -fi -# End automatically added section diff --git a/debian/prerm b/debian/prerm index 80e9110..c1fc8b9 100644 --- a/debian/prerm +++ b/debian/prerm @@ -3,13 +3,3 @@ set -e #DEBHELPER# - -# Automatically added by dh_installinit -if [ -x "/etc/init.d/cntlm" ]; then - if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then - invoke-rc.d cntlm stop || exit $? - else - /etc/init.d/cntlm stop || exit $? - fi -fi -# End automatically added section diff --git a/debian/rules b/debian/rules index 93acd93..b2ad63d 100755 --- a/debian/rules +++ b/debian/rules @@ -64,7 +64,8 @@ binary-arch: build install dh_install cp debian/lintian-override debian/cntlm/usr/share/lintian/overrides/cntlm dh_installdebconf - dh_installinit -n + dh_installsystemd --no-enable + dh_installsystemduser --no-enable dh_installman doc/cntlm.1 dh_link dh_strip diff --git a/rpm/SPECS/cntlm.spec b/rpm/SPECS/cntlm.spec index 43959ce..31175ac 100644 --- a/rpm/SPECS/cntlm.spec +++ b/rpm/SPECS/cntlm.spec @@ -12,7 +12,6 @@ Source1: cntlm.tmpfiles Source2: cntlm.sysconfig Source3: cntlm.service Source4: cntlm-user.service -Source5: cntlm-user Requires: systemd BuildRequires: systemd @@ -42,13 +41,12 @@ CC=gcc ./configure make NOSTRIP=1 %{?_smp_mflags} SYSCONFDIR=%{_sysconfdir} %install -make BINDIR=%{buildroot}%{_sbindir} MANDIR=%{buildroot}%{_mandir} SYSCONFDIR=%{buildroot}%{_sysconfdir} NOSTRIP=1 install +make BINDIR=%{buildroot}%{_sbindir} MANDIR=%{buildroot}%{_mandir} SYSCONFDIR=%{buildroot}%{_sysconfdir} LIBEXECDIR=%{buildroot}%{_libexecdir} NOSTRIP=1 install install -D -m 0644 %{SOURCE1} %{buildroot}%{_tmpfilesdir}/%{name}.conf install -D -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/cntlmd install -D -m 0644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service install -D -m 0644 %{SOURCE4} %{buildroot}%{_userunitdir}/%{name}.service -install -D -m 0755 %{SOURCE5} %{buildroot}%{_libexecdir}/%{name}-user install -D -d -m 0755 %{buildroot}/run/%{name}/