Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Oct 2012 21:48:45 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r241653 - in head/usr.sbin/bsdconfig: include share
Message-ID:  <201210172148.q9HLmjLf071580@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Wed Oct 17 21:48:45 2012
New Revision: 241653
URL: http://svn.freebsd.org/changeset/base/241653

Log:
  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)

Modified:
  head/usr.sbin/bsdconfig/include/messages.subr
  head/usr.sbin/bsdconfig/share/mustberoot.subr

Modified: head/usr.sbin/bsdconfig/include/messages.subr
==============================================================================
--- head/usr.sbin/bsdconfig/include/messages.subr	Wed Oct 17 21:30:16 2012	(r241652)
+++ head/usr.sbin/bsdconfig/include/messages.subr	Wed Oct 17 21:48:45 2012	(r241653)
@@ -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 over
 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?"

Modified: head/usr.sbin/bsdconfig/share/mustberoot.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/mustberoot.subr	Wed Oct 17 21:30:16 2012	(r241652)
+++ head/usr.sbin/bsdconfig/share/mustberoot.subr	Wed Oct 17 21:48:45 2012	(r241653)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210172148.q9HLmjLf071580>