s3:smbclient: add a "tcon" command to do a tree connect (connect to a share)
[kai/samba.git] / source3 / client / clitar.c
index 80968a64d77ccd9c7b306ddf969603cd36c41d82..88824617a0fe3545de5f7125589520418955da6a 100644 (file)
@@ -38,6 +38,7 @@
 #include "system/filesys.h"
 #include "clitar.h"
 #include "client/client_proto.h"
+#include "libsmb/libsmb.h"
 
 static int clipfind(char **aret, int ret, char *tok);
 
@@ -101,7 +102,7 @@ char tar_type='\0';
 static char **cliplist=NULL;
 static int clipn=0;
 static bool must_free_cliplist = False;
-extern const char *cmd_ptr;
+extern char *cmd_ptr;
 
 extern bool lowercase;
 extern uint16 cnum;
@@ -472,7 +473,7 @@ static int strslashcmp(char *s1, char *s2)
 {
        char *s1_0=s1;
 
-       while(*s1 && *s2 && (*s1 == *s2 || tolower_ascii(*s1) == tolower_ascii(*s2) ||
+       while(*s1 && *s2 && (*s1 == *s2 || tolower_m(*s1) == tolower_m(*s2) ||
                                (*s1 == '\\' && *s2=='/') || (*s1 == '/' && *s2=='\\'))) {
                s1++; s2++;
        }
@@ -508,6 +509,7 @@ static bool ensurepath(const char *fname)
        const char *p=fname;
        char *basehack;
        char *saveptr;
+       NTSTATUS status;
 
        DEBUG(5, ( "Ensurepath called with: %s\n", fname));
 
@@ -541,11 +543,13 @@ static bool ensurepath(const char *fname)
        while (p) {
                strlcat(partpath, p, fnamelen);
 
-               if (!NT_STATUS_IS_OK(cli_chkpath(cli, partpath))) {
-                       if (!NT_STATUS_IS_OK(cli_mkdir(cli, partpath))) {
+               status = cli_chkpath(cli, partpath);
+               if (!NT_STATUS_IS_OK(status)) {
+                       status = cli_mkdir(cli, partpath);
+                       if (!NT_STATUS_IS_OK(status)) {
                                SAFE_FREE(partpath);
                                SAFE_FREE(ffname);
-                               DEBUG(0, ("Error mkdir %s\n", cli_errstr(cli)));
+                               DEBUG(0, ("Error mkdir %s\n", nt_errstr(status)));
                                return False;
                        } else {
                                DEBUG(3, ("mkdirhiering %s\n", partpath));
@@ -580,6 +584,7 @@ static int padit(char *buf, uint64_t bufsize, uint64_t padsize)
 static void do_setrattr(char *name, uint16 attr, int set)
 {
        uint16 oldattr;
+       NTSTATUS status;
 
        if (!NT_STATUS_IS_OK(cli_getatr(cli, name, &oldattr, NULL, NULL))) {
                return;
@@ -591,8 +596,9 @@ static void do_setrattr(char *name, uint16 attr, int set)
                attr = oldattr & ~attr;
        }
 
-       if (!NT_STATUS_IS_OK(cli_setatr(cli, name, attr, 0))) {
-               DEBUG(1,("setatr failed: %s\n", cli_errstr(cli)));
+       status = cli_setatr(cli, name, attr, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("setatr failed: %s\n", nt_errstr(status)));
        }
 }
 
@@ -655,7 +661,7 @@ static NTSTATUS do_atar(const char *rname_in, char *lname,
        status = cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("%s opening remote file %s (%s)\n",
-                               cli_errstr(cli),rname, client_get_cur_dir()));
+                               nt_errstr(status),rname, client_get_cur_dir()));
                goto cleanup;
        }
 
@@ -687,11 +693,12 @@ static NTSTATUS do_atar(const char *rname_in, char *lname,
 
                        DEBUG(3,("nread=%.0f\n",(double)nread));
 
-                       datalen = cli_read(cli, fnum, data, nread, read_size);
+                       datalen = cli_read_old(cli, fnum, data, nread, read_size);
 
                        if (datalen == -1) {
-                               DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli)));
                                status = cli_nt_error(cli);
+                               DEBUG(0,("Error reading file %s : %s\n",
+                                        rname, nt_errstr(status)));
                                break;
                        }
 
@@ -1081,10 +1088,10 @@ static int get_file(file_info2 finfo)
        }
 
        /* Now close the file ... */
-
-       if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
+       status = cli_close(cli, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("Error %s closing remote file\n",
-                       cli_errstr(cli)));
+                       nt_errstr(status)));
                return(False);
        }
 
@@ -1291,7 +1298,7 @@ int cmd_block(void)
        char *buf;
        int block;
 
-       if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+       if (!next_token_talloc(ctx, (const char **)&cmd_ptr,&buf,NULL)) {
                DEBUG(0, ("blocksize <n>\n"));
                return 1;
        }
@@ -1316,7 +1323,7 @@ int cmd_tarmode(void)
        TALLOC_CTX *ctx = talloc_tos();
        char *buf;
 
-       while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+       while (next_token_talloc(ctx, (const char **)&cmd_ptr,&buf,NULL)) {
                if (strequal(buf, "full"))
                        tar_inc=False;
                else if (strequal(buf, "inc"))
@@ -1366,7 +1373,7 @@ int cmd_setmode(void)
 
        attra[0] = attra[1] = 0;
 
-       if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+       if (!next_token_talloc(ctx, (const char **)&cmd_ptr,&buf,NULL)) {
                DEBUG(0, ("setmode <filename> <[+|-]rsha>\n"));
                return 1;
        }
@@ -1379,7 +1386,7 @@ int cmd_setmode(void)
                return 1;
        }
 
-       while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+       while (next_token_talloc(ctx, (const char **)&cmd_ptr,&buf,NULL)) {
                q=buf;
 
                while(*q) {
@@ -1481,7 +1488,7 @@ int cmd_tar(void)
        int argcl = 0;
        int ret;
 
-       if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+       if (!next_token_talloc(ctx, (const char **)&cmd_ptr,&buf,NULL)) {
                DEBUG(0,("tar <c|x>[IXbgan] <filename>\n"));
                return 1;
        }