password.subr revision 251264
1238730Sdelphijif [ ! "$_PASSWORD_PASSWORD_SUBR" ]; then _PASSWORD_PASSWORD_SUBR=1 2294286Sdelphij# 3238730Sdelphij# Copyright (c) 2012-2013 Devin Teske 4238730Sdelphij# All rights reserved. 5238730Sdelphij# 6238730Sdelphij# Redistribution and use in source and binary forms, with or without 7238730Sdelphij# modification, are permitted provided that the following conditions 8238730Sdelphij# are met: 960786Sps# 1. Redistributions of source code must retain the above copyright 1060786Sps# notice, this list of conditions and the following disclaimer. 1160786Sps# 2. Redistributions in binary form must reproduce the above copyright 1260786Sps# notice, this list of conditions and the following disclaimer in the 1360786Sps# documentation and/or other materials provided with the distribution. 14191930Sdelphij# 15191930Sdelphij# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16191930Sdelphij# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17191930Sdelphij# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18191930Sdelphij# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19191930Sdelphij# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20191930Sdelphij# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21191930Sdelphij# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22191930Sdelphij# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23191930Sdelphij# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24191930Sdelphij# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25191930Sdelphij# SUCH DAMAGE. 26191930Sdelphij# 27191930Sdelphij# $FreeBSD: head/usr.sbin/bsdconfig/password/share/password.subr 251264 2013-06-02 20:02:50Z dteske $ 28191930Sdelphij# 29191930Sdelphij############################################################ INCLUDES 3060786Sps 31191930SdelphijBSDCFG_SHARE="/usr/share/bsdconfig" 32191930Sdelphij. $BSDCFG_SHARE/common.subr || exit 1 33191930Sdelphijf_dprintf "%s: loading includes..." password/password.subr 34191930Sdelphijf_include $BSDCFG_SHARE/dialog.subr 35191930Sdelphij 36191930SdelphijBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="040.password" 37191930Sdelphijf_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 38191930Sdelphij 39191930Sdelphij############################################################ FUNCTIONS 40191930Sdelphij 41191930Sdelphij# f_dialog_input_password 42191930Sdelphij# 43191930Sdelphij# Prompt the user to enter a password (twice). If the user does not cancel or 44191930Sdelphij# press ESC, the $pw_password environment variable will hold the password. 4560786Sps# 46191930Sdelphijf_dialog_input_password() 47191930Sdelphij{ 48191930Sdelphij local prompt1="$msg_enter_new_password" 49191930Sdelphij local prompt2="$msg_reenter_password" 50191930Sdelphij local hline="$hline_alnum_punc_tab_enter" 51191930Sdelphij 52191930Sdelphij local height1 width1 53191930Sdelphij f_dialog_inputbox_size height1 width1 \ 54191930Sdelphij "$DIALOG_TITLE" \ 55191930Sdelphij "$DIALOG_BACKTITLE" \ 56191930Sdelphij "$prompt1" \ 57191930Sdelphij "" \ 58191930Sdelphij "$hline" 59191930Sdelphij 60191930Sdelphij local height2 width2 61191930Sdelphij f_dialog_inputbox_size height2 width2 \ 62191930Sdelphij "$DIALOG_TITLE" \ 63191930Sdelphij "$DIALOG_BACKTITLE" \ 64191930Sdelphij "$prompt2" \ 65191930Sdelphij "" \ 66191930Sdelphij "$hline" 67191930Sdelphij 6860786Sps # 69191930Sdelphij # Loop until the user provides taint-free/valid input 70191930Sdelphij # 71191930Sdelphij local _password1 _password2 72191930Sdelphij while :; do 73191930Sdelphij _password1=$( $DIALOG \ 74191930Sdelphij --title "$DIALOG_TITLE" \ 75191930Sdelphij --backtitle "$DIALOG_BACKTITLE" \ 76191930Sdelphij --hline "$hline" \ 77191930Sdelphij --ok-label "$msg_ok" \ 78191930Sdelphij --cancel-label "$msg_cancel" \ 79191930Sdelphij --insecure \ 80191930Sdelphij --passwordbox "$prompt1" \ 81191930Sdelphij $height1 $width1 \ 8260786Sps 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 83191930Sdelphij ) || return $? 84191930Sdelphij # Return if user either pressed ESC or chose Cancel/No 85191930Sdelphij debug= f_dialog_line_sanitize _password1 86191930Sdelphij 87191930Sdelphij _password2=$( $DIALOG \ 88191930Sdelphij --title "$DIALOG_TITLE" \ 89191930Sdelphij --backtitle "$DIALOG_BACKTITLE" \ 90191930Sdelphij --hline "$hline" \ 91191930Sdelphij --ok-label "$msg_ok" \ 92191930Sdelphij --cancel-label "$msg_cancel" \ 93191930Sdelphij --insecure \ 94191930Sdelphij --passwordbox "$prompt2" \ 95191930Sdelphij $height2 $width2 \ 96191930Sdelphij 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 97191930Sdelphij ) || return $? 98191930Sdelphij # Return if user either pressed ESC or chose Cancel/No 99191930Sdelphij debug= f_dialog_line_sanitize _password2 100191930Sdelphij 10160786Sps # Check for NULL entry 102191930Sdelphij if ! [ "$_password1" -o "$_password2" ]; then 103191930Sdelphij f_dialog_msgbox "$msg_password_is_empty" 104191930Sdelphij continue 105191930Sdelphij fi 106191930Sdelphij 107191930Sdelphij # Check for password mismatch 108191930Sdelphij if [ "$_password1" != "$_password2" ]; then 109191930Sdelphij f_dialog_msgbox "$msg_passwords_do_not_match" 110191930Sdelphij continue 111191930Sdelphij fi 112191930Sdelphij 113191930Sdelphij pw_password="$_password1" 114191930Sdelphij break 115191930Sdelphij done 116191930Sdelphij 117191930Sdelphij return $SUCCESS 118191930Sdelphij} 119191930Sdelphij 120191930Sdelphij############################################################ MAIN 121191930Sdelphij 122191930Sdelphijf_dprintf "%s: Successfully loaded." password/password.subr 123191930Sdelphij 124191930Sdelphijfi # ! $_PASSWORD_PASSWORD_SUBR 12560786Sps