Minor refactor of secure_session() and easyrsa_mktemp()

Squashed commit of the following:

commit b93c8e60649d835b66fc4ab2c1d6050e6b1ca231
Merge: 17cbf07 130c161
Author: Richard T Bonhomme <tincantech@protonmail.com>
Date:   Wed Oct 26 21:08:00 2022 +0100

    Merge branch 'easyrsa-mktemp' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-easyrsa-mktemp

    Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>

commit 130c161746d8e7885c7c3a86b8d29d28476b3890
Author: Richard T Bonhomme <tincantech@protonmail.com>
Date:   Wed Oct 26 20:00:56 2022 +0100

    Minor refactor of secure_session() and easyrsa_mktemp()

    Return without error on successful completion of final command.

    Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
This commit is contained in:
Richard T Bonhomme 2022-10-26 21:08:54 +01:00
parent 17cbf07b29
commit ab7c4804fb
No known key found for this signature in database
GPG Key ID: 2D767DB92FB6C246

View File

@ -608,10 +608,8 @@ secure_session() {
"$EASYRSA_OPENSSL" rand -hex 4
)" || die "secure_session - rand '$rand'"
mkdir "${EASYRSA_TEMP_DIR}/${rand}" || continue
EASYRSA_TEMP_DIR_session="${EASYRSA_TEMP_DIR}/${rand}"
#EASYRSA_TEMP_DIR_session_rand="${rand}"
return
mkdir "$EASYRSA_TEMP_DIR_session" && return
done
return 1
} # => secure_session()
@ -619,10 +617,14 @@ secure_session() {
# Create tempfile atomically or fail
easyrsa_mktemp() {
# session directory must exist
if [ "$EASYRSA_TEMP_DIR_session" ] && [ -d "$EASYRSA_TEMP_DIR_session" ]; then
if [ "$EASYRSA_TEMP_DIR_session" ] && \
[ -d "$EASYRSA_TEMP_DIR_session" ]
then
: # ok
else
die "Non-existant temporary session: $EASYRSA_TEMP_DIR_session"
die "\
Non-existant temporary session:
* $EASYRSA_TEMP_DIR_session"
fi
for i in 1 2 3; do
@ -640,8 +642,8 @@ easyrsa_mktemp() {
tempfile="${EASYRSA_TEMP_DIR_session}/temp.$rand"
mv "$shotfile" "$tempfile" || continue
printf '%s\n' "$tempfile" || die "easyrsa_mktemp - write temp"
return
# Print the new temporary file-name for the caller
printf '%s\n' "$tempfile" && return
done
return 1
} # => easyrsa_mktemp()