diff options
author | Niels de Vos <ndevos@redhat.com> | 2012-10-02 16:17:22 +0200 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2012-10-10 01:10:46 -0400 |
commit | e5fc29c264397e3c76262b2cff9a4516fd4c6475 (patch) | |
tree | c4d3b3aff3da80b4e6f40e7a3f71d32bfc21b926 | |
parent | e6cb04fa1647111457d2e7cbf6cac8bb584b96d9 (diff) |
common-utils: valid_host_name() should allow (sub)domains starting/ending with a digit
Some (sub)domains start or end with a digit. If this is the case, it
will not be possible to 'gluster peer probe' hosts in that (sub)domain.
This is overly restrictive, and RFC 1912 contains a note that describes
the common use of start/end digits in (sub)domains:
>
> Allowable characters in a label for a host name are only ASCII
> letters, digits, and the `-' character. Labels may not be all
> numbers, but may have a leading digit (e.g., 3com.com). Labels must
> end and begin only with a letter or digit. See [RFC 1035] and [RFC
> 1123]. (Labels were initially restricted in [RFC 1035] to start with
> a letter, and some older hosts still reportedly have problems with
> the relaxation in [RFC 1123].) Note there are some Internet
> hostnames which violate this rule (411.org, 1776.com).
>
This change will also allow (sub)domains to consist out of digits only,
like the example of 411.org above. It is still not allowed to start or
and a (sub)domain with a `-' (dash) character.
Change-Id: Ia2b338b1f727c86ffcc3984d877b63c8476367e7
BUG: 863908
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/4017
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/60
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Tested-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r-- | libglusterfs/src/common-utils.c | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 7662b7f971a..da0d381960d 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1574,11 +1574,9 @@ get_nth_word (const char *str, int n) return word; } -/* RFC 1123 & 952 */ -/* Syntax formed combining RFC 1123 & 952 * - <hname> ::= <first-name>*["."<gen-name>] * - <first-name> ::= <let-or-digit> <[*[<let-or-digit-or-hyphen>]<let-or-digit>] - <gen-name> ::= <let>[*[<let-or-digit-or-hyphen>]<let-or-digit>] */ +/* Syntax formed according to RFC 1912 (RFC 1123 & 952 are more restrictive) * + <hname> ::= <gen-name>*["."<gen-name>] * + <gen-name> ::= <let-or-digit> <[*[<let-or-digit-or-hyphen>]<let-or-digit>] */ char valid_host_name (char *address, int length) { @@ -1599,27 +1597,13 @@ valid_host_name (char *address, int length) ret = 0; goto out; } - temp_str = strtok_r (dup_addr,".", &save_ptr); - - /* first-name */ - if (!temp_str || - !isalnum(temp_str[0]) || - !isalnum (temp_str[strlen(temp_str)-1])) { - ret = 0; - goto out; - } - for (i = 1; i < (strlen (temp_str) - 1); i++) { - if (!isalnum (temp_str[i]) && (temp_str[i] != '-')) { - ret = 0; - goto out; - } - } /* gen-name */ - while ((temp_str = strtok_r (NULL, ".", &save_ptr))) { + temp_str = strtok_r (dup_addr, ".", &save_ptr); + do { str_len = strlen (temp_str); - if (!isalpha (temp_str[0]) || + if (!isalnum (temp_str[0]) || !isalnum (temp_str[str_len-1])) { ret = 0; goto out; @@ -1630,7 +1614,7 @@ valid_host_name (char *address, int length) goto out; } } - } + } while ((temp_str = strtok_r (NULL, ".", &save_ptr))); out: if (dup_addr) |