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.
This commit is contained in:
Devin Teske 2012-12-21 21:33:47 +00:00
parent ab3e5e540b
commit 35a157a0eb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=244565
2 changed files with 74 additions and 18 deletions

View File

@ -40,7 +40,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 +65,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,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
}

View File

@ -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
}