X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Fsecurity%2Fpassword_functions.sh;h=490b94d8189c20b03340cecf5c4556761dab1249;hb=87e48192f16d2d8f36c9a44d436b29f76dfa7bc3;hp=92e0d71e640aaf4c7bb08f401e27652eddcd761d;hpb=42747588c57479a83b831a1940c182a733e25817;p=feisty_meow.git diff --git a/scripts/security/password_functions.sh b/scripts/security/password_functions.sh index 92e0d71e..490b94d8 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,9 @@ function load_password() fi local passwd read passwd < "$passfile" - echo "$passwd" + + # return the password in the variable they provided. + eval $varname="$passwd" } # stores a password into a password file. the password file should be the @@ -46,30 +46,33 @@ and (2) the password that should be stored. fi echo "$passwd" > "$passfile" - test_or_die "writing password into the file $passfile" + exit_on_error "writing password into the file $passfile" chown root:root "$passfile" - test_or_die "chowning the password file to root ownership for: $passfile" + exit_on_error "chowning the password file to root ownership for: $passfile" chmod 600 "$passfile" - test_or_die "restricting permissions on password file for: $passfile" + exit_on_error "restricting permissions on password file for: $passfile" } # 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 " # 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" }