Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Fedora Directory (http://www.linux-archive.org/fedora-directory/)
-   -   Clean up sanityCheckHostname() in network.py (#559626) (http://www.linux-archive.org/fedora-directory/402229-clean-up-sanitycheckhostname-network-py-559626-a.html)

David Cantrell 07-21-2010 03:45 PM

Clean up sanityCheckHostname() in network.py (#559626)
 
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.")
-
- if not inStrRange(hostname[0], string.ascii_letters):
- return _("Hostname must start with a valid character in the range "
- "'a-z' or 'A-Z'")
+ return _("Hostname must be 64 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

--
1.7.1.1

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

08-07-2010 05:42 AM

Clean up sanityCheckHostname() in network.py (#559626)
 
From: David Cantrell <dcantrell@redhat.com>

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.")
-
- if not inStrRange(hostname[0], string.ascii_letters):
- return _("Hostname must start with a valid character in the range "
- "'a-z' or 'A-Z'")
+ return _("Hostname must be 64 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

--
1.7.2.1

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

08-07-2010 05:45 AM

Clean up sanityCheckHostname() in network.py (#559626)
 
From: David Cantrell <dcantrell@redhat.com>

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.")
-
- if not inStrRange(hostname[0], string.ascii_letters):
- return _("Hostname must start with a valid character in the range "
- "'a-z' or 'A-Z'")
+ return _("Hostname must be 64 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

--
1.7.2.1

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

08-07-2010 05:45 AM

Clean up sanityCheckHostname() in network.py (#559626)
 
From: David Cantrell <dcantrell@redhat.com>

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.")
-
- if not inStrRange(hostname[0], string.ascii_letters):
- return _("Hostname must start with a valid character in the range "
- "'a-z' or 'A-Z'")
+ return _("Hostname must be 64 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

--
1.7.2.1

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

"Brian C. Lane" 08-09-2010 05:31 PM

Clean up sanityCheckHostname() in network.py (#559626)
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/06/2010 10:45 PM, dcantrell@redhat.com wrote:
> From: David Cantrell <dcantrell@redhat.com>
>
> 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


- --
Brian C. Lane <bcl@redhat.com>
Red Hat / Port Orchard, WA
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Remember Lexington Green!

iQEVAwUBTGA7YxF+jBaO/jp/AQJnTAf/XZT3nVvV/2FPoL+we5g0997V6u8sIRsJ
Zbq2eg16PQG6aQlCciPnqsABUUq0MJLtpsKNKJIPTZLJmdkRfh 2ZCUT5YZ9ZlBn9
vpUjxPG9E6IIWWP6A9W3cCUN4cVsAtK04zwVW8cSiMAObl/PNmiuqvPgEyrvT1oU
6YtpTwJ1739Vgs90Mh4EyFgZ+VrQBBjM1+Ng7KyRd8S6USj4D8 NLYn1uliFOhFLy
GeX8YZmw9k1JI2zWptgwTmkwCMdCccz/w8rgHXg/p0zZQgqLvQOXzbcmg2SFJ1AV
8w78zJdZRSHakTwkUGiepG25jZN4fpVNHxfiGGIRQoL0Iz5S0n 7a7w==
=60lQ
-----END PGP SIGNATURE-----

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

David Cantrell 08-09-2010 08:36 PM

Clean up sanityCheckHostname() in network.py (#559626)
 
On Mon, 9 Aug 2010, Brian C. Lane wrote:


On 08/06/2010 10:45 PM, dcantrell@redhat.com wrote:

From: David Cantrell <dcantrell@redhat.com>

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@redhat.com>
Red Hat / Honolulu, HI

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


All times are GMT. The time now is 02:11 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.