You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2023/04/13 16:47:41 UTC

[couchdb] branch backport-issues-from-main-to-3.2.x created (now c3029453c)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch backport-issues-from-main-to-3.2.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at c3029453c Make remsh work with quoted cookie

This branch includes the following new commits:

     new c3029453c Make remsh work with quoted cookie

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Make remsh work with quoted cookie

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch backport-issues-from-main-to-3.2.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit c3029453c8ca749754e4f45fcd7e0ef0afebcf6b
Author: jiahuili <Ji...@ibm.com>
AuthorDate: Mon Mar 27 20:16:47 2023 -0500

    Make remsh work with quoted cookie
    
    Allow space and other special characters in cookies.
    
    Test:
      First set the cookie in `vm.args`, then run the script below
      e.g.: `-setcookie 'a b\n\t\xd#{}()[]$&^!-=+?|//c\\d\\\e\\\\f'`
         or `-setcookie "a b\n\t\xd#{}()[]$&^!-=+?|//c\\d\\\e\\\\f"`
    
      ```
      make release
      cd rel/couchdb
      ./bin/couchdb
      ./bin/remsh
      ```
---
 rel/overlay/bin/remsh | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/rel/overlay/bin/remsh b/rel/overlay/bin/remsh
index de37d6cc2..1804336b5 100755
--- a/rel/overlay/bin/remsh
+++ b/rel/overlay/bin/remsh
@@ -49,10 +49,14 @@ NODE="${NODE:-$DEFAULT_NODE}"
 
 # If present, extract cookie from ERL_FLAGS
 # This is used by the CouchDB Dockerfile and Helm chart
-COOKIE=$(echo "$ERL_FLAGS" | sed 's/^.*setcookie \([^ ][^ ]*\).*$/\1/g')
+COOKIE=$(echo "$ERL_FLAGS" | sed -r '
+  s/.*-setcookie[ ]*['\''](.*)['\''].*/\1/
+  s/.*-setcookie[ ]*["](.*)["].*/\1/
+  s/.*-setcookie[ ]*([^ ]*).*/\1/
+')
 if test -f "$ARGS_FILE"; then
 # else attempt to extract from vm.args
-  ARGS_FILE_COOKIE=$(awk '$1=="-setcookie"{print $2}' "$ARGS_FILE")
+  ARGS_FILE_COOKIE=$(awk '$1=="-setcookie"{st=index($0," "); print substr($0,st+1)}' "$ARGS_FILE" | tr -d \" | tr -d \')
   COOKIE="${COOKIE:-$ARGS_FILE_COOKIE}"
 fi
 
@@ -111,7 +115,12 @@ fi
 
 # If present, strip -name or -setcookie from ERL_FLAGS
 # to avoid conflicts with the cli parameters
-ERL_FLAGS_CLEAN=$(echo "$ERL_FLAGS" | sed 's/-setcookie \([^ ][^ ]*\)//g' | sed 's/-name \([^ ][^ ]*\)//g')
+ERL_FLAGS_CLEAN=$(echo "$ERL_FLAGS" | sed -r '
+  s/-setcookie[ ]*['\''].*['\'']//
+  s/-setcookie[ ]*["].*["]//
+  s/-setcookie[ ]*[^ ]*//
+  s/-name[ ]*[^ ]*//
+')
 
 if [ -z "${COOKIE}" ]; then
     echo "No Erlang cookie could be found, please specify with -c" >&2
@@ -120,11 +129,11 @@ fi
 
 if [ -z "$TLSCONF" ]; then
   exec env ERL_FLAGS="$ERL_FLAGS_CLEAN" "$BINDIR/erl" -boot "$ROOTDIR/releases/$APP_VSN/start_clean" \
-      -name remsh$$@$LHOST -remsh $NODE -hidden -setcookie $COOKIE \
+      -name remsh$$@$LHOST -remsh $NODE -hidden -setcookie "$COOKIE" \
       "$@"
 else
   exec env ERL_FLAGS="$ERL_FLAGS_CLEAN" "$BINDIR/erl" -boot "$ROOTDIR/releases/$APP_VSN/start_clean" \
-      -name remsh$$@$LHOST -remsh $NODE -hidden -setcookie $COOKIE \
+      -name remsh$$@$LHOST -remsh $NODE -hidden -setcookie "$COOKIE" \
       -proto_dist inet_tls -ssl_dist_optfile $TLSCONF \
       "$@"
 fi