1ab2043b8SDevin Teskeif [ ! "$_PASSWORD_PASSWORD_SUBR" ]; then _PASSWORD_PASSWORD_SUBR=1
2ab2043b8SDevin Teske#
3d3a0f918SDevin Teske# Copyright (c) 2012-2013 Devin Teske
4ab2043b8SDevin Teske# All rights reserved.
5ab2043b8SDevin Teske#
6ab2043b8SDevin Teske# Redistribution and use in source and binary forms, with or without
7ab2043b8SDevin Teske# modification, are permitted provided that the following conditions
8ab2043b8SDevin Teske# are met:
9ab2043b8SDevin Teske# 1. Redistributions of source code must retain the above copyright
10ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer.
11ab2043b8SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
12ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer in the
13ab2043b8SDevin Teske#    documentation and/or other materials provided with the distribution.
14ab2043b8SDevin Teske#
15ab2043b8SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16ab2043b8SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17ab2043b8SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ab2043b8SDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19ab2043b8SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20ab2043b8SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21ab2043b8SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ab2043b8SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23ab2043b8SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ab2043b8SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ab2043b8SDevin Teske# SUCH DAMAGE.
26ab2043b8SDevin Teske#
27ab2043b8SDevin Teske#
28ab2043b8SDevin Teske############################################################ INCLUDES
29ab2043b8SDevin Teske
30ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
31ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
3256961fd7SDevin Teskef_dprintf "%s: loading includes..." password/password.subr
33ab2043b8SDevin Teskef_include $BSDCFG_SHARE/dialog.subr
34ab2043b8SDevin Teske
35ab2043b8SDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="040.password"
36ab2043b8SDevin Teskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
37ab2043b8SDevin Teske
38ab2043b8SDevin Teske############################################################ FUNCTIONS
39ab2043b8SDevin Teske
40ab2043b8SDevin Teske# f_dialog_input_password
41ab2043b8SDevin Teske#
42ab2043b8SDevin Teske# Prompt the user to enter a password (twice). If the user does not cancel or
43ab2043b8SDevin Teske# press ESC, the $pw_password environment variable will hold the password.
44ab2043b8SDevin Teske#
45ab2043b8SDevin Teskef_dialog_input_password()
46ab2043b8SDevin Teske{
47052f8969SDevin Teske	local prompt1="$msg_enter_new_password"
48052f8969SDevin Teske	local prompt2="$msg_reenter_password"
49ab2043b8SDevin Teske	local hline="$hline_alnum_punc_tab_enter"
50ab2043b8SDevin Teske
5174036c4dSDevin Teske	local height1 width1
5274036c4dSDevin Teske	f_dialog_inputbox_size height1 width1 \
53ab2043b8SDevin Teske	                       "$DIALOG_TITLE"     \
54ab2043b8SDevin Teske	                       "$DIALOG_BACKTITLE" \
55052f8969SDevin Teske	                       "$prompt1"          \
56ab2043b8SDevin Teske	                       ""                  \
5774036c4dSDevin Teske	                       "$hline"
58ab2043b8SDevin Teske
5974036c4dSDevin Teske	local height2 width2
6074036c4dSDevin Teske	f_dialog_inputbox_size height2 width2 \
61ab2043b8SDevin Teske	                       "$DIALOG_TITLE"     \
62ab2043b8SDevin Teske	                       "$DIALOG_BACKTITLE" \
63052f8969SDevin Teske	                       "$prompt2"          \
64ab2043b8SDevin Teske	                       ""                  \
6574036c4dSDevin Teske	                       "$hline"
66ab2043b8SDevin Teske
67ab2043b8SDevin Teske	#
68ab2043b8SDevin Teske	# Loop until the user provides taint-free/valid input
69ab2043b8SDevin Teske	#
70ec7120b5SDevin Teske	local _password1 _password2
71ab2043b8SDevin Teske	while :; do
72ec7120b5SDevin Teske		_password1=$( $DIALOG \
7374036c4dSDevin Teske			--title "$DIALOG_TITLE"         \
7474036c4dSDevin Teske			--backtitle "$DIALOG_BACKTITLE" \
7574036c4dSDevin Teske			--hline "$hline"                \
7674036c4dSDevin Teske			--ok-label "$msg_ok"            \
7774036c4dSDevin Teske			--cancel-label "$msg_cancel"    \
78ab2043b8SDevin Teske			--insecure                      \
79052f8969SDevin Teske			--passwordbox "$prompt1"        \
8074036c4dSDevin Teske			$height1 $width1                \
8189498fdfSDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
82ec7120b5SDevin Teske		) || return $?
83ec7120b5SDevin Teske			# Return if user either pressed ESC or chose Cancel/No
84ec7120b5SDevin Teske		debug= f_dialog_line_sanitize _password1
85ab2043b8SDevin Teske
86ec7120b5SDevin Teske		_password2=$( $DIALOG \
8774036c4dSDevin Teske			--title "$DIALOG_TITLE"         \
8874036c4dSDevin Teske			--backtitle "$DIALOG_BACKTITLE" \
8974036c4dSDevin Teske			--hline "$hline"                \
9074036c4dSDevin Teske			--ok-label "$msg_ok"            \
9174036c4dSDevin Teske			--cancel-label "$msg_cancel"    \
92ab2043b8SDevin Teske			--insecure                      \
93052f8969SDevin Teske			--passwordbox "$prompt2"        \
9474036c4dSDevin Teske			$height2 $width2                \
9589498fdfSDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
96ec7120b5SDevin Teske		) || return $?
97ec7120b5SDevin Teske			# Return if user either pressed ESC or chose Cancel/No
98ec7120b5SDevin Teske		debug= f_dialog_line_sanitize _password2
99ab2043b8SDevin Teske
100ab2043b8SDevin Teske		# Check for NULL entry
101ab2043b8SDevin Teske		if ! [ "$_password1" -o "$_password2" ]; then
1027079fc4eSDevin Teske			f_show_msg "$msg_password_is_empty"
103ab2043b8SDevin Teske			continue
104ab2043b8SDevin Teske		fi
105ab2043b8SDevin Teske
106ab2043b8SDevin Teske		# Check for password mismatch
107ab2043b8SDevin Teske		if [ "$_password1" != "$_password2" ]; then
1087079fc4eSDevin Teske			f_show_msg "$msg_passwords_do_not_match"
109ab2043b8SDevin Teske			continue
110ab2043b8SDevin Teske		fi
111ab2043b8SDevin Teske
112ab2043b8SDevin Teske		pw_password="$_password1"
113ab2043b8SDevin Teske		break
114ab2043b8SDevin Teske	done
115ab2043b8SDevin Teske
116f677a9e2SDevin Teske	return $DIALOG_OK
117ab2043b8SDevin Teske}
118ab2043b8SDevin Teske
11956961fd7SDevin Teske############################################################ MAIN
12056961fd7SDevin Teske
12156961fd7SDevin Teskef_dprintf "%s: Successfully loaded." password/password.subr
12256961fd7SDevin Teske
123ab2043b8SDevin Teskefi # ! $_PASSWORD_PASSWORD_SUBR
124