r3323: more warning reductions
[bbaumbach/samba-autobuild/.git] / source4 / client / clitar.c
index da91ba4bebb9b98dbe5826041e572283c8d7874c..e10a6b669893c64e291de395b5e62f38edac6863 100644 (file)
 #include "includes.h"
 #include "clitar.h"
 
+/**
+ Convert list of tokens to array; dependent on above routine.
+**/
+static char **toktocliplist(char *ptr, int *ctok, const char *sep)
+{
+       char *s = ptr;
+       int ictok=0;
+       char **ret, **iret;
+
+       if (!sep)
+               sep = " \t\n\r";
+
+       while(*s && strchr_m(sep,*s))
+               s++;
+
+       /* nothing left? */
+       if (!*s)
+               return(NULL);
+
+       do {
+               ictok++;
+               while(*s && (!strchr_m(sep,*s)))
+                       s++;
+               while(*s && strchr_m(sep,*s))
+                       *s++=0;
+       } while(*s);
+       
+       *ctok=ictok;
+       s = ptr;
+       
+       if (!(ret=iret=malloc(ictok*sizeof(char *))))
+               return NULL;
+       
+       while(ictok--) {    
+               *iret++=s;
+               while(*s++)
+                       ;
+               while(!*s)
+                       s++;
+       }
+
+       return ret;
+}
+
 static int clipfind(char **aret, int ret, char *tok);
 void dos_clean_name(char *s);
 
@@ -45,8 +89,8 @@ typedef struct file_info_struct file_info2;
 
 struct file_info_struct
 {
-  SMB_BIG_UINT size;
-  uint16 mode;
+  uint64_t size;
+  uint16_t mode;
   uid_t uid;
   gid_t gid;
   /* These times are normally kept in GMT */
@@ -67,14 +111,14 @@ typedef struct
 } stack;
 
 #define SEPARATORS " \t\n\r"
-extern struct cli_state *cli;
+extern struct smbcli_state *cli;
 
 /* These defines are for the do_setrattr routine, to indicate
  * setting and reseting of file attributes in the function call */
 #define ATTRSET 1
 #define ATTRRESET 0
 
-static uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+static uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
 
 #ifndef CLIENT_TIMEOUT
 #define CLIENT_TIMEOUT (30*1000)
@@ -109,9 +153,8 @@ static char **cliplist=NULL;
 static int clipn=0;
 static BOOL must_free_cliplist = False;
 
-extern file_info def_finfo;
 extern BOOL lowercase;
-extern uint16 cnum;
+extern uint16_t cnum;
 extern BOOL readbraw_supported;
 extern int max_xmit;
 extern pstring cur_dir;
@@ -121,11 +164,11 @@ extern int get_total_size;
 static int blocksize=20;
 static int tarhandle;
 
-static void writetarheader(int f,  const char *aname, SMB_BIG_UINT size, time_t mtime,
-                          const char *amode, unsigned char ftype);
-static void do_atar(char *rname,char *lname,file_info *finfo1);
+static void writetarheader(int f,  const char *aname, uint64_t size, time_t mtime,
+                          const char *amode, uint8_t ftype);
+static void do_atar(char *rname,const char *lname,file_info *finfo1);
 static void do_tar(file_info *finfo);
-static void oct_it(SMB_BIG_UINT value, int ndgs, char *p);
+static void oct_it(uint64_t value, int ndgs, char *p);
 static void fixtarname(char *tptr, const char *fp, int l);
 static int dotarbuf(int f, char *b, int n);
 static void dozerobuf(int f, int n);
@@ -164,8 +207,8 @@ static char *string_create_s(int size)
 /****************************************************************************
 Write a tar header to buffer
 ****************************************************************************/
