mustberoot.subr (251242) | mustberoot.subr (251264) |
---|---|
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# | 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 251242 2013-06-02 05:45:25Z dteske $ | 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{ | 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 msg hline height width rows | 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 | 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 ) |
|
93 msg=$( printf "$msg_always_try_sudo_when_run_as" "$USER" ) 94 local menu_list=" 95 'X' '$msg_cancel_exit' 96 '1' '$msg' 97 '2' '$msg_try_sudo_only_this_once' 98 " # END-QUOTE | 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 |
99 msg=$( printf "$msg_you_are_not_root_but" bsdconfig ) | |
100 hline="$hline_arrows_tab_enter" | 100 hline="$hline_arrows_tab_enter" |
101 |
|
101 eval f_dialog_menu_size height width rows \ 102 \"\$DIALOG_TITLE\" \ 103 \"\$DIALOG_BACKTITLE\" \ | 102 eval f_dialog_menu_size height width rows \ 103 \"\$DIALOG_TITLE\" \ 104 \"\$DIALOG_BACKTITLE\" \ |
104 \"\$msg\" \ | 105 \"\$prompt\" \ |
105 \"\$hline\" \ 106 $menu_list 107 108 local mtag 109 mtag=$( eval $DIALOG \ 110 --title \"\$DIALOG_TITLE\" \ 111 --backtitle \"\$DIALOG_BACKTITLE\" \ 112 --hline \"\$hline\" \ 113 --ok-label \"\$msg_ok\" \ 114 --cancel-label \"\$msg_cancel\" \ | 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\" \ |
115 --menu \"\$msg\" \ | 116 --menu \"\$prompt\" \ |
116 $height $width $rows \ 117 $menu_list \ 118 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 119 ) || f_die 120 f_dialog_data_sanitize mtag 121 122 case "$mtag" in 123 X) # Cancel/Exit --- 18 unchanged lines hidden (view full) --- 142 # 143 # Check sudo(8) access before prompting for password. 144 # 145 :| sudo -S -v 2> /dev/null 146 if [ $? -ne $SUCCESS ]; then 147 # 148 # sudo(8) access denied. Prompt for their password. 149 # | 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 # |
150 msg="$msg_please_enter_password" | 151 prompt="$msg_please_enter_password" |
151 hline="$hline_alnum_punc_tab_enter" 152 f_dialog_inputbox_size height width \ 153 "$DIALOG_TITLE" \ 154 "$DIALOG_BACKTITLE" \ | 152 hline="$hline_alnum_punc_tab_enter" 153 f_dialog_inputbox_size height width \ 154 "$DIALOG_TITLE" \ 155 "$DIALOG_BACKTITLE" \ |
155 "$msg" \ | 156 "$prompt" \ |
156 "$hline" 157 158 # 159 # Continue prompting until they either Cancel, succeed 160 # or exceed the number of allowed failures. 161 # 162 local password nfailures=0 retval 163 while [ $nfailures -lt $PASSWD_TRIES ]; do 164 if [ "$USE_XDIALOG" ]; then 165 password=$( $DIALOG \ 166 --title "$DIALOG_TITLE" \ 167 --backtitle "$DIALOG_BACKTITLE" \ 168 --hline "$hline" \ 169 --ok-label "$msg_ok" \ 170 --cancel-label "$msg_cancel" \ | 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" \ |
171 --password --inputbox "$msg" \ | 172 --password --inputbox "$prompt" \ |
172 $height $width \ 173 2>&1 > /dev/null ) 174 retval=$? 175 176 # Catch X11-related errors 177 [ $retval -eq 255 ] && 178 f_die $retval "$password" 179 else 180 password=$( $DIALOG \ 181 --title "$DIALOG_TITLE" \ 182 --backtitle "$DIALOG_BACKTITLE" \ 183 --hline "$hline" \ 184 --ok-label "$msg_ok" \ 185 --cancel-label "$msg_cancel" \ 186 --insecure \ | 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 \ |
187 --passwordbox "$msg" \ | 188 --passwordbox "$prompt" \ |
188 $height $width \ 189 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 190 ) || exit $? 191 fi 192 debug= f_dialog_line_sanitize password 193 194 # 195 # Validate sudo(8) credentials --- 224 unchanged lines hidden --- | 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 --- |