libsmbclient: Vista servers disconnect on netbios keepalive message on port 445

Christopher R. Hertel crh at ubiqx.mn.org
Sun Dec 24 04:53:19 GMT 2006


elupus wrote:
> If libsmbclient is connected to a vista server on port 445, only every
> second command will work. Before every command libsmbclient tries to verify
> that the server is valid by sending it a SMBkeepalive. However this is a
> netbios packet and can't be used on port 445 (smb over tcp). It seems
> previous windows version ignored this, vista however disconnects the client
> on such an invalid request.

Previous versions of Windows that supported "naked transport" also had odd
behavior with respect to NBT messages on port 445.  The NBT Session Request,
 for instance, was ignored by W2K, but the TCP connection was not dropped.
That meant that the client would have to time out waiting for the NBT
Session Response.

  http://ubiqx.org/cifs/SMB.html#SMB.3.3.2

> I changed the smbc_check_server to only do the keepalive when connected on
> port 139, sorry for this not being a patch, but I currently don't have any
> checked out version of samba. The alternative is to use cli_echo, but
> waiting for a roundtrip before trying to do anything seems overkill. 

There should be a cleaner way than port number to determine whether NBT is
in use or not.

It's probably minor, but I remember there being quite an uproar when I left
this out of the SMB URI documentation.  Seems there are a lot of people
using port redirection in order to connect to both Samba and Windows servers
via a NAT/Firewall.

> The proper solution would be to do a retry on a failed request instead of
> the current way if checking connection prior to doing the actual request.
> But that is abit to much work for me.
> 
> Cheers
> 
> 
> /Joakim
> 
> static int
> smbc_check_server(SMBCCTX * context,
>                   SMBCSRV * server) 
> {
>     if (server->cli.port == 139)
>     {
> 		if ( send_keepalive(server->cli.fd) == False )
> 			return 1;
>     }
>     else
>     {
> 		/* can't send netbios keepalive over raw tcp samba sockets
> */
> 		struct sockaddr addr;
> 		int size = sizeof(addr);
> 		if (getpeername(server->cli.fd, &addr, &size))
> 			return 1;
>     }
> 
> 
> 	/* connection is ok */
> 	return 0;
> }
> 

-- 
"Implementing CIFS - the Common Internet FileSystem" ISBN: 013047116X
Samba Team -- http://www.samba.org/     -)-----   Christopher R. Hertel
jCIFS Team -- http://jcifs.samba.org/   -)-----   ubiqx development, uninq.
ubiqx Team -- http://www.ubiqx.org/     -)-----   crh at ubiqx.mn.org
OnLineBook -- http://ubiqx.org/cifs/    -)-----   crh at ubiqx.org


More information about the samba-technical mailing list