From 61a3d370b98ca4b75cd61e22f0d6b0f3fb7561b3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Jan 2005 11:58:52 +0000 Subject: r4758: - added async support to the session request code - added async support to the negprot client code - removed two unused parameters from smbcli_full_connection() code - converted smbclient to use smbcli_full_connection() rather than reinventing everything itself (This used to be commit 71cbe2873473e039b4511511302cb63f1c50bce8) --- source4/client/client.c | 83 ++++++------------------------------------------- 1 file changed, 9 insertions(+), 74 deletions(-) (limited to 'source4/client/client.c') diff --git a/source4/client/client.c b/source4/client/client.c index b2255fc7b8..6449781b3f 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -3045,86 +3045,21 @@ return a connection to a server static struct smbcli_state *do_connect(const char *server, const char *share) { struct smbcli_state *c; - struct nmb_name called, calling; - const char *server_n; - fstring servicename; - char *sharename; NTSTATUS status; - - /* make a copy so we don't modify the global string 'service' */ - fstrcpy(servicename, share); - sharename = servicename; - if (*sharename == '\\') { - server = sharename+2; - sharename = strchr_m(server,'\\'); - if (!sharename) return NULL; - *sharename = 0; - sharename++; - } - - asprintf(&sharename, "\\\\%s\\%s", server, sharename); - server_n = dest_ip?dest_ip:server; - - make_nmb_name(&calling, lp_netbios_name(), 0x0); - choose_called_name(&called, server, name_type); - - again: - /* have to open a new connection */ - if (!(c=smbcli_state_init(NULL)) || !smbcli_socket_connect(c, server_n)) { - d_printf("Connection to %s failed\n", server_n); - return NULL; - } - - if (!smbcli_transport_establish(c, &calling, &called)) { - char *p; - d_printf("session request to %s failed\n", - called.name); - smbcli_shutdown(c); - if ((p=strchr_m(called.name, '.'))) { - *p = 0; - goto again; - } - if (strcmp(called.name, "*SMBSERVER")) { - make_nmb_name(&called , "*SMBSERVER", 0x20); - goto again; - } - return NULL; + if (strncmp(share, "\\\\", 2) == 0 || + strncmp(share, "//", 2) == 0) { + smbcli_parse_unc(share, NULL, &server, &share); } - - DEBUG(4,(" session request ok\n")); - - if (NT_STATUS_IS_ERR(smbcli_negprot(c))) { - d_printf("protocol negotiation failed\n"); - smbcli_shutdown(c); - return NULL; - } - - status = smbcli_session_setup(c, username, password, domain); - if (NT_STATUS_IS_ERR(status)) { - d_printf("authenticated session setup failed: %s\n", nt_errstr(status)); - /* if a password was not supplied then try again with a null username */ - if (password[0] || !username[0]) { - status = smbcli_session_setup(c, "", "", lp_workgroup()); - } - if (NT_STATUS_IS_ERR(status)) { - d_printf("session setup failed: %s\n", nt_errstr(status)); - smbcli_shutdown(c); - return NULL; - } - d_printf("Anonymous login successful\n"); - } - - DEBUG(4,(" session setup ok\n")); - - if (NT_STATUS_IS_ERR(smbcli_send_tconX(c, sharename, "?????", password))) { - d_printf("tree connect failed: %s\n", smbcli_errstr(c->tree)); - smbcli_shutdown(c); + + status = smbcli_full_connection(NULL, &c, lp_netbios_name(), server, + share, NULL, username, domain, password); + if (!NT_STATUS_IS_OK(status)) { + d_printf("Connection to \\\\%s\\%s failed - %s\n", + server, share, nt_errstr(status)); return NULL; } - DEBUG(4,(" tconx ok\n")); - return c; } -- cgit