-static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t mtime,
-                          const char *amode, unsigned char ftype)
+static void writetarheader(int f, const char *aname, uint64_t size, time_t mtime,
+                          const char *amode, uint8_t ftype)
 {
   union hblock hb;
   int i, chk, l;
@@ -203,17 +246,17 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m
 
   hb.dbuf.name[NAMSIZ-1]='\0';
   safe_strcpy(hb.dbuf.mode, amode, strlen(amode));
-  oct_it((SMB_BIG_UINT)0, 8, hb.dbuf.uid);
-  oct_it((SMB_BIG_UINT)0, 8, hb.dbuf.gid);
-  oct_it((SMB_BIG_UINT) size, 13, hb.dbuf.size);
-  oct_it((SMB_BIG_UINT) mtime, 13, hb.dbuf.mtime);
+  oct_it((uint64_t)0, 8, hb.dbuf.uid);
+  oct_it((uint64_t)0, 8, hb.dbuf.gid);
+  oct_it((uint64_t) size, 13, hb.dbuf.size);
+  oct_it((uint64_t) mtime, 13, hb.dbuf.mtime);
   memcpy(hb.dbuf.chksum, "        ", sizeof(hb.dbuf.chksum));
   memset(hb.dbuf.linkname, 0, NAMSIZ);
   hb.dbuf.linkflag=ftype;
   
   for (chk=0, i=sizeof(hb.dummy), jp=hb.dummy; --i>=0;) chk+=(0xFF & *jp++);
 
-  oct_it((SMB_BIG_UINT) chk, 8, hb.dbuf.chksum);
+  oct_it((uint64_t) chk, 8, hb.dbuf.chksum);
   hb.dbuf.chksum[6] = '\0';
 
   (void) dotarbuf(f, hb.dummy, sizeof(hb.dummy));
@@ -427,7 +470,7 @@ static void fixtarname(char *tptr, const char *fp, int l)
 /****************************************************************************
 Convert from decimal to octal string
 ****************************************************************************/
-static void oct_it (SMB_BIG_UINT value, int ndgs, char *p)
+static void oct_it (uint64_t value, int ndgs, char *p)
 {
   /* Converts long to octal string, pads with leading zeros */
 
@@ -539,8 +582,8 @@ static BOOL ensurepath(char *fname)
     {
       safe_strcat(partpath, p, strlen(fname) + 1);
 
-      if (NT_STATUS_IS_ERR(cli_chkpath(cli->tree, partpath))) {
-       if (NT_STATUS_IS_ERR(cli_mkdir(cli->tree, partpath)))
+      if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, partpath))) {
+       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, partpath)))
          {
            DEBUG(0, ("Error mkdirhiering\n"));
            return False;
@@ -574,11 +617,11 @@ static int padit(char *buf, int bufsize, int padsize)
 }
 
 
-static void do_setrattr(char *name, uint16 attr, int set)
+static void do_setrattr(char *name, uint16_t attr, int set)
 {
-       uint16 oldattr;
+       uint16_t oldattr;
 
-       if (NT_STATUS_IS_ERR(cli_getatr(cli->tree, name, &oldattr, NULL, NULL)))
+       if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, name, &oldattr, NULL, NULL)))
                return;
 
        if (set == ATTRSET) {
@@ -587,8 +630,8 @@ static void do_setrattr(char *name, uint16 attr, int set)
                attr = oldattr & ~attr;
        }
 
-       if (NT_STATUS_IS_ERR(cli_setatr(cli->tree, name, attr, 0))) {
-               DEBUG(1,("setatr failed: %s\n", cli_errstr(cli->tree)));
+       if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, name, attr, 0))) {
+               DEBUG(1,("setatr failed: %s\n", smbcli_errstr(cli->tree)));
        }
 }
 
@@ -596,10 +639,10 @@ static void do_setrattr(char *name, uint16 attr, int set)
 /****************************************************************************
 append one remote file to the tar file
 ***************************************************************************/
