From ab7c4804fb8e36cfda1a4b9048fb2c6cd1d78ff5 Mon Sep 17 00:00:00 2001 From: Richard T Bonhomme Date: Wed, 26 Oct 2022 21:08:54 +0100 Subject: [PATCH] Minor refactor of secure_session() and easyrsa_mktemp() Squashed commit of the following: commit b93c8e60649d835b66fc4ab2c1d6050e6b1ca231 Merge: 17cbf07 130c161 Author: Richard T Bonhomme 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 commit 130c161746d8e7885c7c3a86b8d29d28476b3890 Author: Richard T Bonhomme 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 Signed-off-by: Richard T Bonhomme --- easyrsa3/easyrsa | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index a0e5652..24dc06b 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -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()