HADOOP-13030. Handle special characters in passwords in KMS startup script. 
Contributed by Xiao Chen.

(cherry picked from commit 7271e91b791ba277fd2a9b8f870eb9bc4f395566)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/0d4fbf01
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/0d4fbf01
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/0d4fbf01

Branch: refs/heads/branch-2.8
Commit: 0d4fbf01beb6d4ac853f1fd7d74d735c1d0c0561
Parents: bdb0e98
Author: Andrew Wang <[email protected]>
Authored: Wed Apr 27 17:13:50 2016 -0700
Committer: Andrew Wang <[email protected]>
Committed: Wed Apr 27 17:14:00 2016 -0700

----------------------------------------------------------------------
 hadoop-common-project/hadoop-kms/src/main/sbin/kms.sh | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/0d4fbf01/hadoop-common-project/hadoop-kms/src/main/sbin/kms.sh
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-kms/src/main/sbin/kms.sh 
b/hadoop-common-project/hadoop-kms/src/main/sbin/kms.sh
index 2093030..5232068 100644
--- a/hadoop-common-project/hadoop-kms/src/main/sbin/kms.sh
+++ b/hadoop-common-project/hadoop-kms/src/main/sbin/kms.sh
@@ -26,6 +26,14 @@ while [ -h "${PRG}" ]; do
   fi
 done
 
+function hadoop_escape() {
+      # Escape special chars for the later sed which saves the text as xml 
attribute
+      local ret
+      ret=$(sed 's/[\/&]/\\&/g' <<< "$1" | sed 's/&/\&amp;/g' | sed 
's/"/\\\&quot;/g' \
+          | sed "s/'/\\\\\&apos;/g" | sed 's/</\\\&lt;/g' | sed 
's/>/\\\&gt;/g')
+      echo "$ret"
+}
+
 BASEDIR=`dirname ${PRG}`
 BASEDIR=`cd ${BASEDIR}/..;pwd`
 
@@ -76,9 +84,11 @@ fi
 if [ ! "${KMS_SSL_KEYSTORE_PASS}" = "" ] || [ ! "${KMS_SSL_TRUSTSTORE_PASS}" = 
"" ]; then
   # Set a KEYSTORE_PASS if not already set
   KMS_SSL_KEYSTORE_PASS=${KMS_SSL_KEYSTORE_PASS:-password}
+  KMS_SSL_KEYSTORE_PASS_ESCAPED=$(hadoop_escape "$KMS_SSL_KEYSTORE_PASS")
+  KMS_SSL_TRUSTSTORE_PASS_ESCAPED=$(hadoop_escape "$KMS_SSL_TRUSTSTORE_PASS")
   cat ${CATALINA_BASE}/conf/ssl-server.xml.conf \
-    | sed 's/_kms_ssl_keystore_pass_/'${KMS_SSL_KEYSTORE_PASS}'/g' \
-    | sed 's/_kms_ssl_truststore_pass_/'${KMS_SSL_TRUSTSTORE_PASS}'/g' > 
${CATALINA_BASE}/conf/ssl-server.xml
+    | sed 
's/"_kms_ssl_keystore_pass_"/'"\"${KMS_SSL_KEYSTORE_PASS_ESCAPED}\""'/g' \
+    | sed 
's/"_kms_ssl_truststore_pass_"/'"\"${KMS_SSL_TRUSTSTORE_PASS_ESCAPED}\""'/g' > 
${CATALINA_BASE}/conf/ssl-server.xml
 fi 
 
 exec ${KMS_CATALINA_HOME}/bin/catalina.sh "$@"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to