summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2012-10-17 21:48:45 +0000
committerdteske <dteske@FreeBSD.org>2012-10-17 21:48:45 +0000
commit6defc54cbd222e4aa7c820f1ac2faf671a2e8c14 (patch)
tree8bf9ac77902026a1f28b7eb891021fad6d357afa
parentdebabe4d4abfda09e7ca540cb297bcbd3996de03 (diff)
downloadFreeBSD-src-6defc54cbd222e4aa7c820f1ac2faf671a2e8c14.zip
FreeBSD-src-6defc54cbd222e4aa7c820f1ac2faf671a2e8c14.tar.gz
Ask to become root via sudo(8) and give user ability to save this preference.
Reviewed by: adrian (co-mentor) Approved by: adrian (co-mentor)
-rw-r--r--usr.sbin/bsdconfig/include/messages.subr6
-rw-r--r--usr.sbin/bsdconfig/share/mustberoot.subr59
2 files changed, 65 insertions, 0 deletions
diff --git a/usr.sbin/bsdconfig/include/messages.subr b/usr.sbin/bsdconfig/include/messages.subr
index fd38440..26d4188 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 c6514c0..fd37c64 100644
--- a/usr.sbin/bsdconfig/share/mustberoot.subr
+++ b/usr.sbin/bsdconfig/share/mustberoot.subr
@@ -83,6 +83,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.
#
:| sudo -S -v 2> /dev/null
OpenPOWER on IntegriCloud