-static void do_atar(char *rname,char *lname,file_info *finfo1)
+static void do_atar(char *rname,const char *lname,file_info *finfo1)
 {
   int fnum;
-  SMB_BIG_UINT nread=0;
+  uint64_t nread=0;
   char ftype;
   file_info2 finfo;
   BOOL close_done = False;
@@ -621,17 +664,10 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
     finfo.mtime = finfo1 -> mtime;
     finfo.atime = finfo1 -> atime;
     finfo.ctime = finfo1 -> ctime;
-    finfo.name  = finfo1 -> name;
+    finfo.name  = discard_const_p(char, finfo1 -> name);
   }
   else {
-    finfo.size  = def_finfo.size;
-    finfo.mode  = def_finfo.mode;
-    finfo.uid   = def_finfo.uid;
-    finfo.gid   = def_finfo.gid;
-    finfo.mtime = def_finfo.mtime;
-    finfo.atime = def_finfo.atime;
-    finfo.ctime = def_finfo.ctime;
-    finfo.name  = def_finfo.name;
+         ZERO_STRUCT(finfo);
   }
 
   if (dry_run)
@@ -645,13 +681,13 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
       return;
     }
 
-  fnum = cli_open(cli->tree, rname, O_RDONLY, DENY_NONE);
+  fnum = smbcli_open(cli->tree, rname, O_RDONLY, DENY_NONE);
 
   dos_clean_name(rname);
 
   if (fnum == -1) {
          DEBUG(0,("%s opening remote file %s (%s)\n",
-                  cli_errstr(cli->tree),rname, cur_dir));
+                  smbcli_errstr(cli->tree),rname, cur_dir));
          return;
   }
 
@@ -664,8 +700,8 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
   safe_strcpy(finfo.name,rname, strlen(rname));
   if (!finfo1) {
          size_t size;
-         if (NT_STATUS_IS_ERR(cli_getattrE(cli->tree, fnum, &finfo.mode, &size, NULL, &finfo.atime, &finfo.mtime))) {
-                 DEBUG(0, ("getattrE: %s\n", cli_errstr(cli->tree)));
+         if (NT_STATUS_IS_ERR(smbcli_getattrE(cli->tree, fnum, &finfo.mode, &size, NULL, &finfo.atime, &finfo.mtime))) {
+                 DEBUG(0, ("getattrE: %s\n", smbcli_errstr(cli->tree)));
                  return;
          }
          finfo.size = size;
@@ -703,10 +739,10 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
              
              DEBUG(3,("nread=%.0f\n",(double)nread));
              
-             datalen = cli_read(cli->tree, fnum, data, nread, read_size);
+             datalen = smbcli_read(cli->tree, fnum, data, nread, read_size);
              
              if (datalen == -1) {
-                     DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli->tree)));
+                     DEBUG(0,("Error reading file %s : %s\n", rname, smbcli_errstr(cli->tree)));
                      break;
              }
              
@@ -751,7 +787,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1)
       ntarf++;
     }
   
