While adding FreeBSD support to the type I noticed various issues: - We were making sure that the KeyTable and SigningTable were created in __opendkim_genkey, but that was being done with the default cdist permissions (0400) which could result in issues when reloading the service after privilege drop. This is addressed by checking that it exists/creating it in __opendkim (just once, not once per __opendkim_genkey call) with laxer permissions (0444). - In __opendkim, the service was being started after the config file was installed. This is insufficient as OpenDKIM will refuse to start with the generated config if either SigningTable or KeyTable do not exist yet. - __opendkim_genkey had the implicit assumption that the --directory parameter always ended in a slash. This was not documented and error-prone; we are now a bit laxer and add the trailing slash if it is missing. - __opendkim_genkey was not changing permissions for the resulting .txt file. This was not critical for it to function, but it was inconsistent. - As documented in #17, __opendkim allows for a --userid parameter that might cause issues with keys generated by __opendkim_genkey. This issue has not been addressed yet, but I recommend deprecating the --userid parameter.
56 lines
1.8 KiB
Bash
Executable file
56 lines
1.8 KiB
Bash
Executable file
#!/bin/sh -e
|
|
#
|
|
# 2021 Joachim Desroches (joachim.desroches@epfl.ch)
|
|
#
|
|
# This file is part of cdist.
|
|
#
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# cdist is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
# Required parameters
|
|
DOMAIN="$(cat "${__object:?}/parameter/domain")"
|
|
SELECTOR="$(cat "${__object:?}/parameter/selector")"
|
|
|
|
# Optional parameters
|
|
BITS=
|
|
if [ -f "${__object:?}/parameter/bits" ]; then
|
|
BITS="-b $(cat "${__object:?}/parameter/bits")"
|
|
fi
|
|
|
|
DIRECTORY="/var/db/dkim/"
|
|
if [ -f "${__object:?}/parameter/directory" ]; then
|
|
# Be forgiving about a lack of trailing slash
|
|
DIRECTORY="$(sed -E 's!([^/])$!\1/!' < "${__object:?}/parameter/directory")"
|
|
fi
|
|
|
|
# Boolean parameters
|
|
SUBDOMAINS=
|
|
if [ -f "${__object:?}/parameter/no-subdomains" ]; then
|
|
SUBDOMAINS='--nosubdomains'
|
|
fi
|
|
|
|
RESTRICTED='--restrict'
|
|
if [ -f "${__object:?}/parameters/unrestricted" ]; then
|
|
RESTRICTED=
|
|
fi
|
|
|
|
user="$(cat "${__object:?}/user")"
|
|
group="$(cat "${__object:?}/group")"
|
|
|
|
if ! [ -f "${DIRECTORY}${SELECTOR}.private" ]; then
|
|
echo "opendkim-genkey $BITS --domain=$DOMAIN --directory=$DIRECTORY $RESTRICTED --selector=$SELECTOR $SUBDOMAINS"
|
|
echo "chown ${user}:${group} ${DIRECTORY}${SELECTOR}.private"
|
|
# This is usually generated, if it weren't we do not want to fail
|
|
echo "chown ${user}:${group} ${DIRECTORY}${SELECTOR}.txt || true"
|
|
fi
|