diff options
author | jiahuili <Jiahui.Li@ibm.com> | 2023-03-27 20:16:47 -0500 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2023-04-12 18:46:55 -0400 |
commit | e755e2352afdf45001995cdce3f95a6dbbd74ac9 (patch) | |
tree | 5c557693263487f9e93670b34687a794ae2812af | |
parent | a6ab75b43685117467ff0c1628022d9487d1ade9 (diff) | |
download | couchdb-e755e2352afdf45001995cdce3f95a6dbbd74ac9.tar.gz |
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
```
-rwxr-xr-x | rel/overlay/bin/remsh | 19 |
1 files 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 |