Bug 112719 - rhn_register hardware.py function findHostByRoute badly used
rhn_register hardware.py function findHostByRoute badly used
Status: CLOSED DUPLICATE of bug 112276
Product: Red Hat Enterprise Linux 2.1
Classification: Red Hat
Component: rhn_register (Show other bugs)
2.1
All Linux
medium Severity medium
: ---
: ---
Assigned To: Adrian Likins
Fanny Augustin
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-12-29 15:33 EST by Philippe April
Modified: 2007-11-30 17:06 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-02-21 14:00:31 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Philippe April 2003-12-29 15:33:53 EST
Description of problem: 
While trying to register one of our machines on the RedHat network, 
I ran rhn_register and it would hang with an error message saying it 
could not connect to the host (Connection Timed Out, 110). 
 
After investigation, I found that it was hanging at the function 
findHostByRoute trying to connect to serverURL directly (not using 
the specified proxy). I believe the function is made to return the 
hostname, according to the DNS by using the IP address bound to the 
interface used for the connect(), and it should only be used in a 
worst case scenario (hostname is not set, etc.) 
 
It should only do this if the hostname has not been found/well 
detected, however it seems like it does it all the time because the 
machine's detected hostname is overriden at some point (which is 
what I believe is the bug). 
 
This is the actual part of the script where it does not seem to work 
properly. 
----- 
    netdict['hostname'] = socket.gethostname() 
    try: 
        netdict['ipaddr'] = 
socket.gethostbyname(socket.gethostname()) 
    except: 
        netdict['ipaddr'] = "127.0.0.1" 
 
    # THIS PART WILL, I BELIEVE, ALWAYS OVERRIDE 
    # THEREFORE ALWAYS RUN findHostByRoute() 
    netdict['hostname'] = 'localhost.localdomain' 
    netdict['ipaddr'] = "127.0.0.1" 
 
    if netdict['hostname'] == 'localhost.localdomain' or \ 
        netdict['ipaddr'] == "127.0.0.1": 
        hostname, ipaddr = findHostByRoute() 
        netdict['hostname'] = hostname 
        netdict['ipaddr'] = ipaddr 
    return netdict 
----- 
 
This is what I believe it should be: 
----- 
    netdict['hostname'] = socket.gethostname() 
    try: 
        netdict['ipaddr'] = 
socket.gethostbyname(socket.gethostname()) 
    except: 
        netdict['ipaddr'] = "127.0.0.1" 
        netdict['hostname'] = 'localhost.localdomain' 
 
    if netdict['hostname'] == 'localhost.localdomain' or \ 
        netdict['ipaddr'] == "127.0.0.1": 
        hostname, ipaddr = findHostByRoute() 
        netdict['hostname'] = hostname 
        netdict['ipaddr'] = ipaddr 
    return netdict 
----- 
 
That way, it will only override the hostname and ip address detected 
if socket.gethostbyname(socket.gethostname()) was not succesful 
instead of doing it ALL THE TIME. 
 
Version-Release number of selected component (if applicable): 
rhn_register-2.9.2-1.2.1AS 
 
How reproducible: 
Try to register to the network behind a firewall that does not allow 
direct connections to port 80, going through a proxy (squid in this 
case, but irrelevant). 
 
Steps to Reproduce: 
1. try to register through a proxy while behind a firewall that does 
not allow connecting to port 80 directly 
2. 
3. 
   
Actual results: 
rhn_register fails without proceeding to the registration, saying 
"Error 110 Connection Timed Out" while trying to connect to 
serverUrl port 80. 
 
Expected results: 
Succesful registration 
 
Additional info:
Comment 1 Jason Burks 2003-12-31 11:18:54 EST
I also experienced this bug while trying to run rhn_register behind a
firewall.  I tried Phillipe's proposed fix, and it does solve the
problem, but not in all cases.  It occurs to me that the statements in
the findHostByRoute() function in hardware.py will still cause a fatal
error behind a firewall/web proxy because they are not wrapped in a
try block.  

I think that the findHostByRoute() function either needs to be
re-written to handle proxies, or at the very least, made to properly
handle exceptions that might occur (such as the timeout that will
occur when the connection cannot be made through the proxy).

Best regards,
Jason Burks
Comment 2 Bastien Nocera 2004-01-13 12:38:47 EST

*** This bug has been marked as a duplicate of 112276 ***
Comment 3 Philippe April 2004-01-13 12:52:04 EST
It definitely needs to be rewritten or patched... 
 
I'd like to include some details: 
 
If /etc/hosts is not setup correctly (ie. you just installed and 
used DHCP) it will contain: 
 
127.0.0.1 yourhostname.yourdomainname, etc... 
 
So the function will run socket.gethostbyname(socket.gethostname()) 
and will get 127.0.0.1 for return, and therefore fail. 
 
Philippe April 
Comment 4 Red Hat Bugzilla 2006-02-21 14:00:31 EST
Changed to 'CLOSED' state since 'RESOLVED' has been deprecated.

Note You need to log in before you can comment on or make changes to this bug.