hostname.subr (fa2e39c89210ec44b1afdceadcb999bf9acd2a67) hostname.subr (35a157a0eb81363303899064c3078f63cda511e1)
1if [ ! "$_NETWORKING_HOSTNAME_SUBR" ]; then _NETWORKING_HOSTNAME_SUBR=1
2#
3# Copyright (c) 2006-2012 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:

--- 26 unchanged lines hidden (view full) ---

35f_include $BSDCFG_SHARE/networking/common.subr
36f_include $BSDCFG_SHARE/networking/resolv.subr
37
38BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
39f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40
41############################################################ FUNCTIONS
42
1if [ ! "$_NETWORKING_HOSTNAME_SUBR" ]; then _NETWORKING_HOSTNAME_SUBR=1
2#
3# Copyright (c) 2006-2012 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:

--- 26 unchanged lines hidden (view full) ---

35f_include $BSDCFG_SHARE/networking/common.subr
36f_include $BSDCFG_SHARE/networking/resolv.subr
37
38BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
39f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40
41############################################################ FUNCTIONS
42
43# f_dialog_validate_hostname $hostname
43# f_validate_hostname $hostname
44#
45# Returns zero if the given argument (a fully-qualified hostname) is compliant
46# with standards set-forth in RFC's 952 and 1123 of the Network Working Group:
47#
48# RFC 952 - DoD Internet host table specification
49# http://tools.ietf.org/html/rfc952
50#
51# RFC 1123 - Requirements for Internet Hosts - Application and Support

--- 8 unchanged lines hidden (view full) ---

60# 1 One or more individual labels within the hostname contains one
61# or more invalid characters.
62# 2 One or more individual labels within the hostname starts or
63# ends with a hyphen (hyphens are allowed, but a label cannot
64# begin or end with a hyphen).
65# 3 One or more individual labels within the hostname are null.
66#
67# If the hostname is determined to be invalid, the appropriate error will be
44#
45# Returns zero if the given argument (a fully-qualified hostname) is compliant
46# with standards set-forth in RFC's 952 and 1123 of the Network Working Group:
47#
48# RFC 952 - DoD Internet host table specification
49# http://tools.ietf.org/html/rfc952
50#
51# RFC 1123 - Requirements for Internet Hosts - Application and Support

--- 8 unchanged lines hidden (view full) ---

60# 1 One or more individual labels within the hostname contains one
61# or more invalid characters.
62# 2 One or more individual labels within the hostname starts or
63# ends with a hyphen (hyphens are allowed, but a label cannot
64# begin or end with a hyphen).
65# 3 One or more individual labels within the hostname are null.
66#
67# If the hostname is determined to be invalid, the appropriate error will be
68# displayed using the f_dialog_msgbox function.
68# displayed using the f_show_msg function.
69#
69#
70f_dialog_validate_hostname()
70f_validate_hostname()
71{
72 local fqhn="$1"
73
74 ( # Operate within a sub-shell to protect the parent environment
75
76 # Return error if the hostname exceeds 255 characters
77 [ ${#fqhn} -gt 255 ] && exit 255
78

--- 11 unchanged lines hidden (view full) ---

90 -*|*-) exit 2
91 esac
92
93 # Return error if the label contains any invalid chars
94 echo "$label" | grep -q '^[[:alnum:]-]*$' || exit 1
95
96 done
97 )
71{
72 local fqhn="$1"
73
74 ( # Operate within a sub-shell to protect the parent environment
75
76 # Return error if the hostname exceeds 255 characters
77 [ ${#fqhn} -gt 255 ] && exit 255
78

--- 11 unchanged lines hidden (view full) ---

90 -*|*-) exit 2
91 esac
92
93 # Return error if the label contains any invalid chars
94 echo "$label" | grep -q '^[[:alnum:]-]*$' || exit 1
95
96 done
97 )
98}
98
99
99 #
100 # Produce an appropriate error message if necessary.
101 #
102 local retval=$?
103 case $retval in
100# f_dialog_hnerror $error $hostname
101#
102# Display a msgbox with the appropriate error message for an error returned by
103# the f_validate_hostname function.
104#
105f_dialog_hnerror()
106{
107 local error="$1" fqhn="$2"
108
109 [ ${error:-0} -ne 0 ] || return $SUCCESS
110
111 case "$error" in
104 1) f_show_msg "$msg_hostname_label_contains_invalid_chars" "$fqhn";;
105 2) f_show_msg "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn";;
106 3) f_show_msg "$msg_hostname_label_is_null" "$fqhn";;
107 63) f_show_msg "$msg_hostname_label_exceeds_max_length" "$fqhn";;
108 255) f_show_msg "$msg_hostname_exceeds_max_length" "$fqhn";;
109 esac
112 1) f_show_msg "$msg_hostname_label_contains_invalid_chars" "$fqhn";;
113 2) f_show_msg "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn";;
114 3) f_show_msg "$msg_hostname_label_is_null" "$fqhn";;
115 63) f_show_msg "$msg_hostname_label_exceeds_max_length" "$fqhn";;
116 255) f_show_msg "$msg_hostname_exceeds_max_length" "$fqhn";;
117 esac
118}
110
119
120# f_dialog_validate_hostname $hostname
121#
122# Returns zero if the given argument (a fully-qualified hostname) is compliant
123# with standards set-forth in RFC's 952 and 1123 of the Network Working Group:
124#
125# RFC 952 - DoD Internet host table specification
126# http://tools.ietf.org/html/rfc952
127#
128# RFC 1123 - Requirements for Internet Hosts - Application and Support
129# http://tools.ietf.org/html/rfc1123
130#
131# If the hostname is determined to be invalid, the appropriate error will be
132# displayed using the f_dialog_hnerror function above.
133#
134f_dialog_validate_hostname()
135{
136 local fqhn="$1"
137
138 f_validate_hostname "$fqhn"
139 local retval=$?
140
141 # Produce an appropriate error message if necessary.
142 [ $retval -eq $SUCCESS ] || f_dialog_hnerror $retval "$fqhn"
143
111 return $retval
112}
113
114# f_dialog_input_hostname
115#
116# Edits the current hostname.
117#
118f_dialog_input_hostname()

--- 63 unchanged lines hidden ---
144 return $retval
145}
146
147# f_dialog_input_hostname
148#
149# Edits the current hostname.
150#
151f_dialog_input_hostname()

--- 63 unchanged lines hidden ---