Skip to content

Commit

Permalink
write_legacy_file_v2(): Correct over-write logic
Browse files Browse the repository at this point in the history
If 'overwrite' is not enabled AND the target exists then skip this
target, instead of erroring out. Include EASYRSA_DEBUG output.

Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Dec 22, 2024
1 parent 939e456 commit ee363c6
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions easyrsa3/easyrsa
Original file line number Diff line number Diff line change
Expand Up @@ -4990,7 +4990,7 @@ write_legacy_file_v2() {
write_type="$1"
write_file="$2"
write_over=
[ "$3" = overwrite ] && write_over="$3"
[ "$3" = overwrite ] && write_over=1

# Select by type
case "$write_type" in
Expand Down Expand Up @@ -5022,29 +5022,40 @@ write_legacy_file_v2() {
if [ -f "$write_file" ]; then
# if this is a temp file then enable auto-overwrite
path="${write_file%%/temp.*}"
if [ "${secured_session}" = "$path" ]; then
if [ "$path" = "${secured_session}" ]; then
verbose ": write_legacy_file_v2 - temp-file ACCEPTED"
write_over=overwrite
write_over=1
else
# target is not a temp-file, overwrite not changed
verbose ": Target is not a temp-file: $write_file"
fi
else
# enable overwrite, "there is no file" to over write
verbose ": Missing input file: $write_file"
write_over=overwrite
verbose ": Create new file: $write_file"
fi
else
verbose ": No target file - output to stdout"
fi

# write legacy data stream to stdout or file
if [ "$write_file" ]; then
if [ -f "$write_file" ]; then
if [ "$write_over" ]; then
verbose ": write_legacy_file_v2 - over-write ENABLED"
create_legacy_stream "$write_type" > "$write_file" || \
die "write failed"
[ "$EASYRSA_DEBUG" ] && print \
"### write OVERWRITE: $write_type to $write_file"
else
user_error "write: Over-write refused for existing file!"
# Preserve existing file and continue
verbose "write_legacy_file_v2 - over-write DISABLED "
[ "$EASYRSA_DEBUG" ] && print \
"### write PRESERVE existing: $write_file"
fi
elif [ "$write_file" ]; then
verbose ": write_legacy_file_v2 - over-write DISABLED"
create_legacy_stream "$write_type" > "$write_file" || \
die "write failed"
[ "$EASYRSA_DEBUG" ] && print \
"### write NEWFILE: $write_type to $write_file"
else
# write stream to stdout ONLY
create_legacy_stream "$write_type"
Expand Down

0 comments on commit ee363c6

Please sign in to comment.