-  cli_close(cli->tree, fnum);
+  smbcli_close(cli->tree, fnum);
 
   if (shallitime)
     {
@@ -967,7 +1003,7 @@ static int get_file(file_info2 finfo)
   DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, (int)finfo.size));
 
   if (ensurepath(finfo.name) && 
-      (fnum=cli_open(cli->tree, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) {
+      (fnum=smbcli_open(cli->tree, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) {
       DEBUG(0, ("abandoning restore\n"));
       return(False);
   }
@@ -984,7 +1020,7 @@ static int get_file(file_info2 finfo)
     dsize = MIN(dsize, rsize);  /* Should be only what is left */
     DEBUG(5, ("writing %i bytes, bpos = %i ...\n", dsize, bpos));
 
-    if (cli_write(cli->tree, fnum, 0, buffer_p + bpos, pos, dsize) != dsize) {
+    if (smbcli_write(cli->tree, fnum, 0, buffer_p + bpos, pos, dsize) != dsize) {
            DEBUG(0, ("Error writing remote file\n"));
            return 0;
     }
@@ -1037,7 +1073,7 @@ static int get_file(file_info2 finfo)
 
   /* Now close the file ... */
 
-  if (NT_STATUS_IS_ERR(cli_close(cli->tree, fnum))) {
+  if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
          DEBUG(0, ("Error closing remote file\n"));
          return(False);
   }
@@ -1046,7 +1082,7 @@ static int get_file(file_info2 finfo)
 
   DEBUG(5, ("Updating creation date on %s\n", finfo.name));
 
-  if (NT_STATUS_IS_ERR(cli_setatr(cli->tree, finfo.name, finfo.mode, finfo.mtime))) {
+  if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, finfo.name, finfo.mode, finfo.mtime))) {
          if (tar_real_noisy) {
                  DEBUG(0, ("Could not set time on file: %s\n", finfo.name));
                  /*return(False); */ /* Ignore, as Win95 does not allow changes */
@@ -1280,12 +1316,12 @@ static void do_tarput(void)
 /****************************************************************************
 Blocksize command
 ***************************************************************************/
-int cmd_block(void)
+int cmd_block(const char **cmd_ptr)
 {
   fstring buf;
   int block;
 
-  if (!next_token_nr(NULL,buf,NULL,sizeof(buf)))
+  if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)))
     {
       DEBUG(0, ("blocksize <n>\n"));
       return 1;
@@ -1307,11 +1343,11 @@ int cmd_block(void)
 /****************************************************************************
 command to set incremental / reset mode
 ***************************************************************************/
-int cmd_tarmode(void)
+int cmd_tarmode(const char **cmd_ptr)
 {
   fstring buf;
 
-  while (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+  while (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
     if (strequal(buf, "full"))
       tar_inc=False;
     else if (strequal(buf, "inc"))
@@ -1348,17 +1384,17 @@ int cmd_tarmode(void)
 /****************************************************************************
 Feeble attrib command
 ***************************************************************************/
-int cmd_setmode(void)
+int cmd_setmode(const char **cmd_ptr)
 {
   char *q;
   fstring buf;
   pstring fname;
-  uint16 attra[2];
+  uint16_t attra[2];
   int direct=1;
 
   attra[0] = attra[1] = 0;
 
-  if (!next_token_nr(NULL,buf,NULL,sizeof(buf)))
+  if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)))
     {
       DEBUG(0, ("setmode <filename> <[+|-]rsha>\n"));
       return 1;
@@ -1367,7 +1403,7 @@ int cmd_setmode(void)
   safe_strcpy(fname, cur_dir, sizeof(pstring));
   safe_strcat(fname, buf, sizeof(pstring));
 
-  while (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+  while (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
     q=buf;
 
     while(*q)
@@ -1405,19 +1441,19 @@ int cmd_setmode(void)
 /****************************************************************************
 Principal command for creating / extracting
 ***************************************************************************/
-int cmd_tar(void)
+int cmd_tar(char **cmd_ptr)
 {
   fstring buf;
   char **argl;
   int argcl;
 
-  if (!next_token_nr(NULL,buf,NULL,sizeof(buf)))
+  if (!next_token((const char **)cmd_ptr,buf,NULL,sizeof(buf)))
     {
       DEBUG(0,("tar <c|x>[IXbgan] <filename>\n"));
       return 1;
     }
 
-  argl=toktocliplist(&argcl, NULL);
+  argl=toktocliplist(*cmd_ptr, &argcl, NULL);
   if (!tar_parseargs(argcl, argl, buf, 0))
     return 1;
 
@@ -1691,7 +1727,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind)
        if (sys_stat(argv[Optind], &stbuf) == 0) {
          newer_than = stbuf.st_mtime;
          DEBUG(1,("Getting files newer than %s",
-                  asctime(LocalTime(&newer_than))));
+                  asctime(localtime(&newer_than))));
          Optind++;
        } else {
          DEBUG(0,("Error setting newer-than time\n"));