summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/libsmb/libsmb_server.c101
1 files changed, 20 insertions, 81 deletions
diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c
index 45be66072f..80faaed1af 100644
--- a/source3/libsmb/libsmb_server.c
+++ b/source3/libsmb/libsmb_server.c
@@ -247,19 +247,13 @@ SMBC_server_internal(TALLOC_CTX *ctx,
SMBCSRV *srv=NULL;
char *workgroup = NULL;
struct cli_state *c;
- struct nmb_name called, calling;
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;
@@ -393,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;
}
@@ -424,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)) {