From owner-svn-src-head@FreeBSD.ORG Fri Dec 21 21:33:48 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A46932DC; Fri, 21 Dec 2012 21:33:48 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 878528FC13; Fri, 21 Dec 2012 21:33:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBLLXmxh042433; Fri, 21 Dec 2012 21:33:48 GMT (envelope-from dteske@svn.freebsd.org) Received: (from dteske@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBLLXmqT042431; Fri, 21 Dec 2012 21:33:48 GMT (envelope-from dteske@svn.freebsd.org) Message-Id: <201212212133.qBLLXmqT042431@svn.freebsd.org> From: Devin Teske Date: Fri, 21 Dec 2012 21:33:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244565 - head/usr.sbin/bsdconfig/networking/share X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Dec 2012 21:33:48 -0000 Author: dteske Date: Fri Dec 21 21:33:47 2012 New Revision: 244565 URL: http://svnweb.freebsd.org/changeset/base/244565 Log: Split dialog(1)-based validators for hostname/netmask into two, providing transparent validators that can be used free of dialog(1) where needed. Syntax/return of the original dialog(1)-based validators remains unchanged. Modified: head/usr.sbin/bsdconfig/networking/share/hostname.subr head/usr.sbin/bsdconfig/networking/share/netmask.subr Modified: head/usr.sbin/bsdconfig/networking/share/hostname.subr ============================================================================== --- head/usr.sbin/bsdconfig/networking/share/hostname.subr Fri Dec 21 21:26:36 2012 (r244564) +++ head/usr.sbin/bsdconfig/networking/share/hostname.subr Fri Dec 21 21:33:47 2012 (r244565) @@ -40,7 +40,7 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/inc ############################################################ 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 +65,9 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/inc # 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,18 +95,51 @@ f_dialog_validate_hostname() done ) +} - # - # Produce an appropriate error message if necessary. - # - local retval=$? - case $retval in +# 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 } Modified: head/usr.sbin/bsdconfig/networking/share/netmask.subr ============================================================================== --- head/usr.sbin/bsdconfig/networking/share/netmask.subr Fri Dec 21 21:26:36 2012 (r244564) +++ head/usr.sbin/bsdconfig/networking/share/netmask.subr Fri Dec 21 21:33:47 2012 (r244565) @@ -69,7 +69,7 @@ f_ifconfig_netmask() echo $netmask } -# f_dialog_validate_netmask $netmask +# f_validate_netmask $netmask # # Returns zero if the given argument (a subnet mask) is of the proper format. # @@ -85,10 +85,7 @@ f_ifconfig_netmask() # invalid integer (only 0,128,192,224,240,248,252,254,255 are # valid integers). # -# If the subnet mask is determined to be invalid, the appropriate error will be -# displayed using the f_dialog_msgbox function. -# -f_dialog_validate_netmask() +f_validate_netmask() { local mask="$1" @@ -121,18 +118,44 @@ f_dialog_validate_netmask() [ $nfields -eq 4 ] || exit 4 ) +} - # - # Produce an appropriate error message if necessary. - # - local retval=$? - case $retval in +# f_dialog_maskerror $error $netmask +# +# Display a msgbox with the appropriate error message for an error returned by +# the f_validate_netmask function. +# +f_dialog_maskerror() +{ + local error="$1" netmask="$2" + + [ ${error:-0} -ne 0 ] || return $SUCCESS + + case "$error" in 1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask";; 2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask";; 3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask";; 4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask";; 5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask";; esac +} + +# f_dialog_validate_netmask $netmask +# +# Returns zero if the given argument (a subnet mask) is of the proper format. +# +# If the subnet mask is determined to be invalid, the appropriate error will be +# displayed using the f_dialog_maskerror function above. +# +f_dialog_validate_netmask() +{ + local netmask="$1" + + f_validate_netmask "$netmask" + local retval=$? + + # Produce an appropriate error message if necessary. + [ $retval -eq $SUCCESS ] || f_dialog_maskerror $retval "$netmask" return $retval }