bug-cfengine
[Top][All Lists]
Advanced

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

inconsistent use of getservbyname


From: Eric Sorenson
Subject: inconsistent use of getservbyname
Date: Tue, 20 Jul 2004 16:25:08 -0700 (PDT)

Hello, in tracking down a problem for a friend I found a problem 
with cfagent talking to a cfservd that is running on a port other
than 5308. My friend's site has misconfigured their /etc/services
to register cfengine on tcp/5038 and, until everything can be
changed, they've propagated the malfeasance to all the clients'
/etc/services.  

The problem that I tracked down is that cfagent tries to talk to
5308 regardless of what getservbyname() returns, because 
getservbyname() isn't called at the time the socket connection
is made!  MakeImages in do.c:2395 does a getservbyname and
falls through to set PORTNUMBER=htons((unsigned short)5308); but
as far as I can tell this isn't used during the actual connection 
stage -- MakeImages calls OpenServerConnection, passing it just
the ip of the server, OpenServerConnection calls RemoteConnect
at client.c:57 , and RemoteConnect does the actual socket() call
based on the results of this:

     56    if ((err = getaddrinfo(host,"5308",&query,&response)) != 0)
     57       {
     58       snprintf(OUTPUT,CF_BUFSIZE,"Unable to lookup hostname or cfengine 
service: %s",gai_strerror(err));
     59       CfLog(cfinform,OUTPUT,"");
     60       return false;
     61       }

I think that second argument ot getaddrinfo() ought to be the
symbolic name "cfengine" instead of the port number, eg.

--- ip.c.orig   2004-07-20 16:07:02.000000000 -0700
+++ ip.c        2004-07-20 16:07:07.000000000 -0700
@@ -53,7 +53,7 @@
    query.ai_family = AF_UNSPEC;
    query.ai_socktype = SOCK_STREAM;
    
-   if ((err = getaddrinfo(host,"5308",&query,&response)) != 0)
+   if ((err = getaddrinfo(host,"cfengine",&query,&response)) != 0)
       {
       snprintf(OUTPUT,CF_BUFSIZE,"Unable to lookup hostname or cfengine 
service: %s",gai_strerror(err));
       CfLog(cfinform,OUTPUT,"");

That said, this is a bit naive. I am not sure what the effect of the PORTNUMBER
macro being set back in MakeImages is but this seems right and fixed my
friend's problem.

-- 

    Eric Sorenson - EXPLOSIVE Networking - http://explosive.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]