From: Travis Kemen <thepeople@openwrt.org>
Date: Thu, 8 May 2008 00:57:21 +0000 (+0000)
Subject: A new package smtptrapd to provide a (secondary) SMTP server returning 4xx soft error... 
X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=9e0983c91db20a8a1f16030549a987529fa4796a;p=openwrt%2Fsvn-archive%2Fpackages.git

A new package smtptrapd to provide a (secondary) SMTP server returning 4xx soft error. Signed-off-by: Lubos Stanek (lubek) <lubek@lubek.name>

SVN-Revision: 11065
---

diff --git a/net/smtptrapd/Makefile b/net/smtptrapd/Makefile
new file mode 100644
index 000000000..3665d84df
--- /dev/null
+++ b/net/smtptrapd/Makefile
@@ -0,0 +1,51 @@
+#
+# Copyright (C) 2008 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=smtptrapd
+PKG_VERSION:=1.5
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=http://smtptrapd.inodes.org
+PKG_MD5SUM:=edc5f2f3ea9f9bdd9e0f479a58903bf1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/smtptrapd
+  SECTION:=net
+  CATEGORY:=Network
+  DEPENDS:=+libpthread
+  TITLE:=SMTP Trap Daemon
+  URL:=http://smtptrapd.inodes.org/
+endef
+
+define Package/smtptrapd/description
+	The smtptrapd program is a multi-threaded daemon that provides 
+	a RFC 2821 compliant SMTP service that always returns a 4xx soft 
+	error to the RCPT TO verb.
+endef
+
+define Build/Compile
+	$(TARGET_CC) \
+		$(TARGET_CFLAGS) \
+		-I $(STAGING_DIR)/usr/include \
+		-D_REENTRANT \
+		$(PKG_BUILD_DIR)/smtptrapd.c \
+		-o $(PKG_BUILD_DIR)/smtptrapd \
+		-L$(STAGING_DIR)/usr/lib/ -lpthread
+endef
+	
+define Package/smtptrapd/install
+	$(INSTALL_DIR) $(1)/etc/init.d
+	$(INSTALL_BIN) ./files/smtptrapd.init $(1)/etc/init.d/smtptrapd
+	$(INSTALL_DIR) $(1)/usr/sbin
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/smtptrapd $(1)/usr/sbin/
+endef
+
+$(eval $(call BuildPackage,smtptrapd))
diff --git a/net/smtptrapd/files/smtptrapd.init b/net/smtptrapd/files/smtptrapd.init
new file mode 100644
index 000000000..56e5f9780
--- /dev/null
+++ b/net/smtptrapd/files/smtptrapd.init
@@ -0,0 +1,144 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008 OpenWrt.org
+
+START=90
+
+NAME="smtptrapd"
+DAEMON="/usr/sbin/$NAME"
+RUN_D="/var/run"
+
+EXTRA_COMMANDS="list status exconf"
+EXTRA_HELP="	list	Lists available configurations
+	status	Prints status of the service
+	exconf	Shows an example config file
+
+The actions start, stop, restart, reload, status operate
+globally on all configurations unless the particular
+configuration has been provided as the next parameter.
+"
+
+check_req() {
+	if [ -x "$DAEMON" ]; then
+		return 0
+	else
+		echo "The daemon binary is missing!"
+		return 1
+	fi
+}
+
+check_section() {
+	echo "$1" | grep -vq '^cfg[[:xdigit:]]\{6\}$'
+}
+
+start_service() {
+	local cfg="$1"
+	local named="$2"
+	check_section "$cfg" || return 1
+	[ "$named" != "" -a "$cfg" != "$named" ] && return 0
+	local args listen_ip banner_host username num_threads listen_port accept_queue_len
+	config_get listen_ip "$cfg" listen_ip
+	[ -n "$listen_ip" ] && append args "-l $listen_ip"
+	config_get listen_port "$cfg" listen_port
+	[ -n "$listen_port" ] && append args "-p $listen_port"
+	config_get username "$cfg" username
+	[ -n "$username" ] && append args "-u $username"
+	config_get banner_host "$cfg" banner_host
+	[ -n "$banner_host" ] && append args "-b \"$banner_host\""
+	config_get num_threads "$cfg" num_threads
+	[ -n "$num_threads" ] && append args "-t $num_threads"
+	config_get accept_queue_len "$cfg" accept_queue_len
+	[ -n "$accept_queue_len" ] && append args "-m $accept_queue_len"
+	append args "-f ${RUN_D}/${NAME}-${cfg}.pid"
+	eval "$DAEMON $args"
+}
+
+stop_service() {
+	local cfg="$1"
+	local named="$2"
+	check_section "$cfg" || return 1
+	[ "$named" != "" -a "$cfg" != "$named" ] && return 0
+	local PID_F="${RUN_D}/${NAME}-${cfg}.pid"
+	[ -f $PID_F ] && {
+		local ppid=$(cat $PID_F)
+		ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>" && kill $ppid
+		rm -f $PID_F
+	}
+}
+
+status_service() {
+	local cfg="$1"
+	local named="$2"
+	check_section "$cfg" || return 1
+	[ "$named" != "" -a "$cfg" != "$named" ] && return 0
+	local PID_F="${RUN_D}/${NAME}-${cfg}.pid"
+	[ -f $PID_F ] && {
+		local ppid=$(cat $PID_F)
+		if ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>"; then
+			echo "$cfg (pid $ppid) is running"
+		else
+			echo "$cfg is not running (stale pid file exists)"
+		fi
+	}
+}
+
+list_service() {
+	local cfg="$1"
+	check_section "$cfg" || return 1
+	echo "	$cfg"
+}
+
+start() {
+	local svc_cfg="$1"
+	check_req || return 1
+	[ ! -d $RUN_D ] && mkdir -p $RUN_D
+	config_load "$NAME"
+	config_foreach start_service "$NAME" "$svc_cfg"
+}
+
+stop() {
+	local svc_cfg="$1"
+	check_req || return 1
+	config_load "/etc/config/$NAME"
+	if [ -n "$svc_cfg" ]; then
+		config_foreach stop_service "$NAME" "$svc_cfg"
+	else
+		config_foreach stop_service "$NAME"
+		local pf
+		for pf in $(ls ${RUN_D}/${NAME}*.pid 2>/dev/null); do
+			local ppid=$(cat $pf)
+			ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>" && kill "$ppid"
+			rm -f $pf
+		done
+	fi
+}
+
+status() {
+	local svc_cfg="$1"
+	check_req || return 1
+	config_load "$NAME"
+	config_foreach status_service "$NAME" "$svc_cfg"
+}
+
+list() {
+	check_req || return 1
+	echo "Available $NAME configurations:"
+	config_load "$NAME"
+	config_foreach list_service "$NAME"
+}
+
+exconf() {
+	echo "An example configuration in /etc/config/$NAME:" >&2
+	cat <<EOF
+config '$NAME' 'myfailhost'
+	option 'num_threads' '1'
+
+# The init script operates only with named sections
+# All options (default values)
+#	option 'banner_host' '<hostname>'
+#	option 'username' 'nobody'
+#	option 'listen_ip' '<all addresses>'
+#	option 'listen_port' '25'
+#	option 'num_threads' '10'
+#	option 'accept_queue_len' '100'
+EOF
+}
diff --git a/net/smtptrapd/patches/200-missing_opt.patch b/net/smtptrapd/patches/200-missing_opt.patch
new file mode 100644
index 000000000..c989b0140
--- /dev/null
+++ b/net/smtptrapd/patches/200-missing_opt.patch
@@ -0,0 +1,12 @@
+diff -urN smtptrapd-1.5.orig/smtptrapd.c smtptrapd-1.5.dev/smtptrapd.c
+--- smtptrapd-1.5.orig/smtptrapd.c	2008-04-15 12:56:20.000000000 +0200
++++ smtptrapd-1.5.dev/smtptrapd.c	2008-04-16 18:23:03.000000000 +0200
+@@ -545,7 +545,7 @@
+ 	config.threads = NUM_CONSUMER;
+ 	config.max_queue_len = MAX_QUEUE_LEN;
+ 
+-	while ((c = getopt(argc, argv, "hc:l:p:b:u:m:t:")) != -1) {
++	while ((c = getopt(argc, argv, "hc:l:p:b:u:m:t:f:")) != -1) {
+ 		switch (c) {
+ 			case 'h':
+