Blame SOURCES/bz1815013-redis-parse-password-correctly-based-on-version.patch

bcdf71
From 2270c5d6aaf8b3b6d663d413a8e7193a493cfdc5 Mon Sep 17 00:00:00 2001
bcdf71
From: Konstantin Pokotilenko <pokotilenko@mail.ru>
bcdf71
Date: Tue, 24 Sep 2019 17:26:11 +0300
bcdf71
Subject: [PATCH 1/2] Consider redis-cli features to choose optimal password
bcdf71
 passing method and warning filtering workaround
bcdf71
bcdf71
---
bcdf71
 heartbeat/redis.in | 60 +++++++++++++++++++++++++++++++++++++++++++---
bcdf71
 1 file changed, 57 insertions(+), 3 deletions(-)
bcdf71
bcdf71
diff --git a/heartbeat/redis.in b/heartbeat/redis.in
bcdf71
index ec7186d8b..409961d0b 100644
bcdf71
--- a/heartbeat/redis.in
bcdf71
+++ b/heartbeat/redis.in
bcdf71
@@ -237,6 +237,51 @@ CRM_ATTR_REPL_INFO="${HA_SBIN_DIR}/crm_attribute --type crm_config --name ${INST
bcdf71
 MASTER_HOST=""
bcdf71
 MASTER_ACTIVE_CACHED=""
bcdf71
 MASTER_ACTIVE=""
bcdf71
+CLI_HAVE_AUTH_WARNING=0
bcdf71
+CLI_HAVE_ARG_NO_AUTH_WARNING=0
bcdf71
+CLI_HAVE_ENV_AUTH=0
bcdf71
+
bcdf71
+cmp_redis_version()
bcdf71
+{
bcdf71
+
bcdf71
+        if [ "$1" == "$2" ]; then
bcdf71
+                return 1
bcdf71
+        elif [ $(echo -e "$1\n$2" | sort -V | head -1) == "$1" ]; then
bcdf71
+                return 0
bcdf71
+        else
bcdf71
+                return 2
bcdf71
+        fi
bcdf71
+}
bcdf71
+
bcdf71
+redis_cli_features()
bcdf71
+{
bcdf71
+
bcdf71
+        CLI_VER=$(redis-cli --version | tr " " "\n" | tail -1)
bcdf71
+        # Starting with 4.0.10 there is a warning on stderr when using a pass
bcdf71
+        # Starting with 5.0.0 there is an argument to silence the warning: --no-auth-warning
bcdf71
+        # Starting with 5.0.3 there is an option to use REDISCLI_AUTH evironment variable for password, no warning in this case
bcdf71
+
bcdf71
+        cmp_redis_version $CLI_VER 5.0.3
bcdf71
+        res=$?
bcdf71
+        echo 5.0.3: $res
bcdf71
+        if [[ res -ge 1 ]]; then
bcdf71
+                CLI_HAVE_ENV_AUTH=1
bcdf71
+        fi
bcdf71
+
bcdf71
+        cmp_redis_version $CLI_VER 5.0.0
bcdf71
+        res=$?
bcdf71
+        echo 5.0.0: $res
bcdf71
+        if [[ res -ge 1 ]]; then
bcdf71
+                CLI_HAVE_ARG_NO_AUTH_WARNING=1
bcdf71
+        fi
bcdf71
+
bcdf71
+        cmp_redis_version $CLI_VER 4.0.10
bcdf71
+        res=$?
bcdf71
+        echo 4.0.10: $res
bcdf71
+        if [[ res -ge 1 ]]; then
bcdf71
+                CLI_HAVE_AUTH_WARNING=1
bcdf71
+        fi
bcdf71
+}
bcdf71
 
bcdf71
 master_is_active()
bcdf71
 {
bcdf71
@@ -315,9 +360,16 @@ set_score()
bcdf71
 redis_client() {
bcdf71
 	ocf_log debug "redis_client: '$REDIS_CLIENT' -s '$REDIS_SOCKET' $*"
bcdf71
 	if [ -n "$clientpasswd" ]; then
bcdf71
-		# Starting with 4.0.10 there is a warning on stderr when using a pass
bcdf71
-		# Once we stop supporting versions < 5.0.0 we can add --no-auth-warning here
bcdf71
-		("$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" 2>&1 >&3 3>&- | grep -v "Using a password" >&2 3>&-) 3>&1 | sed 's/\r//'
bcdf71
+		# Consider redis-cli features to choose optimal password passing method and warning filtering workaround
bcdf71
+		if [[ CLI_HAVE_ENV_AUTH -eq 1 ]]; then
bcdf71
+			REDISCLI_AUTH=$clientpasswd "$REDIS_CLIENT" -s "$REDIS_SOCKET" "$@" | sed 's/\r//'
bcdf71
+		elif [[ CLI_HAVE_ARG_NO_AUTH_WARNING -eq 1 ]]; then
bcdf71
+			"$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" --no-auth-warning | sed 's/\r//'
bcdf71
+		elif [[ CLI_HAVE_AUTH_WARNING -eq 1 ]]; then
bcdf71
+			("$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" 2>&1 >&3 3>&- | grep -v "Using a password" >&2 3>&-) 3>&1 | sed 's/\r//'
bcdf71
+		else
bcdf71
+			"$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" | sed 's/\r//'
bcdf71
+		fi
bcdf71
 	else
bcdf71
 		"$REDIS_CLIENT" -s "$REDIS_SOCKET" "$@" | sed 's/\r//'
bcdf71
 	fi
bcdf71
@@ -686,6 +738,8 @@ if [ -r "$REDIS_CONFIG" ]; then
bcdf71
 	clientpasswd="$(sed -n -e  's/^\s*requirepass\s*\(.*\)\s*$/\1/p' < $REDIS_CONFIG | tail -n 1)"
bcdf71
 fi
bcdf71
 
bcdf71
+redis_cli_features
bcdf71
+
bcdf71
 ocf_log debug "action=${1:-$__OCF_ACTION} notify_type=${OCF_RESKEY_CRM_meta_notify_type} notify_operation=${OCF_RESKEY_CRM_meta_notify_operation} master_host=${OCF_RESKEY_CRM_meta_notify_master_uname} slave_host=${OCF_RESKEY_CRM_meta_notify_slave_uname} promote_host=${OCF_RESKEY_CRM_meta_notify_promote_uname} demote_host=${OCF_RESKEY_CRM_meta_notify_demote_uname}; params: bin=${OCF_RESKEY_bin} client_bin=${OCF_RESKEY_client_bin} config=${OCF_RESKEY_config} user=${OCF_RESKEY_user} rundir=${OCF_RESKEY_rundir} port=${OCF_RESKEY_port}"
bcdf71
 
bcdf71
 case "${1:-$__OCF_ACTION}" in
bcdf71
bcdf71
From 0b9f942a88bfc3ad04938aa5135fad8f8bece69c Mon Sep 17 00:00:00 2001
bcdf71
From: Konstantin Pokotilenko <pokotilenko@mail.ru>
bcdf71
Date: Tue, 24 Sep 2019 18:35:59 +0300
bcdf71
Subject: [PATCH 2/2] use ocf_version_cmp instead of own implementation use
bcdf71
 same method of getting redis-cli version as already used before in file, this
bcdf71
 also uses redis client from variable instead of hardcoded remove debug output
bcdf71
 fix --no-auth-warning argument position
bcdf71
bcdf71
---
bcdf71
 heartbeat/redis.in | 25 +++++--------------------
bcdf71
 1 file changed, 5 insertions(+), 20 deletions(-)
bcdf71
bcdf71
diff --git a/heartbeat/redis.in b/heartbeat/redis.in
bcdf71
index 409961d0b..d722fb12c 100644
bcdf71
--- a/heartbeat/redis.in
bcdf71
+++ b/heartbeat/redis.in
bcdf71
@@ -241,43 +241,28 @@ CLI_HAVE_AUTH_WARNING=0
bcdf71
 CLI_HAVE_ARG_NO_AUTH_WARNING=0
bcdf71
 CLI_HAVE_ENV_AUTH=0
bcdf71
 
bcdf71
-cmp_redis_version()
bcdf71
-{
bcdf71
-
bcdf71
-        if [ "$1" == "$2" ]; then
bcdf71
-                return 1
bcdf71
-        elif [ $(echo -e "$1\n$2" | sort -V | head -1) == "$1" ]; then
bcdf71
-                return 0
bcdf71
-        else
bcdf71
-                return 2
bcdf71
-        fi
bcdf71
-}
bcdf71
-
bcdf71
 redis_cli_features()
bcdf71
 {
bcdf71
 
bcdf71
-        CLI_VER=$(redis-cli --version | tr " " "\n" | tail -1)
bcdf71
+        CLI_VER=$("$REDIS_CLIENT" -v | awk '{print $NF}')
bcdf71
         # Starting with 4.0.10 there is a warning on stderr when using a pass
bcdf71
         # Starting with 5.0.0 there is an argument to silence the warning: --no-auth-warning
bcdf71
         # Starting with 5.0.3 there is an option to use REDISCLI_AUTH evironment variable for password, no warning in this case
bcdf71
 
bcdf71
-        cmp_redis_version $CLI_VER 5.0.3
bcdf71
+        ocf_version_cmp $CLI_VER 5.0.3
bcdf71
         res=$?
bcdf71
-        echo 5.0.3: $res
bcdf71
         if [[ res -ge 1 ]]; then
bcdf71
                 CLI_HAVE_ENV_AUTH=1
bcdf71
         fi
bcdf71
 
bcdf71
-        cmp_redis_version $CLI_VER 5.0.0
bcdf71
+        ocf_version_cmp $CLI_VER 5.0.0
bcdf71
         res=$?
bcdf71
-        echo 5.0.0: $res
bcdf71
         if [[ res -ge 1 ]]; then
bcdf71
                 CLI_HAVE_ARG_NO_AUTH_WARNING=1
bcdf71
         fi
bcdf71
 
bcdf71
-        cmp_redis_version $CLI_VER 4.0.10
bcdf71
+        ocf_version_cmp $CLI_VER 4.0.10
bcdf71
         res=$?
bcdf71
-        echo 4.0.10: $res
bcdf71
         if [[ res -ge 1 ]]; then
bcdf71
                 CLI_HAVE_AUTH_WARNING=1
bcdf71
         fi
bcdf71
@@ -364,7 +349,7 @@ redis_client() {
bcdf71
 		if [[ CLI_HAVE_ENV_AUTH -eq 1 ]]; then
bcdf71
 			REDISCLI_AUTH=$clientpasswd "$REDIS_CLIENT" -s "$REDIS_SOCKET" "$@" | sed 's/\r//'
bcdf71
 		elif [[ CLI_HAVE_ARG_NO_AUTH_WARNING -eq 1 ]]; then
bcdf71
-			"$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" --no-auth-warning | sed 's/\r//'
bcdf71
+			"$REDIS_CLIENT" -s "$REDIS_SOCKET" --no-auth-warning -a "$clientpasswd" "$@" | sed 's/\r//'
bcdf71
 		elif [[ CLI_HAVE_AUTH_WARNING -eq 1 ]]; then
bcdf71
 			("$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" 2>&1 >&3 3>&- | grep -v "Using a password" >&2 3>&-) 3>&1 | sed 's/\r//'
bcdf71
 		else