hardcoded port 445

Andrew Bartlett abartlet at samba.org
Mon Oct 31 14:41:06 MDT 2011


On Sun, 2011-10-30 at 08:24 +0100, Oskar Liljeblad wrote:
> Hello
> 
> I am writing a small application doing MSRPC using Samba4. It relies on
> forwarded ports, it will for instance connect to 127.0.0.1:12345 which is
> forwarded to 445 on some remote machine.  So I looked at the Samba code and
> noticed two places where 445 is hardcoded:
> 
> source4/libcli/raw/clitransport.c:
> 
> bool smbcli_transport_connect(struct smbcli_transport *transport,
>                               struct nbt_name *calling,
>                               struct nbt_name *called)
> {
>         struct smbcli_request *req;
>         NTSTATUS status;
> 
>         if (transport->socket->port == 445) {
>                 return true;
>         }
> 
>         req = smbcli_transport_connect_send(transport,
>                                             calling, called);
>         status = smbcli_transport_connect_recv(req);
>         return NT_STATUS_IS_OK(status);
> }
> 
> source4/libcli/smb_composite/connect.c:
> 
> static NTSTATUS connect_socket(struct composite_context *c,
>                                struct smb_composite_connect *io)
> {
> [..]
>         /* we have a connected socket - next step is a session
>            request, if needed. Port 445 doesn't need it, so it goes
>            straight to the negprot */
>         if (state->sock->port == 445) {
>                 status = nbt_name_dup(state->transport, &called,
>                                       &state->transport->called);
>                 NT_STATUS_NOT_OK_RETURN(status);
>                 return connect_send_negprot(c, io);
>         }
> 
>         state->req = smbcli_transport_connect_send(state->transport, &calling, &called);
>         NT_STATUS_HAVE_NO_MEMORY(state->req);
> 
>         state->req->async.fn = request_handler;
>         state->req->async.private_data = c;
>         state->stage = CONNECT_SESSION_REQUEST;
> 
>         return NT_STATUS_OK;
> }
> 
> My application will not be connecting to 445 so will this cause
> incompatibility?  If so I see only one solution: Always keep track of what
> type of port is specified, NetBIOS or CIFS.  That would be needed in many
> places, libcli (struct smbcli_socket), lib/socket/connect_multi.c etc,
> and many functions would need to be modified.
> 
> Any suggestions how to go about here?

First, it's great to see new folks using Samba and the Samba4 libraries
in interesting ways. 

Have you tested this to see if it actually causes a problem?  If the
remote server swallows or errors the nbt name request for example, it
may not cause an issue in the real world.  If it does cause a real-world
problem, then I guess the best approach would be some kind of flag, or
to invert the test to be == 139.  

(Elsewhere in Samba we have had bugs were we fail to connect to port
139-only servers, and it took quite some time for them to be noticed.
Therefore, such beasts may be rare enough for us to not support 'port
139 semantics not on port 139'). 

Andrew Bartlett

-- 
Andrew Bartlett                                http://samba.org/~abartlet/
Authentication Developer, Samba Team           http://samba.org



More information about the samba-technical mailing list