summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/usermgmt
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/usermgmt
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/usermgmt')
-rw-r--r--usr.sbin/bsdconfig/usermgmt/share/group_input.subr32
-rw-r--r--usr.sbin/bsdconfig/usermgmt/share/user_input.subr82
2 files changed, 41 insertions, 73 deletions
diff --git a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
index 16d9083..49986cf 100644
--- a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
+++ b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
@@ -125,9 +125,8 @@ f_dialog_input_group_name()
while :; do
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_group" "$_input" \
- "$hline_alnum_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_group" "$_input" \
+ "$hline_alnum_tab_enter" || return
# Check for no-change
[ "$_input" = "$_name" ] && return $SUCCESS
@@ -198,8 +197,7 @@ f_dialog_input_group_password()
#
local retval _password1 _password2
while :; do
- local dialog_inputbox
- dialog_inputbox=$( $DIALOG \
+ _password1=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
@@ -210,15 +208,13 @@ f_dialog_input_group_password()
$height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password1=$( f_dialog_inputstr )
+ debug= f_dialog_line_sanitize _password1
# 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" \
@@ -229,10 +225,8 @@ f_dialog_input_group_password()
$height2 $width2 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password2=$( f_dialog_inputstr )
+ debug= f_dialog_line_sanitize _password2
# Return if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $SUCCESS ] || return $retval
@@ -275,9 +269,8 @@ f_dialog_input_group_gid()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_group_id_leave_empty_for_default" \
- "$_input" "$hline_num_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_group_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter" || return
group_gid="$_input"
save_flag=1
@@ -392,11 +385,10 @@ f_dialog_input_group_members()
2) # Enter Group Members manually
msg="$msg_group_members ($msg_separated_by_commas)"
- # Return to previous menu if user has either
- # pressed ESC or chosen Cancel/No
- _group_members=$( f_dialog_input "$msg" "$_input" \
- "$hline_num_tab_enter"
- ) || continue
+ f_dialog_input _group_members "$msg" "$_input" \
+ "$hline_num_tab_enter" || continue
+ # Return to previous menu if user either
+ # pressed ESC or chose Cancel/No
_input="$_group_members"
;;
diff --git a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
index 68df2cf..7b79d7b 100644
--- a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
+++ b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
@@ -226,9 +226,8 @@ f_dialog_input_name()
while :; do
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_login" "$_input" \
- "$hline_alnum_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_login" "$_input" \
+ "$hline_alnum_tab_enter" || return
# Check for no-change
[ "$_input" = "$_name" ] && return $SUCCESS
@@ -297,10 +296,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" \
@@ -310,13 +308,11 @@ f_dialog_input_password()
--passwordbox "$msg" \
$height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password1=$( f_dialog_inputstr )
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ debug= f_dialog_line_sanitize _password1
- dialog_inputbox=$( $DIALOG \
+ _password2=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
@@ -326,14 +322,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 password mismatch
if [ "$_password1" != "$_password2" ]; then
@@ -373,9 +364,8 @@ f_dialog_input_gecos()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_full_name" "$_input" \
- "$hline_alnum_punc_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_full_name" "$_input" \
+ "$hline_alnum_punc_tab_enter" || return
pw_gecos="$_input"
save_flag=1
@@ -396,9 +386,8 @@ f_dialog_input_uid()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_user_id_leave_empty_for_default" \
- "$_input" "$hline_num_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_user_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter" || return
pw_uid="$_input"
save_flag=1
@@ -419,9 +408,8 @@ f_dialog_input_gid()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_group_id_leave_empty_for_default" \
- "$_input" "$hline_num_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_group_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter" || return
pw_gid="$_input"
save_flag=1
@@ -442,9 +430,8 @@ f_dialog_input_class()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_login_class" "$_input" \
- "$hline_alnum_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_login_class" "$_input" \
+ "$hline_alnum_tab_enter" || return
pw_class="$_input"
save_flag=1
@@ -585,10 +572,9 @@ f_dialog_input_change()
ret_days=$(( $ret_days + 1 ))
# Return to menu if either ESC or Cancel/No
- ret_days=$( f_dialog_input \
+ f_dialog_input ret_days \
"$msg_password_expires_in_how_many_days" \
- "$ret_days" "$hline"
- ) || continue
+ "$ret_days" "$hline" || continue
# Taint-check the user's input
if ! f_isinteger "$ret_days"; then
@@ -606,16 +592,12 @@ f_dialog_input_change()
break ;;
4) # Enter value manually
- local ret_secs
-
msg=$( printf "$msg_number_of_seconds_since_epoch" \
"$( date -r 1 "+%c %Z" )" )
# Return to menu if either ESC or Cancel/No
- ret_secs=$( f_dialog_input \
- "$msg" "$_input" "$hline" ) || continue
-
- _input="$ret_secs"
+ f_dialog_input _input \
+ "$msg" "$_input" "$hline" || continue
# Taint-check the user's input
if ! f_isinteger "${_input:-0}"; then
@@ -771,10 +753,9 @@ f_dialog_input_expire()
ret_days=$(( $ret_days + 1 ))
# Return to menu if either ESC or Cancel/No
- ret_days=$( f_dialog_input \
+ f_dialog_input ret_days \
"$msg_account_expires_in_how_many_days" \
- "$ret_days" "$hline"
- ) || continue
+ "$ret_days" "$hline" || continue
# Taint-check the user's input
if ! f_isinteger "$ret_days"; then
@@ -792,16 +773,12 @@ f_dialog_input_expire()
break ;;
4) # Enter value manually
- local ret_secs
-
msg=$( printf "$msg_number_of_seconds_since_epoch" \
"$( date -r 1 "+%c %Z" )" )
# Return to menu if either ESC or Cancel/No
- ret_secs=$( f_dialog_input \
- "$msg" "$_input" "$hline" ) || continue
-
- _input="$ret_secs"
+ f_dialog_input _input "$msg" \
+ "$_input" "$hline" || continue
# Taint-check the user's input
if ! f_isinteger "${_input:-0}"; then
@@ -837,9 +814,8 @@ f_dialog_input_home_dir()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_home_directory" "$_input" \
- "$hline_alnum_punc_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_home_directory" "$_input" \
+ "$hline_alnum_punc_tab_enter" || return
pw_home_dir="$_input"
save_flag=1
OpenPOWER on IntegriCloud