[type/__dma_auth] Drop --server parameter

Currently, dma does not differentiate between login users on the SMTP server.
It will pick whatever entry it finds first
(https://github.com/corecode/dma/blob/v0.13/net.c#L531).
As a result, the --server parameter only adds confusion.
This commit is contained in:
Dennis Camera 2020-09-28 10:59:13 +02:00
parent 49d39eaee5
commit 445bc75deb
4 changed files with 26 additions and 34 deletions

View file

@ -17,25 +17,18 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
# This explorer looks for a line matching the login and server parameters
# This explorer looks for a line matching the server parameter
# in dma's auth.conf and reports:
# present: a line matching login + host + password exists
# absent: no line matching login + host exists
# different_password: a line exists but with a different pasword
# multiple: multiple lines matching login + host exist
# (should never happen)
# different_login: a line exists but with a different login user
# different_password: a line exists but with a different password
# multiple: multiple lines matching host exist (should not happen)
auth_conf=$("${__type_explorer}/auth_conf")
test -r "${auth_conf}" || exit 0
if test -f "${__object}/parameter/server"
then
server=$(cat "${__object}/parameter/server")
else
server=$__object_id
fi
awk -F'\n' -v server="${server}" '
awk -F'\n' '
function getvalue(path) {
# Reads the first line of the file located at path and returns it.
getline < path
@ -49,8 +42,7 @@ BEGIN {
parameter_dir = ENVIRON["__object"] "/parameter/"
# Read the parameters of this object
host_param = getvalue(parameter_dir "server")
if (!host_param) host_param = ENVIRON["__object_id"]
host_param = ENVIRON["__object_id"]
login_param = getvalue(parameter_dir "login")
passwd_param = getvalue(parameter_dir "password")
@ -78,10 +70,15 @@ BEGIN {
}
}
host == host_param && login == login_param {
host == host_param {
# a match…
if (state == "absent") {
state = ((passwd == passwd_param) ? "present" : "different_password")
if (login != login_param)
state = "different_login"
else if (passwd != passwd_param)
state = "different_password"
else
state = "present"
} else {
# report "multiple" to that the type can remove the duplicates.
state = "multiple"

View file

@ -21,14 +21,16 @@
state_is=$(cat "${__object}/explorer/state")
state_should=$(cat "${__object}/parameter/state")
if test -f "${__object}/parameter/server"
then
server=$(cat "${__object}/parameter/server")
else
server=$__object_id
fi
login=$(cat "${__object}/parameter/login")
auth_conf=$(cat "${__object}/explorer/auth_conf")
test -n "${auth_conf}" || {
echo 'Cannot determine path of dma auth.conf' >&2
exit 1
}
if test "${state_is}" = "${state_should}"
then
# state is as it should
@ -61,13 +63,6 @@ in
;;
esac
auth_conf=$(cat "${__object}/explorer/auth_conf")
test -n "${auth_conf}" || {
echo 'Cannot determine path of dma auth.conf' >&2
exit 1
}
cat <<EOF
auth_conf='${auth_conf}'
@ -94,8 +89,7 @@ BEGIN {
parameter_dir = ENVIRON["__object"] "/parameter/"
host_param = getvalue(parameter_dir "server")
if (!host_param) host_param = ENVIRON["__object_id"]
host_param = ENVIRON["__object_id"]
login_param = getvalue(parameter_dir "login")
passwd_param = getvalue(parameter_dir "password")
}

View file

@ -11,6 +11,10 @@ DESCRIPTION
This cdist type allows you to set up credentials to log in to remote SMTP
servers.
NB: dma currently (v0.13) does not differentiate between users on a host.
It will use whatever user it finds in the ``auth.conf`` first.
Thus, this type will use the ``__object_id`` as the host specifier.
REQUIRED PARAMETERS
-------------------
@ -22,8 +26,6 @@ password
OPTIONAL PARAMETERS
-------------------
server
The SMTP server on which the login is valid. Defaults to `__object_id`.
state
Either `present` or `absent`. Defaults to `present`.

View file

@ -1,2 +1 @@
server
state