summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/password
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2013-06-02 05:45:25 +0000
committerdteske <dteske@FreeBSD.org>2013-06-02 05:45:25 +0000
commit5b05f067655217732e94ad77b1c57a3cb7a3945e (patch)
treec82ae86b5bfe7b5e527099673025931ffda2e584 /usr.sbin/bsdconfig/password
parentc13ee16ab4b2ed670be4b050ae59d428dab4196f (diff)
downloadFreeBSD-src-5b05f067655217732e94ad77b1c57a3cb7a3945e.zip
FreeBSD-src-5b05f067655217732e94ad77b1c57a3cb7a3945e.tar.gz
Similar to r251236, improve the portion of dialog(1) API in dialog.subr
responsible for retrieving stored input (for the --inputbox and --password widgets). When we (Ron McDowell and I) developed the first version of bsdconfig, it used temporary files to store responses from dialog(1). That hasn't been true for a very long time, so the need to always execute some clean-up function is long-deprecated. The function that used to perform these clean- up routines for these widgets was f_dialog_inputstr(). We really don't need f_dialog_inputstr() for its originally designed purpose as all dialog invocations no longer require temporary files. Just as in r251236, redesign f_dialog_inputstr() in the following four ways: 1. Rename f_dialog_inputstr() to f_dialog_inputstr_fetch() 2. Introduce the new first-argument of $var_to_set to reduce forking 3. Create a corresponding f_dialog_inputstr_store() to abstract storage 4. Offload the sanitization to a new function, f_dialog_line_sanitize() It should be noted that f_dialog_line_sanitize() -- unlike its cousin from SVN r251236, f_dialog_data_sanitize() -- trims leading/trailing whitespace from the user's input. This helps prevent errors and common mistakes caused by the fact that the new cdialog implementation allows the right-arrow cursor key to go beyond the last byte of realtime input (adding whitespace at the end of the typed value). While we're centralizing the sanitization, let's rewrite f_dialog_input() while we're here to likewise reduce forking. The f_dialog_input() function now expects the first argument of $var_to_set instead of producing results on standard-out. These changes greatly improve readability and also improve performance.
Diffstat (limited to 'usr.sbin/bsdconfig/password')
-rw-r--r--usr.sbin/bsdconfig/password/share/password.subr29
1 files changed, 9 insertions, 20 deletions
diff --git a/usr.sbin/bsdconfig/password/share/password.subr b/usr.sbin/bsdconfig/password/share/password.subr
index 2d407c4..ad1b2a1 100644
--- a/usr.sbin/bsdconfig/password/share/password.subr
+++ b/usr.sbin/bsdconfig/password/share/password.subr
@@ -69,10 +69,9 @@ f_dialog_input_password()
#
# Loop until the user provides taint-free/valid input
#
- local retval _password1 _password2
+ local _password1 _password2
while :; do
- local dialog_inputbox
- dialog_inputbox=$( $DIALOG \
+ _password1=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
@@ -82,16 +81,11 @@ f_dialog_input_password()
--passwordbox "$msg" \
$height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ debug= f_dialog_line_sanitize _password1
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password1=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
-
- dialog_inputbox=$( $DIALOG \
+ _password2=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
@@ -101,14 +95,9 @@ f_dialog_input_password()
--passwordbox "$rmsg" \
$height2 $width2 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password2=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ debug= f_dialog_line_sanitize _password2
# Check for NULL entry
if ! [ "$_password1" -o "$_password2" ]; then
OpenPOWER on IntegriCloud