Merge commit 'release-4-0-0alpha15' into master4-tmp
[kai/samba-autobuild/.git] / source3 / libsmb / clidfs.c
index 957bf4d707ccd913870eab45451c74c13e9c5066..5c5257fb6f88efca6f440cd975543328337d5d8c 100644 (file)
 */
 
 #include "includes.h"
+#include "libsmb/libsmb.h"
 #include "libsmb/clirap.h"
 #include "msdfs.h"
+#include "trans2.h"
+#include "libsmb/nmblib.h"
 
 /********************************************************************
  Important point.
@@ -85,10 +88,6 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
                                        int name_type)
 {
        struct cli_state *c = NULL;
-       struct nmb_name called, calling;
-       const char *called_str;
-       const char *server_n;
-       struct sockaddr_storage ss;
        char *servicename;
        char *sharename;
        char *newserver, *newshare;
@@ -104,7 +103,6 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
        sharename = servicename;
        if (*sharename == '\\') {
                sharename += 2;
-               called_str = sharename;
                if (server == NULL) {
                        server = sharename;
                }
@@ -114,36 +112,19 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
                }
                *sharename = 0;
                sharename++;
-       } else {
-               called_str = server;
        }
-
-       server_n = server;
-
-       zero_sockaddr(&ss);
-
-       make_nmb_name(&calling, global_myname(), 0x0);
-       make_nmb_name(&called , called_str, name_type);
-
- again:
-       zero_sockaddr(&ss);
-
-       /* have to open a new connection */
-       c = cli_initialise_ex(get_cmdline_auth_info_signing_state(auth_info));
-       if (c == NULL) {
-               d_printf("Connection to %s failed\n", server_n);
+       if (server == NULL) {
                return NULL;
        }
-       if (port) {
-               cli_set_port(c, port);
-       }
 
-       status = cli_connect(c, server_n, &ss);
+       status = cli_connect_nb(
+               server, NULL, port, name_type, NULL,
+               get_cmdline_auth_info_signing_state(auth_info), &c);
+
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Connection to %s failed (Error %s)\n",
-                               server_n,
+                               server,
                                nt_errstr(status));
-               cli_shutdown(c);
                return NULL;
        }
 
@@ -156,23 +137,6 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
                get_cmdline_auth_info_fallback_after_kerberos(auth_info);
        c->use_ccache = get_cmdline_auth_info_use_ccache(auth_info);
 
-       if (!cli_session_request(c, &calling, &called)) {
-               char *p;
-               d_printf("session request to %s failed (%s)\n",
-                        called.name, cli_errstr(c));
-               cli_shutdown(c);
-               c = NULL;
-               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;
-       }
-
        DEBUG(4,(" session request ok\n"));
 
        status = cli_negprot(c);
@@ -918,10 +882,19 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
        }
 
        if (extrapath && strlen(extrapath) > 0) {
-               *pp_targetpath = talloc_asprintf(ctx,
-                                               "%s%s",
-                                               extrapath,
-                                               *pp_targetpath);
+               /* EMC Celerra NAS version 5.6.50 (at least) doesn't appear to */
+               /* put the trailing \ on the path, so to be save we put one in if needed */
+               if (extrapath[strlen(extrapath)-1] != '\\' && **pp_targetpath != '\\') {
+                       *pp_targetpath = talloc_asprintf(ctx,
+                                                 "%s\\%s",
+                                                 extrapath,
+                                                 *pp_targetpath);
+               } else {
+                       *pp_targetpath = talloc_asprintf(ctx,
+                                                 "%s%s",
+                                                 extrapath,
+                                                 *pp_targetpath);
+               }
                if (!*pp_targetpath) {
                        return false;
                }