diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-01 23:58:44 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-01 23:58:44 +0000 |
commit | 9e2431c34dc087e0ff7bb1a5ae076865b37fd54e (patch) | |
tree | aff553824a76a9a13ba24f03ece60b3c50def184 /usr.sbin/bsdconfig/usermgmt | |
parent | 2201176ef968245558d98feec1de87cfdca36bf4 (diff) | |
download | FreeBSD-src-9e2431c34dc087e0ff7bb1a5ae076865b37fd54e.zip FreeBSD-src-9e2431c34dc087e0ff7bb1a5ae076865b37fd54e.tar.gz |
Improve portion of the dialog(1) API in dialog.subr responsible for
retrieving stored data (for the --menu, --calendar, --timebox, --checklist,
and --radiolist 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 some very long time, so the need to always store the return status
of dialog(1) and then call some function to clean-up is long-deprecated. The
function that used to do the clean-up was f_dialog_menutag().
We really don't need f_dialog_menutag() for its originally designed purpose,
as all dialog invocations (even when in a sub-shell) do not use temporary
files anymore.
However, we do need to keep f_dialog_menutag() around because it still fills
the need of being able to abstract the procedure for fetching stored data
provided by functions that display the aforementioned widgets.
In re-designing f_dialog_menutag(), four important changes are made:
1. Rename f_dialog_menutag() to f_dialog_menutag_fetch()
2. Introduce the new first-argument of $var_to_set to reduce number of forks
3. Create a corresponding f_dialog_menutag_store() to abstract the storage
4. Offload the sanitization to a new function, f_dialog_data_sanitize()
NOTE: That last one is important. Not all functions need to store their data
for later fetching, meanwhile every invocation of dialog should be sanitized
(as we learned early-on in the i18n-effort -- underlying libraries will spit
warnings to stderr for bad values of $LANG and since dialog outputs its
responses to stderr, we need to sanitize every response of these warnings).
These changes greatly improve readbaility and also improve performance by
reducing unnecessary forking.
Diffstat (limited to 'usr.sbin/bsdconfig/usermgmt')
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupdel | 2 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupedit | 2 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupinput | 10 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/usermgmt/share/group_input.subr | 37 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/usermgmt/share/user_input.subr | 73 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/userdel | 2 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/useredit | 2 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/userinput | 10 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/usermgmt | 11 |
9 files changed, 63 insertions, 86 deletions
diff --git a/usr.sbin/bsdconfig/usermgmt/groupdel b/usr.sbin/bsdconfig/usermgmt/groupdel index e5a759f..693623f 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupdel +++ b/usr.sbin/bsdconfig/usermgmt/groupdel @@ -71,7 +71,7 @@ defaultitem="" while :; do f_dialog_menu_group_list "$defaultitem" retval=$? - mtag=$( f_dialog_menutag ) + f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" defaultitem="$mtag" diff --git a/usr.sbin/bsdconfig/usermgmt/groupedit b/usr.sbin/bsdconfig/usermgmt/groupedit index ba249c3..9dfc6b8 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupedit +++ b/usr.sbin/bsdconfig/usermgmt/groupedit @@ -71,7 +71,7 @@ defaultitem="" while :; do f_dialog_menu_group_list "$defaultitem" retval=$? - mtag=$( f_dialog_menutag ) + f_dialog_menutag_fetch mtag f_dprintf "retval=%s mtag=[%s]" $retval "$mtag" defaultitem="$mtag" diff --git a/usr.sbin/bsdconfig/usermgmt/groupinput b/usr.sbin/bsdconfig/usermgmt/groupinput index 19b5307..f1c8d68 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupinput +++ b/usr.sbin/bsdconfig/usermgmt/groupinput @@ -228,7 +228,7 @@ while :; do \"\$hline\" \ $menu_items - dialog_menu=$( eval $DIALOG \ + mtag=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -240,11 +240,9 @@ while :; do $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) - retval=$? - setvar DEFAULTITEM_$$ "$dialog_menu" - setvar DIALOG_MENU_$$ "$dialog_menu" - mtag=$( f_dialog_menutag ) + f_dialog_data_sanitize mtag + setvar DEFAULTITEM_$$ "$mtag" f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No @@ -263,7 +261,7 @@ while :; do Edit/View|Delete) f_dialog_menu_group_list "$group_name" retval=$? - mtag=$( f_dialog_menutag ) + f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Loop if user has either pressed ESC or chosen Cancel/No diff --git a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr index 7fc8b83..16d9083 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr @@ -88,8 +88,8 @@ f_dialog_menu_group_list() \"\$hline\" \ $menu_list - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local menu_choice + menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -102,7 +102,7 @@ f_dialog_menu_group_list() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" + f_dialog_menutag_store -s "$menu_choice" return $retval } @@ -310,7 +310,7 @@ f_dialog_input_group_members() '2' '$msg_enter_group_members_manually' " # END-QUOTE - local dialog_menu defaultitem= + local menu_choice defaultitem= local mheight mwidth mrows eval f_dialog_menu_size mheight mwidth mrows \ \"\$DIALOG_TITLE\" \ @@ -320,7 +320,7 @@ f_dialog_input_group_members() $menu_list while :; do - dialog_menu=$( eval $DIALOG \ + menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -333,9 +333,8 @@ f_dialog_input_group_members() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" - defaultitem="$dialog_menu" - menu_choice=$( f_dialog_menutag ) + f_dialog_data_sanitize menu_choice + defaultitem="$menu_choice" f_dprintf "retval=%u menu_choice=[%s]" $retval "$menu_choice" # Return if user has either pressed ESC or chosen Cancel/No @@ -364,8 +363,7 @@ f_dialog_input_group_members() \"\" \ \"\$hline\" \ $checklist_users - local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ + _group_members=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --separate-output \ @@ -376,15 +374,18 @@ f_dialog_input_group_members() $cheight $cwidth $crows \ $checklist_users \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) || continue + # Return to previous menu if user either + # pressed ESC or chose Cancel/No + f_dialog_data_sanitize _group_members + + # Convert the newline separated list into a comma- + # separated one so that if the user switches over to + # manual editing, list reflects checklist selections + _group_members=$( echo "$_group_members" | + tr '\n' ' ' | + sed -e 's/[[:space:]]\{1,\}/,/g;s/^,//;s/,$//' ) - retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - _group_members=$( f_dialog_inputstr | tr '\n' ' ' | - sed -e 's/[[:space:]]\{1,\}/,/g;s/^,//;s/,$//' ) - - # Return to previous menu if user has either - # pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || continue _input="$_group_members" ;; diff --git a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr index f088548..68df2cf 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr @@ -113,8 +113,8 @@ f_dialog_menu_user_list() \"\$hline\" \ $menu_list - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local menu_choice + menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -127,7 +127,7 @@ f_dialog_menu_user_list() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" + f_dialog_menutag_store -s "$menu_choice" return $retval } @@ -168,8 +168,7 @@ f_dialog_input_member_groups() \"\" \ \"\$hline\" \ $checklist_groups - local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ + _member_groups=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --separate-output \ @@ -180,14 +179,9 @@ f_dialog_input_member_groups() $height $width $rows \ $checklist_groups \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD - ) - - retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - _member_groups=$( 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 + f_dialog_data_sanitize _member_groups # # Validate each of the groups the user has entered @@ -503,9 +497,9 @@ f_dialog_input_change() # # Loop until the user provides taint-free/cancellation-free input # + local date_type while :; do - local dialog_menu - dialog_menu=$( eval $DIALOG \ + date_type=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -517,8 +511,7 @@ f_dialog_input_change() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" - date_type=$( f_dialog_menutag ) + f_dialog_data_sanitize date_type f_dprintf "retval=%u date_type=[%s]" $retval "$date_type" # Return if user has either pressed ESC or chosen Cancel/No @@ -536,8 +529,7 @@ f_dialog_input_change() { f_isinteger "$secs" && [ $secs -gt 0 ]; } || secs= _input_date=$( date -j -f "%s" -- "$secs" \ "+%d %m %Y" 2> /dev/null ) - local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ + ret_date=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -549,8 +541,7 @@ f_dialog_input_change() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - ret_date=$( f_dialog_inputstr ) + f_dialog_data_sanitize ret_date f_dprintf "retval=%u ret_date=[%s]" $retval "$ret_date" # Return to menu if either ESC or Cancel/No @@ -559,8 +550,7 @@ f_dialog_input_change() _input_time= [ "$secs" ] && _input_time=$( date -j \ -f %s -- "$_input" "+%H %M %S" 2> /dev/null ) - local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ + ret_time=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -572,8 +562,7 @@ f_dialog_input_change() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - ret_time=$( f_dialog_inputstr ) + f_dialog_data_sanitize ret_time f_dprintf "retval=%u ret_time=[%s]" $retval "$ret_time" # Return to menu if either ESC or Cancel/No @@ -694,9 +683,9 @@ f_dialog_input_expire() # # Loop until the user provides taint-free/cancellation-free input # + local date_type while :; do - local dialog_menu - dialog_menu=$( eval $DIALOG \ + date_type=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -708,8 +697,7 @@ f_dialog_input_expire() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" - date_type=$( f_dialog_menutag ) + f_dialog_data_sanitize date_type f_dprintf "retval=%u date_type=[%s]" $retval "$date_type" # Return if user has either pressed ESC or chosen Cancel/No @@ -727,8 +715,7 @@ f_dialog_input_expire() { f_isinteger "$secs" && [ $secs -gt 0 ]; } || secs= _input_date=$( date -j -f "%s" -- "$secs" \ "+%d %m %Y" 2> /dev/null ) - local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ + ret_date=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -740,8 +727,7 @@ f_dialog_input_expire() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - ret_date=$( f_dialog_inputstr ) + f_dialog_data_sanitize ret_date f_dprintf "retval=%u ret_date=[%s]" $retval "$ret_date" # Return to menu if either ESC or Cancel/No @@ -750,7 +736,7 @@ f_dialog_input_expire() _input_time= [ "$secs" ] && _input_time=$( date -j \ -f %s -- "$_input" "+%H %M %S" 2> /dev/null ) - dialog_inputbox=$( eval $DIALOG \ + ret_time=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -762,8 +748,7 @@ f_dialog_input_expire() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - ret_time=$( f_dialog_inputstr ) + f_dialog_data_sanitize ret_time f_dprintf "retval=%u ret_time=[%s]" $retval "$ret_time" # Return to menu if either ESC or Cancel/No @@ -998,7 +983,7 @@ f_dialog_input_dotfiles_create() # f_dialog_input_shell() { - local retval shells shell_list _input="$1" + local shells shell_list _input="$1" local hline="$hline_arrows_space_tab_enter" local prompt="$msg_select_login_shell" @@ -1021,8 +1006,7 @@ f_dialog_input_shell() \"\$hline\" \ $shell_list - local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ + _input=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -1032,14 +1016,9 @@ f_dialog_input_shell() $height $width $rows \ $shell_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD - ) - - retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - _input=$( 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 + f_dialog_data_sanitize _input pw_shell="$_input" save_flag=1 diff --git a/usr.sbin/bsdconfig/usermgmt/userdel b/usr.sbin/bsdconfig/usermgmt/userdel index 05b160f..8ed747a 100755 --- a/usr.sbin/bsdconfig/usermgmt/userdel +++ b/usr.sbin/bsdconfig/usermgmt/userdel @@ -71,7 +71,7 @@ defaultitem="" while :; do f_dialog_menu_user_list "$defaultitem" retval=$? - mtag=$( f_dialog_menutag ) + f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" defaultitem="$mtag" diff --git a/usr.sbin/bsdconfig/usermgmt/useredit b/usr.sbin/bsdconfig/usermgmt/useredit index 60a3377..0226712 100755 --- a/usr.sbin/bsdconfig/usermgmt/useredit +++ b/usr.sbin/bsdconfig/usermgmt/useredit @@ -71,7 +71,7 @@ defaultitem="" while :; do f_dialog_menu_user_list "$defaultitem" retval=$? - mtag=$( f_dialog_menutag ) + f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" defaultitem="$mtag" diff --git a/usr.sbin/bsdconfig/usermgmt/userinput b/usr.sbin/bsdconfig/usermgmt/userinput index 2f9a58e..7df1993 100755 --- a/usr.sbin/bsdconfig/usermgmt/userinput +++ b/usr.sbin/bsdconfig/usermgmt/userinput @@ -391,7 +391,7 @@ while :; do \"\$hline\" \ $menu_items - dialog_menu=$( eval $DIALOG \ + mtag=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -403,11 +403,9 @@ while :; do $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) - retval=$? - setvar DEFAULTITEM_$$ "$dialog_menu" - setvar DIALOG_MENU_$$ "$dialog_menu" - mtag=$( f_dialog_menutag ) + f_dialog_data_sanitize mtag + setvar DEFAULTITEM_$$ "$mtag" f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No @@ -426,7 +424,7 @@ while :; do Edit/View|Delete) f_dialog_menu_user_list "$pw_name" retval=$? - mtag=$( f_dialog_menutag ) + f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Loop if user has either pressed ESC or chosen Cancel/No diff --git a/usr.sbin/bsdconfig/usermgmt/usermgmt b/usr.sbin/bsdconfig/usermgmt/usermgmt index 8ea5ae2..e91b44c 100755 --- a/usr.sbin/bsdconfig/usermgmt/usermgmt +++ b/usr.sbin/bsdconfig/usermgmt/usermgmt @@ -76,8 +76,8 @@ dialog_menu_main() # When using Xdialog(1) we need to bump the width for the buttons [ "$USE_XDIALOG" ] && width=40 - local dialog_menu - dialog_menu=$( eval $DIALOG \ + local menu_choice + menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ @@ -93,10 +93,11 @@ dialog_menu_main() 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? - setvar DIALOG_MENU_$$ "$dialog_menu" + f_dialog_data_sanitize menu_choice + f_dialog_menutag_store "$menu_choice" # Only update default-item on success - [ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$dialog_menu" + [ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice" return $retval } @@ -129,7 +130,7 @@ f_mustberoot_init while :; do dialog_menu_main retval=$? - mtag=$( f_dialog_menutag ) + f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" if [ $retval -eq 2 ]; then |