diff options
Diffstat (limited to 'usr.sbin/bsdconfig/networking/share/hostname.subr')
-rw-r--r-- | usr.sbin/bsdconfig/networking/share/hostname.subr | 109 |
1 files changed, 57 insertions, 52 deletions
diff --git a/usr.sbin/bsdconfig/networking/share/hostname.subr b/usr.sbin/bsdconfig/networking/share/hostname.subr index fed8679..959c7df 100644 --- a/usr.sbin/bsdconfig/networking/share/hostname.subr +++ b/usr.sbin/bsdconfig/networking/share/hostname.subr @@ -30,6 +30,7 @@ if [ ! "$_NETWORKING_HOSTNAME_SUBR" ]; then _NETWORKING_HOSTNAME_SUBR=1 BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading includes..." networking/hostname.subr f_include $BSDCFG_SHARE/sysrc.subr f_include $BSDCFG_SHARE/dialog.subr f_include $BSDCFG_SHARE/networking/common.subr @@ -40,7 +41,7 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr ############################################################ FUNCTIONS -# f_dialog_validate_hostname $hostname +# f_validate_hostname $hostname # # Returns zero if the given argument (a fully-qualified hostname) is compliant # with standards set-forth in RFC's 952 and 1123 of the Network Working Group: @@ -65,9 +66,9 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr # 3 One or more individual labels within the hostname are null. # # If the hostname is determined to be invalid, the appropriate error will be -# displayed using the f_dialog_msgbox function. +# displayed using the f_show_msg function. # -f_dialog_validate_hostname() +f_validate_hostname() { local fqhn="$1" @@ -95,23 +96,51 @@ f_dialog_validate_hostname() done ) +} - # - # Produce an appropriate error message if necessary. - # - local retval=$? - case $retval in - 1) f_dialog_msgbox "$( printf \ - "$msg_hostname_label_contains_invalid_chars" "$fqhn" )";; - 2) f_dialog_msgbox "$( printf \ - "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn" )";; - 3) f_dialog_msgbox "$( printf \ - "$msg_hostname_label_is_null" "$fqhn" )";; - 63) f_dialog_msgbox "$( printf \ - "$msg_hostname_label_exceeds_max_length" "$fqhn" )";; - 255) f_dialog_msgbox "$( printf \ - "$msg_hostname_exceeds_max_length" "$fqhn" )";; +# f_dialog_hnerror $error $hostname +# +# Display a msgbox with the appropriate error message for an error returned by +# the f_validate_hostname function. +# +f_dialog_hnerror() +{ + local error="$1" fqhn="$2" + + [ ${error:-0} -ne 0 ] || return $SUCCESS + + case "$error" in + 1) f_show_msg "$msg_hostname_label_contains_invalid_chars" "$fqhn";; + 2) f_show_msg "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn";; + 3) f_show_msg "$msg_hostname_label_is_null" "$fqhn";; + 63) f_show_msg "$msg_hostname_label_exceeds_max_length" "$fqhn";; + 255) f_show_msg "$msg_hostname_exceeds_max_length" "$fqhn";; esac +} + +# f_dialog_validate_hostname $hostname +# +# Returns zero if the given argument (a fully-qualified hostname) is compliant +# with standards set-forth in RFC's 952 and 1123 of the Network Working Group: +# +# RFC 952 - DoD Internet host table specification +# http://tools.ietf.org/html/rfc952 +# +# RFC 1123 - Requirements for Internet Hosts - Application and Support +# http://tools.ietf.org/html/rfc1123 +# +# If the hostname is determined to be invalid, the appropriate error will be +# displayed using the f_dialog_hnerror function above. +# +f_dialog_validate_hostname() +{ + local fqhn="$1" + + f_validate_hostname "$fqhn" + local retval=$? + + # Produce an appropriate error message if necessary. + [ $retval -eq $SUCCESS ] || f_dialog_hnerror $retval "$fqhn" return $retval } @@ -132,41 +161,15 @@ f_dialog_input_hostname() msg="$msg_please_enter_fqhn" fi - local hline="$hline_alnum_punc_tab_enter" - # # Loop until the user provides taint-free input. # - local size height width while :; do - - size=$( f_dialog_inputbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "$hostname" \ - "$hline" ) - local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --inputbox \"\$msg\" $size \ - \"\$hostname\" \ - 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD - ) - - local retval=$? - setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" - hostname=$( f_dialog_inputstr ) - - [ $retval -eq $SUCCESS ] || return $retval - + hostname=$( f_dialog_input "$msg" "$hostname" \ + "$hline_alnum_punc_tab_enter" + ) || return # Taint-check the user's input f_dialog_validate_hostname "$hostname" && break - done # @@ -187,7 +190,7 @@ f_dialog_input_hostname() # the stored configuration (in rc.conf(5)). # if [ "$( hostname )" != "$( f_sysrc_get hostname )" ]; then - [ ! "$USE_XDIALOG" ] && dialog_clear + [ ! "$USE_XDIALOG" ] && f_dialog_clear # # If connected via ssh(1) and performing X11-Forwarding, don't @@ -195,10 +198,8 @@ f_dialog_input_hostname() # "X11 connection rejected because of wrong authentication." # if [ "$USE_XDIALOG" -a "$SSH_CONNECTION" ]; then - f_dialog_msgbox "$( - printf "$msg_activate_hostname_x11warning" \ - "$( hostname )" "$hostname" - )" + f_show_msg "$msg_activate_hostname_x11warning" \ + "$( hostname )" "$hostname" else f_dialog_yesno "$( printf "$msg_activate_hostname" \ @@ -211,4 +212,8 @@ f_dialog_input_hostname() return $SUCCESS } +############################################################ MAIN + +f_dprintf "%s: Successfully loaded." networking/hostname.subr + fi # ! $_NETWORKING_HOSTNAME_SUBR |