From 43d7648168b1a452ab5460415ac9b36f0df8843f Mon Sep 17 00:00:00 2001 From: Richard T Bonhomme Date: Sun, 20 Nov 2022 13:32:49 +0000 Subject: [PATCH] Option --subca-len - Allow value to be 0 (zero) Squashed commit of the following: commit 3a5e7539db93b88a9db8b2fb9fc6520870f337ac Merge: 1a46e32 3d9fa5e Author: Richard T Bonhomme Date: Sun Nov 20 13:31:57 2022 +0000 Merge branch 'path-len-zero' of ssh://github.com/TinCanTech/easy-rsa into TinCanTech-path-len-zero Signed-off-by: Richard T Bonhomme commit 3d9fa5e955f0ed517c63bb8c35e6fde180af8b6a Author: Richard T Bonhomme Date: Sun Nov 20 00:30:59 2022 +0000 Option --subca-len - Allow value to be 0 (zero) For an intermediate CA certificate, Path length of zero (0) is valid. Therefore, allow the character '0' as a valid numeric input for EasyRSA option --subca-len= This method allows character zero (0) ONLY, as a numeric input for options which accept zero as a value. Add comment: # Reset per pass flags Signed-off-by: Richard T Bonhomme Signed-off-by: Richard T Bonhomme --- easyrsa3/easyrsa | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index f9a28df..f9e4850 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -4986,8 +4986,10 @@ unset -v die_error_exit easyrsa_error_exit \ # Parse options while :; do + # Reset per pass flags + unset -v opt val is_empty empty_ok number_only zero_allowed + # Separate option from value: - unset -v opt val is_empty empty_ok number_only opt="${1%%=*}" val="${1#*=}" @@ -5111,6 +5113,7 @@ while :; do ;; --subca-len) number_only=1 + zero_allowed=1 export EASYRSA_SUBCA_LEN="$val" ;; --vars) @@ -5136,19 +5139,24 @@ subjectAltName = $val" break esac - # fatal error when a number is expected but not provided - if [ "$number_only" ]; then - case "$val" in - (*[!1234567890]*|0*) - die "$opt - Number expected: '$val'" - esac - fi - # fatal error when no value was provided if [ "$is_empty" ]; then [ "$empty_ok" ] || die "Missing value to option: $opt" fi + # fatal error when a number is expected but not provided + if [ "$number_only" ]; then + case "$val" in + (0) + # Allow zero only + [ "$zero_allowed" ] || \ + die "$opt - Number expected: '$val'" + ;; + (*[!1234567890]*|0*) + die "$opt - Number expected: '$val'" + esac + fi + shift done