From 21616e4ec28871ce40a43ea165995ad7274820c3 Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Thu, 29 Sep 2022 21:03:48 +0200 Subject: [PATCH] lnd.check.sh -> harden rpc user/pass parsing against double entries (#3282) --- home.admin/config.scripts/lnd.check.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/home.admin/config.scripts/lnd.check.sh b/home.admin/config.scripts/lnd.check.sh index 55b7904b6..199de1d75 100755 --- a/home.admin/config.scripts/lnd.check.sh +++ b/home.admin/config.scripts/lnd.check.sh @@ -154,11 +154,25 @@ if [ "$1" == "prestart" ]; then setting ${lndConfFile} ${insertLine} "${network}d\.zmqpubrawblock" "tcp\:\/\/127\.0\.0\.1\:${zmqprefix}332" # SET/UPDATE rpcpass - RPCPSW=$(cat /mnt/hdd/${network}/${network}.conf | grep "rpcpassword=" | cut -d "=" -f2) + RPCPSW=$(cat /mnt/hdd/${network}/${network}.conf | grep "^rpcpassword=" | tail -1 | cut -d "=" -f2 | tail -n 1) + if [ "${RPCPSW}" == "" ]; then + RPCPSW=$(cat /mnt/hdd/${network}/${network}.conf | grep "^${network}d.rpcpassword=" | cut -d "=" -f2 | tail -n 1) + fi + if [ "${RPCPSW}" == "" ]; then + 1>&2 echo "FAIL: 'rpcpassword' not found in /mnt/hdd/${network}/${network}.conf" + exit 11 + fi setting ${lndConfFile} ${insertLine} "${network}d\.rpcpass" "${RPCPSW}" # SET/UPDATE rpcuser - RPCUSER=$(cat /mnt/hdd/${network}/${network}.conf | grep "rpcuser=" | cut -d "=" -f2) + RPCUSER=$(cat /mnt/hdd/${network}/${network}.conf | grep "^rpcuser=" | cut -d "=" -f2 | tail -n 1) + if [ "${RPCUSER}" == "" ]; then + RPCUSER=$(cat /mnt/hdd/${network}/${network}.conf | grep "^${network}d.rpcuser=" | cut -d "=" -f2 | tail -n 1) + fi + if [ "${RPCUSER}" == "" ]; then + 1>&2 echo "FAIL: 'rpcuser' not found in /mnt/hdd/${network}/${network}.conf" + exit 12 + fi setting ${lndConfFile} ${insertLine} "${network}d\.rpcuser" "${RPCUSER}" # SET/UPDATE rpchost