summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share
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 /usr.sbin/bsdconfig/share
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)
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r--usr.sbin/bsdconfig/share/mustberoot.subr59
1 files changed, 59 insertions, 0 deletions
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