#include "includes.h"
#include "clitar.h"
+#include "system/time.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);
} 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 */
static int tarhandle;
static void writetarheader(int f, const char *aname, uint64_t size, time_t mtime,
- const char *amode, unsigned char ftype);
-static void do_atar(char *rname,char *lname,file_info *finfo1);
+ 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(uint64_t value, int ndgs, char *p);
static void fixtarname(char *tptr, const char *fp, int l);
Write a tar header to buffer
****************************************************************************/
static void writetarheader(int f, const char *aname, uint64_t size, time_t mtime,
- const char *amode, unsigned char ftype)
+ const char *amode, uint8_t ftype)
{
union hblock hb;
int i, chk, l;
****************************************************************************/
static void dotareof(int f)
{
- SMB_STRUCT_STAT stbuf;
+ struct stat stbuf;
/* Two zero blocks at end of file, write out full buffer */
if (dry_run)
(void) dozerobuf(f, TBLOCK);
(void) dozerobuf(f, TBLOCK);
- if (sys_fstat(f, &stbuf) == -1)
+ if (fstat(f, &stbuf) == -1)
{
DEBUG(0, ("Couldn't stat file handle\n"));
return;
{
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;
{
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) {
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)));
}
}
/****************************************************************************
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;
uint64_t nread=0;
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 {
ZERO_STRUCT(finfo);
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;
}
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;
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;
}
ntarf++;
}
- cli_close(cli->tree, fnum);
+ smbcli_close(cli->tree, fnum);
if (shallitime)
{
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);
}
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;
}
/* 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);
}
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 */
/****************************************************************************
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;
/****************************************************************************
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"))
/****************************************************************************
Feeble attrib command
***************************************************************************/
-int cmd_setmode(void)
+int cmd_setmode(const char **cmd_ptr)
{
char *q;
fstring buf;
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;
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)
/****************************************************************************
Principal command for creating / extracting
***************************************************************************/
-int cmd_tar(void)
+int cmd_tar(const char **cmd_ptr)
{
fstring buf;
char **argl;
int argcl;
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf)))
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)))
{
DEBUG(0,("tar <c|x>[IXbgan] <filename>\n"));
return 1;
}
- argl=toktocliplist(&argcl, NULL);
+ argl=toktocliplist(discard_const_p(char, *cmd_ptr), &argcl, NULL);
if (!tar_parseargs(argcl, argl, buf, 0))
return 1;
DEBUG(0,("Option N must be followed by valid file name\n"));
return 0;
} else {
- SMB_STRUCT_STAT stbuf;
+ struct stat stbuf;
extern time_t newer_than;
- if (sys_stat(argv[Optind], &stbuf) == 0) {
+ if (stat(argv[Optind], &stbuf) == 0) {
newer_than = stbuf.st_mtime;
DEBUG(1,("Getting files newer than %s",
asctime(localtime(&newer_than))));
}
tarhandle=-1;
} else
- if ((tar_type=='x' && (tarhandle = sys_open(argv[Optind], O_RDONLY, 0)) == -1)
- || (tar_type=='c' && (tarhandle=sys_creat(argv[Optind], 0644)) < 0))
+ if ((tar_type=='x' && (tarhandle = open(argv[Optind], O_RDONLY, 0)) == -1)
+ || (tar_type=='c' && (tarhandle=creat(argv[Optind], 0644)) < 0))
{
DEBUG(0,("Error opening local file %s - %s\n",
argv[Optind], strerror(errno)));