From 60fe37eec705bfcb6496c552365f361b10e8f9fa Mon Sep 17 00:00:00 2001 From: Adam Weinberger Date: Sun, 6 Jul 2014 02:54:34 +0000 Subject: [PATCH] Add mail/postsrsd. PostSRSd provides the Sender Rewriting Scheme (SRS) via TCP-based lookup tables for Postfix. SRS is needed if your mail server acts as forwarder. WWW: https://github.com/roehling/postsrsd PR: ports/191292 Submitted by: Krzysztof Stryjek --- mail/Makefile | 1 + mail/postsrsd/Makefile | 34 +++++++ mail/postsrsd/distinfo | 2 + mail/postsrsd/files/patch-CMakeLists.txt | 71 +++++++++++++++ .../postsrsd/files/patch-postinstall.cmake.in | 49 ++++++++++ mail/postsrsd/files/patch-postsrsd.c | 20 ++++ mail/postsrsd/files/patch-srs2.c | 11 +++ mail/postsrsd/files/patch-srs2.h | 10 ++ mail/postsrsd/files/postsrsd.in | 91 +++++++++++++++++++ mail/postsrsd/pkg-descr | 4 + mail/postsrsd/pkg-plist | 3 + 11 files changed, 296 insertions(+) create mode 100644 mail/postsrsd/Makefile create mode 100644 mail/postsrsd/distinfo create mode 100644 mail/postsrsd/files/patch-CMakeLists.txt create mode 100644 mail/postsrsd/files/patch-postinstall.cmake.in create mode 100644 mail/postsrsd/files/patch-postsrsd.c create mode 100644 mail/postsrsd/files/patch-srs2.c create mode 100644 mail/postsrsd/files/patch-srs2.h create mode 100644 mail/postsrsd/files/postsrsd.in create mode 100644 mail/postsrsd/pkg-descr create mode 100644 mail/postsrsd/pkg-plist diff --git a/mail/Makefile b/mail/Makefile index 5d86687a4205..0b8158724277 100644 --- a/mail/Makefile +++ b/mail/Makefile @@ -511,6 +511,7 @@ SUBDIR += postfixadmin SUBDIR += postgrey SUBDIR += postpals + SUBDIR += postsrsd SUBDIR += prayer SUBDIR += premail SUBDIR += prepflog diff --git a/mail/postsrsd/Makefile b/mail/postsrsd/Makefile new file mode 100644 index 000000000000..72a471fd10d5 --- /dev/null +++ b/mail/postsrsd/Makefile @@ -0,0 +1,34 @@ +# Created by: Krzysztof Stryjek +# $FreeBSD$ + +PORTNAME= postsrsd +PORTVERSION= 1.1 +CATEGORIES= mail + +MAINTAINER= ports@bsdserwis.com +COMMENT= Postfix Sender Rewriting Scheme daemon + +LICENSE= GPLv2 + +BUILD_DEPENDS+= help2man:${PORTSDIR}/misc/help2man \ + base64:${PORTSDIR}/converters/base64 +RUN_DEPENDS+= base64:${PORTSDIR}/converters/base64 + +USE_GITHUB= yes +GH_ACCOUNT= roehling +GH_COMMIT= 4a3349d + +USES= cmake pkgconfig +CMAKE_ARGS+= --no-warn-unused-cli \ + -DCMAKE_INCLUDE_PATH="${LOCALBASE}/include" \ + -DCMAKE_LIBRARY_PATH="${LOCALBASE}/lib" +USE_LDCONFIG= ${PREFIX}/lib/${PORTNAME} +USE_RC_SUBR= ${PORTNAME} + +PORTDOCS= README.md main.cf.ex + +OPTIONS_DEFINE= DOCS + +DOCS_CMAKE_ON= -DENABLE_DOCS:STRING="ON" + +.include diff --git a/mail/postsrsd/distinfo b/mail/postsrsd/distinfo new file mode 100644 index 000000000000..a4927e677d8e --- /dev/null +++ b/mail/postsrsd/distinfo @@ -0,0 +1,2 @@ +SHA256 (postsrsd-1.1.tar.gz) = 5565cf1ee49540686abcc272eef0dbdfbae2e899bd7b8cc49eb0b5dacf802acf +SIZE (postsrsd-1.1.tar.gz) = 24219 diff --git a/mail/postsrsd/files/patch-CMakeLists.txt b/mail/postsrsd/files/patch-CMakeLists.txt new file mode 100644 index 000000000000..b554b3a5eefb --- /dev/null +++ b/mail/postsrsd/files/patch-CMakeLists.txt @@ -0,0 +1,71 @@ +--- CMakeLists.txt 2014-01-03 01:01:47.000000000 +0100 ++++ CMakeLists.txt.new 2014-06-18 02:01:27.734952000 +0200 +@@ -3,45 +3,22 @@ + + option(GENERATE_SRS_SECRET "Generate a random SRS secret if none exists during install" ON) + option(USE_APPARMOR "Enable AppArmor profile" OFF) ++option(MK_CHROOT_DIR "Chroot jail for daemon" OFF) + ++if(MK_CHROOT_DIR) + set(CHROOT_DIR "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}" CACHE PATH "Chroot jail for daemon") +-set(CONFIG_DIR "/etc/default" CACHE PATH "Location of configuration file") ++endif() ++set(CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/etc" CACHE PATH "Location of configuration file") + + find_program(HELP2MAN help2man DOC "path to help2man executable") + find_program(DD dd DOC "path to dd executable") + find_program(BASE64 base64 DOC "path to base64 executable") +-find_program(INSSERV insserv DOC "path to insserv executable") +-find_program(CHKCONFIG chkconfig DOC "path to chkconfig executable") +- +-if(NOT DEFINED INIT_FLAVOR) +- if(IS_DIRECTORY "/etc/init" AND EXISTS "/lib/init/upstart-job") +- message(STATUS "Detected init flavor: upstart") +- set(INIT_FLAVOR "upstart" CACHE STRING "Init daemon of this system") +- elseif(IS_DIRECTORY "/etc/init.d" AND EXISTS "/lib/lsb/init-functions") +- message(STATUS "Detected init flavor: sysv-lsb") +- set(INIT_FLAVOR "sysv-lsb" CACHE STRING "Init daemon of this system") +- elseif(IS_DIRECTORY "/etc/init.d" AND EXISTS "/etc/init.d/functions") +- message(STATUS "Detected init flavor: sysv-redhat") +- set(INIT_FLAVOR "sysv-redhat" CACHE STRING "Init daemon of this system") +- else() +- message(STATUS "Detected init flavor: none") +- message(STATUS "System startup files will not be installed") +- set(INIT_FLAVOR "" CACHE STRING "Init daemon of this system") +- endif() +-endif() + + add_executable(${PROJECT_NAME} postsrsd.c sha1.c srs2.c) + + get_target_property(POSTSRSD ${PROJECT_NAME} LOCATION) + get_filename_component(POSTSRSD ${POSTSRSD} NAME_WE) +-set(APPARMOR_PROFILE "${CMAKE_INSTALL_PREFIX}/sbin/${POSTSRSD}") +-string(REGEX REPLACE "^/+" "" APPARMOR_PROFILE "${APPARMOR_PROFILE}") +-string(REPLACE "/" "." APPARMOR_PROFILE "${APPARMOR_PROFILE}") +- +-configure_file(${PROJECT_NAME}.lsb_init.in ${PROJECT_NAME}.lsb_init @ONLY) +-configure_file(${PROJECT_NAME}.rh_init.in ${PROJECT_NAME}.rh_init @ONLY) +-configure_file(${PROJECT_NAME}.upstart.in ${PROJECT_NAME}.upstart @ONLY) +-configure_file(${PROJECT_NAME}.apparmor.in ${PROJECT_NAME}.apparmor @ONLY) ++ + configure_file(postinstall.cmake.in postinstall.cmake @ONLY) + + if(HELP2MAN) +@@ -49,7 +26,7 @@ + COMMAND ${HELP2MAN} ARGS -s8 -o${PROJECT_NAME}.8 -n "Postfix Sender Rewriting Scheme daemon" -N -h-h -v-v ${CMAKE_CURRENT_BINARY_DIR}/${POSTSRSD} + VERBATIM + ) +-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.8 DESTINATION "share/man/man8") ++install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.8 DESTINATION "man/man8") + endif() + + if(USE_APPARMOR) +@@ -57,6 +34,8 @@ + endif() + + install(TARGETS ${PROJECT_NAME} DESTINATION "sbin") ++if(ENABLE_DOCS) + install(FILES README.md main.cf.ex DESTINATION "share/doc/${PROJECT_NAME}") ++endif() + install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/postinstall.cmake") + diff --git a/mail/postsrsd/files/patch-postinstall.cmake.in b/mail/postsrsd/files/patch-postinstall.cmake.in new file mode 100644 index 000000000000..9af6d915e9ad --- /dev/null +++ b/mail/postsrsd/files/patch-postinstall.cmake.in @@ -0,0 +1,49 @@ +--- postinstall.cmake.in 2014-01-03 01:01:47.000000000 +0100 ++++ postinstall.cmake.in.new 2014-06-18 01:47:16.240011867 +0200 +@@ -5,37 +5,13 @@ + set(SECRET_FILE "@PROJECT_NAME@.secret") + set(DD "@DD@") + set(BASE64 "@BASE64@") +-set(INSSERV "@INSSERV@") +-set(CHKCONFIG "@CHKCONFIG@") + + if(CHROOT_DIR AND NOT EXISTS "$ENV{DESTDIR}${CHROOT_DIR}") + message(STATUS "Chroot jail: $ENV{DESTDIR}${CHROOT_DIR}") + file(MAKE_DIRECTORY "$ENV{DESTDIR}${CHROOT_DIR}") + endif() + +-if(INIT_FLAVOR AND NOT EXISTS "$ENV{DESTDIR}${CONFIG_DIR}/@PROJECT_NAME@") +- file(INSTALL FILES "@CMAKE_CURRENT_SOURCE_DIR@/@PROJECT_NAME@.default" DESTINATION "${CONFIG_DIR}" RENAME "@PROJECT_NAME@") +-endif() +- +-if(INIT_FLAVOR STREQUAL "sysv-lsb") +- file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.lsb_init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@") +- if(INSSERV) +- execute_process( +- COMMAND ${INSSERV} -p "$ENV{DESTDIR}/etc/init.d" @PROJECT_NAME@ +- ) +- endif() +-elseif(INIT_FLAVOR STREQUAL "sysv-redhat") +- file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.rh_init" TYPE PROGRAM DESTINATION "/etc/init.d" RENAME "@PROJECT_NAME@") +- if(CHKCONFIG AND NOT "$ENV{DESTDIR}") +- execute_process( +- COMMAND ${CHKCONFIG} --add @PROJECT_NAME@ +- ) +- endif() +-elseif(INIT_FLAVOR STREQUAL "upstart") +- file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/@PROJECT_NAME@.upstart" DESTINATION "/etc/init" RENAME "@PROJECT_NAME@.conf") +-endif() +- +-if(GENERATE_SRS_SECRET AND DD AND BASE64 AND EXISTS "/dev/urandom" AND NOT EXISTS "$ENV{DESTDIR}/etc/${SECRET_FILE}") ++if(GENERATE_SRS_SECRET AND DD AND BASE64 AND EXISTS "/dev/urandom") + message(STATUS "Generating secret key") + execute_process( + COMMAND ${DD} if=/dev/urandom bs=18 count=1 +@@ -44,6 +20,6 @@ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +-file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}" DESTINATION "/etc" RENAME "${SECRET_FILE}" FILE_PERMISSIONS OWNER_READ OWNER_WRITE) ++file(INSTALL FILES "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}" DESTINATION "${CONFIG_DIR}" RENAME "${SECRET_FILE}" FILE_PERMISSIONS OWNER_READ OWNER_WRITE) + file(REMOVE "@CMAKE_CURRENT_BINARY_DIR@/${SECRET_FILE}") + endif() diff --git a/mail/postsrsd/files/patch-postsrsd.c b/mail/postsrsd/files/patch-postsrsd.c new file mode 100644 index 000000000000..755b29b48692 --- /dev/null +++ b/mail/postsrsd/files/patch-postsrsd.c @@ -0,0 +1,20 @@ +--- postsrsd.c 2014-01-03 01:01:47.000000000 +0100 ++++ postsrsd.c.new 2014-06-18 23:31:33.290651741 +0200 +@@ -28,7 +28,7 @@ + #include + #include + #include +-#include ++#include + #include + + #ifndef VERSION +@@ -47,7 +47,7 @@ + memset (&hints, 0, sizeof(hints)); + hints.ai_family = family; + hints.ai_socktype = SOCK_STREAM; +- hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED; ++ hints.ai_flags = AI_ADDRCONFIG; + err = getaddrinfo(NULL, service, &hints, &addr); + if (err != 0) { + fprintf(stderr, "%s: bind_service(%s): %s\n", self, service, gai_strerror(err)); diff --git a/mail/postsrsd/files/patch-srs2.c b/mail/postsrsd/files/patch-srs2.c new file mode 100644 index 000000000000..42f6074ac187 --- /dev/null +++ b/mail/postsrsd/files/patch-srs2.c @@ -0,0 +1,11 @@ +--- srs2.c 2014-01-03 01:01:47.000000000 +0100 ++++ srs2.c.new 2014-06-17 16:13:45.773381667 +0200 +@@ -21,7 +21,7 @@ + #include /* tyepdefs */ + #include /* timeval / timezone struct */ + #include /* memcpy, strcpy, memset */ +-#include ++#include + + #ifdef USE_OPENSSL + #include diff --git a/mail/postsrsd/files/patch-srs2.h b/mail/postsrsd/files/patch-srs2.h new file mode 100644 index 000000000000..2c4d472bc656 --- /dev/null +++ b/mail/postsrsd/files/patch-srs2.h @@ -0,0 +1,10 @@ +--- srs2.h 2014-01-03 01:01:47.000000000 +0100 ++++ srs2.h.new 2014-06-17 16:16:22.880373371 +0200 +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + + #ifndef __BEGIN_DECLS + #define __BEGIN_DECLS diff --git a/mail/postsrsd/files/postsrsd.in b/mail/postsrsd/files/postsrsd.in new file mode 100644 index 000000000000..b479f8c1d9de --- /dev/null +++ b/mail/postsrsd/files/postsrsd.in @@ -0,0 +1,91 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: postsrsd +# REQUIRE: DAEMON +# BEFORE: mail +# KEYWORD: shutdown + +# Define these postsrsd_* variables in one of these files: +# /etc/rc.conf +# /etc/rc.conf.local +# /etc/rc.conf.d/postsrsd +# +# postsrsd_enable (bool): Set to "NO" by default. +# Set it to "YES" to enable dkim-milter +# postsrsd_uid (str): Set username to run postsrsd. +# postsrsd_secret (str): Secret file file. See postsrsd(8) +# postsrsd_domain (str): Local domain name: rewrite to originate from this domain +# postsrsd_flags (str): Flags passed to start command. + +. /etc/rc.subr + +name="postsrsd" +rcvar=postsrsd_enable + +start_precmd="postsrsd_prepcmd" +stop_postcmd="postsrsd_postcmd" +command="%%PREFIX%%/sbin/postsrsd" +_piddir="/var/run/postsrsd" +pidfile="${_piddir}/${name}.pid" + +load_rc_config $name + +# +# DO NOT CHANGE THESE DEFAULT VALUES HERE +# +: ${postsrsd_enable="NO"} +: ${postsrsd_domain=`/bin/hostname`} +: ${postsrsd_uid="mailnull"} +: ${postsrsd_secret="%%PREFIX%%/etc/postsrsd.secret"} +: ${postsrsd_forward_port="10001"} +: ${postsrsd_reverse_port="10002"} +: ${postsrsd_idle_timeout="1800"} +: ${postsrsd_exclude_domains=""} + +# Options other than above can be set with $postsrsd_flags. +# see postsrsd documentation for detail. + +if [ "x${postsrsd_uid}" != "x" ];then + _uid_prefix="-u" +fi +if [ "x${postsrsd_domain}" != "x" ];then + postsrsd_domain="-d ${postsrsd_domain}" +fi +if [ "x${postsrsd_secret}" != "x" ];then + postsrsd_secret="-s ${postsrsd_secret}" +fi +if [ "x${postsrsd_forward_port}" != "x" ];then + postsrsd_forward_port="-f ${postsrsd_forward_port}" +fi +if [ "x${postsrsd_reverse_port}" != "x" ];then + postsrsd_reverse_port="-r ${postsrsd_reverse_port}" +fi +if [ "x${postsrsd_idle_timeout}" != "x" ];then + postsrsd_idle_timeout="-t ${postsrsd_idle_timeout}" +fi +if [ "x${postsrsd_exclude_domains}" != "x" ];then + postsrsd_exclude_domains="-X ${postsrsd_exclude_domains}" +fi + +command_args=" -D ${_uid_prefix} ${postsrsd_uid} -p ${pidfile} ${postsrsd_domain} ${postsrsd_secret} ${postsrsd_forward_port} ${postsrsd_reverse_port} ${postsrsd_idle_timeout} ${postsrsd_exclude_domains} ${postsrsd_flags}" + +postsrsd_prepcmd () +{ + if [ ! -d ${_piddir} ] ; then + mkdir -p ${_piddir} + fi + if [ -n "${postsrsd_uid}" ] ; then + chown ${postsrsd_uid} ${_piddir} + fi +} + +postsrsd_postcmd() +{ + # just if the directory is empty + rmdir ${_piddir} > /dev/null 2>&1 +} + +run_rc_command "$1" diff --git a/mail/postsrsd/pkg-descr b/mail/postsrsd/pkg-descr new file mode 100644 index 000000000000..f4ffddf6a9a7 --- /dev/null +++ b/mail/postsrsd/pkg-descr @@ -0,0 +1,4 @@ +PostSRSd provides the Sender Rewriting Scheme (SRS) via TCP-based lookup +tables for Postfix. SRS is needed if your mail server acts as forwarder. + +WWW: https://github.com/roehling/postsrsd diff --git a/mail/postsrsd/pkg-plist b/mail/postsrsd/pkg-plist new file mode 100644 index 000000000000..9bb5962002b2 --- /dev/null +++ b/mail/postsrsd/pkg-plist @@ -0,0 +1,3 @@ +sbin/postsrsd +man/man8/postsrsd.8.gz +etc/postsrsd.secret