From 73b23c525bb63550160955c18d4a59d5d0d46389 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 1 Sep 2019 17:39:38 +0200 Subject: [PATCH 1/4] Failsafe home dir obtaining + When estimating $INSTALL_HOME, assure grep can only match user names, to avoid possible wrong multi-line value + Remove possible trailing slash from $INSTALL_HOME, to avoid double slash in "$INSTALL_HOME/ovpns" + Avoid "cat | grep ", since grep can process files directly Signed-off-by: MichaIng --- auto_install/install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/auto_install/install.sh b/auto_install/install.sh index bedbb8e..ed30c10 100755 --- a/auto_install/install.sh +++ b/auto_install/install.sh @@ -1131,8 +1131,9 @@ confOVPN() { # verify server name to strengthen security $SUDO sed -i "s/SRVRNAME/${SERVER_NAME}/" /etc/openvpn/easy-rsa/pki/Default.txt - INSTALL_HOME=$(cat /etc/passwd | grep "$INSTALL_USER" | cut -d: -f6) - if [ ! -d "$INSTALL_HOME/ovpns" ]; then + INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6) + INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash + if [ ! -d "$INSTALL_HOME/ovpns" ]; then $SUDO mkdir "$INSTALL_HOME/ovpns" fi $SUDO chmod 0777 -R "$INSTALL_HOME/ovpns" From 51333a93131219448a1b7def1b7660e12151d2eb Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 1 Sep 2019 17:41:44 +0200 Subject: [PATCH 2/4] Failsafe home dir obtaining + When estimating $INSTALL_HOME, assure grep can only match user names, to avoid possible wrong multi-line value + Remove possible trailing slash from $INSTALL_HOME, to avoid double slash in "$INSTALL_HOME/ovpns" + Avoid "cat | grep ", since grep can process files directly Signed-off-by: MichaIng --- scripts/uninstall.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index ecd2765..d9b972b 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -2,7 +2,8 @@ # PiVPN: Uninstall Script INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) -INSTALL_HOME=$(cat /etc/passwd | grep "$INSTALL_USER" | cut -d: -f6) +INSTALL_HOME=$(grep -m1 "^${INSTALL_USER}:" /etc/passwd | cut -d: -f6) +INSTALL_HOME=${INSTALL_HOME%/} # remove possible trailing slash PLAT=$(cat /etc/pivpn/DET_PLATFORM) NO_UFW=$(cat /etc/pivpn/NO_UFW) OLD_UFW=$(cat /etc/pivpn/NO_UFW) From d79dc3db6199e98d131b200c5d8813bc842199f4 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 1 Sep 2019 17:46:07 +0200 Subject: [PATCH 3/4] Failsafe home dir obtaining + When estimating $INSTALL_HOME, assure grep can only match user names, to avoid possible wrong multi-line value + Remove possible trailing slash from $INSTALL_HOME, to avoid double slash in "$INSTALL_HOME/ovpns" + Avoid "cat | grep ", since grep can process files directly + Avoid "VAR=$(cat file)", since "VAR=$( --- scripts/makeOVPN.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/makeOVPN.sh b/scripts/makeOVPN.sh index 29605eb..c06f2fa 100755 --- a/scripts/makeOVPN.sh +++ b/scripts/makeOVPN.sh @@ -8,7 +8,7 @@ KEY=".key" CA="ca.crt" TA="ta.key" INDEX="/etc/openvpn/easy-rsa/pki/index.txt" -INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) +INSTALL_USER=$( Date: Sun, 1 Sep 2019 17:47:38 +0200 Subject: [PATCH 4/4] Failsafe home dir obtaining + When estimating $INSTALL_HOME, assure grep can only match user names, to avoid possible wrong multi-line value + Remove possible trailing slash from $INSTALL_HOME, to avoid double slash in "$INSTALL_HOME/ovpns" + Avoid "cat | grep ", since grep can process files directly + Avoid "VAR=$(cat file)", since "VAR=$( --- scripts/removeOVPN.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/removeOVPN.sh b/scripts/removeOVPN.sh index 462b25c..b2d726f 100755 --- a/scripts/removeOVPN.sh +++ b/scripts/removeOVPN.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # PiVPN: revoke client script -INSTALL_USER=$(cat /etc/pivpn/INSTALL_USER) -PLAT=$(cat /etc/pivpn/DET_PLATFORM) +INSTALL_USER=$(