diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-06-24 16:26:23 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-06-24 16:26:23 +1000 |
commit | 6da26870e0ae5acd6ff49a30ec2f6886b44d095e (patch) | |
tree | 850c71039563c16a5d563c47e7ba2ab645baf198 /source3/libsmb/libsmb_server.c | |
parent | 6925a799d04c6fa59dd2ddef1f5510f9bb7d17d1 (diff) | |
parent | 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 (diff) | |
download | samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.gz samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.bz2 samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.zip |
Merge 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 as Samba-4.0alpha16
Diffstat (limited to 'source3/libsmb/libsmb_server.c')
-rw-r--r-- | source3/libsmb/libsmb_server.c | 110 |
1 files changed, 27 insertions, 83 deletions
diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c index 961c9cde83..755ef2d32b 100644 --- a/source3/libsmb/libsmb_server.c +++ b/source3/libsmb/libsmb_server.c @@ -24,6 +24,7 @@ */ #include "includes.h" +#include "libsmb/libsmb.h" #include "libsmbclient.h" #include "libsmb_internal.h" #include "../librpc/gen_ndr/ndr_lsa.h" @@ -245,20 +246,14 @@ SMBC_server_internal(TALLOC_CTX *ctx, { SMBCSRV *srv=NULL; char *workgroup = NULL; - struct cli_state *c; - struct nmb_name called, calling; + struct cli_state *c = NULL; const char *server_n = server; - struct sockaddr_storage ss; - int tried_reverse = 0; - int port_try_first; - int port_try_next; int is_ipc = (share != NULL && strcmp(share, "IPC$") == 0); uint32 fs_attrs = 0; const char *username_used; NTSTATUS status; char *newserver, *newshare; - zero_sockaddr(&ss); ZERO_STRUCT(c); *in_cache = false; @@ -392,20 +387,32 @@ SMBC_server_internal(TALLOC_CTX *ctx, return NULL; } - make_nmb_name(&calling, smbc_getNetbiosName(context), 0x0); - make_nmb_name(&called , server, 0x20); - DEBUG(4,("SMBC_server: server_n=[%s] server=[%s]\n", server_n, server)); DEBUG(4,(" -> server_n=[%s] server=[%s]\n", server_n, server)); -again: + status = NT_STATUS_UNSUCCESSFUL; - zero_sockaddr(&ss); + if (share == NULL || *share == '\0' || is_ipc) { + /* + * Try 139 first for IPC$ + */ + status = cli_connect_nb(server_n, NULL, 139, 0x20, + smbc_getNetbiosName(context), + Undefined, &c); + } - /* have to open a new connection */ - if ((c = cli_initialise()) == NULL) { - errno = ENOMEM; + if (!NT_STATUS_IS_OK(status)) { + /* + * No IPC$ or 139 did not work + */ + status = cli_connect_nb(server_n, NULL, 0, 0x20, + smbc_getNetbiosName(context), + Undefined, &c); + } + + if (!NT_STATUS_IS_OK(status)) { + errno = map_errno_from_nt_status(status); return NULL; } @@ -423,73 +430,6 @@ again: c->timeout = smbc_getTimeout(context); - /* - * Force use of port 139 for first try if share is $IPC, empty, or - * null, so browse lists can work - */ - if (share == NULL || *share == '\0' || is_ipc) { - port_try_first = 139; - port_try_next = 445; - } else { - port_try_first = 445; - port_try_next = 139; - } - - c->port = port_try_first; - - status = cli_connect(c, server_n, &ss); - if (!NT_STATUS_IS_OK(status)) { - - /* First connection attempt failed. Try alternate port. */ - c->port = port_try_next; - - status = cli_connect(c, server_n, &ss); - if (!NT_STATUS_IS_OK(status)) { - cli_shutdown(c); - errno = ETIMEDOUT; - return NULL; - } - } - - if (!cli_session_request(c, &calling, &called)) { - cli_shutdown(c); - if (strcmp(called.name, "*SMBSERVER")) { - make_nmb_name(&called , "*SMBSERVER", 0x20); - goto again; - } else { /* Try one more time, but ensure we don't loop */ - - /* Only try this if server is an IP address ... */ - - if (is_ipaddress(server) && !tried_reverse) { - fstring remote_name; - struct sockaddr_storage rem_ss; - - if (!interpret_string_addr(&rem_ss, server, - NI_NUMERICHOST)) { - DEBUG(4, ("Could not convert IP address " - "%s to struct sockaddr_storage\n", - server)); - errno = ETIMEDOUT; - return NULL; - } - - tried_reverse++; /* Yuck */ - - if (name_status_find("*", 0, 0, - &rem_ss, remote_name)) { - make_nmb_name(&called, - remote_name, - 0x20); - goto again; - } - } - } - errno = ETIMEDOUT; - return NULL; - } - - DEBUG(4,(" session request ok\n")); - status = cli_negprot(c); if (!NT_STATUS_IS_OK(status)) { @@ -646,6 +586,10 @@ done: workgroup = *pp_workgroup; } if(!workgroup) { + if (c != NULL) { + cli_shutdown(c); + } + SAFE_FREE(srv); return NULL; } @@ -773,7 +717,7 @@ SMBC_attr_server(TALLOC_CTX *ctx, zero_sockaddr(&ss); nt_status = cli_full_connection(&ipc_cli, - global_myname(), server, + lp_netbios_name(), server, &ss, 0, "IPC$", "?????", *pp_username, *pp_workgroup, |