Index: mail/opendkim/Makefile =================================================================== --- mail/opendkim/Makefile +++ mail/opendkim/Makefile @@ -1,9 +1,8 @@ # Created by: Hirohisa Yamaguchi -# $FreeBSD$ PORTNAME= opendkim PORTVERSION= 2.10.3 -PORTREVISION= 11 +PORTREVISION= 12 CATEGORIES= mail security MASTER_SITES= SF/${PORTNAME} \ SF/${PORTNAME}/Previous%20Releases \ Index: mail/opendkim/files/milter-opendkim.in =================================================================== --- mail/opendkim/files/milter-opendkim.in +++ mail/opendkim/files/milter-opendkim.in @@ -1,13 +1,10 @@ #!/bin/sh # -# $FreeBSD$ -# - # PROVIDE: milter-opendkim # REQUIRE: DAEMON # BEFORE: mail # KEYWORD: shutdown - +# # Define these milteropendkim_* variables in one of these files: # /etc/rc.conf # /etc/rc.conf.local @@ -40,37 +37,67 @@ name="milteropendkim" rcvar=milteropendkim_enable -extra_commands="reload" -start_precmd="dkim_prepcmd" -start_postcmd="dkim_start_postcmd" -stop_postcmd="dkim_postcmd" -command="%%PREFIX%%/sbin/opendkim" -_piddir="/var/run/milteropendkim" -pidfile="${_piddir}/pid" -sig_reload="USR1" - load_rc_config $name # # DO NOT CHANGE THESE DEFAULT VALUES HERE # -: ${milteropendkim_enable="NO"} -: ${milteropendkim_uid="mailnull"} -: ${milteropendkim_gid="mailnull"} -: ${milteropendkim_cfgfile="%%PREFIX%%/etc/mail/opendkim.conf"} +: ${milteropendkim_enable:="NO"} +: ${milteropendkim_uid:="mailnull"} +: ${milteropendkim_gid:="mailnull"} +: ${milteropendkim_cfgfile:="%%PREFIX%%/etc/mail/opendkim.conf"} : ${milteropendkim_socket_perms="0755"} # Options other than above can be set with $milteropendkim_flags. # see dkim-milter documentation for detail. +extra_commands="reload" +start_precmd="dkim_prepcmd" +start_postcmd="dkim_start_postcmd" +stop_postcmd="dkim_cleansockets" +command="%%PREFIX%%/sbin/opendkim" +sig_reload="USR1" + +dkim_cleansockets() +{ + rm -f "${milteropendkim_socket##local:}" "${milteropendkim_socket##unix:}" +} + +dkim_get_pidfile() +{ + if get_pidfile_from_conf PidFile ${milteropendkim_cfgfile#-x }; then + pidfile="$_pidfile_from_conf" + else + pidfile="/var/run/milteropendkim/${profile:-pid}" + fi +} + +dkim_prepcmd() +{ + dkim_cleansockets + dkim_get_pidfile + install -d -o ${milteropendkim_uid%:*} -g $milteropendkim_gid \ + -m ${milteropendkim_socket_perms} ${pidfile%/*} +} + +dkim_start_postcmd() +{ + if [ -n "${milteropendkim_socket}" ] ; then + # postcmd is executed too fast and socket is not created before checking... + sleep 1 + chmod -f ${milteropendkim_socket_perms} \ + ${milteropendkim_socket##local:} \ + ${milteropendkim_socket##unix:} + fi +} + if [ -n "$2" ]; then profile="$2" - if [ "x${milteropendkim_profiles}" != "x" ]; then - pidfile="${_piddir}/${profile}.pid" + if [ -n "${milteropendkim_profiles}" ]; then eval milteropendkim_enable="\${milteropendkim_${profile}_enable:-${milteropendkim_enable}}" eval milteropendkim_socket="\${milteropendkim_${profile}_socket:-}" eval milteropendkim_socket_perms="\${milteropendkim_${profile}_socket_perms:-}" - if [ "x${milteropendkim_socket}" = "x" ];then + if [ -z "${milteropendkim_socket}" ];then echo "You must define a socket (milteropendkim_${profile}_socket)" exit 1 fi @@ -85,122 +112,82 @@ else milteropendkim_cfgfile="" fi - if [ "x${milteropendkim_socket}" != "x" ];then + if [ -n "${milteropendkim_socket}" ]; then _socket_prefix="-p" fi - if [ "x${milteropendkim_uid}" != "x" ];then + if [ -n "${milteropendkim_uid}" ]; then _uid_prefix="-u" - if [ "x${milteropendkim_gid}" != "x" ];then + if [ -n "${milteropendkim_gid}" ]; then milteropendkim_uid=${milteropendkim_uid}:${milteropendkim_gid} fi fi - if [ "x${milteropendkim_domain}" != "x" ];then + if [ -n "${milteropendkim_domain}" ]; then milteropendkim_domain="-d ${milteropendkim_domain}" fi - if [ "x${milteropendkim_key}" != "x" ];then + if [ -n "${milteropendkim_key}" ]; then milteropendkim_key="-k ${milteropendkim_key}" fi - if [ "x${milteropendkim_selector}" != "x" ];then + if [ -n "${milteropendkim_selector}" ]; then milteropendkim_selector="-s ${milteropendkim_selector}" fi - if [ "x${milteropendkim_alg}" != "x" ];then + if [ -n "${milteropendkim_alg}" ]; then milteropendkim_alg="-S ${milteropendkim_alg}" fi + dkim_get_pidfile command_args="-l ${_socket_prefix} ${milteropendkim_socket} ${_uid_prefix} ${milteropendkim_uid} -P ${pidfile} ${milteropendkim_cfgfile} ${milteropendkim_domain} ${milteropendkim_key} ${milteropendkim_selector} ${milteropendkim_alg}" else echo "$0: extra argument ignored" fi else - if [ "x${milteropendkim_profiles}" != "x" -a "x$1" != "x" ]; then - if [ "x$1" != "xrestart" ]; then + if [ -n "${milteropendkim_profiles}" -a -n "$1" ]; then + case "$1" in + restart) + restart_precmd="" + ;; + *) for profile in ${milteropendkim_profiles}; do echo "===> milteropendkim profile: ${profile}" %%PREFIX%%/etc/rc.d/milter-opendkim $1 ${profile} retcode="$?" - if [ "0${retcode}" -ne 0 ]; then - failed="${profile} (${retcode}) ${failed:-}" + if [ "${retcode}" -ne 0 ]; then + failed="${profile} (${retcode}) ${failed}" else - success="${profile} ${success:-}" + success="${profile} ${success}" fi done exit 0 - else - restart_precmd="" - fi + ;; + esac else - if [ -f "${milteropendkim_cfgfile}" ];then + if [ -f "${milteropendkim_cfgfile}" ]; then milteropendkim_cfgfile="-x ${milteropendkim_cfgfile}" else milteropendkim_cfgfile="" fi - if [ "x${milteropendkim_socket}" != "x" ];then + if [ -n "${milteropendkim_socket}" ]; then _socket_prefix="-p" fi - if [ "x${milteropendkim_uid}" != "x" ];then + if [ -n "${milteropendkim_uid}" ]; then _uid_prefix="-u" - if [ "x${milteropendkim_gid}" != "x" ];then + if [ -n "${milteropendkim_gid}" ];then milteropendkim_uid=${milteropendkim_uid}:${milteropendkim_gid} fi fi - if [ "x${milteropendkim_domain}" != "x" ];then + if [ -n "${milteropendkim_domain}" ];then milteropendkim_domain="-d ${milteropendkim_domain}" fi - if [ "x${milteropendkim_key}" != "x" ];then + if [ -n "${milteropendkim_key}" ];then milteropendkim_key="-k ${milteropendkim_key}" fi - if [ "x${milteropendkim_selector}" != "x" ];then + if [ -n "${milteropendkim_selector}" ];then milteropendkim_selector="-s ${milteropendkim_selector}" fi - if [ "x${milteropendkim_alg}" != "x" ];then + if [ -n "${milteropendkim_alg}" ];then milteropendkim_alg="-S ${milteropendkim_alg}" fi + dkim_get_pidfile command_args="-l ${_socket_prefix} ${milteropendkim_socket} ${_uid_prefix} ${milteropendkim_uid} -P ${pidfile} ${milteropendkim_cfgfile} ${milteropendkim_domain} ${milteropendkim_key} ${milteropendkim_selector} ${milteropendkim_alg}" fi fi -dkim_prepcmd () -{ - if [ -S ${milteropendkim_socket##local:} ] ; then - rm -f ${milteropendkim_socket##local:} - elif [ -S ${milteropendkim_socket##unix:} ] ; then - rm -f ${milteropendkim_socket##unix:} - fi - if [ ! -d ${_piddir} ] ; then - mkdir -p ${_piddir} - fi - if [ -n "${milteropendkim_uid}" ] ; then - chown ${milteropendkim_uid} ${_piddir} - fi - if [ -n "${milteropendkim_gid}" ] ; then - chgrp ${milteropendkim_gid} ${_piddir} - fi - chmod ${milteropendkim_socket_perms} ${_piddir} -} - -dkim_start_postcmd () -{ - if [ "x${milteropendkim_socket}" != "x" ] ; then - # postcmd is executed too fast and socket is not created before checking... - sleep 1 - if [ -S ${milteropendkim_socket##local:} ] ; then - chmod ${milteropendkim_socket_perms} ${milteropendkim_socket##local:} - elif [ -S ${milteropendkim_socket##unix:} ] ; then - chmod ${milteropendkim_socket_perms} ${milteropendkim_socket##unix:} - fi - fi -} - -dkim_postcmd() -{ - if [ "x${milteropendkim_socket}" != "x" ] ; then - if [ -S ${milteropendkim_socket##local:} ] ; then - rm -f ${milteropendkim_socket##local:} - elif [ -S ${milteropendkim_socket##unix:} ] ; then - rm -f ${milteropendkim_socket##unix:} - fi - fi - # just if the directory is empty - rmdir ${_piddir} > /dev/null 2>&1 -} - run_rc_command "$1"