Skip to content

Commit 4b46b1d

Browse files
committed
Fix #180: Rename authentication methods
This is a really dirt fix for issue #180. It will replace "well-known" enumerated plugin names with SASL mechanism names. While this is more of a "bandage" than the actual proper fix, I have currently found no better ways to do it. Most likely this issue will rise up again with another SASL plugin and we will deal with it then. At this stage, it should cover most of the use cases transparently.
1 parent a26f85d commit 4b46b1d

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

scripts/common-run.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ postfix_setup_xoauth2_post_setup() {
406406
do_postconf -e 'smtp_tls_session_cache_database=lmdb:${data_directory}/smtp_scache'
407407
else
408408
# So, this fix should solve the issue #106, when password in the 'smtp_sasl_password_maps' was
409-
# read as file instead of the actual password. It turns out that the culprit is the sasl-xoauth2
409+
# read as file instead of the actual password. It turns out that the culprit is the sasl-xoauth2
410410
# plugin, which expect the filename in place of the password. And as the plugin injects itself
411411
# automatically in the list of SASL login mechanisms, it tries to read the password as a file and --
412412
# naturally -- fails.
@@ -418,7 +418,7 @@ postfix_setup_xoauth2_post_setup() {
418418
# Ubuntu/Debian have renamed pluginviewer to saslpluginviewer so this fails with those distros.
419419
plugin_viewer="saslpluginviewer"
420420
fi
421-
other_plugins="$(${plugin_viewer} -c | grep Plugin | cut -d\ -f2 | cut -c2- | rev | cut -c2- | rev | grep -v EXTERNAL | grep -v sasl-xoauth2 | tr '\n' ',' | rev | cut -c2- | rev)"
421+
other_plugins="$(${plugin_viewer} -c | grep Plugin | cut -d\ -f2 | cut -c2- | rev | cut -c2- | rev | grep -v EXTERNAL | grep -v sasl-xoauth2 | tr '\n' ',' | rev | cut -c2- | rev | convert_plugin_names_to_filter_names)"
422422
do_postconf -e "smtp_sasl_mechanism_filter=${other_plugins}"
423423
fi
424424
}
@@ -472,7 +472,7 @@ EOF
472472
)"
473473
fi
474474

475-
debug 'Sasldb configured'
475+
debug 'Sasldb configured'
476476
fi
477477
}
478478

scripts/common.sh

+57
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,61 @@ zone_info_dir() {
227227
return
228228
}
229229

230+
###################################################################
231+
# Remove leading and trailing whitespace from string
232+
###################################################################
233+
trim() {
234+
local var
235+
IFS='' read -d -r var
236+
#var="$(<&1)"
237+
# remove leading whitespace characters
238+
var="${var#"${var%%[![:space:]]*}"}"
239+
# remove trailing whitespace characters
240+
var="${var%"${var##*[![:space:]]}"}"
241+
printf '%s' "${var}"
242+
}
243+
244+
###################################################################
245+
# Potential fix for #180. Plugin names do not neccessarily match
246+
# filter names.
247+
#
248+
# This is an utility method which converts SASL plugin names into
249+
# filter names. There's no reliable way to guess this, so the names
250+
# have been hardcoded here.
251+
#
252+
# INPUT:
253+
# The method expects as an input a list of plugin names, comma
254+
# separated.
255+
#
256+
# OUTPUT:
257+
# The list of plugin names, comma separated.
258+
###################################################################
259+
convert_plugin_names_to_filter_names() {
260+
local line first value lowercase
261+
while IFS=$',' read -ra line; do
262+
for value in "${line[@]}"; do
263+
value="$(printf '%s' "${value}" | trim)"
264+
if [[ -z "${value}" ]]; then
265+
continue;
266+
fi
267+
268+
if [[ -z "${first}" ]]; then
269+
first="0"
270+
else
271+
printf '%s' ','
272+
fi
273+
274+
lowercase="${value,,}"
275+
276+
if [[ "${lowercase}" == "digestmd5" ]]; then
277+
printf '%s' 'DIGEST-MD5'
278+
elif [[ "${lowercase}" == "crammd5" ]]; then
279+
printf '%s' 'CRAM-MD5'
280+
else
281+
printf '%s' "${value}"
282+
fi
283+
done
284+
done
285+
}
286+
230287
export reset green yellow orange orange_emphasis lightblue red gray emphasis underline
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bats
2+
3+
load /code/scripts/common.sh
4+
5+
assert_equals() {
6+
local expected="$1"
7+
local actual="$2"
8+
if [[ "${expected}" != "${actual}" ]]; then
9+
echo "Expected: \"${expected}\". Got: \"${actual}\"." >&2
10+
exit 1
11+
fi
12+
}
13+
14+
@test "check if trim works properly" {
15+
assert_equals "bar" "$(echo "bar" | trim)"
16+
assert_equals "foo bar" "$(echo "foo bar" | trim)"
17+
assert_equals "foo bar" "$(echo " foo bar" | trim)"
18+
assert_equals "foo bar" "$(echo "foo bar " | trim)"
19+
assert_equals "foo bar" "$(echo " foo bar " | trim)"
20+
assert_equals "foo bar" "$(printf '%s' " foo bar" | trim)"
21+
assert_equals "foo bar" "$(printf '%s' $'\t\tfoo bar\r\n' | trim)"
22+
assert_equals "foo bar" "$(printf '%s' $' foo bar\r\n' | trim)"
23+
}
24+
25+
@test "check if convert_plugin_names_to_filter_names works" {
26+
assert_equals "foo" "$(echo "foo" | convert_plugin_names_to_filter_names)"
27+
assert_equals "foo,bar" "$(echo "foo,bar" | convert_plugin_names_to_filter_names)"
28+
assert_equals "foo,bar,baz" "$(echo "foo, bar, baz," | convert_plugin_names_to_filter_names)"
29+
assert_equals "DIGEST-MD5" "$(echo "digestmd5" | convert_plugin_names_to_filter_names)"
30+
assert_equals "CRAM-MD5" "$(echo "crammd5" | convert_plugin_names_to_filter_names)"
31+
assert_equals "DIGEST-MD5,ntlm,CRAM-MD5,plain,login,anonymous" "$(echo "digestmd5,ntlm,crammd5,plain,login,anonymous" | convert_plugin_names_to_filter_names)"
32+
assert_equals "DIGEST-MD5,ntlm,CRAM-MD5,plain,login,anonymous" "$(echo "DIGESTMD5,ntlm,CRAMMD5,plain,login,anonymous" | convert_plugin_names_to_filter_names)"
33+
34+
}
35+

unit-tests/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
ARG ALPINE_VERSION=latest
1+
# Changed this to specific alpine version so it doesn't get refreshed / pulled from Docker hub every time.
2+
ARG ALPINE_VERSION=3.19
23
FROM alpine:${ALPINE_VERSION} as build
34

45
ARG SASL_XOAUTH2_REPO_URL=https://github.com/tarickb/sasl-xoauth2.git

0 commit comments

Comments
 (0)