packages/openssh: use new service functions, move user/group creation from postinst...
authorNicolas Thill <nico@openwrt.org>
Wed, 9 Nov 2011 23:11:43 +0000 (23:11 +0000)
committerNicolas Thill <nico@openwrt.org>
Wed, 9 Nov 2011 23:11:43 +0000 (23:11 +0000)
SVN-Revision: 28899

net/openssh/Makefile
net/openssh/files/sshd.init

index 05a44b9b823f96bb7386e5aa78d8a41579b38846..19b89427e15b921cf9a81e86ccda6614f40452f2 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006,2008-2011 OpenWrt.org
+# Copyright (C) 2006-2011 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=openssh
 PKG_VERSION:=5.9p1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/ \
@@ -179,23 +179,6 @@ define Package/openssh-server/install
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/sshd $(1)/usr/sbin/
 endef
 
-define Package/openssh-server/postinst
-#!/bin/sh
-
-name=sshd
-id=22
-
-if [ -z "$$(grep ^\\$${name}: $${IPKG_INSTROOT}/etc/group)" ]; then
-       echo "adding group $$name to /etc/group"
-       echo "$${name}:x:$${id}:" >> $${IPKG_INSTROOT}/etc/group
-fi
-
-if [ -z "$$(grep ^\\$${name}: $${IPKG_INSTROOT}/etc/passwd)" ]; then
-       echo "adding user $$name to /etc/passwd"
-       echo "$${name}:x:$${id}:$${id}:$${name}:/var/empty/.$${name}:/bin/false" >> $${IPKG_INSTROOT}/etc/passwd
-fi
-endef
-
 define Package/openssh-sftp-client/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/sftp $(1)/usr/bin/
index 58b5ce72061be370e17ec4a383ee544afe8f7a52..ff66338a7b968589d999596db65bfd0cc540e12d 100644 (file)
@@ -1,8 +1,11 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2006 OpenWrt.org
+# Copyright (C) 2006-2011 OpenWrt.org
+
 START=50
 STOP=50
 
+SERVICE_USE_PID=1
+
 start() {
        for type in rsa dsa; do {
                # check for keys
@@ -15,15 +18,29 @@ start() {
                        exit 0
                }
        }; done
-       mkdir -p /var/empty
-       chmod 0700 /var/empty
-       /usr/sbin/sshd
+       user_exists sshd 22 || user_add sshd 22
+       group_exists sshd 22 || group_add ssh 22
+       mkdir -m 0700 -p /var/empty
+       mkdir -m 0755 -p /var/run/sshd
+       service_start /usr/sbin/sshd
 }
 
 stop() {
-       kill $(cat /var/run/sshd.pid)
+       service_stop /usr/sbin/sshd
 }
 
 shutdown() {
-       killall sshd
+       local pid
+       local pids
+       local pid_mine
+
+       stop
+
+       # kill active clients
+       pid_mine="$$"
+       pids="$(pidof sshd)"
+       for pid in $pids; do
+               [ "$pid" = "$pid_mine" ] && continue
+               [ -e "/proc/$pid/stat" ] && kill $pid
+       done
 }