Re: [PATCH 2/4] Clean up sanityCheckHostname() in network.py (#559626)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 9 Aug 2010, Brian C. Lane wrote:

On 08/06/2010 10:45 PM, dcantrell@xxxxxxxxxx wrote:
From: David Cantrell <dcantrell@xxxxxxxxxx>

Hostnames can start with digits.  Removed inStrRange() since
it seemed a little redundant.  Left hostname length check at
64 characters, but put a comment reminding me that POSIX
sets this limit to 255, so we should examine this in the
future again.
---
 network.py |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/network.py b/network.py
index 0327ef9..0feb8fd 100644
--- a/network.py
+++ b/network.py
@@ -37,26 +37,25 @@ class IPError(Exception):
 class IPMissing(Exception):
     pass

-def inStrRange(v, s):
-    if string.find(s, v) == -1:
-	return 0
-    else:
-	return 1
-
 def sanityCheckHostname(hostname):
     if len(hostname) < 1:
 	return None

+    # XXX: POSIX says this limit is 255, but Linux also defines HOST_NAME_MAX
+    # as 64, so I don't know which we should believe.  --dcantrell
     if len(hostname) > 64:
-	return _("Hostname must be 64 or less characters in length.")

In RHEL6 this has been changed to 255

New patch:


Clean up sanityCheckHostname() in network.py (#559626)

Hostnames can start with digits and be up to 255 characters in length.
Removed inStrRange() since it seemed a little redundant.
---
 network.py |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/network.py b/network.py
index 0327ef9..6036b59 100644
--- a/network.py
+++ b/network.py
@@ -37,26 +37,23 @@ class IPError(Exception):
 class IPMissing(Exception):
     pass

-def inStrRange(v, s):
-    if string.find(s, v) == -1:
-	return 0
-    else:
-	return 1
-
 def sanityCheckHostname(hostname):
     if len(hostname) < 1:
 	return None

-    if len(hostname) > 64:
-	return _("Hostname must be 64 or less characters in length.")
- - if not inStrRange(hostname[0], string.ascii_letters):
-	return _("Hostname must start with a valid character in the range "
-		 "'a-z' or 'A-Z'")
+    if len(hostname) > 255:
+	return _("Hostname must be 255 or fewer characters in length.")
+
+    validStart = string.ascii_letters + string.digits
+    validAll = validStart + ".-"
+
+    if string.find(validStart, hostname[0]) == -1:
+	return _("Hostname must start with a valid character in the ranges "
+		 "'a-z', 'A-Z', or '0-9'")

     for i in range(1, len(hostname)):
-	if not inStrRange(hostname[i], string.ascii_letters+string.digits+".-"):
-	    return _("Hostnames can only contain the characters 'a-z', 'A-Z', '-', or '.'")
+	if string.find(validAll, hostname[i]) == -1:
+	    return _("Hostnames can only contain the characters 'a-z', 'A-Z', '0-9', '-', or '.'")

     return None


--
David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux