From d8afc76fdf8f10ef578347463dfaf578eabf16ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Wed, 29 May 2024 15:34:04 +0200 Subject: [PATCH] [__opendkim*] address cdist-contrib #32 review --- type/__opendkim/files/opendkim.conf.sh | 6 +++--- type/__opendkim/man.rst | 6 +----- type/__opendkim/manifest | 21 +++++++++------------ type/__opendkim/parameter/optional | 1 - type/__opendkim_genkey/explorer/key-state | 4 +--- type/__opendkim_genkey/man.rst | 2 +- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/type/__opendkim/files/opendkim.conf.sh b/type/__opendkim/files/opendkim.conf.sh index 7e7fab0..237b515 100755 --- a/type/__opendkim/files/opendkim.conf.sh +++ b/type/__opendkim/files/opendkim.conf.sh @@ -3,9 +3,6 @@ echo "# Managed remotely, manual changes will be lost." -# Used for OS-specific configuration. -os=$(cat "${__global:?}/explorer/os") - # Optional chdir(2) if [ "$BASEDIR" ]; then @@ -71,3 +68,6 @@ if [ "$PIDFILE" ]; then printf "PidFile %s\n" "$PIDFILE" fi + +# Custom user configuration, if any (passed via --custom-config): +$CUSTOM_CONFIG diff --git a/type/__opendkim/man.rst b/type/__opendkim/man.rst index 765e7d3..4b37558 100644 --- a/type/__opendkim/man.rst +++ b/type/__opendkim/man.rst @@ -14,7 +14,7 @@ installation and basic configuration of an instance of OpenDKIM. Note that this type does not generate or ensure that a key is present: use `cdist-type__opendkim-genkey(7)` for that. -Note that this type is currently only implemented for Debian, Alpine Linux and +Note that this type is currently only implemented for Alpine Linux, Debian and FreeBSD. Please contribute an implementation if you can. @@ -45,10 +45,6 @@ custom-config The string following this parameter is appended as-is in the configuration, to enable more complex configurations. -pidfile - Specifies the path to a file that should be created at process start - containing the process ID. - BOOLEAN PARAMETERS ------------------ syslog diff --git a/type/__opendkim/manifest b/type/__opendkim/manifest index 9565493..445139d 100755 --- a/type/__opendkim/manifest +++ b/type/__opendkim/manifest @@ -77,9 +77,10 @@ if [ -f "${__object:?}/parameter/userid" ]; then export USERID fi -if [ -f "${__object:?}/parameter/pidfile" ]; then - PIDFILE="$(cat "${__object:?}/parameter/pidfile")" - export PIDFILE +# Custom configuration handling. +if [ -f "${__object:?}/parameter/custom-config" ]; then + CUSTOM_CONFIG="$(cat "${__object:?}/parameter/custom-config")" + export CUSTOM_CONFIG fi # Debian: set configuration specific to debian packaging if no explicit value @@ -89,15 +90,17 @@ if [ "$os" = "debian" ]; then # using a local socket with MTAs that access the socket as a non-privileged # user (for example, Postfix). You may need to add user "postfix" to group # "opendkim" in that case. - if [ -z "$USERID" ]; then + + # We only set UserID if it is not provided via custom configuration. + if [ -z "$USERID" ] && echo "$CUSTOM_CONFIG" | grep -Eq '^UserID\s+\w+$'; then export USERID="opendkim" fi - if [ -z "$UMASK" ]; then + if [ -z "$UMASK" ] && echo "$CUSTOM_CONFIG" | grep -Eq '^UMask\s+\w+$'; then export UMASK="007" fi - if [ -z "$PIDFILE" ]; then + if ! echo "$CUSTOM_CONFIG" | grep -Eq '^PidFile\s+\w+$'; then export PIDFILE="/run/opendkim/opendkim.pid" fi fi @@ -113,12 +116,6 @@ mkdir -p "${__object:?}/files" "${__type:?}/files/opendkim.conf.sh" >"$source_file" -# Add user custom config -if [ -f "${__object:?}/parameter/custom-config" ]; then - echo "# Custom user config" >>"$source_file" - cat "${__object:?}/parameter/custom-config" >>"$source_file" -fi - require="__package/opendkim" __file "$target_file" \ --source "$source_file" --mode 0644 diff --git a/type/__opendkim/parameter/optional b/type/__opendkim/parameter/optional index 3ad5a9b..af59609 100644 --- a/type/__opendkim/parameter/optional +++ b/type/__opendkim/parameter/optional @@ -4,4 +4,3 @@ subdomains umask userid custom-config -pidfile diff --git a/type/__opendkim_genkey/explorer/key-state b/type/__opendkim_genkey/explorer/key-state index 5c6724d..906abc0 100755 --- a/type/__opendkim_genkey/explorer/key-state +++ b/type/__opendkim_genkey/explorer/key-state @@ -1,13 +1,11 @@ #!/bin/sh -e os=$( "${__explorer:?}/os" ) + case "$os" in 'debian') DIRECTORY="/etc/dkimkeys/" ;; -'alpine'|'freebsd') - DIRECTORY="/var/db/dkim/" -;; *) DIRECTORY="/var/db/dkim/" ;; diff --git a/type/__opendkim_genkey/man.rst b/type/__opendkim_genkey/man.rst index 5a9305f..08a0f27 100644 --- a/type/__opendkim_genkey/man.rst +++ b/type/__opendkim_genkey/man.rst @@ -22,7 +22,7 @@ associating any given `sigkey` values to this key. Take into account that if you use this type without the `--domain` and `--selector` parameters, the `$__object_id` must be in form `$domain/$selector`. -Currently, this type is only implemented for Debian, Alpine Linux and FreeBSD. +Currently, this type is only implemented for Alpine Linux, Debian and FreeBSD. Please contribute an implementation if you can. NOTE: the name of the key file under `--directory` will default to