From: Chris Koeritz Date: Wed, 7 Feb 2018 20:47:11 +0000 (-0500) Subject: got the password functions right maybe X-Git-Tag: 2.140.109^2~5 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=b1e7d8ba0ee42faaeed416dac81d5b55a3aec508;p=feisty_meow.git got the password functions right maybe had to drop the awful approach of echoing the result for much nicer approach of setting a variable name provided by the caller. this is a lot better technique. --- diff --git a/scripts/security/password_functions.sh b/scripts/security/password_functions.sh index 637e352d..ca365fd2 100644 --- a/scripts/security/password_functions.sh +++ b/scripts/security/password_functions.sh @@ -8,14 +8,12 @@ # two requirements are done automatically by the store_password function. # load_password: -# provides a way to read a password out of a file. -# the return value is an echoed password, so this method should always be -# called from within a subshell, e.g.: -# mypass="$(load_password /etc/glorp/secret_passcode)" -# the returned echo will be blank if the function failed. +# provides a way to read a password out of a file. the filename is the first +# paramater and the variable to fill with the password is the second. function load_password() { local passfile="$1"; shift + local varname="$1"; shift if [ -z "$passfile" ]; then echo 'The load_password function needs a filename to read the password from.' return 1 @@ -27,7 +25,11 @@ function load_password() fi local passwd read passwd < "$passfile" - echo "$passwd" + + # return the password in the variable they provided. + eval $varname="$passwd" +#echo varname is: $varname +#echo new value of that variable is ${!varname} } # stores a password into a password file. the password file should be the @@ -56,21 +58,25 @@ and (2) the password that should be stored. } # reads a password from the console, without echoing the letters when they -# are typed. the prompt to show the user is required as the first parameter. -# the password read in is returned as an echo, like load_password above. +# are typed. the prompt to show the user is required as the first parameter, +# and the variable to fill with the result is the second parameter. function read_password() { - prompt="$1"; shift + local prompt="$1"; shift + local varname="$1"; shift +#hmmm: complain if not enough parms. echo -n "$prompt " -# sync # turn off echo but remember former setting. stty_orig=`stty -g` stty -echo + local the_passwd read the_passwd # turn echo back on. stty $stty_orig - # return the password as an echo. - echo "$the_passwd" + # return the password in the variable they provided. + eval $varname="$the_passwd" +#echo varname is: $varname +#echo new value of that variable is ${!varname} } diff --git a/scripts/site_avenger/revamp_cakelampvm.sh b/scripts/site_avenger/revamp_cakelampvm.sh index d86a35d7..773e5a89 100644 --- a/scripts/site_avenger/revamp_cakelampvm.sh +++ b/scripts/site_avenger/revamp_cakelampvm.sh @@ -25,11 +25,11 @@ source "$FEISTY_MEOW_SCRIPTS/security/password_functions.sh" # new requirement to have the sql root password, since we need to do some sql db configuration. echo A -mysql_passwd="$(load_password /etc/mysql/secret_password)" +load_password /etc/mysql/secret_password mysql_passwd echo B if [ -z "$mysql_password" ]; then echo C - mysql_password="$(read_password "Please enter the MySQL root account password:")" + read_password "Please enter the MySQL root account password:" mysql_password echo D # echo -n "Please enter the MySQL root account password: " # # turn off echo but remember former setting.