diff options
Diffstat (limited to 'source/client/clitar.c')
-rw-r--r-- | source/client/clitar.c | 195 |
1 files changed, 115 insertions, 80 deletions
diff --git a/source/client/clitar.c b/source/client/clitar.c index c453cfbb548..50a46c70007 100644 --- a/source/client/clitar.c +++ b/source/client/clitar.c @@ -1,5 +1,6 @@ /* - Unix SMB/CIFS implementation. + Unix SMB/Netbios implementation. + Version 1.9. Tar Extensions Copyright (C) Ricky Poulten 1995-1998 Copyright (C) Richard Sharpe 1998 @@ -37,7 +38,6 @@ #include "includes.h" #include "clitar.h" -#include "../client/client_proto.h" static int clipfind(char **aret, int ret, char *tok); @@ -66,8 +66,11 @@ typedef struct } stack; +stack dir_stack = {NULL, 0}; /* Want an empty stack */ + #define SEPARATORS " \t\n\r" extern struct cli_state *cli; +extern FILE *dbf; /* These defines are for the do_setrattr routine, to indicate * setting and reseting of file attributes in the function call */ @@ -84,25 +87,25 @@ static char *tarbuf, *buffer_p; static int tp, ntarf, tbufsiz; static double ttarf; /* Incremental mode */ -static BOOL tar_inc=False; +BOOL tar_inc=False; /* Reset archive bit */ -static BOOL tar_reset=False; +BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ -static BOOL tar_excl=True; +BOOL tar_excl=True; /* use regular expressions for search on file names */ -static BOOL tar_re_search=False; +BOOL tar_re_search=False; #ifdef HAVE_REGEX_H regex_t *preg; #endif /* Do not dump anything, just calculate sizes */ -static BOOL dry_run=False; +BOOL dry_run=False; /* Dump files with System attribute */ -static BOOL tar_system=True; +BOOL tar_system=True; /* Dump files with Hidden attribute */ -static BOOL tar_hidden=True; +BOOL tar_hidden=True; /* Be noisy - make a catalogue */ -static BOOL tar_noisy=True; -static BOOL tar_real_noisy=False; /* Don't want to be really noisy by default */ +BOOL tar_noisy=True; +BOOL tar_real_noisy=False; /* Don't want to be really noisy by default */ char tar_type='\0'; static char **cliplist=NULL; @@ -117,9 +120,10 @@ extern int max_xmit; extern pstring cur_dir; extern int get_total_time_ms; extern int get_total_size; +extern int Protocol; -static int blocksize=20; -static int tarhandle; +int blocksize=20; +int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); @@ -416,12 +420,31 @@ static void dotareof(int f) ****************************************************************************/ static void fixtarname(char *tptr, char *fp, int l) { - /* add a '.' to start of file name, convert from ugly dos \'s in path - * to lovely unix /'s :-} */ - *tptr++='.'; - - safe_strcpy(tptr, fp, l); - string_replace(tptr, '\\', '/'); + /* add a '.' to start of file name, convert from ugly dos \'s in path + * to lovely unix /'s :-} */ + + *tptr++='.'; + + while (l > 0) { + int skip = get_character_len(*fp); + if(skip != 0) { + if (skip == 2) { + *tptr++ = *fp++; + *tptr++ = *fp++; + l -= 2; + } else if (skip == 1) { + *tptr++ = *fp++; + l--; + } + } else if (*fp == '\\') { + *tptr++ = '/'; + fp++; + l--; + } else { + *tptr++ = *fp++; + l--; + } + } } /**************************************************************************** @@ -492,7 +515,7 @@ static int strslashcmp(char *s1, char *s2) if (!*s2 && (*s1 == '/' || *s1 == '\\') && !*(s1+1)) return 0; /* check for s1 is an "initial" string of s2 */ - if ((*s2 == '/' || *s2 == '\\') && !*s1) return 0; + if (*s2 == '/' || *s2 == '\\') return 0; return *s1-*s2; } @@ -528,7 +551,7 @@ static BOOL ensurepath(char *fname) safe_strcpy(ffname, fname, strlen(fname)); /* do a `basename' on ffname, so don't try and make file name directory */ - if ((basehack=strrchr_m(ffname, '\\')) == NULL) + if ((basehack=strrchr(ffname, '\\')) == NULL) return True; else *basehack='\0'; @@ -853,25 +876,43 @@ Convert from UNIX to DOS file names ***************************************************************************/ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) { - /* remove '.' from start of file name, convert from unix /'s to - * dos \'s in path. Kill any absolute path names. But only if first! - */ - - DEBUG(5, ("firstb=%lX, secondb=%lX, len=%i\n", (long)tptr, (long)fp, l)); - - if (first) { - if (*fp == '.') { - fp++; - l--; - } - if (*fp == '\\' || *fp == '/') { - fp++; - l--; - } - } + /* remove '.' from start of file name, convert from unix /'s to + * dos \'s in path. Kill any absolute path names. But only if first! + */ - safe_strcpy(tptr, fp, l); - string_replace(tptr, '/', '\\'); + DEBUG(5, ("firstb=%lX, secondb=%lX, len=%i\n", (long)tptr, (long)fp, l)); + + if (first) { + if (*fp == '.') { + fp++; + l--; + } + if (*fp == '\\' || *fp == '/') { + fp++; + l--; + } + } + + while (l > 0) { + int skip = get_character_len(*fp); + if(skip != 0) { + if (skip == 2) { + *tptr++ = *fp++; + *tptr++ = *fp++; + l -= 2; + } else if (skip == 1) { + *tptr++ = *fp++; + l--; + } + } else if (*fp == '/') { + *tptr++ = '\\'; + fp++; + l--; + } else { + *tptr++ = *fp++; + l--; + } + } } @@ -1275,38 +1316,36 @@ static void do_tarput(void) /**************************************************************************** Blocksize command ***************************************************************************/ -int cmd_block(void) +void cmd_block(void) { fstring buf; int block; - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) + if (!next_token(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("blocksize <n>\n")); - return 1; + return; } block=atoi(buf); if (block < 0 || block > 65535) { DEBUG(0, ("blocksize out of range")); - return 1; + return; } blocksize=block; DEBUG(2,("blocksize is now %d\n", blocksize)); - - return 0; } /**************************************************************************** command to set incremental / reset mode ***************************************************************************/ -int cmd_tarmode(void) +void cmd_tarmode(void) { fstring buf; - while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { + while (next_token(NULL,buf,NULL,sizeof(buf))) { if (strequal(buf, "full")) tar_inc=False; else if (strequal(buf, "inc")) @@ -1337,13 +1376,12 @@ int cmd_tarmode(void) tar_reset ? "reset" : "noreset", tar_noisy ? "verbose" : "quiet")); - return 0; } /**************************************************************************** Feeble attrib command ***************************************************************************/ -int cmd_setmode(void) +void cmd_setmode(void) { char *q; fstring buf; @@ -1353,16 +1391,16 @@ int cmd_setmode(void) attra[0] = attra[1] = 0; - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) + if (!next_token(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("setmode <filename> <[+|-]rsha>\n")); - return 1; + return; } 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(NULL,buf,NULL,sizeof(buf))) { q=buf; while(*q) @@ -1380,47 +1418,43 @@ int cmd_setmode(void) case 'a': attra[direct]|=aARCH; break; default: DEBUG(0, ("setmode <filename> <perm=[+|-]rsha>\n")); - return 1; + return; } } if (attra[ATTRSET]==0 && attra[ATTRRESET]==0) { DEBUG(0, ("setmode <filename> <[+|-]rsha>\n")); - return 1; + return; } DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); do_setrattr(fname, attra[ATTRSET], ATTRSET); do_setrattr(fname, attra[ATTRRESET], ATTRRESET); - - return 0; } /**************************************************************************** Principal command for creating / extracting ***************************************************************************/ -int cmd_tar(void) +void cmd_tar(void) { fstring buf; char **argl; int argcl; - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) + if (!next_token(NULL,buf,NULL,sizeof(buf))) { DEBUG(0,("tar <c|x>[IXbgan] <filename>\n")); - return 1; + return; } argl=toktocliplist(&argcl, NULL); if (!tar_parseargs(argcl, argl, buf, 0)) - return 1; + return; process_tar(); SAFE_FREE(argl); - - return 0; } /**************************************************************************** @@ -1453,7 +1487,7 @@ int process_tar(void) *(cliplist[i]+strlen(cliplist[i])-1)='\0'; } - if (strrchr_m(cliplist[i], '\\')) { + if (strrchr(cliplist[i], '\\')) { pstring saved_dir; safe_strcpy(saved_dir, cur_dir, sizeof(pstring)); @@ -1465,7 +1499,7 @@ int process_tar(void) safe_strcat(tarmac, cliplist[i], sizeof(pstring)); } safe_strcpy(cur_dir, tarmac, sizeof(pstring)); - *(strrchr_m(cur_dir, '\\')+1)='\0'; + *(strrchr(cur_dir, '\\')+1)='\0'; DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); @@ -1516,13 +1550,13 @@ static int clipfind(char **aret, int ret, char *tok) if (aret==NULL) return 0; /* ignore leading slashes or dots in token */ - while(strchr_m("/\\.", *tok)) tok++; + while(strchr("/\\.", *tok)) tok++; while(ret--) { char *pkey=*aret++; /* ignore leading slashes or dots in list */ - while(strchr_m("/\\.", *pkey)) pkey++; + while(strchr("/\\.", *pkey)) pkey++; if (!strslashcmp(pkey, tok)) return 1; } @@ -1536,7 +1570,7 @@ accordingly. ***************************************************************************/ static int read_inclusion_file(char *filename) { - XFILE *inclusion = NULL; + FILE *inclusion = NULL; char buf[MAXPATHLEN + 1]; char *inclusion_buffer = NULL; int inclusion_buffer_size = 0; @@ -1548,7 +1582,7 @@ static int read_inclusion_file(char *filename) clipn = 0; buf[MAXPATHLEN] = '\0'; /* guarantee null-termination */ - if ((inclusion = x_fopen(filename, O_RDONLY, 0)) == NULL) { + if ((inclusion = sys_fopen(filename, "r")) == NULL) { /* XXX It would be better to include a reason for failure, but without * autoconf, it's hard to use strerror, sys_errlist, etc. */ @@ -1556,7 +1590,7 @@ static int read_inclusion_file(char *filename) return 0; } - while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) { + while ((! error) && (fgets(buf, sizeof(buf)-1, inclusion))) { if (inclusion_buffer == NULL) { inclusion_buffer_size = 1024; if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) { @@ -1575,19 +1609,18 @@ static int read_inclusion_file(char *filename) inclusion_buffer_size *= 2; ib = Realloc(inclusion_buffer,inclusion_buffer_size); if (! ib) { - DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", - inclusion_buffer_size)); - error = 1; - break; - } - else inclusion_buffer = ib; + DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", inclusion_buffer_size)); + error = 1; + break; + } else + inclusion_buffer = ib; } safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar); inclusion_buffer_sofar += strlen(buf) + 1; clipn++; } - x_fclose(inclusion); + fclose(inclusion); if (! error) { /* Allocate an array of clipn + 1 char*'s for cliplist */ @@ -1608,7 +1641,7 @@ static int read_inclusion_file(char *filename) } else { unfixtarname(tmpstr, p, strlen(p) + 1, True); cliplist[i] = tmpstr; - if ((p = strchr_m(p, '\000')) == NULL) { + if ((p = strchr(p, '\000')) == NULL) { DEBUG(0,("INTERNAL ERROR: inclusion_buffer is of unexpected contents.\n")); abort(); } @@ -1619,7 +1652,9 @@ static int read_inclusion_file(char *filename) } } - SAFE_FREE(inclusion_buffer); + if (inclusion_buffer) { + SAFE_FREE(inclusion_buffer); + } if (error) { if (cliplist) { char **pp; @@ -1683,7 +1718,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) SMB_STRUCT_STAT stbuf; extern time_t newer_than; - if (sys_stat(argv[Optind], &stbuf) == 0) { + if (sys_stat(dos_to_unix_static(argv[Optind]), &stbuf) == 0) { newer_than = stbuf.st_mtime; DEBUG(1,("Getting files newer than %s", asctime(LocalTime(&newer_than)))); @@ -1828,7 +1863,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) * tar output */ if (tarhandle == 1) - dbf = x_stderr; + dbf = stderr; } else { if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) { |