diff options
author | dteske <dteske@FreeBSD.org> | 2013-10-09 08:12:26 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-10-09 08:12:26 +0000 |
commit | ee2fafc6a903bcdb2569fc1d6c3ffce0f14c3ebd (patch) | |
tree | 4b1792e416c982abbc7d554b2fb8ab80ba5afb91 /usr.sbin/bsdconfig/usermgmt | |
parent | 255d648aec920f8660ba18ef659a9a08f5ee0198 (diff) | |
download | FreeBSD-src-ee2fafc6a903bcdb2569fc1d6c3ffce0f14c3ebd.zip FreeBSD-src-ee2fafc6a903bcdb2569fc1d6c3ffce0f14c3ebd.tar.gz |
Introduce centralized [X]dialog(1) exit codes to `dialog.subr' and make-use
throughout the bsdconfig(8) code. While we're here, add an explicit argument
to lvalue-seeking invocations of "return" that previously had no argument.
Also, consolidate a single instance of double-newline and remove some
comments that are no longer required (given increased readability with new
exit codes).
Approved by: re (glebius)
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 | 18 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/usermgmt/share/group_input.subr | 26 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/usermgmt/share/user_input.subr | 70 | ||||
-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 | 8 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/usermgmt | 7 |
9 files changed, 67 insertions, 70 deletions
diff --git a/usr.sbin/bsdconfig/usermgmt/groupdel b/usr.sbin/bsdconfig/usermgmt/groupdel index 3076216..2f41164 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupdel +++ b/usr.sbin/bsdconfig/usermgmt/groupdel @@ -75,7 +75,7 @@ while :; do f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" defaultitem="$mtag" - [ $retval -eq 0 ] || f_die + [ $retval -eq $DIALOG_OK ] || f_die [ "$mtag" = "X $msg_exit" ] && break diff --git a/usr.sbin/bsdconfig/usermgmt/groupedit b/usr.sbin/bsdconfig/usermgmt/groupedit index 1f1c744..3eacaff 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupedit +++ b/usr.sbin/bsdconfig/usermgmt/groupedit @@ -75,7 +75,7 @@ while :; do f_dprintf "retval=%s mtag=[%s]" $retval "$mtag" defaultitem="$mtag" - [ $retval -eq 0 ] || f_die + [ $retval -eq $DIALOG_OK ] || f_die [ "$mtag" = "X $msg_exit" ] && break diff --git a/usr.sbin/bsdconfig/usermgmt/groupinput b/usr.sbin/bsdconfig/usermgmt/groupinput index 6fff40f..5b60bb2 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupinput +++ b/usr.sbin/bsdconfig/usermgmt/groupinput @@ -162,9 +162,9 @@ if [ "$mode" = "Add" ]; then f_dialog_noyes "$msg_use_default_values_for_all_account_details" retval=$? - if [ $retval -eq 255 ]; then # User pressed ESC + if [ $retval -eq $DIALOG_ESC ]; then exit $SUCCESS - elif [ $retval -ne $SUCCESS ]; then + elif [ $retval -ne $DIALOG_OK ]; then # # Ask a series of questions to pre-fill the editor screen. # @@ -174,9 +174,9 @@ if [ "$mode" = "Add" ]; then # [ "$passwdtype" = "yes" ] && - { f_dialog_input_group_password || exit 0; } - f_dialog_input_group_gid || exit 0 - f_dialog_input_group_members || exit 0 + { f_dialog_input_group_password || exit $SUCCESS; } + f_dialog_input_group_gid || exit $SUCCESS + f_dialog_input_group_members || exit $SUCCESS fi fi @@ -255,13 +255,11 @@ while :; do f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || f_die + [ $retval -eq $DIALOG_OK ] || f_die case "$mtag" in X) # Exit - if [ "$save_flag" ]; then - save_changes || continue - fi + [ "$save_flag" ] && { save_changes || continue; } break ;; 1) # Group Name @@ -274,7 +272,7 @@ while :; do f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Loop if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || continue + [ $retval -eq $DIALOG_OK ] || continue [ "$mtag" = "X $msg_exit" ] && continue diff --git a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr index 93d981a..2ca141e 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr @@ -125,15 +125,15 @@ f_dialog_input_group_name() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_group" "$_input" \ - "$hline_alnum_tab_enter" || return + "$hline_alnum_tab_enter" || return $? # Check for no-change - [ "$_input" = "$_name" ] && return $SUCCESS + [ "$_input" = "$_name" ] && return $DIALOG_OK # Check for reversion if [ "$_input" = "$cur_group_name" ]; then group_name="$cur_group_name" - return $SUCCESS + return $DIALOG_OK fi # Check for NULL entry @@ -161,7 +161,7 @@ f_dialog_input_group_name() f_dprintf "group_name: [%s]->[%s]" "$cur_group_name" "$group_name" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_group_password @@ -210,7 +210,7 @@ f_dialog_input_group_password() debug= f_dialog_line_sanitize _password1 # Return if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || return $retval + [ $retval -eq $DIALOG_OK ] || return $retval _password2=$( $DIALOG \ --title "$DIALOG_TITLE" \ @@ -227,7 +227,7 @@ f_dialog_input_group_password() debug= f_dialog_line_sanitize _password2 # Return if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || return $retval + [ $retval -eq $DIALOG_OK ] || return $retval # Check for password mismatch if [ "$_password1" != "$_password2" ]; then @@ -239,9 +239,9 @@ f_dialog_input_group_password() if [ ! "$_password1" ]; then f_dialog_yesno "$msg_disable_password_auth_for_group" local retval=$? - if [ $retval -eq 255 ]; then # ESC was pressed + if [ $retval -eq $DIALOG_ESC ]; then return $retval - elif [ $retval -eq $SUCCESS ]; then + elif [ $retval -eq $DIALOG_OK ]; then pw_group_password_disable=1 else continue # back to password prompt @@ -258,7 +258,7 @@ f_dialog_input_group_password() f_dprintf "group_password: [%s]->[%s]" \ "$cur_group_password" "$group_password" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_group_gid [$group_gid] @@ -273,14 +273,14 @@ f_dialog_input_group_gid() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_group_id_leave_empty_for_default" \ - "$_input" "$hline_num_tab_enter" || return + "$_input" "$hline_num_tab_enter" || return $? group_gid="$_input" save_flag=1 f_dprintf "group_gid: [%s]->[%s]" "$cur_group_gid" "$group_gid" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_group_members [$group_members] @@ -329,7 +329,7 @@ f_dialog_input_group_members() f_dprintf "retval=%u menu_choice=[%s]" $retval "$menu_choice" # Return if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || return $retval + [ $retval -eq $DIALOG_OK ] || return $retval local _group_members case "$menu_choice" in @@ -399,7 +399,7 @@ f_dialog_input_group_members() f_dprintf "group_members: [%s]->[%s]" \ "$cur_group_members" "$group_members" - return $SUCCESS + return $DIALOG_OK } ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr index 21bfbd3..bd2fc9b 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr @@ -206,7 +206,7 @@ f_dialog_input_member_groups() f_dprintf "pw_member_groups: [%s]->[%s]" \ "$cur_pw_member_groups" "$pw_member_groups" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_name [$name] @@ -229,15 +229,15 @@ f_dialog_input_name() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_login" "$_input" \ - "$hline_alnum_tab_enter" || return + "$hline_alnum_tab_enter" || return $? # Check for no-change - [ "$_input" = "$_name" ] && return $SUCCESS + [ "$_input" = "$_name" ] && return $DIALOG_OK # Check for reversion if [ "$_input" = "$cur_pw_name" ]; then pw_name="$cur_pw_name" - return $SUCCESS + return $DIALOG_OK fi # Check for NULL entry @@ -265,7 +265,7 @@ f_dialog_input_name() f_dprintf "pw_name: [%s]->[%s]" "$cur_pw_name" "$pw_name" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_password @@ -336,9 +336,9 @@ f_dialog_input_password() if [ ! "$_password1" ]; then f_dialog_yesno "$msg_disable_password_auth_for_account" local retval=$? - if [ $retval -eq 255 ]; then # ESC was pressed + if [ $retval -eq $DIALOG_ESC ]; then return $retval - elif [ $retval -eq $SUCCESS ]; then + elif [ $retval -eq $DIALOG_OK ]; then pw_password_disable=1 else continue # back to password prompt @@ -354,7 +354,7 @@ f_dialog_input_password() f_dprintf "pw_password: [%s]->[%s]" "$cur_pw_password" "$pw_password" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_gecos [$gecos] @@ -370,14 +370,14 @@ f_dialog_input_gecos() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_full_name" "$_input" \ - "$hline_alnum_punc_tab_enter" || return + "$hline_alnum_punc_tab_enter" || return $? pw_gecos="$_input" save_flag=1 f_dprintf "pw_gecos: [%s]->[%s]" "$cur_pw_gecos" "$pw_gecos" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_uid [$uid] @@ -392,14 +392,14 @@ f_dialog_input_uid() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_user_id_leave_empty_for_default" \ - "$_input" "$hline_num_tab_enter" || return + "$_input" "$hline_num_tab_enter" || return $? pw_uid="$_input" save_flag=1 f_dprintf "pw_uid: [%s]->[%s]" "$cur_pw_uid" "$pw_uid" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_gid [$gid] @@ -414,14 +414,14 @@ f_dialog_input_gid() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_group_id_leave_empty_for_default" \ - "$_input" "$hline_num_tab_enter" || return + "$_input" "$hline_num_tab_enter" || return $? pw_gid="$_input" save_flag=1 f_dprintf "pw_gid: [%s]->[%s]" "$cur_pw_gid" "$pw_gid" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_class [$class] @@ -436,14 +436,14 @@ f_dialog_input_class() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_login_class" "$_input" \ - "$hline_alnum_tab_enter" || return + "$hline_alnum_tab_enter" || return $? pw_class="$_input" save_flag=1 f_dprintf "pw_class: [%s]->[%s]" "$cur_pw_class" "$pw_class" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_expire_password [$seconds] @@ -508,7 +508,7 @@ f_dialog_input_expire_password() f_dprintf "retval=%u date_type=[%s]" $retval "$date_type" # Return if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || return $retval + [ $retval -eq $DIALOG_OK ] || return $retval case "$date_type" in 1) # Password does not expire @@ -538,7 +538,7 @@ f_dialog_input_expire_password() f_dprintf "retval=%u ret_date=[%s]" $retval "$ret_date" # Return to menu if either ESC or Cancel/No - [ $retval -eq $SUCCESS ] || continue + [ $retval -eq $DIALOG_OK ] || continue _input_time= [ "$secs" ] && _input_time=$( date -j \ @@ -559,7 +559,7 @@ f_dialog_input_expire_password() f_dprintf "retval=%u ret_time=[%s]" $retval "$ret_time" # Return to menu if either ESC or Cancel/No - [ $retval -eq $SUCCESS ] || continue + [ $retval -eq $DIALOG_OK ] || continue _input=$( date \ -j -f "%d/%m/%Y %T" \ @@ -627,7 +627,7 @@ f_dialog_input_expire_password() f_dprintf "pw_password_expire: [%s]->[%s]" \ "$cur_pw_password_expire" "$pw_password_expire" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_expire_account [$seconds] @@ -692,7 +692,7 @@ f_dialog_input_expire_account() f_dprintf "retval=%u date_type=[%s]" $retval "$date_type" # Return if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || return $retval + [ $retval -eq $DIALOG_OK ] || return $retval case "$date_type" in 1) # Account does not expire @@ -722,7 +722,7 @@ f_dialog_input_expire_account() f_dprintf "retval=%u ret_date=[%s]" $retval "$ret_date" # Return to menu if either ESC or Cancel/No - [ $retval -eq $SUCCESS ] || continue + [ $retval -eq $DIALOG_OK ] || continue _input_time= [ "$secs" ] && _input_time=$( date -j \ @@ -743,7 +743,7 @@ f_dialog_input_expire_account() f_dprintf "retval=%u ret_time=[%s]" $retval "$ret_time" # Return to menu if either ESC or Cancel/No - [ $retval -eq $SUCCESS ] || continue + [ $retval -eq $DIALOG_OK ] || continue _input=$( date \ -j -f "%d/%m/%Y %T" \ @@ -811,7 +811,7 @@ f_dialog_input_expire_account() f_dprintf "pw_account_expire: [%s]->[%s]" \ "$cur_pw_account_expire" "$pw_account_expire" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_home_dir [$home_dir] @@ -826,14 +826,14 @@ f_dialog_input_home_dir() # Return if user has either pressed ESC or chosen Cancel/No f_dialog_input _input "$msg_home_directory" "$_input" \ - "$hline_alnum_punc_tab_enter" || return + "$hline_alnum_punc_tab_enter" || return $? pw_home_dir="$_input" save_flag=1 f_dprintf "pw_home_dir: [%s]->[%s]" "$cur_pw_home_dir" "$pw_home_dir" - return $SUCCESS + return $DIALOG_OK } # f_dialog_input_home_create @@ -850,7 +850,7 @@ f_dialog_input_home_create() f_dialog_yesno "$msg_create_home_directory" retval=$? - if [ $retval -eq $SUCCESS ]; then + if [ $retval -eq $DIALOG_OK ]; then pw_home_create="$msg_yes" else pw_home_create="$msg_no" @@ -860,7 +860,7 @@ f_dialog_input_home_create() f_dprintf "pw_home_create: [%s]->[%s]" \ "$cur_pw_home_create" "$pw_home_create" - [ $retval -ne 255 ] # return failure if user pressed ESC + [ $retval -ne $DIALOG_ESC ] # return failure if user pressed ESC } # f_dialog_input_group_delete @@ -893,7 +893,7 @@ f_dialog_input_group_delete() fi retval=$? - if [ $retval -eq $SUCCESS ]; then + if [ $retval -eq $DIALOG_OK ]; then pw_group_delete="$msg_yes" else pw_group_delete="$msg_no" @@ -903,7 +903,7 @@ f_dialog_input_group_delete() f_dprintf "pw_group_delete: [%s]->[%s]" \ "$cur_pw_group_delete" "$pw_group_delete" - [ $retval -ne 255 ] # return failure if user pressed ESC + [ $retval -ne $DIALOG_ESC ] # return failure if user pressed ESC } # f_dialog_input_home_delete @@ -920,7 +920,7 @@ f_dialog_input_home_delete() f_dialog_yesno "$msg_delete_home_directory" retval=$? - if [ $retval -eq $SUCCESS ]; then + if [ $retval -eq $DIALOG_OK ]; then pw_home_delete="$msg_yes" else pw_home_delete="$msg_no" @@ -930,7 +930,7 @@ f_dialog_input_home_delete() f_dprintf "pw_home_delete: [%s]->[%s]" \ "$cur_pw_home_delete" "$pw_home_delete" - [ $retval -ne 255 ] # return failure if user pressed ESC + [ $retval -ne $DIALOG_ESC ] # return failure if user pressed ESC } # f_dialog_input_dotfiles_create @@ -948,7 +948,7 @@ f_dialog_input_dotfiles_create() f_dialog_yesno "$msg_create_dotfiles" retval=$? - if [ $retval -eq $SUCCESS ]; then + if [ $retval -eq $DIALOG_OK ]; then pw_dotfiles_create="$msg_yes" else pw_dotfiles_create="$msg_no" @@ -958,7 +958,7 @@ f_dialog_input_dotfiles_create() f_dprintf "pw_dotfiles_create: [%s]->[%s]" \ "$cur_pw_dotfiles_create" "$pw_dotfiles_create" - [ $retval -ne 255 ] # return failure if user pressed ESC + [ $retval -ne $DIALOG_ESC ] # return failure if user pressed ESC } # f_dialog_input_shell [$shell] @@ -1015,7 +1015,7 @@ f_dialog_input_shell() f_dprintf "pw_shell: [%s]->[%s]" "$cur_pw_shell" "$pw_shell" - return $SUCCESS + return $DIALOG_OK } ############################################################ MAIN diff --git a/usr.sbin/bsdconfig/usermgmt/userdel b/usr.sbin/bsdconfig/usermgmt/userdel index f266497..299e25b 100755 --- a/usr.sbin/bsdconfig/usermgmt/userdel +++ b/usr.sbin/bsdconfig/usermgmt/userdel @@ -75,7 +75,7 @@ while :; do f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" defaultitem="$mtag" - [ $retval -eq 0 ] || f_die + [ $retval -eq $DIALOG_OK ] || f_die [ "$mtag" = "X $msg_exit" ] && break diff --git a/usr.sbin/bsdconfig/usermgmt/useredit b/usr.sbin/bsdconfig/usermgmt/useredit index 64b7b8e..a4bee68 100755 --- a/usr.sbin/bsdconfig/usermgmt/useredit +++ b/usr.sbin/bsdconfig/usermgmt/useredit @@ -75,7 +75,7 @@ while :; do f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" defaultitem="$mtag" - [ $retval -eq 0 ] || f_die + [ $retval -eq $DIALOG_OK ] || f_die [ "$mtag" = "X $msg_exit" ] && break diff --git a/usr.sbin/bsdconfig/usermgmt/userinput b/usr.sbin/bsdconfig/usermgmt/userinput index 196262b..aad6ef3 100755 --- a/usr.sbin/bsdconfig/usermgmt/userinput +++ b/usr.sbin/bsdconfig/usermgmt/userinput @@ -257,9 +257,9 @@ if [ "$mode" = "Add" ]; then f_dialog_noyes "$msg_use_default_values_for_all_account_details" retval=$? - if [ $retval -eq 255 ]; then # User pressed ESC + if [ $retval -eq $DIALOG_ESC ]; then exit $SUCCESS - elif [ $retval -ne $SUCCESS ]; then + elif [ $retval -ne $DIALOG_OK ]; then # # Ask a series of questions to pre-fill the editor screen. # @@ -431,7 +431,7 @@ while :; do f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || f_die + [ $retval -eq $DIALOG_OK ] || f_die case "$mtag" in X) # Exit @@ -450,7 +450,7 @@ while :; do f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Loop if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || continue + [ $retval -eq $DIALOG_OK ] || continue [ "$mtag" = "X $msg_exit" ] && continue diff --git a/usr.sbin/bsdconfig/usermgmt/usermgmt b/usr.sbin/bsdconfig/usermgmt/usermgmt index 0a4c160..5335bd6 100755 --- a/usr.sbin/bsdconfig/usermgmt/usermgmt +++ b/usr.sbin/bsdconfig/usermgmt/usermgmt @@ -100,7 +100,7 @@ dialog_menu_main() f_dialog_menutag_store "$menu_choice" # Only update default-item on success - [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" + [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" return $retval } @@ -136,11 +136,10 @@ while :; do f_dialog_menutag_fetch mtag f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" - if [ $retval -eq 2 ]; then - # The Help button was pressed + if [ $retval -eq $DIALOG_HELP ]; then f_show_help "$USERMGMT_HELPFILE" continue - elif [ $retval -ne $SUCCESS ]; then + elif [ $retval -ne $DIALOG_OK ]; then f_die fi |