1238438Sdteskeif [ ! "$_PASSWORD_PASSWORD_SUBR" ]; then _PASSWORD_PASSWORD_SUBR=1 2238438Sdteske# 3249751Sdteske# Copyright (c) 2012-2013 Devin Teske 4238438Sdteske# All rights reserved. 5238438Sdteske# 6238438Sdteske# Redistribution and use in source and binary forms, with or without 7238438Sdteske# modification, are permitted provided that the following conditions 8238438Sdteske# are met: 9238438Sdteske# 1. Redistributions of source code must retain the above copyright 10238438Sdteske# notice, this list of conditions and the following disclaimer. 11238438Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12238438Sdteske# notice, this list of conditions and the following disclaimer in the 13238438Sdteske# documentation and/or other materials provided with the distribution. 14238438Sdteske# 15238438Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16238438Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17238438Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18238438Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19238438Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20238438Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21238438Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22238438Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23238438Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24238438Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25238438Sdteske# SUCH DAMAGE. 26238438Sdteske# 27238438Sdteske# $FreeBSD$ 28238438Sdteske# 29238438Sdteske############################################################ INCLUDES 30238438Sdteske 31240684SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32240684Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33244675Sdteskef_dprintf "%s: loading includes..." password/password.subr 34240684Sdteskef_include $BSDCFG_SHARE/dialog.subr 35238438Sdteske 36240684SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="040.password" 37238438Sdteskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 38238438Sdteske 39238438Sdteske############################################################ FUNCTIONS 40238438Sdteske 41238438Sdteske# f_dialog_input_password 42238438Sdteske# 43238438Sdteske# Prompt the user to enter a password (twice). If the user does not cancel or 44238438Sdteske# press ESC, the $pw_password environment variable will hold the password. 45238438Sdteske# 46238438Sdteskef_dialog_input_password() 47238438Sdteske{ 48251264Sdteske local prompt1="$msg_enter_new_password" 49251264Sdteske local prompt2="$msg_reenter_password" 50238438Sdteske local hline="$hline_alnum_punc_tab_enter" 51238438Sdteske 52251190Sdteske local height1 width1 53251190Sdteske f_dialog_inputbox_size height1 width1 \ 54251190Sdteske "$DIALOG_TITLE" \ 55251190Sdteske "$DIALOG_BACKTITLE" \ 56251264Sdteske "$prompt1" \ 57251190Sdteske "" \ 58251190Sdteske "$hline" 59238438Sdteske 60251190Sdteske local height2 width2 61251190Sdteske f_dialog_inputbox_size height2 width2 \ 62251190Sdteske "$DIALOG_TITLE" \ 63251190Sdteske "$DIALOG_BACKTITLE" \ 64251264Sdteske "$prompt2" \ 65251190Sdteske "" \ 66251190Sdteske "$hline" 67238438Sdteske 68238438Sdteske # 69238438Sdteske # Loop until the user provides taint-free/valid input 70238438Sdteske # 71251242Sdteske local _password1 _password2 72238438Sdteske while :; do 73251242Sdteske _password1=$( $DIALOG \ 74251190Sdteske --title "$DIALOG_TITLE" \ 75251190Sdteske --backtitle "$DIALOG_BACKTITLE" \ 76251190Sdteske --hline "$hline" \ 77251190Sdteske --ok-label "$msg_ok" \ 78251190Sdteske --cancel-label "$msg_cancel" \ 79251190Sdteske --insecure \ 80251264Sdteske --passwordbox "$prompt1" \ 81251190Sdteske $height1 $width1 \ 82240768Sdteske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 83251242Sdteske ) || return $? 84251242Sdteske # Return if user either pressed ESC or chose Cancel/No 85251242Sdteske debug= f_dialog_line_sanitize _password1 86238438Sdteske 87251242Sdteske _password2=$( $DIALOG \ 88251190Sdteske --title "$DIALOG_TITLE" \ 89251190Sdteske --backtitle "$DIALOG_BACKTITLE" \ 90251190Sdteske --hline "$hline" \ 91251190Sdteske --ok-label "$msg_ok" \ 92251190Sdteske --cancel-label "$msg_cancel" \ 93251190Sdteske --insecure \ 94251264Sdteske --passwordbox "$prompt2" \ 95251190Sdteske $height2 $width2 \ 96240768Sdteske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 97251242Sdteske ) || return $? 98251242Sdteske # Return if user either pressed ESC or chose Cancel/No 99251242Sdteske debug= f_dialog_line_sanitize _password2 100238438Sdteske 101238438Sdteske # Check for NULL entry 102238438Sdteske if ! [ "$_password1" -o "$_password2" ]; then 103252795Sdteske f_show_msg "$msg_password_is_empty" 104238438Sdteske continue 105238438Sdteske fi 106238438Sdteske 107238438Sdteske # Check for password mismatch 108238438Sdteske if [ "$_password1" != "$_password2" ]; then 109252795Sdteske f_show_msg "$msg_passwords_do_not_match" 110238438Sdteske continue 111238438Sdteske fi 112238438Sdteske 113238438Sdteske pw_password="$_password1" 114238438Sdteske break 115238438Sdteske done 116238438Sdteske 117256181Sdteske return $DIALOG_OK 118238438Sdteske} 119238438Sdteske 120244675Sdteske############################################################ MAIN 121244675Sdteske 122244675Sdteskef_dprintf "%s: Successfully loaded." password/password.subr 123244675Sdteske 124238438Sdteskefi # ! $_PASSWORD_PASSWORD_SUBR 125