1if [ ! "$_MUSTBEROOT_SUBR" ]; then _MUSTBEROOT_SUBR=1 2# 3# Copyright (c) 2006-2013 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/usr.sbin/bsdconfig/share/mustberoot.subr 251264 2013-06-02 20:02:50Z dteske $ |
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." mustberoot.subr 34f_include $BSDCFG_SHARE/dialog.subr 35 --- 36 unchanged lines hidden (view full) --- 72# 73# The following environment variables effect functionality: 74# 75# USE_XDIALOG Either NULL or Non-NULL. If given a value will indicate 76# that Xdialog(1) should be used instead of dialog(1). 77# 78f_become_root_via_sudo() 79{ |
80 local prompt hline height width rows msg |
81 82 [ "$( id -u )" = "0" ] && return $SUCCESS 83 84 f_have sudo || f_die 1 "$msg_must_be_root_to_execute" "$pgm" 85 86 # 87 # Ask the user if it's OK to become root via sudo(8) and give them 88 # the option to save this preference (by touch(1)ing a file in the 89 # user's $HOME directory). 90 # 91 local checkpath="${HOME%/}/.bsdconfig_uses_sudo" 92 if [ ! -e "$checkpath" ]; then |
93 prompt=$( printf "$msg_you_are_not_root_but" bsdconfig ) |
94 msg=$( printf "$msg_always_try_sudo_when_run_as" "$USER" ) 95 local menu_list=" 96 'X' '$msg_cancel_exit' 97 '1' '$msg' 98 '2' '$msg_try_sudo_only_this_once' 99 " # END-QUOTE |
100 hline="$hline_arrows_tab_enter" |
101 |
102 eval f_dialog_menu_size height width rows \ 103 \"\$DIALOG_TITLE\" \ 104 \"\$DIALOG_BACKTITLE\" \ |
105 \"\$prompt\" \ |
106 \"\$hline\" \ 107 $menu_list 108 109 local mtag 110 mtag=$( eval $DIALOG \ 111 --title \"\$DIALOG_TITLE\" \ 112 --backtitle \"\$DIALOG_BACKTITLE\" \ 113 --hline \"\$hline\" \ 114 --ok-label \"\$msg_ok\" \ 115 --cancel-label \"\$msg_cancel\" \ |
116 --menu \"\$prompt\" \ |
117 $height $width $rows \ 118 $menu_list \ 119 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 120 ) || f_die 121 f_dialog_data_sanitize mtag 122 123 case "$mtag" in 124 X) # Cancel/Exit --- 18 unchanged lines hidden (view full) --- 143 # 144 # Check sudo(8) access before prompting for password. 145 # 146 :| sudo -S -v 2> /dev/null 147 if [ $? -ne $SUCCESS ]; then 148 # 149 # sudo(8) access denied. Prompt for their password. 150 # |
151 prompt="$msg_please_enter_password" |
152 hline="$hline_alnum_punc_tab_enter" 153 f_dialog_inputbox_size height width \ 154 "$DIALOG_TITLE" \ 155 "$DIALOG_BACKTITLE" \ |
156 "$prompt" \ |
157 "$hline" 158 159 # 160 # Continue prompting until they either Cancel, succeed 161 # or exceed the number of allowed failures. 162 # 163 local password nfailures=0 retval 164 while [ $nfailures -lt $PASSWD_TRIES ]; do 165 if [ "$USE_XDIALOG" ]; then 166 password=$( $DIALOG \ 167 --title "$DIALOG_TITLE" \ 168 --backtitle "$DIALOG_BACKTITLE" \ 169 --hline "$hline" \ 170 --ok-label "$msg_ok" \ 171 --cancel-label "$msg_cancel" \ |
172 --password --inputbox "$prompt" \ |
173 $height $width \ 174 2>&1 > /dev/null ) 175 retval=$? 176 177 # Catch X11-related errors 178 [ $retval -eq 255 ] && 179 f_die $retval "$password" 180 else 181 password=$( $DIALOG \ 182 --title "$DIALOG_TITLE" \ 183 --backtitle "$DIALOG_BACKTITLE" \ 184 --hline "$hline" \ 185 --ok-label "$msg_ok" \ 186 --cancel-label "$msg_cancel" \ 187 --insecure \ |
188 --passwordbox "$prompt" \ |
189 $height $width \ 190 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 191 ) || exit $? 192 fi 193 debug= f_dialog_line_sanitize password 194 195 # 196 # Validate sudo(8) credentials --- 224 unchanged lines hidden --- |