summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/networking
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2012-12-21 21:33:47 +0000
committerdteske <dteske@FreeBSD.org>2012-12-21 21:33:47 +0000
commit777c7fa05d0e27302d79b46b228dbbd72462832d (patch)
treefc772cd14bc7442c2e3e9fda729baa5218bad31e /usr.sbin/bsdconfig/networking
parentddf809931fdd7bcce325e32e1cf30843342497e3 (diff)
downloadFreeBSD-src-777c7fa05d0e27302d79b46b228dbbd72462832d.zip
FreeBSD-src-777c7fa05d0e27302d79b46b228dbbd72462832d.tar.gz
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.
Diffstat (limited to 'usr.sbin/bsdconfig/networking')
-rw-r--r--usr.sbin/bsdconfig/networking/share/hostname.subr49
-rw-r--r--usr.sbin/bsdconfig/networking/share/netmask.subr43
2 files changed, 74 insertions, 18 deletions
diff --git a/usr.sbin/bsdconfig/networking/share/hostname.subr b/usr.sbin/bsdconfig/networking/share/hostname.subr
index 1e954ed..6d7949e 100644
--- a/usr.sbin/bsdconfig/networking/share/hostname.subr
+++ b/usr.sbin/bsdconfig/networking/share/hostname.subr
@@ -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
}
diff --git a/usr.sbin/bsdconfig/networking/share/netmask.subr b/usr.sbin/bsdconfig/networking/share/netmask.subr
index c120621..4b28743 100644
--- a/usr.sbin/bsdconfig/networking/share/netmask.subr
+++ b/usr.sbin/bsdconfig/networking/share/netmask.subr
@@ -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
}
OpenPOWER on IntegriCloud