Bug 112719 - rhn_register hardware.py function findHostByRoute badly used
Summary: rhn_register hardware.py function findHostByRoute badly used
Keywords:
Status: CLOSED DUPLICATE of bug 112276
Alias: None
Product: Red Hat Enterprise Linux 2.1
Classification: Red Hat
Component: rhn_register
Version: 2.1
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Adrian Likins
QA Contact: Fanny Augustin
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-12-29 20:33 UTC by Philippe April
Modified: 2007-11-30 22:06 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-02-21 19:00:31 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Philippe April 2003-12-29 20:33:53 UTC
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 16:18:54 UTC
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 17:38:47 UTC

*** This bug has been marked as a duplicate of 112276 ***

Comment 3 Philippe April 2004-01-13 17:52:04 UTC
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 19:00:31 UTC
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.