smbc_opendir() returns -1 but sets errno to 0

Richard Sharpe rsharpe at
Wed Nov 26 19:06:00 GMT 2003

On Wed, 26 Nov 2003, Stephan Kulow wrote:

> > Well... no, not really.  If there is a new election and some other node
> > becomes LMB then the cache would be invalid.  The real question is:  Why did
> > a query for smb://WORKGROUP_NAME/ return the IP address of something other
> > than a browser for the WORKGROUP_NAME workgroup?  Another question: Is it
> > possible that the workgroup browse list was, in fact, empty?  That can
> > happen fairly easily.
> > 
> > Ethereal... Your best friend.
> > 
> The issue is quite clear and I once discussed this problem already with Richard:
> The LMB is resolved through netbios and from the result only the host name is
> taken and then resolved over DNS - which can (as you say) result in a different
> IP. And when then the server behind the IP doesn't want the connection, then
> libsmbclient is confused and returns this strange -1, errno = 0 case (which
> resulted in the nice konqueror error "Unknown error: success" for quite 
> some time :)
> libsmbclient needs to be changed to not resolve the name _again_ when it found
> out the master browser. Just noone got to that so far. And yes, that's an invalid
> network setup, but there are tons of reports for that - just one example:

OK, I think I can see where the problem is:

    if (!is_ipaddress(server) &&  /* Not an IP addr so check next */
         (resolve_name(server, &rem_ip, 0x1d) ||   /* Found LMB */
          resolve_name(server, &rem_ip, 0x1b) )) { /* Found DMB */

If either of the resolve_name calls uses DNS, and there is a 
mis-configuration, we could end up returning an incorrect IP address.

If I have this correct, this could be fixed by forcing name resolve order 
to WINS, DNS ... 

However, we might need to cause it to do the right things manually.

Also, we should probably return an ERRNO that indicates problems. 

Damn, POSIX error handling is so braindead!

Richard Sharpe, rsharpe[at], rsharpe[at], 

More information about the samba-technical mailing list