diff --git a/usr.sbin/bsdconfig/include/messages.subr b/usr.sbin/bsdconfig/include/messages.subr index fd3844028ab8..26d41881123b 100644 --- a/usr.sbin/bsdconfig/include/messages.subr +++ b/usr.sbin/bsdconfig/include/messages.subr @@ -29,8 +29,12 @@ field_username="Username:" field_password="Password:" hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER" hline_arrows_tab_enter="Press arrows, TAB or ENTER" +msg_always_try_sudo_when_run_as="Always try sudo(8) when run as %s" +msg_becoming_root_via_sudo="Becoming root via sudo(8)..." msg_cancel="Cancel" +msg_cancel_exit="Cancel/Exit" msg_cannot_create_permission_denied="%s: cannot create %s: Permission denied" +msg_created_path="Created %s" msg_directory_not_found="%s: Directory not found." msg_exit="Exit" msg_exit_bsdconfig="Exit bsdconfig" @@ -51,6 +55,8 @@ msg_previous_syntax_errors="%s: Not overwriting \`%s' due to previous syntax err msg_secure_mode_requires_x11="Secure-mode requires X11 (use \`-X')!" msg_secure_mode_requires_root="Secure-mode requires root-access!" msg_sorry_try_again="Sorry, try again." +msg_try_sudo_only_this_once="Try sudo(8) only this once" msg_unknown_user="Unknown user: %s" msg_user_disallowed="User disallowed: %s" msg_yes="Yes" +msg_you_are_not_root_but="You are not root but %s can use sudo(8).\nWhat would you like to do?" diff --git a/usr.sbin/bsdconfig/share/mustberoot.subr b/usr.sbin/bsdconfig/share/mustberoot.subr index c6514c0d4b1e..fd37c641db8f 100644 --- a/usr.sbin/bsdconfig/share/mustberoot.subr +++ b/usr.sbin/bsdconfig/share/mustberoot.subr @@ -82,6 +82,65 @@ f_become_root_via_sudo() f_have sudo || f_die 1 "$msg_must_be_root_to_execute" "$pgm" + # + # Ask the user if it's OK to become root via sudo(8) and give them + # the option to save this preference (by touch(1)ing a file in the + # user's $HOME directory). + # + local checkpath="${HOME%/}/.bsdconfig_uses_sudo" + if [ ! -e "$checkpath" ]; then + msg=$( printf "$msg_always_try_sudo_when_run_as" "$USER" ) + local menu_list=" + 'X' '$msg_cancel_exit' + '1' '$msg' + '2' '$msg_try_sudo_only_this_once' + " # END-QUOTE + msg=$( printf "$msg_you_are_not_root_but" bsdconfig ) + hline="$hline_arrows_tab_enter" + size=$( eval f_dialog_menu_size \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$msg\" \ + \"\$hline\" \ + $menu_list ) + + local dialog_menu mtag retval + dialog_menu=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --menu \"\$msg\" $size \ + $menu_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + retval=$? + setvar DIALOG_MENU_$$ "$dialog_menu" + mtag=$( f_dialog_menutag ) + + [ $retval -eq 0 ] || f_die + + case "$mtag" in + X) # Cancel/Exit + f_die ;; + 1) # Always try sudo(8) when run as $user + local err + if ! err=$( touch "$checkpath" 2>&1 ); then + f_show_msg "%s" "$err" + else + f_show_msg "$msg_created_path" "$checkpath" + fi + esac + else + # + # This user has created the path signing-off on sudo(8)-use + # but let's still give them a short/quick/unobtrusive reminder + # + f_dialog_info "$msg_becoming_root_via_sudo" + [ "$USE_XDIALOG" ] || sleep 0.6 + fi + # # Check sudo(8) access before prompting for password. #