OpenWrt Forum Archive

Topic: Migrate pure-ftpd configuration to UCI

The content of this topic has been archived on 16 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm starting to migrate the pure-ftpd configuration to UCI. Here is a basic UCI configuration file with a few options for pure-ftpd. The Pure-FTPd README describes the command-line options. If you are using 7.09 you have to enable the start-stop-daemon in Busybox and recompile.

If you have and ideas what should be added or removed let me know...

So, here is what I have so far (patch):

Index: files/pure-ftpd.init
===================================================================
--- files/pure-ftpd.init    (Revision 9158)
+++ files/pure-ftpd.init    (Arbeitskopie)
@@ -2,20 +2,57 @@
 # Copyright (C) 2006 OpenWrt.org
 START=50
 
-BIN=pure-ftpd
-DEFAULT=/etc/default/$BIN
-LOG_D=/var/log/$BIN
-RUN_D=/var/run
-PID_F=$RUN_D/$BIN.pid
-OPTIONS="-A -B -c 10 -C 4 -E -lunix -U 133:022 -g $PID_F -y 3:4"
-[ -f $DEFAULT ] && . $DEFAULT
+SSD=start-stop-daemon
+PIDF=/var/run/pure-ftpd.pid
+PROG=/usr/sbin/pure-ftpd
 
+append_bool() {
+    local section="$1"
+    local option="$2"
+    local value="$3"
+    local _val
+    config_get_bool _val "$section" "$option" '0'
+    [ "$_val" -gt 0 ] && append args "$3"
+}
+
+append_string() {
+    local section="$1"
+    local option="$2"
+    local value="$3"
+    local _val
+    config_get _val "$section" "$option"
+    [ -n "$_val" ] && append args "$3 $_val"
+}
+
+start_service() {
+    local section="$1"
+    args=""
+
+    append_string "$section" port "-S"
+    append_bool "$section" noanonymous "-E"
+    append_bool "$section" chrooteveryone "-A"
+    append_string "$section" maxclientsperip "-c"
+    append_string "$section" maxclientsnumber "-C"
+    append_string "$section" peruserlimits "-y"
+    append_string "$section" umask "-U"
+    append_string "$section" authentication "-l"
+    config_get_bool "enabled" "$section" "enabled" '1'
+    [ "$enabled" -gt 0 ] && $SSD -S -p $PIDF -q -x $PROG -- -g $PIDF -B $args
+}
+
+stop_service() {
+    [ -f $PID_F ] && kill `cat $PIDF`
+
+    # FIXME: Fix Busybox start-stop-daemon to work with multiple PIDs
+    # $SSD -K -p $PIDF -q
+}
+
 start() {
-        mkdir -p $LOG_D
-        mkdir -p $RUN_D
-        $BIN $OPTIONS
+    config_load "pure-ftpd"
+    config_foreach start_service "pure-ftpd"
 }
 
 stop() {
-        [ -f $PID_F ] && kill $(cat $PID_F)
+    config_load "pure-ftpd"
+    config_foreach stop_service "pure-ftpd"
 }
