From e0ac37c257bf08db8d220d13773859d9202305d2 Mon Sep 17 00:00:00 2001 From: Dmitry Guryanov Date: Mon, 30 Nov 2015 18:48:23 +0300 Subject: [PATCH] Fix path setup in add_sudo_secure_path There are two bugs in add_sudo_secure_path. Firstly we don't properly check if the file exists, so always append the new line. This will overwrite any existing changes. Secondly the logic for checking if the path exists is inverted, so we miss adding paths when we should. This particularly causes failures when installing with virtualenv's since the paths are inside the virtualenv, rather than the standard system locations. Change-Id: I646fe0c68958470d464fe4f3d81d5c17dd6f2ab6 Closes-bug: #1521241 --- inc/rootwrap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/rootwrap b/inc/rootwrap index 63ab59adc7..2a6e4b648f 100644 --- a/inc/rootwrap +++ b/inc/rootwrap @@ -22,14 +22,14 @@ function add_sudo_secure_path { local line # This is pretty simplistic for now - assume only the first line is used - if [[ -r SUDO_SECURE_PATH_FILE ]]; then + if [[ -r $SUDO_SECURE_PATH_FILE ]]; then line=$(head -1 $SUDO_SECURE_PATH_FILE) else line="Defaults:$STACK_USER secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/bin:/bin" fi # Only add ``dir`` if it is not already present - if [[ $line =~ $dir ]]; then + if [[ ! $line =~ $dir ]]; then echo "${line}:$dir" | sudo tee $SUDO_SECURE_PATH_FILE sudo chmod 400 $SUDO_SECURE_PATH_FILE sudo chown root:root $SUDO_SECURE_PATH_FILE