Index: files/pure-ftpd.config
===================================================================
--- files/pure-ftpd.config    (Revision 0)
+++ files/pure-ftpd.config    (Revision 0)
@@ -0,0 +1,13 @@
+# pure-pw useradd ftpuser1 -u ftpuser -d /srv/ftp/ftpuser1 -n 100 -N 100 -t 10
+# pure-pw mkdb
+
+config pure-ftpd
+    option port             '21'
+    option noanonymous      '1'
+    option chrooteveryone   '1'
+    option maxclientsperip  '10'
+    option maxclientsnumber '4'
+    option peruserlimits    '3:4'
+    option umask            '133:022'
+    option authentication   'unix'
+    option enabled          '0'
Index: patches/001-cross_compile.patch
===================================================================
--- patches/001-cross_compile.patch    (Revision 9158)
+++ patches/001-cross_compile.patch    (Arbeitskopie)
@@ -1,5 +1,7 @@
---- pure-ftpd-1.0.21/configure    2006-02-19 15:33:05.000000000 +0100
-+++ pure-ftpd-1.0.21.new/configure    2006-12-11 16:07:29.000000000 +0100
+Index: pure-ftpd-1.0.21/configure
+===================================================================
+--- pure-ftpd-1.0.21.orig/configure    2007-10-14 22:03:46.000000000 +0200
++++ pure-ftpd-1.0.21/configure    2007-10-14 22:03:46.000000000 +0200
 @@ -9273,7 +9273,7 @@
    if test "$cross_compiling" = yes; then
    { { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
Index: Makefile
===================================================================
--- Makefile    (Revision 9158)
+++ Makefile    (Arbeitskopie)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006 OpenWrt.org
+# Copyright (C) 2007 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -10,16 +10,11 @@
 PKG_NAME:=pure-ftpd
 PKG_VERSION:=1.0.21
 PKG_RELEASE:=1
-PKG_MD5SUM:=ca8a8dbec0cd9c8ea92fc4c37ea9c410
 
-PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
-PKG_SOURCE_URL:=http://download.pureftpd.org/pub/pure-ftpd/releases/
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+PKG_SOURCE_URL:=http://download.pureftpd.org/pub/pure-ftpd/releases/
+PKG_MD5SUM:=ca8a8dbec0cd9c8ea92fc4c37ea9c410
 
-PKG_CAT:=bzcat
-
-PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
-
 include $(INCLUDE_DIR)/package.mk
 
 define Package/pure-ftpd
@@ -28,23 +23,27 @@
   CATEGORY:=Network
   DEPENDS:=+libelf
   TITLE:=Secure FTP made easy!
-  DESCRIPTION:=\
-      Pure-FTPd is a free (BSD), secure, production-quality and standard-conformant FTP server.\
-    It doesn't provide useless bells and whistles, but focuses on efficiency and ease of use.\
-    It provides simple answers to common needs, plus unique useful features for personal users\
-    as well as hosting providers.
   URL:=http://www.pureftpd.org/project/pure-ftpd
 endef
 
-define Build/Configure
-    $(call Build/Configure/Default,--with-everything)
+define Package/pure-ftpd/description
+ Pure-FTPd is a free (BSD), secure, production-quality and standard-conformant
+ FTP server. It doesn't provide useless bells and whistles, but focuses on
+ efficiency and ease of use.
+ It provides simple answers to common needs, plus unique  useful features for
+ personal users as well as hosting providers.
 endef
 
+CONFIGURE_ARGS += \
+    --with-everything \
+
 define Package/pure-ftpd/install
-    $(INSTALL_DIR) $(1)/etc/init.d $(1)/usr/sbin
-    install -m0755 ./files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
-    $(CP) $(PKG_BUILD_DIR)/src/pure-{ftpd,pw,ftpwho,mrtginfo,pwconvert,quotacheck,statsdecode,uploadscript,authd} $(1)/usr/sbin/
-    $(CP) $(PKG_BUILD_DIR)/src/ptracetest $(1)/usr/sbin/
+    $(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d $(1)/usr/sbin
+    $(INSTALL_DATA) ./files/$(PKG_NAME).config $(1)/etc/config/$(PKG_NAME)
+    $(INSTALL_BIN) ./files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
+    $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/ptracetest $(1)/usr/sbin
+    $(INSTALL_BIN) $(foreach i,ftpd pw ftpwho mrtginfo pwconvert quotacheck statsdecode uploadscript authd, \
+        $(PKG_BUILD_DIR)/src/pure-$(i)) $(1)/usr/sbin
 endef
 
 $(eval $(call BuildPackage,pure-ftpd))

(Last edited by forum2006 on 14 Oct 2007, 21:11)

Added to subversion with revision 9325 (https://dev.openwrt.org/changeset/9325). If you have better descriptions for the options in the config file (/etc/config/pure-ftpd) let me know or just file a ticket with a patch...

The discussion might have continued from here.