From 0e8fd3398771da2f016d72830179507f3edda51b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 4 May 1996 07:50:46 +0000 Subject: Initial version imported to CVS (This used to be commit 291551d80711daab7b7581720bcd9a08d6096517) --- source3/client/clitar.c | 1713 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1713 insertions(+) create mode 100644 source3/client/clitar.c (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c new file mode 100644 index 0000000000..1433ec5941 --- /dev/null +++ b/source3/client/clitar.c @@ -0,0 +1,1713 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Tar Extensions + Copyright (C) Ricky Poulten 1995 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include "includes.h" +#include "clitar.h" + +extern void setup_pkt(char *outbuf); +extern BOOL reopen_connection(char *inbuf,char *outbuf); +extern void do_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (*fn)(),BOOL recurse_dir); + +int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind); + +extern BOOL recurse; + +#define SEPARATORS " \t\n\r" +extern int DEBUGLEVEL; +extern int Client; + +/* 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 int attribute = aDIR | aSYSTEM | aHIDDEN; + +#ifndef CLIENT_TIMEOUT +#define CLIENT_TIMEOUT (30*1000) +#endif + +static char *tarbuf; +static int tp, ntarf, tbufsiz; +/* Incremental mode */ +BOOL tar_inc=False; +/* Reset archive bit */ +BOOL tar_reset=False; +/* Include / exclude mode (true=include, false=exclude) */ +BOOL tar_excl=True; +char tar_type='\0'; +static char **cliplist=NULL; +static int clipn=0; + +extern file_info def_finfo; +extern BOOL lowercase; +extern int cnum; +extern BOOL readbraw_supported; +extern int max_xmit; +extern pstring cur_dir; +extern int get_total_time_ms; +extern int get_total_size; +extern int Protocol; + +int blocksize=20; +int tarhandle; + +static void writetarheader(); +static void do_atar(); +static void do_tar(); +static void oct_it(); +static void fixtarname(); +static int dotarbuf(); +static void dozerobuf(); +static void dotareof(); +static void initarbuf(); +static int do_setrattr(); +void cmd_tar(); +int process_tar(); +char **toktocliplist(); +int clipfind(); +/* restore functions */ +static long readtarheader(); +static long unoct(); +static void do_tarput(); +static void unfixtarname(); + +/* + * tar specific utitlities + */ + +/**************************************************************************** +Write a tar header to buffer +****************************************************************************/ +static void writetarheader(int f, char *aname, int size, time_t mtime, + char *amode) +{ + union hblock hb; + int i, chk, l; + char *jp; + + memset(hb.dummy, 0, sizeof(hb.dummy)); + + l=strlen(aname); + if (l >= NAMSIZ) + { + DEBUG(0, ("tar file %s name length exceeds NAMSIZ\n", aname)); + } + + /* use l + 1 to do the null too */ + fixtarname(hb.dbuf.name, aname, (l >= NAMSIZ) ? NAMSIZ : l + 1); + + if (lowercase) + strlower(hb.dbuf.name); + + /* write out a "standard" tar format header */ + + hb.dbuf.name[NAMSIZ-1]='\0'; + strcpy(hb.dbuf.mode, amode); + oct_it(0L, 8, hb.dbuf.uid); + oct_it(0L, 8, hb.dbuf.gid); + oct_it((long) size, 13, hb.dbuf.size); + oct_it((long) mtime, 13, hb.dbuf.mtime); + memcpy(hb.dbuf.chksum, " ", sizeof(hb.dbuf.chksum)); + hb.dbuf.linkflag='0'; + memset(hb.dbuf.linkname, 0, NAMSIZ); + + for (chk=0, i=sizeof(hb.dummy), jp=hb.dummy; --i>=0;) chk+=(0xFF & *jp++); + + oct_it((long) chk, 8, hb.dbuf.chksum); + hb.dbuf.chksum[6] = '\0'; + + (void) dotarbuf(f, hb.dummy, sizeof(hb.dummy)); +} + +/**************************************************************************** +Read a tar header into a hblock structure, and validate +***************************************************************************/ +static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) +{ + long chk, fchk; + int i; + char *jp; + + /* + * read in a "standard" tar format header - we're not that interested + * in that many fields, though + */ + + /* check the checksum */ + for (chk=0, i=sizeof(hb->dummy), jp=hb->dummy; --i>=0;) chk+=(0xFF & *jp++); + + if (chk == 0) + return chk; + + /* compensate for blanks in chksum header */ + for (i=sizeof(hb->dbuf.chksum), jp=hb->dbuf.chksum; --i>=0;) + chk-=(0xFF & *jp++); + + chk += ' ' * sizeof(hb->dbuf.chksum); + + fchk=unoct(hb->dbuf.chksum, sizeof(hb->dbuf.chksum)); + + DEBUG(5, ("checksum totals chk=%d fchk=%d chksum=%s\n", + chk, fchk, hb->dbuf.chksum)); + + if (fchk != chk) + { + DEBUG(0, ("checksums don't match %d %d\n", fchk, chk)); + return -1; + } + + strcpy(finfo->name, prefix); + + /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ + unfixtarname(finfo->name + strlen(prefix), hb->dbuf.name, + strlen(hb->dbuf.name) + 1); + +/* can't handle links at present */ + if (hb->dbuf.linkflag != '0') { + if (hb->dbuf.linkflag == 0) { + DEBUG(6, ("Warning: NULL link flag (gnu tar archive ?) %s\n", + finfo->name)); + } else { + DEBUG(0, ("this tar file appears to contain some kind of link - ignoring\n")); + return -2; + } + } + + if ((unoct(hb->dbuf.mode, sizeof(hb->dbuf.mode)) & S_IFDIR) + || (*(finfo->name+strlen(finfo->name)-1) == '\\')) + { + finfo->mode=aDIR; + } + else + finfo->mode=0; /* we don't care about mode at the moment, we'll + * just make it a regular file */ + /* + * Bug fix by richard@sj.co.uk + * + * REC: restore times correctly (as does tar) + * We only get the modification time of the file; set the creation time + * from the mod. time, and the access time to current time + */ + finfo->mtime = finfo->ctime = strtol(hb->dbuf.mtime, NULL, 8); + finfo->atime = time(NULL); + finfo->size = unoct(hb->dbuf.size, sizeof(hb->dbuf.size)); + + return True; +} + +/**************************************************************************** +Write out the tar buffer to tape or wherever +****************************************************************************/ +static int dotarbuf(int f, char *b, int n) +{ + int fail=1, writ=n; + + /* This routine and the next one should be the only ones that do write()s */ + if (tp + n >= tbufsiz) + { + int diff; + + diff=tbufsiz-tp; + memcpy(tarbuf + tp, b, diff); + fail=fail && (1+write(f, tarbuf, tbufsiz)); + n-=diff; + b+=diff; + tp=0; + + while (n >= tbufsiz) + { + fail=fail && (1 + write(f, b, tbufsiz)); + n-=tbufsiz; + b+=tbufsiz; + } + } + if (n>0) { + memcpy(tarbuf+tp, b, n); + tp+=n; + } + + return(fail ? writ : 0); +} + +/**************************************************************************** +Write a zeros to buffer / tape +****************************************************************************/ +static void dozerobuf(int f, int n) +{ + /* short routine just to write out n zeros to buffer - + * used to round files to nearest block + * and to do tar EOFs */ + + if (n+tp >= tbufsiz) + { + memset(tarbuf+tp, 0, tbufsiz-tp); + write(f, tarbuf, tbufsiz); + memset(tarbuf, 0, (tp+=n-tbufsiz)); + } + else + { + memset(tarbuf+tp, 0, n); + tp+=n; + } +} + +/**************************************************************************** +Malloc tape buffer +****************************************************************************/ +static void initarbuf() +{ + /* initialize tar buffer */ + tbufsiz=blocksize*TBLOCK; + tarbuf=malloc(tbufsiz); + + /* reset tar buffer pointer and tar file counter */ + tp=0; ntarf=0; +} + +/**************************************************************************** +Write two zero blocks at end of file +****************************************************************************/ +static void dotareof(int f) +{ + struct stat stbuf; + /* Two zero blocks at end of file, write out full buffer */ + + (void) dozerobuf(f, TBLOCK); + (void) dozerobuf(f, TBLOCK); + + if (fstat(f, &stbuf) == -1) + { + DEBUG(0, ("Couldn't stat file handle\n")); + return; + } + + /* Could be a pipe, in which case S_ISREG should fail, + * and we should write out at full size */ + if (tp > 0) write(f, tarbuf, S_ISREG(stbuf.st_mode) ? tp : tbufsiz); +} + +/**************************************************************************** +(Un)mangle DOS pathname, make nonabsolute +****************************************************************************/ +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++='.'; +#ifdef KANJI + while (l > 0) { + if (is_shift_jis (*fp)) { + *tptr++ = *fp++; + *tptr++ = *fp++; + l -= 2; + } else if (is_kana (*fp)) { + *tptr++ = *fp++; + l--; + } else if (*fp == '\\') { + *tptr++ = '/'; + fp++; + l--; + } else { + *tptr++ = *fp++; + l--; + } + } +#else + while (l--) { *tptr=(*fp == '\\') ? '/' : *fp; tptr++; fp++; } +#endif +} + +/**************************************************************************** +Convert from decimal to octal string +****************************************************************************/ +static void oct_it (register long value, register int ndgs, register char *p) +{ + /* Converts long to octal string, pads with leading zeros */ + + /* skip final null, but do final space */ + --ndgs; + p[--ndgs] = ' '; + + /* Loop does at least one digit */ + do { + p[--ndgs] = '0' + (char) (value & 7); + value >>= 3; + } + while (ndgs > 0 && value != 0); + + /* Do leading zeros */ + while (ndgs > 0) + p[--ndgs] = '0'; +} + +/**************************************************************************** +Convert from octal string to long +***************************************************************************/ +static long unoct(char *p, int ndgs) +{ + long value=0; + /* Converts octal string to long, ignoring any non-digit */ + + while (--ndgs) + { + if (isdigit(*p)) + value = (value << 3) | (long) (*p - '0'); + + p++; + } + + return value; +} + +/**************************************************************************** +Compare two strings in a slash insensitive way +***************************************************************************/ +int strslashcmp(const char *s1, const char *s2) +{ + while(*s1 && *s2 && + (*s1 == *s2 + || tolower(*s1) == tolower(*s2) + || (*s1 == '\\' && *s2=='/') + || (*s1 == '/' && *s2=='\\'))) { + s1++; s2++; + } + + return *s1-*s2; +} + +/* + * general smb utility functions + */ +/**************************************************************************** +Set DOS file attributes +***************************************************************************/ +static int do_setrattr(char *fname, int attr, int setit) +{ + /* + * First get the existing attribs from existing file + */ + char *inbuf,*outbuf; + char *p; + pstring name; + int fattr; + + strcpy(name,fname); + strcpy(fname,"\\"); + strcat(fname,name); + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) + { + DEBUG(0,("out of memory\n")); + return False; + } + + /* send an smb getatr message */ + + memset(outbuf,0,smb_size); + set_message(outbuf,0,2 + strlen(fname),True); + CVAL(outbuf,smb_com) = SMBgetatr; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + p = smb_buf(outbuf); + *p++ = 4; + strcpy(p,fname); + p += (strlen(fname)+1); + + *p++ = 4; + *p++ = 0; + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + DEBUG(5,("getatr: %s\n",smb_errstr(inbuf))); + else + { + DEBUG(5,("\nattr 0x%X time %d size %d\n", + (int)CVAL(inbuf,smb_vwv0), + SVAL(inbuf,smb_vwv1), + SVAL(inbuf,smb_vwv3))); + } + + fattr=CVAL(inbuf,smb_vwv0); + + /* combine found attributes with bits to be set or reset */ + + attr=setit ? (fattr | attr) : (fattr & ~attr); + + /* now try and set attributes by sending smb reset message */ + + /* clear out buffer and start again */ + memset(outbuf,0,smb_size); + set_message(outbuf,8,4 + strlen(fname),True); + CVAL(outbuf,smb_com) = SMBsetatr; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + SSVAL(outbuf,smb_vwv0,attr); + + p = smb_buf(outbuf); + *p++ = 4; + strcpy(p,fname); + p += (strlen(fname)+1); + + *p++ = 4; + *p++ = 0; + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("%s setting attributes on file %s\n", + smb_errstr(inbuf), fname)); + free(inbuf);free(outbuf); + return(False); + } + + free(inbuf);free(outbuf); + return(True); +} + +/**************************************************************************** +Create a file on a share +***************************************************************************/ +static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) +{ + char *p; + /* *must* be called with buffer ready malloc'ed */ + /* open remote file */ + + memset(outbuf,0,smb_size); + set_message(outbuf,3,2 + strlen(finfo.name),True); + CVAL(outbuf,smb_com) = SMBcreate; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + SSVAL(outbuf,smb_vwv0,finfo.mode); + put_dos_date3(outbuf,smb_vwv1,finfo.mtime); + + p = smb_buf(outbuf); + *p++ = 4; + strcpy(p,finfo.name); + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("%s opening remote file %s\n",smb_errstr(inbuf), + finfo.name)); + return 0; + } + + *fnum = SVAL(inbuf,smb_vwv0); + return True; +} + +/**************************************************************************** +Write a file to a share +***************************************************************************/ +static BOOL smbwrite(int fnum, int n, int low, int high, int left, + char *bufferp, char *inbuf, char *outbuf) +{ + /* *must* be called with buffer ready malloc'ed */ + + memset(outbuf,0,smb_size); + set_message(outbuf,5,n + 3,True); + + memcpy(smb_buf(outbuf)+3, bufferp, n); + + set_message(outbuf,5,n + 3, False); + CVAL(outbuf,smb_com) = SMBwrite; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + SSVAL(outbuf,smb_vwv0,fnum); + SSVAL(outbuf,smb_vwv1,n); + SIVAL(outbuf,smb_vwv2,low); + SSVAL(outbuf,smb_vwv4,left); + CVAL(smb_buf(outbuf),0) = 1; + SSVAL(smb_buf(outbuf),1,n); + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("%s writing remote file\n",smb_errstr(inbuf))); + return False; + } + + if (n != SVAL(inbuf,smb_vwv0)) + { + DEBUG(0,("Error: only wrote %d bytes out of %d\n", + SVAL(inbuf,smb_vwv0), n)); + return False; + } + + return True; +} + +/**************************************************************************** +Close a file on a share +***************************************************************************/ +static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) +{ + /* *must* be called with buffer ready malloc'ed */ + + memset(outbuf,0,smb_size); + set_message(outbuf,3,0,True); + CVAL(outbuf,smb_com) = SMBclose; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + SSVAL(outbuf,smb_vwv0,fnum); + put_dos_date3(outbuf,smb_vwv1,finfo.mtime); + + DEBUG(3,("Setting date to %s (0x%X)", + asctime(LocalTime(&finfo.mtime,GMT_TO_LOCAL)), + finfo.mtime)); + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("%s closing remote file %s\n",smb_errstr(inbuf), + finfo.name)); + return False; + } + + return True; +} + +/**************************************************************************** +Verify existence of path on share +***************************************************************************/ +static BOOL smbchkpath(char *fname, char *inbuf, char *outbuf) +{ + char *p; + + memset(outbuf,0,smb_size); + set_message(outbuf,0,4 + strlen(fname),True); + CVAL(outbuf,smb_com) = SMBchkpth; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + p = smb_buf(outbuf); + *p++ = 4; + strcpy(p,fname); + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + DEBUG(5,("smbchkpath: %s\n",smb_errstr(inbuf))); + + return(CVAL(inbuf,smb_rcls) == 0); +} + +/**************************************************************************** +Make a directory on share +***************************************************************************/ +static BOOL smbmkdir(char *fname, char *inbuf, char *outbuf) +{ + /* *must* be called with buffer ready malloc'ed */ + char *p; + + memset(outbuf,0,smb_size); + set_message(outbuf,0,2 + strlen(fname),True); + + CVAL(outbuf,smb_com) = SMBmkdir; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + p = smb_buf(outbuf); + *p++ = 4; + strcpy(p,fname); + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("%s making remote directory %s\n", + smb_errstr(inbuf),fname)); + return(False); + } + + return(True); +} + +/**************************************************************************** +Ensure a remote path exists (make if necessary) +***************************************************************************/ +static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) +{ + /* *must* be called with buffer ready malloc'ed */ + /* ensures path exists */ + + pstring partpath, ffname; + char *p=fname, *basehack; + + *partpath = 0; + + /* fname copied to ffname so can strtok */ + + strcpy(ffname, fname); + + /* do a `basename' on ffname, so don't try and make file name directory */ + if ((basehack=strrchr(ffname, '\\')) == NULL) + return True; + else + *basehack='\0'; + + p=strtok(ffname, "\\"); + + while (p) + { + strcat(partpath, p); + + if (!smbchkpath(partpath, inbuf, outbuf)) { + if (!smbmkdir(partpath, inbuf, outbuf)) + { + DEBUG(0, ("Error mkdirhiering\n")); + return False; + } + else + DEBUG(3, ("mkdirhiering %s\n", partpath)); + + } + + strcat(partpath, "\\"); + p = strtok(NULL,"/\\"); + } + + return True; +} + +/* + * smbclient functions + */ +/**************************************************************************** +append one remote file to the tar file +***************************************************************************/ +static void do_atar(char *rname,char *lname,file_info *finfo1) +{ + int fnum; + uint32 nread=0; + char *p; + char *inbuf,*outbuf; + file_info finfo; + BOOL close_done = False; + BOOL shallitime=True; + BOOL ignore_close_error = False; + char *dataptr=NULL; + int datalen=0; + + struct timeval tp_start; + GetTimeOfDay(&tp_start); + + if (finfo1) + finfo = *finfo1; + else + finfo = def_finfo; + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) + { + DEBUG(0,("out of memory\n")); + return; + } + + memset(outbuf,0,smb_size); + set_message(outbuf,15,1 + strlen(rname),True); + + CVAL(outbuf,smb_com) = SMBopenX; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + SSVAL(outbuf,smb_vwv0,0xFF); + SSVAL(outbuf,smb_vwv2,1); + SSVAL(outbuf,smb_vwv3,(DENY_NONE<<4)); + SSVAL(outbuf,smb_vwv4,aSYSTEM | aHIDDEN); + SSVAL(outbuf,smb_vwv5,aSYSTEM | aHIDDEN); + SSVAL(outbuf,smb_vwv8,1); + + p = smb_buf(outbuf); + strcpy(p,rname); + p = skip_string(p,1); + + dos_clean_name(rname); + + /* do a chained openX with a readX? */ + if (finfo.size > 0) + { + SSVAL(outbuf,smb_vwv0,SMBreadX); + SSVAL(outbuf,smb_vwv1,PTR_DIFF(p,outbuf) - 4); + memset(p,0,200); + p -= smb_wct; + SSVAL(p,smb_wct,10); + SSVAL(p,smb_vwv0,0xFF); + SSVAL(p,smb_vwv5,MIN(max_xmit-500,finfo.size)); + SSVAL(p,smb_vwv9,MIN(0xFFFF,finfo.size)); + smb_setlen(outbuf,smb_len(outbuf)+11*2+1); + } + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + if (CVAL(inbuf,smb_rcls) == ERRSRV && + SVAL(inbuf,smb_err) == ERRnoresource && + reopen_connection(inbuf,outbuf)) + { + do_atar(rname,lname,finfo1); + free(inbuf);free(outbuf); + return; + } + + DEBUG(0,("%s opening remote file %s\n",smb_errstr(inbuf),rname)); + free(inbuf);free(outbuf); + return; + } + + strcpy(finfo.name,rname); + if (!finfo1) + { + finfo.mode = SVAL(inbuf,smb_vwv3); + finfo.size = IVAL(inbuf,smb_vwv4); + finfo.mtime = make_unix_date3(inbuf+smb_vwv6); + finfo.atime = finfo.ctime = finfo.mtime; + } + + DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); + + fnum = SVAL(inbuf,smb_vwv2); + + if (tar_inc && !(finfo.mode & aARCH)) + { + DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name)); + shallitime=0; + } + else + { + if (SVAL(inbuf,smb_vwv0) == SMBreadX) + { + p = (inbuf+4+SVAL(inbuf,smb_vwv1)) - smb_wct; + datalen = SVAL(p,smb_vwv5); + dataptr = inbuf + 4 + SVAL(p,smb_vwv6); + } + else + { + dataptr = NULL; + datalen = 0; + } + + DEBUG(2,("getting file %s of size %d bytes as a tar file %s", + finfo.name, + finfo.size, + lname)); + + /* write a tar header, don't bother with mode - just set to 100644 */ + writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0"); + + while (nread < finfo.size && !close_done) + { + int method = -1; + static BOOL can_chain_close=True; + + p=NULL; + + DEBUG(3,("nread=%d\n",nread)); + + /* 3 possible read types. readbraw if a large block is required. + readX + close if not much left and read if neither is supported */ + + /* we might have already read some data from a chained readX */ + if (dataptr && datalen>0) + method=3; + + /* if we can finish now then readX+close */ + if (method<0 && can_chain_close && (Protocol >= PROTOCOL_LANMAN1) && + ((finfo.size - nread) < + (max_xmit - (2*smb_size + 13*SIZEOFWORD + 300)))) + method = 0; + + /* if we support readraw then use that */ + if (method<0 && readbraw_supported) + method = 1; + + /* if we can then use readX */ + if (method<0 && (Protocol >= PROTOCOL_LANMAN1)) + method = 2; + + + switch (method) + { + /* use readX */ + case 0: + case 2: + if (method == 0) + close_done = True; + + /* use readX + close */ + memset(outbuf,0,smb_size); + set_message(outbuf,10,0,True); + CVAL(outbuf,smb_com) = SMBreadX; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + if (close_done) + { + CVAL(outbuf,smb_vwv0) = SMBclose; + SSVAL(outbuf,smb_vwv1,PTR_DIFF(smb_buf(outbuf),outbuf) - 4); + } + else + CVAL(outbuf,smb_vwv0) = 0xFF; + + + SSVAL(outbuf,smb_vwv2,fnum); + SIVAL(outbuf,smb_vwv3,nread); + SSVAL(outbuf,smb_vwv5,MIN(max_xmit-200,finfo.size - nread)); + SSVAL(outbuf,smb_vwv6,0); + SIVAL(outbuf,smb_vwv7,0); + SSVAL(outbuf,smb_vwv9,MIN(0xFFFF,finfo.size-nread)); + + if (close_done) + { + p = smb_buf(outbuf); + memset(p,0,9); + + CVAL(p,0) = 3; + SSVAL(p,1,fnum); + SIVALS(p,3,-1); + + /* now set the total packet length */ + smb_setlen(outbuf,smb_len(outbuf)+9); + } + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("Error %s reading remote file\n",smb_errstr(inbuf))); + break; + } + + if (close_done && + SVAL(inbuf,smb_vwv0) != SMBclose) + { + /* NOTE: WfWg sometimes just ignores the chained + command! This seems to break the spec? */ + DEBUG(3,("Rejected chained close?\n")); + close_done = False; + can_chain_close = False; + ignore_close_error = True; + } + + datalen = SVAL(inbuf,smb_vwv5); + dataptr = inbuf + 4 + SVAL(inbuf,smb_vwv6); + break; + + + /* use readbraw */ + case 1: + { + static int readbraw_size = 0xFFFF; + + extern int Client; + memset(outbuf,0,smb_size); + set_message(outbuf,8,0,True); + CVAL(outbuf,smb_com) = SMBreadbraw; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + SSVAL(outbuf,smb_vwv0,fnum); + SIVAL(outbuf,smb_vwv1,nread); + SSVAL(outbuf,smb_vwv3,MIN(finfo.size-nread,readbraw_size)); + SSVAL(outbuf,smb_vwv4,0); + SIVALS(outbuf,smb_vwv5,-1); + send_smb(Client,outbuf); + + /* Now read the raw data into the buffer and write it */ + if(read_smb_length(Client,inbuf,0) == -1) { + DEBUG(0,("Failed to read length in readbraw\n")); + exit(1); + } + + /* Even though this is not an smb message, smb_len + returns the generic length of an smb message */ + datalen = smb_len(inbuf); + + if (datalen == 0) + { + /* we got a readbraw error */ + DEBUG(4,("readbraw error - reducing size\n")); + readbraw_size = (readbraw_size * 9) / 10; + + if (readbraw_size < max_xmit) + { + DEBUG(0,("disabling readbraw\n")); + readbraw_supported = False; + } + + dataptr=NULL; + continue; + } + + if(read_data(Client,inbuf,datalen) != datalen) { + DEBUG(0,("Failed to read data in readbraw\n")); + exit(1); + } + dataptr = inbuf; + } + break; + + case 3: + /* we've already read some data with a chained readX */ + break; + + default: + /* use plain read */ + memset(outbuf,0,smb_size); + set_message(outbuf,5,0,True); + CVAL(outbuf,smb_com) = SMBread; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + SSVAL(outbuf,smb_vwv0,fnum); + SSVAL(outbuf,smb_vwv1,MIN(max_xmit-200,finfo.size - nread)); + SIVAL(outbuf,smb_vwv2,nread); + SSVAL(outbuf,smb_vwv4,finfo.size - nread); + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("Error %s reading remote file\n",smb_errstr(inbuf))); + break; + } + + datalen = SVAL(inbuf,smb_vwv0); + dataptr = smb_buf(inbuf) + 3; + break; + } + + + /* add received bits of file to buffer - dotarbuf will + * write out in 512 byte intervals */ + if (dotarbuf(tarhandle,dataptr,datalen) != datalen) + { + DEBUG(0,("Error writing local file\n")); + break; + } + + nread += datalen; + if (datalen == 0) + { + DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); + break; + } + + dataptr=NULL; + datalen=0; + } + + /* round tar file to nearest block */ + if (finfo.size % TBLOCK) + dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); + + ntarf++; + } + + if (!close_done) + { + memset(outbuf,0,smb_size); + set_message(outbuf,3,0,True); + CVAL(outbuf,smb_com) = SMBclose; + SSVAL(outbuf,smb_tid,cnum); + setup_pkt(outbuf); + + SSVAL(outbuf,smb_vwv0,fnum); + SIVALS(outbuf,smb_vwv1,-1); + + send_smb(Client,outbuf); + receive_smb(Client,inbuf,CLIENT_TIMEOUT); + + if (!ignore_close_error && CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("Error %s closing remote file\n",smb_errstr(inbuf))); + free(inbuf);free(outbuf); + return; + } + } + + if (shallitime) + { + struct timeval tp_end; + int this_time; + + /* if shallitime is true then we didn't skip */ + if (tar_reset) (void) do_setrattr(finfo.name, aARCH, ATTRRESET); + + GetTimeOfDay(&tp_end); + this_time = + (tp_end.tv_sec - tp_start.tv_sec)*1000 + + (tp_end.tv_usec - tp_start.tv_usec)/1000; + get_total_time_ms += this_time; + get_total_size += finfo.size; + + /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ + DEBUG(2,("(%g kb/s) (average %g kb/s)\n", + finfo.size / MAX(0.001, (1.024*this_time)), + get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); + } + + free(inbuf);free(outbuf); +} + +/**************************************************************************** +Append single file to tar file (or not) +***************************************************************************/ +static void do_tar(file_info *finfo) +{ + pstring rname; + + if (strequal(finfo->name,".") || strequal(finfo->name,"..")) + return; + + /* Is it on the exclude list ? */ + if (!tar_excl && clipn) { + pstring exclaim; + + strcpy(exclaim, cur_dir); + *(exclaim+strlen(exclaim)-1)='\0'; + + if (clipfind(cliplist, clipn, exclaim)) { + DEBUG(3,("Skipping directory %s\n", exclaim)); + return; + } + + strcat(exclaim, "\\"); + strcat(exclaim, finfo->name); + + if (clipfind(cliplist, clipn, exclaim)) { + DEBUG(3,("Skipping file %s\n", exclaim)); + return; + } + } + + if (finfo->mode & aDIR) + { + pstring saved_curdir; + pstring mtar_mask; + char *inbuf,*outbuf; + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) + { + DEBUG(0,("out of memory\n")); + return; + } + + strcpy(saved_curdir,cur_dir); + + strcat(cur_dir,finfo->name); + strcat(cur_dir,"\\"); + + /* write a tar directory, don't bother with mode - just set it to + * 40755 */ + writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0"); + strcpy(mtar_mask,cur_dir); + strcat(mtar_mask,"*"); + + do_dir((char *)inbuf,(char *)outbuf,mtar_mask,attribute,do_tar,recurse); + strcpy(cur_dir,saved_curdir); + free(inbuf);free(outbuf); + } + else + { + strcpy(rname,cur_dir); + strcat(rname,finfo->name); + do_atar(rname,finfo->name,finfo); + } +} + +/**************************************************************************** +Convert from UNIX to DOS file names +***************************************************************************/ +static void unfixtarname(char *tptr, char *fp, int l) +{ + /* remove '.' from start of file name, convert from unix /'s to + * dos \'s in path. Kill any absolute path names. + */ + + if (*fp == '.') fp++; + if (*fp == '\\' || *fp == '/') fp++; + +#ifdef KANJI + while (l > 0) { + if (is_shift_jis (*fp)) { + *tptr++ = *fp++; + *tptr++ = *fp++; + l -= 2; + } else if (is_kana (*fp)) { + *tptr++ = *fp++; + l--; + } else if (*fp == '/') { + *tptr++ = '\\'; + fp++; + l--; + } else { + *tptr++ = *fp++; + l--; + } + } +#else + while (l--) { *tptr=(*fp == '/') ? '\\' : *fp; tptr++; fp++; } +#endif +} + +static void do_tarput() +{ + file_info finfo; + int nread=0, bufread; + char *inbuf,*outbuf; + int fsize=0; + int fnum; + struct timeval tp_start; + BOOL tskip=False; /* We'll take each file as it comes */ + + GetTimeOfDay(&tp_start); + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) + { + DEBUG(0,("out of memory\n")); + return; + } + + /* + * Must read in tbufsiz dollops + */ + + /* These should be the only reads in clitar.c */ + while ((bufread=read(tarhandle, tarbuf, tbufsiz))>0) { + char *bufferp, *endofbuffer; + int chunk; + + /* Code to handle a short read. + * We always need a TBLOCK full of stuff + */ + if (bufread % TBLOCK) { + int lchunk=TBLOCK-(bufread % TBLOCK); + int lread; + + /* It's a shorty - a short read that is */ + DEBUG(3, ("Short read, read %d so far (need %d)\n", bufread, lchunk)); + + while ((lread=read(tarhandle, tarbuf+bufread, lchunk))>0) { + bufread+=lread; + if (!(lchunk-=lread)) break; + } + + /* If we've reached EOF then that must be a short file */ + if (lread<=0) break; + } + + bufferp=tarbuf; + endofbuffer=tarbuf+bufread; + + if (tskip) { + if (fsize= endofbuffer) break; + } /* if (!fsize) */ + + /* write out the file in chunk sized chunks - don't + * go past end of buffer though */ + chunk=(fsize-nread < endofbuffer - bufferp) + ? fsize - nread : endofbuffer - bufferp; + + while (chunk > 0) { + int minichunk=MIN(chunk, max_xmit-200); + + if (!smbwrite(fnum, /* file descriptor */ + minichunk, /* n */ + nread, /* offset low */ + 0, /* offset high - not implemented */ + fsize-nread, /* left - only hint to server */ + bufferp, + inbuf, + outbuf)) + { + DEBUG(0, ("Error writing remote file\n")); + free(inbuf); free(outbuf); + return; + } + DEBUG(5, ("chunk writing fname=%s fnum=%d nread=%d minichunk=%d chunk=%d size=%d\n", finfo.name, fnum, nread, minichunk, chunk, fsize)); + + bufferp+=minichunk; nread+=minichunk; + chunk-=minichunk; + } + + if (nread>=fsize) + { + if (!smbshut(finfo, fnum, inbuf, outbuf)) + { + DEBUG(0, ("Error closing remote file\n")); + free(inbuf);free(outbuf); + return; + } + if (fsize % TBLOCK) bufferp+=TBLOCK - (fsize % TBLOCK); + DEBUG(5, ("bufferp is now %d (psn=%d)\n", + (long) bufferp, (long)(bufferp - tarbuf))); + ntarf++; + fsize=0; + } + } while (bufferp < endofbuffer); + } + + DEBUG(0, ("premature eof on tar file ?\n")); + DEBUG(0,("total of %d tar files restored to share\n", ntarf)); + + free(inbuf); free(outbuf); +} + +/* + * samba interactive commands + */ + +/**************************************************************************** +Blocksize command +***************************************************************************/ +void cmd_block(void) +{ + fstring buf; + int block; + + if (!next_token(NULL,buf,NULL)) + { + DEBUG(0, ("blocksize \n")); + return; + } + + block=atoi(buf); + if (block < 0 || block > 65535) + { + DEBUG(0, ("blocksize out of range")); + return; + } + + blocksize=block; + DEBUG(2,("blocksize is now %d\n", blocksize)); +} + +/**************************************************************************** +command to set incremental / reset mode +***************************************************************************/ +void cmd_tarmode(void) +{ + fstring buf; + + while (next_token(NULL,buf,NULL)) { + if (strequal(buf, "full")) + tar_inc=False; + else if (strequal(buf, "inc")) + tar_inc=True; + else if (strequal(buf, "reset")) + tar_reset=True; + else if (strequal(buf, "noreset")) + tar_reset=False; + else DEBUG(0, ("tarmode: unrecognised option %s\n", buf)); + } + + DEBUG(0, ("tarmode is now %s, %s\n", + tar_inc ? "incremental" : "full", + tar_reset ? "reset" : "noreset")); +} + +/**************************************************************************** +Feeble attrib command +***************************************************************************/ +void cmd_setmode(void) +{ + char *q; + fstring buf; + pstring fname; + int attra[2]; + int direct=1; + + attra[0] = attra[1] = 0; + + if (!next_token(NULL,buf,NULL)) + { + DEBUG(0, ("setmode \n")); + return; + } + + strcpy(fname, cur_dir); + strcat(fname, buf); + + while (next_token(NULL,buf,NULL)) { + q=buf; + + while(*q) + switch (*q++) { + case '+': direct=1; + break; + case '-': direct=0; + break; + case 'r': attra[direct]|=aRONLY; + break; + case 'h': attra[direct]|=aHIDDEN; + break; + case 's': attra[direct]|=aSYSTEM; + break; + case 'a': attra[direct]|=aARCH; + break; + default: DEBUG(0, ("setmode \n")); + return; + } + } + + if (attra[ATTRSET]==0 && attra[ATTRRESET]==0) + { + DEBUG(0, ("setmode \n")); + return; + } + +DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); + (void) do_setrattr(fname, attra[ATTRSET], ATTRSET); + (void) do_setrattr(fname, attra[ATTRRESET], ATTRRESET); +} + +/**************************************************************************** +Principal command for creating / extracting +***************************************************************************/ +void cmd_tar(char *inbuf, char *outbuf) +{ + fstring buf; + char **argl; + int argcl; + + if (!next_token(NULL,buf,NULL)) + { + DEBUG(0,("tar [IXbga] \n")); + return; + } + + argl=toktocliplist(&argcl, NULL); + if (!tar_parseargs(argcl, argl, buf, 0)) + return; + + process_tar(inbuf, outbuf); + + free(argl); +} + +/**************************************************************************** +Command line (option) version +***************************************************************************/ +int process_tar(char *inbuf, char *outbuf) +{ + initarbuf(); + switch(tar_type) { + case 'x': + do_tarput(); + free(tarbuf); + close(tarhandle); + break; + case 'r': + case 'c': + if (clipn && tar_excl) { + int i; + pstring tarmac; + + for (i=0; i=argc || !(blocksize=atoi(argv[Optind]))) { + DEBUG(0,("Option b must be followed by valid blocksize\n")); + return 0; + } else { + Optind++; + } + break; + case 'g': + tar_inc=True; + break; + case 'N': + if (Optind>=argc) { + DEBUG(0,("Option N must be followed by valid file name\n")); + return 0; + } else { + struct stat stbuf; + extern time_t newer_than; + + if (sys_stat(argv[Optind], &stbuf) == 0) { + newer_than = stbuf.st_mtime; + DEBUG(1,("Getting files newer than %s", + asctime(LocalTime(&newer_than,GMT_TO_LOCAL)))); + Optind++; + } else { + DEBUG(0,("Error setting newer-than time\n")); + return 0; + } + } + break; + case 'a': + tar_reset=True; + break; + case 'I': + if (tar_clipfl) { + DEBUG(0,("Only one of I,X must be specified\n")); + return 0; + } + tar_clipfl='I'; + break; + case 'X': + if (tar_clipfl) { + DEBUG(0,("Only one of I,X must be specified\n")); + return 0; + } + tar_clipfl='X'; + break; + default: + DEBUG(0,("Unknown tar option\n")); + return 0; + } + + if (!tar_type) { + printf("Option T must be followed by one of c or x.\n"); + return 0; + } + + if (Optind>=argc || !strcmp(argv[Optind], "-")) { + /* Sets tar handle to either 0 or 1, as appropriate */ + tarhandle=(tar_type=='c'); + } else { + tar_excl=tar_clipfl!='X'; + + if (Optind+1 Date: Fri, 31 May 1996 15:13:29 +0000 Subject: Lots of changes! - add faq info on NT printer handling - add "delete readonly" option to help rcs users - add stuff to man pages on new printer options - add "proxy name resolution" option - add "command string" -c option to smbclient (thanks Ken) - split time functions into time.c - rearrange the quotas stuff a bit and fix some bugs - complete rehash of the time handling code thanks to Paul Eggert - fix nmblookup output a bit - add plp print queue parsing from Bertrand Wallrich (This used to be commit 635b56f19c817527c52e9bbde31faa6a8a47777b) --- source3/client/clitar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 1433ec5941..0701aac1cf 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -591,7 +591,7 @@ static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) put_dos_date3(outbuf,smb_vwv1,finfo.mtime); DEBUG(3,("Setting date to %s (0x%X)", - asctime(LocalTime(&finfo.mtime,GMT_TO_LOCAL)), + asctime(LocalTime(&finfo.mtime)), finfo.mtime)); send_smb(Client,outbuf); @@ -1655,7 +1655,7 @@ int tar_parseargs(int argc, char *argv[], 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,GMT_TO_LOCAL)))); + asctime(LocalTime(&newer_than)))); Optind++; } else { DEBUG(0,("Error setting newer-than time\n")); -- cgit From a2c1623827406667a4f2f058c24f1d971f6627f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 1996 06:42:03 +0000 Subject: a huge pile of changes :-) The biggest thing is the integration of Lukes new nmbd. Its still largely untested, so we will really need some feedback I've also added auto prototype generation and cleaned up a lot of minor things as a result (This used to be commit 0d8dcfa13c527ec2c8aca39ba49c09e4e694b26c) --- source3/client/clitar.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0701aac1cf..2de09c66c1 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -23,12 +23,6 @@ #include "includes.h" #include "clitar.h" -extern void setup_pkt(char *outbuf); -extern BOOL reopen_connection(char *inbuf,char *outbuf); -extern void do_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (*fn)(),BOOL recurse_dir); - -int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind); - extern BOOL recurse; #define SEPARATORS " \t\n\r" -- cgit From 7e3b4a1c0df1434eb3d02f93c736ce065f9898d8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jun 1996 04:38:24 +0000 Subject: got rid of a lot of redundent header files as we now globally generate prototypes automatically using "make proto". This is much less prone to error than the old method of manually adding prototypes (This used to be commit b551dc98f7cc194a5fc2e67a4ebae7fd67a01bbc) --- source3/client/clitar.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 2de09c66c1..a4c1f00adf 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -75,10 +75,7 @@ static void dozerobuf(); static void dotareof(); static void initarbuf(); static int do_setrattr(); -void cmd_tar(); -int process_tar(); -char **toktocliplist(); -int clipfind(); + /* restore functions */ static long readtarheader(); static long unoct(); @@ -1486,7 +1483,7 @@ void cmd_setmode(void) return; } -DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); + DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); (void) do_setrattr(fname, attra[ATTRSET], ATTRSET); (void) do_setrattr(fname, attra[ATTRRESET], ATTRRESET); } -- cgit From 5a2f52b79e28530c454cb488a44588147640f061 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Oct 1996 14:09:22 +0000 Subject: - a huge pile of changes from Luke which implement the browse.conf stuff and also fix a pile of nmbd bugs. Unfortunately I found it very hard to disentangle the new features from the bug fixes so I am putting in the new code. I hope this is the last big pile of changes to the 1.9.16 series! (This used to be commit 20b6203dac4bbb43e4e7bea0b214496d76d679d9) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index a4c1f00adf..13df5fef9a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -374,7 +374,7 @@ static long unoct(char *p, int ndgs) /**************************************************************************** Compare two strings in a slash insensitive way ***************************************************************************/ -int strslashcmp(const char *s1, const char *s2) +int strslashcmp(char *s1,char *s2) { while(*s1 && *s2 && (*s1 == *s2 -- cgit From 38087ccb4071bfff29801026e2bf5c47565305b4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Oct 1996 02:54:37 +0000 Subject: - use workgroup from smb.conf in smbclient - change debug level on clitar stuff - define MAP_FILE if not defined - ensure we never set authoritative on queries in nmbd - fake a positive response to SMBioctl, apparently this is needed for some WfWg printer drivers - deny file access for non-fcbopen queries when (access_allowed == AREAD && flags == O_RDWR) - add sys_waitpid() (This used to be commit 61e3116e573637d6b5a878eeb8db72831e3c5bd1) --- source3/client/clitar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 13df5fef9a..191e0e4dab 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -823,7 +823,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen = 0; } - DEBUG(2,("getting file %s of size %d bytes as a tar file %s", + DEBUG(1,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, lname)); @@ -1079,7 +1079,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_size += finfo.size; /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(2,("(%g kb/s) (average %g kb/s)\n", + DEBUG(1,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); } @@ -1406,7 +1406,7 @@ void cmd_block(void) } blocksize=block; - DEBUG(2,("blocksize is now %d\n", blocksize)); + DEBUG(1,("blocksize is now %d\n", blocksize)); } /**************************************************************************** @@ -1483,7 +1483,7 @@ void cmd_setmode(void) return; } - DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); + DEBUG(1, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); (void) do_setrattr(fname, attra[ATTRSET], ATTRSET); (void) do_setrattr(fname, attra[ATTRRESET], ATTRRESET); } -- cgit From 8bc7d6bebd4fcf8c95cb6d58da14404a5e46de91 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 9 Jan 1997 18:02:17 +0000 Subject: Makefile: Changes to split Solaris into Solaris2.3 and previous, and 2.4 and after from Paul Eggert. Makefile: Added AMIGA changes from Rask Ingemann Lambertsen . charset.c: Patch for Western European Languages from Josef Hinteregger charset.h: Patch for Western European Languages from Josef Hinteregger clitar.c: Patch to re-sync after read fail from (lost contributor name, sorry). includes.h: Patch for AMIGA from Rask Ingemann Lambertsen includes.h: Patch for SunOS atexit by Jeremy (jra@cygnus.com) interface.c: Patch for AMIGA from Rask Ingemann Lambertsen kanji.h: Patch for Western European Languages from Josef Hinteregger locking.c: Patch to fix file locking from Jeremy (jra@cygnus.com) locking.c: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) pipes.c: Patch to fix file locking from Jeremy (jra@cygnus.com) proto.h: Patch to fix file locking from Jeremy (jra@cygnus.com) reply.c: Patch to fix file locking from Jeremy (jra@cygnus.com) server.c: Patch to fix file locking from Jeremy (jra@cygnus.com) server.c: Patch for FAST_SHARE_MODE fix from (lost contributor name, sorry). smb.h: Patch to fix file locking from Jeremy (jra@cygnus.com) smb.h: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) status.c: Patch to fix file locking from Jeremy (jra@cygnus.com) statuc.c: Patch to add granularity of lock files to usec by Jeremy (jra@cygnus.com) system.c: Patch for Western European Languages from Josef Hinteregger trans2.c: Patch to fix file locking from Jeremy (jra@cygnus.com) trans2.c: Patch to fix volume name reported to Win95 from Jeremy (jra@cygnus.com) util.c: Patch for Western European Languages from Josef Hinteregger util.c: Patch to fix client_name from continuously returning UNKNOWN (from various contributors). version.h: Update to 1.9.16p10. (This used to be commit 03d28fa32eb094affa33133ebe2602fdb70f6361) --- source3/client/clitar.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 191e0e4dab..cd819ad21f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -702,6 +702,22 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) return True; } +int padit(char *buf, int bufsize, int padsize) +{ + int berr= 0; + int bytestowrite; + + DEBUG(0, ("Padding with %d zeros\n", padsize)); + memset(buf, 0, bufsize); + while( !berr && padsize > 0 ) { + bytestowrite= MIN(bufsize, padsize); + berr = dotarbuf(tarhandle, buf, bytestowrite) != bytestowrite; + padsize -= bytestowrite; + } + + return berr; +} + /* * smbclient functions */ @@ -1033,7 +1049,15 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) dataptr=NULL; datalen=0; } - + + /* pad tar file with zero's if we couldn't get entire file */ + if (nread < finfo.size) + { + DEBUG(0, ("Didn't get entire file. size=%d, nread=%d\n", finfo.size, nread)); + if (padit(inbuf, BUFFER_SIZE, finfo.size - nread)) + DEBUG(0,("Error writing local file\n")); + } + /* round tar file to nearest block */ if (finfo.size % TBLOCK) dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); @@ -1681,17 +1705,15 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) return 0; } + tar_excl=tar_clipfl!='X'; + if (Optind+1=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); } else { - tar_excl=tar_clipfl!='X'; - - if (Optind+1 Date: Tue, 8 Jul 1997 16:54:44 +0000 Subject: Makefile: Added AIX targets from Ole Holm Nielsen chgpasswd.c: Added Samba/GPL notice (for obvious reasons). clitar.c: Updated Copyright date to include 1997 (for obvious reasons). getsmbpass.c: Updated Copyright date to include 1997 (for obvious reasons). includes.h: Added stropts for solaris. loadparm.c: Changed comment for hide files option. nameconf.c: Updated Copyright date to include 1997 (for obvious reasons). nmbd.c: Updated Copyright date to include 1997 (for obvious reasons). pcap.c: Updated Copyright date to include 1997 (for obvious reasons). proto.h: Re-added accidentaly deleted smb_shm_ calls. quotas.c: Added AIX quota patch from Ole Holm Nielsen server.c: Optimization on calling is_hidden_path. Updated Copyrights. smb.h: Changed DEFAULT_FILES_TO_HIDE from "*/.*" to ".*". smbpass.c: Updated Copyright date to include 1997 (for obvious reasons). ufc.c: Updated Copyright date to include 1997 (for obvious reasons). util.c: Added last component code to is_in_path(). Jeremy (jallison@whistle.com) (This used to be commit 9385ae1005f13c8ed51f1319e3949b5c8571e62d) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index cd819ad21f..5afff63de4 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. Tar Extensions - Copyright (C) Ricky Poulten 1995 + Copyright (C) Ricky Poulten 1995-1997 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From 816897d4a2a92e815b4df9a9427b9649a83f841b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 24 Jul 1997 20:04:16 +0000 Subject: patch by glenn burkhardt to allow recursive excluding of directories. glenn@aoi.ultranet.com lkcl (This used to be commit 4aac8449ae1f4e9d214071e8b254ce8b391496a4) --- source3/client/clitar.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 5afff63de4..951947ecb2 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -372,10 +372,15 @@ static long unoct(char *p, int ndgs) } /**************************************************************************** -Compare two strings in a slash insensitive way +Compare two strings in a slash insensitive way, allowing s1 to match s2 +if s1 is an "initial" string (up to directory marker). Thus, if s2 is +a file in any subdirectory of s1, declare a match. ***************************************************************************/ -int strslashcmp(char *s1,char *s2) +static +int strslashcmp(char *s1, char *s2) { + char *s1_0=s1; + while(*s1 && *s2 && (*s1 == *s2 || tolower(*s1) == tolower(*s2) @@ -384,6 +389,17 @@ int strslashcmp(char *s1,char *s2) s1++; s2++; } + /* if s1 has a trailing slash, it compared equal, so s1 is an "initial" + string of s2. + */ + if (!*s1 && s1 != s1_0 && (*(s1-1) == '/' || *(s1-1) == '\\')) return 0; + + /* ignore trailing slash on s1 */ + if (!*s2 && (*s1 == '/' || *s1 == '\\') && !*(s1+1)) return 0; + + /* check for s1 is an "initial" string of s2 */ + if (*s2 == '/' || *s2 == '\\') return 0; + return *s1-*s2; } @@ -1128,11 +1144,6 @@ static void do_tar(file_info *finfo) strcpy(exclaim, cur_dir); *(exclaim+strlen(exclaim)-1)='\0'; - if (clipfind(cliplist, clipn, exclaim)) { - DEBUG(3,("Skipping directory %s\n", exclaim)); - return; - } - strcat(exclaim, "\\"); strcat(exclaim, finfo->name); -- cgit From 7314126d9e1d84997d818166f27e2076d55ff04e Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Mon, 28 Jul 1997 18:59:57 +0000 Subject: client.c: Added amanda fixes. clitar.c: Added amanda fixes. nameannounce.c: Removed redundent code. nameelect.c: Removed redundent code. nameserv.h: Removed redundent code. nameservresp.c: Removed redundent code. namework.c: Removed redundent code. password.c: Prevented crash if getpwnam fails. Jeremy (jallison@whistle.com) (This used to be commit 760fe30353de66e8e6571f8ff4ec1064261b5428) --- source3/client/clitar.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 951947ecb2..f70e639e90 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -41,7 +41,7 @@ static int attribute = aDIR | aSYSTEM | aHIDDEN; #endif static char *tarbuf; -static int tp, ntarf, tbufsiz; +static int tp, ntarf, tbufsiz, ttarf; /* Incremental mode */ BOOL tar_inc=False; /* Reset archive bit */ @@ -271,8 +271,8 @@ static void initarbuf() tbufsiz=blocksize*TBLOCK; tarbuf=malloc(tbufsiz); - /* reset tar buffer pointer and tar file counter */ - tp=0; ntarf=0; + /* reset tar buffer pointer and tar file counter and total dumped */ + tp=0; ntarf=0; ttarf=0; } /**************************************************************************** @@ -1078,6 +1078,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) if (finfo.size % TBLOCK) dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); + ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); ntarf++; } @@ -1606,6 +1607,7 @@ int process_tar(char *inbuf, char *outbuf) free(tarbuf); DEBUG(0, ("tar: dumped %d tar files\n", ntarf)); + DEBUG(0, ("Total bytes written: %d\n", ttarf)); break; } -- cgit From 7971fb1febc67a845cde6bbb9b92842aa0a283ce Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 27 Aug 1997 20:20:58 +0000 Subject: charset.c: Added patch for client code page 852 (Eastern European) from Leos Bitto . clitar.c: proto.h: Fixed proto mismatch for strslashcmp(). Jermey (jallison@netcom.com) (This used to be commit c7a4647b7a84641f5fed6b67d45c241fff19c2b3) --- source3/client/clitar.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f70e639e90..d5bca8c5bb 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -376,8 +376,7 @@ Compare two strings in a slash insensitive way, allowing s1 to match s2 if s1 is an "initial" string (up to directory marker). Thus, if s2 is a file in any subdirectory of s1, declare a match. ***************************************************************************/ -static -int strslashcmp(char *s1, char *s2) +static int strslashcmp(char *s1, char *s2) { char *s1_0=s1; -- cgit From 30416c0b8a0f54f6cc1179c2e00860eaf5f58401 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Sep 1997 20:17:32 +0000 Subject: charcnv.c client.c clitar.c kanji.c kanji.h loadparm.c mangle.c smb.h util.c: Big merge to allow KANJI support to be in the main binary without explicitly compiling with it. locking.c: Fix for smbstatus not being able to read files. namepacket.c: Removed unneccesary debug statement. trans2.c: Added Luke's proposed fix (ifdefed out until further testing). nmblookup.c: Fixed bug where query fails and status is done on bogus IP. Jeremy (jallison@whistle.com) (This used to be commit 9196255022ae8c51b527412747b324819bea2c13) --- source3/client/clitar.c | 88 +++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 36 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index d5bca8c5bb..a30f6c2960 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -306,27 +306,35 @@ static void fixtarname(char *tptr, char *fp, int l) * to lovely unix /'s :-} */ *tptr++='.'; -#ifdef KANJI - while (l > 0) { - if (is_shift_jis (*fp)) { - *tptr++ = *fp++; - *tptr++ = *fp++; - l -= 2; - } else if (is_kana (*fp)) { - *tptr++ = *fp++; - l--; - } else if (*fp == '\\') { - *tptr++ = '/'; + if(lp_client_code_page() == KANJI_CODEPAGE) + { + while (l > 0) { + if (is_shift_jis (*fp)) { + *tptr++ = *fp++; + *tptr++ = *fp++; + l -= 2; + } else if (is_kana (*fp)) { + *tptr++ = *fp++; + l--; + } else if (*fp == '\\') { + *tptr++ = '/'; + fp++; + l--; + } else { + *tptr++ = *fp++; + l--; + } + } + } + else + { + while (l--) + { + *tptr=(*fp == '\\') ? '/' : *fp; + tptr++; fp++; - l--; - } else { - *tptr++ = *fp++; - l--; } } -#else - while (l--) { *tptr=(*fp == '\\') ? '/' : *fp; tptr++; fp++; } -#endif } /**************************************************************************** @@ -1203,27 +1211,35 @@ static void unfixtarname(char *tptr, char *fp, int l) if (*fp == '.') fp++; if (*fp == '\\' || *fp == '/') fp++; -#ifdef KANJI - while (l > 0) { - if (is_shift_jis (*fp)) { - *tptr++ = *fp++; - *tptr++ = *fp++; - l -= 2; - } else if (is_kana (*fp)) { - *tptr++ = *fp++; - l--; - } else if (*fp == '/') { - *tptr++ = '\\'; + if(lp_client_code_page() == KANJI_CODEPAGE) + { + while (l > 0) { + if (is_shift_jis (*fp)) { + *tptr++ = *fp++; + *tptr++ = *fp++; + l -= 2; + } else if (is_kana (*fp)) { + *tptr++ = *fp++; + l--; + } else if (*fp == '/') { + *tptr++ = '\\'; + fp++; + l--; + } else { + *tptr++ = *fp++; + l--; + } + } + } + else + { + while (l--) + { + *tptr=(*fp == '/') ? '\\' : *fp; + tptr++; fp++; - l--; - } else { - *tptr++ = *fp++; - l--; } } -#else - while (l--) { *tptr=(*fp == '/') ? '\\' : *fp; tptr++; fp++; } -#endif } static void do_tarput() -- cgit From 102fb715376349d47491fc56f823188b036bc2f3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 18 Sep 1997 06:52:49 +0000 Subject: John asked the other day about using the tar feature in smbclient to handle file paths longer than 100 characters (the limit of the normal tar format). This patch adds support for producing GNU tar files (which have no real limit on the path length) in smbclient. Note that I have only added support for producing GNU tar files, I haven't added support for accepting them when restoring. I thought I'd leave that up to John :-) (This used to be commit d5daf85162e844c9e953cc4dfbb3f1d800747130) --- source3/client/clitar.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index a30f6c2960..344263967f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -90,7 +90,7 @@ static void unfixtarname(); Write a tar header to buffer ****************************************************************************/ static void writetarheader(int f, char *aname, int size, time_t mtime, - char *amode) + char *amode) { union hblock hb; int i, chk, l; @@ -99,10 +99,21 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(hb.dummy, 0, sizeof(hb.dummy)); l=strlen(aname); - if (l >= NAMSIZ) - { - DEBUG(0, ("tar file %s name length exceeds NAMSIZ\n", aname)); - } + if (l >= NAMSIZ) { + /* write a GNU tar style long header */ + char *b; + b = (char *)malloc(l+TBLOCK+100); + if (!b) { + DEBUG(0,("out of memory\n")); + exit(1); + } + writetarheader(f, "/./@LongLink", l+1, 0, " 0 \0"); + memset(b, 0, l+TBLOCK+100); + fixtarname(b, aname, l+1); + i = strlen(b)+1; + dotarbuf(f, b, TBLOCK*((i+(TBLOCK-1)/TBLOCK))); + free(b); + } /* use l + 1 to do the null too */ fixtarname(hb.dbuf.name, aname, (l >= NAMSIZ) ? NAMSIZ : l + 1); @@ -119,8 +130,13 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, oct_it((long) size, 13, hb.dbuf.size); oct_it((long) mtime, 13, hb.dbuf.mtime); memcpy(hb.dbuf.chksum, " ", sizeof(hb.dbuf.chksum)); - hb.dbuf.linkflag='0'; memset(hb.dbuf.linkname, 0, NAMSIZ); + if (strcmp("/./@LongLink", aname) == 0) { + /* we're doing a GNU tar long filename */ + hb.dbuf.linkflag='L'; + } else { + hb.dbuf.linkflag='0'; + } for (chk=0, i=sizeof(hb.dummy), jp=hb.dummy; --i>=0;) chk+=(0xFF & *jp++); -- cgit From 5a7b3294dbbe88f0d5da25a74b8112fc6c70af1f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 26 Sep 1997 09:06:51 +0000 Subject: add error string reporting to clitar (This used to be commit 2c5587a6fe425b1cc57cf28e92e77ba84f08ce33) --- source3/client/clitar.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 344263967f..c085cd9e5a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1074,7 +1074,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) * write out in 512 byte intervals */ if (dotarbuf(tarhandle,dataptr,datalen) != datalen) { - DEBUG(0,("Error writing local file\n")); + DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); break; } @@ -1094,7 +1094,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) { DEBUG(0, ("Didn't get entire file. size=%d, nread=%d\n", finfo.size, nread)); if (padit(inbuf, BUFFER_SIZE, finfo.size - nread)) - DEBUG(0,("Error writing local file\n")); + DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); } /* round tar file to nearest block */ @@ -1761,7 +1761,8 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) if ((tar_type=='x' && (tarhandle = open(argv[Optind], O_RDONLY)) == -1) || (tar_type=='c' && (tarhandle=creat(argv[Optind], 0644)) < 0)) { - DEBUG(0,("Error opening local file %s\n",argv[Optind])); + DEBUG(0,("Error opening local file %s - %s\n", + argv[Optind], strerror(errno))); return(0); } } -- cgit From 5897f0493d0665ae53ea181e122c467faa0c7642 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 22 Oct 1997 14:28:19 +0000 Subject: Makefile client.c clientutil.c clitar.c nmbsync.c : redid the split that i did a year ago, taking the functions in client.c out into clientutil.c. guess what? we could now do encrypted password NetServerEnum2 calls in nmbd, if we wanted to. i can now use cli_call_api() to send to different pipes. i hope. pipenetlog.c: allow adding to users group _and_ to admin group. if adding to guest group, don't allow adding to users or admin as well. smb.h : added some pipe #defines (\PIPE\NETLOGON \PIPE\srvsvc ...) proto.h : usual. (This used to be commit 6ee065ce6e099acfc7e83ad399ef6e60b4c625c1) --- source3/client/clitar.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c085cd9e5a..1e7c45691b 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -461,7 +461,7 @@ static int do_setrattr(char *fname, int attr, int setit) set_message(outbuf,0,2 + strlen(fname),True); CVAL(outbuf,smb_com) = SMBgetatr; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); p = smb_buf(outbuf); *p++ = 4; @@ -497,7 +497,7 @@ static int do_setrattr(char *fname, int attr, int setit) set_message(outbuf,8,4 + strlen(fname),True); CVAL(outbuf,smb_com) = SMBsetatr; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,attr); @@ -537,7 +537,7 @@ static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) set_message(outbuf,3,2 + strlen(finfo.name),True); CVAL(outbuf,smb_com) = SMBcreate; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,finfo.mode); put_dos_date3(outbuf,smb_vwv1,finfo.mtime); @@ -576,7 +576,7 @@ static BOOL smbwrite(int fnum, int n, int low, int high, int left, set_message(outbuf,5,n + 3, False); CVAL(outbuf,smb_com) = SMBwrite; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,fnum); SSVAL(outbuf,smb_vwv1,n); @@ -615,7 +615,7 @@ static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) set_message(outbuf,3,0,True); CVAL(outbuf,smb_com) = SMBclose; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,fnum); put_dos_date3(outbuf,smb_vwv1,finfo.mtime); @@ -648,7 +648,7 @@ static BOOL smbchkpath(char *fname, char *inbuf, char *outbuf) set_message(outbuf,0,4 + strlen(fname),True); CVAL(outbuf,smb_com) = SMBchkpth; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); p = smb_buf(outbuf); *p++ = 4; @@ -675,7 +675,7 @@ static BOOL smbmkdir(char *fname, char *inbuf, char *outbuf) CVAL(outbuf,smb_com) = SMBmkdir; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); p = smb_buf(outbuf); *p++ = 4; @@ -798,7 +798,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) CVAL(outbuf,smb_com) = SMBopenX; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,0xFF); SSVAL(outbuf,smb_vwv2,1); @@ -834,7 +834,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) { if (CVAL(inbuf,smb_rcls) == ERRSRV && SVAL(inbuf,smb_err) == ERRnoresource && - reopen_connection(inbuf,outbuf)) + cli_reopen_connection(inbuf,outbuf)) { do_atar(rname,lname,finfo1); free(inbuf);free(outbuf); @@ -930,7 +930,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) set_message(outbuf,10,0,True); CVAL(outbuf,smb_com) = SMBreadX; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); if (close_done) { @@ -996,7 +996,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) set_message(outbuf,8,0,True); CVAL(outbuf,smb_com) = SMBreadbraw; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,fnum); SIVAL(outbuf,smb_vwv1,nread); SSVAL(outbuf,smb_vwv3,MIN(finfo.size-nread,readbraw_size)); @@ -1048,7 +1048,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) set_message(outbuf,5,0,True); CVAL(outbuf,smb_com) = SMBread; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,fnum); SSVAL(outbuf,smb_vwv1,MIN(max_xmit-200,finfo.size - nread)); @@ -1111,7 +1111,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) set_message(outbuf,3,0,True); CVAL(outbuf,smb_com) = SMBclose; SSVAL(outbuf,smb_tid,cnum); - setup_pkt(outbuf); + cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,fnum); SIVALS(outbuf,smb_vwv1,-1); -- cgit From be71d43585cf4b42efff7995dbf061fddd6077f5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 20 Dec 1997 14:36:11 +0000 Subject: client.c: clientgen.c: clientutil.c: clitar.c: Changed usage of receive_smb to new function client_receive_smb except for one use of receive_smb in client.c. This is the receive_smb used to discard packets received whilst in a keyboard wait state. util.c: Created new function client_receive_smb that ignores session keepalives just as the old receive_smb used to do. Created internal function read_smb_length_return_keepalive that is used internally by the changed receive_smb call. Changed read_smb_len to not use an internal buffer - it is never called with a null buffer so such code is redundant. Jeremy. (This used to be commit 1084fb46821cb96702da35439da4a8df9d255698) --- source3/client/clitar.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 1e7c45691b..05cb13656a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -472,7 +472,7 @@ static int do_setrattr(char *fname, int attr, int setit) *p++ = 0; send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) DEBUG(5,("getatr: %s\n",smb_errstr(inbuf))); @@ -510,7 +510,7 @@ static int do_setrattr(char *fname, int attr, int setit) *p++ = 0; send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -547,7 +547,7 @@ static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) strcpy(p,finfo.name); send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -586,7 +586,7 @@ static BOOL smbwrite(int fnum, int n, int low, int high, int left, SSVAL(smb_buf(outbuf),1,n); send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -625,7 +625,7 @@ static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) finfo.mtime)); send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -655,7 +655,7 @@ static BOOL smbchkpath(char *fname, char *inbuf, char *outbuf) strcpy(p,fname); send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); DEBUG(5,("smbchkpath: %s\n",smb_errstr(inbuf))); @@ -682,7 +682,7 @@ static BOOL smbmkdir(char *fname, char *inbuf, char *outbuf) strcpy(p,fname); send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -828,7 +828,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) } send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -962,7 +962,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) } send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -1056,7 +1056,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) SSVAL(outbuf,smb_vwv4,finfo.size - nread); send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (CVAL(inbuf,smb_rcls) != 0) { @@ -1117,7 +1117,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) SIVALS(outbuf,smb_vwv1,-1); send_smb(Client,outbuf); - receive_smb(Client,inbuf,CLIENT_TIMEOUT); + client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (!ignore_close_error && CVAL(inbuf,smb_rcls) != 0) { -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 05cb13656a..6763d221ce 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. Tar Extensions - Copyright (C) Ricky Poulten 1995-1997 + Copyright (C) Ricky Poulten 1995-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From a093e73d946922b32d1d17c1f21b803637b362a7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Feb 1998 12:40:23 +0000 Subject: Fix for crash bug with amanda - from "Michael C. Povel" . Jeremy. (This used to be commit 735adfa01b7b2e540bb5476a77d6b689ca70852a) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 6763d221ce..6a811f41c7 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -111,7 +111,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l+1); i = strlen(b)+1; - dotarbuf(f, b, TBLOCK*((i+(TBLOCK-1)/TBLOCK))); + dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); free(b); } -- cgit From b7fb6c6b38784d25c9c85e9b27b08e30111dbd0c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Mar 1998 20:19:14 +0000 Subject: Change the multibyte character set support so that Kanji support is one case of multibyte character support, rather than being a specific case in single byte character support. This allows us to add Big5 Chinese support (code page 950) and Korean Hangul support (code page 949) at very little cost. Also allows us to easily add future multibyte code pages. Makefile: Added codepages 949, 950 as we now support more multibyte codepages. asyncdns.c: Fixed problem with child being re-spawned when parent killed. charcnv.c charset.c client.c clitar.c kanji.c kanji.h smb.h util.c loadparm.c: Generic multibyte codepage support (adding Big5 Chinese and Korean Hangul). nmbd.c: Fixed problem with child being re-spawned when parent killed. mangle.c: Modified str_checksum so that first 15 characters have more effect on outcome. This helps with short name mangling as most 'long' names are still shorter than 15 chars (bug was foobar_mng and foobar_sum would hash to the same value, with the modified code they hash differently. Jeremy. (This used to be commit 299016338cfb47f0c585875ef9b468121fcee97d) --- source3/client/clitar.c | 63 ++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 6a811f41c7..ccaab486d0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -322,33 +322,25 @@ static void fixtarname(char *tptr, char *fp, int l) * to lovely unix /'s :-} */ *tptr++='.'; - if(lp_client_code_page() == KANJI_CODEPAGE) - { - while (l > 0) { - if (is_shift_jis (*fp)) { + + while (l > 0) { + int skip; + if((skip = skip_multibyte_char( *fp)) != 0) { + if (skip == 2) { *tptr++ = *fp++; *tptr++ = *fp++; l -= 2; - } else if (is_kana (*fp)) { - *tptr++ = *fp++; - l--; - } else if (*fp == '\\') { - *tptr++ = '/'; - fp++; - l--; - } else { + } else if (skip == 1) { *tptr++ = *fp++; l--; } - } - } - else - { - while (l--) - { - *tptr=(*fp == '\\') ? '/' : *fp; - tptr++; + } else if (*fp == '\\') { + *tptr++ = '/'; fp++; + l--; + } else { + *tptr++ = *fp++; + l--; } } } @@ -1227,33 +1219,24 @@ static void unfixtarname(char *tptr, char *fp, int l) if (*fp == '.') fp++; if (*fp == '\\' || *fp == '/') fp++; - if(lp_client_code_page() == KANJI_CODEPAGE) - { - while (l > 0) { - if (is_shift_jis (*fp)) { + while (l > 0) { + int skip; + if(( skip = skip_multibyte_char( *fp )) != 0) { + if (skip == 2) { *tptr++ = *fp++; *tptr++ = *fp++; l -= 2; - } else if (is_kana (*fp)) { - *tptr++ = *fp++; - l--; - } else if (*fp == '/') { - *tptr++ = '\\'; - fp++; - l--; - } else { + } else if (skip == 1) { *tptr++ = *fp++; l--; } - } - } - else - { - while (l--) - { - *tptr=(*fp == '/') ? '\\' : *fp; - tptr++; + } else if (*fp == '/') { + *tptr++ = '\\'; fp++; + l--; + } else { + *tptr++ = *fp++; + l--; } } } -- cgit From 612cbb6a6039c2cafb3de5e644f23a2a26d6c645 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Apr 1998 01:01:24 +0000 Subject: Patch from Chris Maltby . His comments follow: + improvement to smbtar to allow exclusion/inclusion of system and hidden files, and to generate a listing of what has been archived in a format useful for automated backup systems. + add the "Softq" spooling system to samba's printing capabilities. + I have "fixed" the intrusion of US style dates into samba reporting as well. The format yyyy/mm/dd is not only uunambiguous, but also has the benefit of making lexicographic sorts work correctly. Jeremy. (This used to be commit f9dacd1d8b89fccad859c0c6bc7a492823eb4b06) --- source3/client/clitar.c | 52 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index ccaab486d0..36cefeec55 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -48,6 +48,13 @@ BOOL tar_inc=False; BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ BOOL tar_excl=True; +/* Dump files with System attribute */ +BOOL tar_system=False; +/* Dump files with Hidden attribute */ +BOOL tar_hidden=True; +/* Be noisy - make a catalogue */ +BOOL tar_noisy=True; + char tar_type='\0'; static char **cliplist=NULL; static int clipn=0; @@ -856,6 +863,16 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name)); shallitime=0; } + else if (!tar_system && (finfo.mode & aSYSTEM)) + { + DEBUG(4, ("skipping %s - system bit is set\n", finfo.name)); + shallitime=0; + } + else if (!tar_hidden && (finfo.mode & aHIDDEN)) + { + DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name)); + shallitime=0; + } else { if (SVAL(inbuf,smb_vwv0) == SMBreadX) @@ -870,7 +887,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen = 0; } - DEBUG(1,("getting file %s of size %d bytes as a tar file %s", + DEBUG(2,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, lname)); @@ -1135,9 +1152,16 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_size += finfo.size; /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(1,("(%g kb/s) (average %g kb/s)\n", + DEBUG(2,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); + if (tar_noisy) + { + printf("%10d (%7.1f kb/s) %s\n", + finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), + finfo.name); + } + } free(inbuf);free(outbuf); @@ -1456,7 +1480,7 @@ void cmd_block(void) } blocksize=block; - DEBUG(1,("blocksize is now %d\n", blocksize)); + DEBUG(2,("blocksize is now %d\n", blocksize)); } /**************************************************************************** @@ -1475,12 +1499,28 @@ void cmd_tarmode(void) tar_reset=True; else if (strequal(buf, "noreset")) tar_reset=False; + else if (strequal(buf, "system")) + tar_system=True; + else if (strequal(buf, "nosystem")) + tar_system=False; + else if (strequal(buf, "hidden")) + tar_hidden=True; + else if (strequal(buf, "nohidden")) + tar_hidden=False; + else if (strequal(buf, "verbose") || strequal(buf, "noquiet")) + tar_noisy=True; + else if (strequal(buf, "quiet") || strequal(buf, "noverbose")) + tar_noisy=False; else DEBUG(0, ("tarmode: unrecognised option %s\n", buf)); } - DEBUG(0, ("tarmode is now %s, %s\n", + DEBUG(0, ("tarmode is now %s, %s, %s, %s, %s\n", tar_inc ? "incremental" : "full", - tar_reset ? "reset" : "noreset")); + tar_system ? "system" : "nosystem", + tar_hidden ? "hidden" : "nohidden", + tar_reset ? "reset" : "noreset", + tar_noisy ? "verbose" : "quiet")); + } /**************************************************************************** @@ -1533,7 +1573,7 @@ void cmd_setmode(void) return; } - DEBUG(1, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); + DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); (void) do_setrattr(fname, attra[ATTRSET], ATTRSET); (void) do_setrattr(fname, attra[ATTRRESET], ATTRRESET); } -- cgit From e0c21df69ad2558a96a24567a89594d9ed7ee6ed Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 11 Apr 1998 07:52:13 +0000 Subject: Changes to client.c support the need for directories to be processed by whatever action is passed to do_dir. Changes to clitar.c as requested by Canon Information Systems Research Australia: 1. Support restoring long file names 2. Write directory entries to TAR files as first part of setting directory create times 3. Ensure zero length files get correct mtime 4. Allow DOS and UNIX pathnames in command line parameters. (This used to be commit 0c228f0b33950c8d38de0529e88a38848742a50d) --- source3/client/clitar.c | 326 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 274 insertions(+), 52 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 36cefeec55..130c5e7a27 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -18,10 +18,22 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* The following changes developed by Richard Sharpe for Canon Information + Systems Research Australia (CISRA) are Copyright (C) 1998 by CISRA and are + made available under the terms of the GPL as listed above: + + 1. Restore can now restore files with long file names + 2. Save now saves directory information so that we can restore + directory creation times + 3. tar now accepts both UNIX path names and DOS path names. I prefer + those lovely /'s to those UGLY \'s :-) + +*/ #include "includes.h" #include "clitar.h" +#include extern BOOL recurse; @@ -72,7 +84,8 @@ extern int Protocol; int blocksize=20; int tarhandle; -static void writetarheader(); +static void writetarheader(int f, char *aname, int size, time_t mtime, + char *amode, unsigned char ftype); static void do_atar(); static void do_tar(); static void oct_it(); @@ -97,12 +110,14 @@ static void unfixtarname(); Write a tar header to buffer ****************************************************************************/ static void writetarheader(int f, char *aname, int size, time_t mtime, - char *amode) + char *amode, unsigned char ftype) { union hblock hb; int i, chk, l; char *jp; + DEBUG(5, ("WriteTarHdr, Type = %c, Name = %s\n", ftype, aname)); + memset(hb.dummy, 0, sizeof(hb.dummy)); l=strlen(aname); @@ -114,7 +129,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, DEBUG(0,("out of memory\n")); exit(1); } - writetarheader(f, "/./@LongLink", l+1, 0, " 0 \0"); + writetarheader(f, "/./@LongLink", l+1, 0, " 0 \0", 'L'); memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l+1); i = strlen(b)+1; @@ -138,12 +153,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, oct_it((long) mtime, 13, hb.dbuf.mtime); memcpy(hb.dbuf.chksum, " ", sizeof(hb.dbuf.chksum)); memset(hb.dbuf.linkname, 0, NAMSIZ); - if (strcmp("/./@LongLink", aname) == 0) { - /* we're doing a GNU tar long filename */ - hb.dbuf.linkflag='L'; - } else { - hb.dbuf.linkflag='0'; - } + hb.dbuf.linkflag=ftype; for (chk=0, i=sizeof(hb.dummy), jp=hb.dummy; --i>=0;) chk+=(0xFF & *jp++); @@ -196,14 +206,21 @@ static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) unfixtarname(finfo->name + strlen(prefix), hb->dbuf.name, strlen(hb->dbuf.name) + 1); -/* can't handle links at present */ - if (hb->dbuf.linkflag != '0') { +/* can't handle some links at present */ + if ((hb->dbuf.linkflag != '0') && (hb -> dbuf.linkflag != '5')) { if (hb->dbuf.linkflag == 0) { DEBUG(6, ("Warning: NULL link flag (gnu tar archive ?) %s\n", finfo->name)); } else { - DEBUG(0, ("this tar file appears to contain some kind of link - ignoring\n")); - return -2; + if (hb -> dbuf.linkflag == 'L') { /* We have a longlink */ + /* Do nothing here at the moment. do_tarput will handle this + as long as the longlink gets back to it, as it has to advance + the buffer pointer, etc */ + + } else { + DEBUG(0, ("this tar file appears to contain some kind of link other than a GNUtar Longlink - ignoring\n")); + return -2; + } } } @@ -264,7 +281,7 @@ static int dotarbuf(int f, char *b, int n) } /**************************************************************************** -Write a zeros to buffer / tape +Write zeros to buffer / tape ****************************************************************************/ static void dozerobuf(int f, int n) { @@ -275,6 +292,7 @@ static void dozerobuf(int f, int n) if (n+tp >= tbufsiz) { memset(tarbuf+tp, 0, tbufsiz-tp); + write(f, tarbuf, tbufsiz); memset(tarbuf, 0, (tp+=n-tbufsiz)); } @@ -292,7 +310,7 @@ static void initarbuf() { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; - tarbuf=malloc(tbufsiz); + tarbuf=malloc(tbufsiz); /* FIXME: We might not get the buffer */ /* reset tar buffer pointer and tar file counter and total dumped */ tp=0; ntarf=0; ttarf=0; @@ -428,6 +446,70 @@ static int strslashcmp(char *s1, char *s2) /* * general smb utility functions */ +/********************************************************************** +do_setrtime, set time on a file or dir ... +**********************************************************************/ + +static int do_setrtime(char *fname, int mtime) +{ + char *inbuf, *outbuf, *p; + char *name; + + name = (char *)malloc(strlen(fname) + 1 + 1); + if (name == NULL) { + + DEBUG(0, ("Failed to allocate space while setting time on file: %s", fname)); + return False; + + } + + strcpy(name, fname); + strcpy(fname, "\\"); + strcat(fname, name); + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) { + + DEBUG(0, ("Could not allocate memory for inbuf or outbuf while changing time on: %s\n", fname)); + return False; + + } + + memset(outbuf, 0, smb_size); + set_message(outbuf, 8, 4 + strlen(fname), True); + CVAL(outbuf, smb_com) = SMBsetatr; + SSVAL(outbuf, smb_tid, cnum); + cli_setup_pkt(outbuf); + + SSVAL(outbuf, smb_vwv0, 0); + put_dos_date3(outbuf, smb_vwv1, mtime); + + p = smb_buf(outbuf); + *p++ = 4; + strcpy(p, fname); + p+= (strlen(fname)+1); + + *p++ = 4; + *p++ = 0; + + send_smb(Client, outbuf); + client_receive_smb(Client, inbuf, CLIENT_TIMEOUT); + + if (CVAL(inbuf,smb_rcls) != 0) + { + DEBUG(0,("%s setting attributes on file %s\n", + smb_errstr(inbuf), fname)); + free(inbuf);free(outbuf); + return(False); + } + + free(inbuf);free(outbuf); + return(True); + +} + /**************************************************************************** Set DOS file attributes ***************************************************************************/ @@ -499,7 +581,7 @@ static int do_setrattr(char *fname, int attr, int setit) cli_setup_pkt(outbuf); SSVAL(outbuf,smb_vwv0,attr); - + p = smb_buf(outbuf); *p++ = 4; strcpy(p,fname); @@ -531,7 +613,7 @@ static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) char *p; /* *must* be called with buffer ready malloc'ed */ /* open remote file */ - + memset(outbuf,0,smb_size); set_message(outbuf,3,2 + strlen(finfo.name),True); CVAL(outbuf,smb_com) = SMBcreate; @@ -704,6 +786,8 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) pstring partpath, ffname; char *p=fname, *basehack; + DEBUG(5, ( "Ensurepath called with: %s\n", fname)); + *partpath = 0; /* fname copied to ffname so can strtok */ @@ -766,7 +850,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) { int fnum; uint32 nread=0; - char *p; + char *p, ftype; char *inbuf,*outbuf; file_info finfo; BOOL close_done = False; @@ -778,6 +862,8 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) struct timeval tp_start; GetTimeOfDay(&tp_start); + ftype = '0'; /* An ordinary file ... */ + if (finfo1) finfo = *finfo1; else @@ -893,7 +979,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) lname)); /* write a tar header, don't bother with mode - just set to 100644 */ - writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0"); + writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); while (nread < finfo.size && !close_done) { @@ -1174,7 +1260,7 @@ static void do_tar(file_info *finfo) { pstring rname; - if (strequal(finfo->name,".") || strequal(finfo->name,"..")) + if (strequal(finfo->name,"..")) return; /* Is it on the exclude list ? */ @@ -1213,14 +1299,16 @@ static void do_tar(file_info *finfo) strcat(cur_dir,finfo->name); strcat(cur_dir,"\\"); + DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); + /* write a tar directory, don't bother with mode - just set it to * 40755 */ - writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0"); + writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); + ntarf++; /* Make sure we have a file on there */ strcpy(mtar_mask,cur_dir); strcat(mtar_mask,"*"); - - do_dir((char *)inbuf,(char *)outbuf,mtar_mask,attribute,do_tar,recurse); - strcpy(cur_dir,saved_curdir); + /* do_dir((char *)inbuf,(char *)outbuf,mtar_mask,attribute,do_tar,recurse,True); */ + strcpy(cur_dir,saved_curdir); free(inbuf);free(outbuf); } else @@ -1265,11 +1353,25 @@ static void unfixtarname(char *tptr, char *fp, int l) } } +/**************************************************************************** +Move to the next block in the buffer, which may mean read in another set of +blocks. +****************************************************************************/ +int next_block(char *tarbuf, char *bufferp, int bufsiz) +{ + int bufread, total = 0; + + for (bufread = read(tarhandle, tarbuf, bufsiz); total += bufread; total < bufsiz) { + + } + +} + static void do_tarput() { file_info finfo; int nread=0, bufread; - char *inbuf,*outbuf; + char *inbuf,*outbuf, *longname = NULL; int fsize=0; int fnum; struct timeval tp_start; @@ -1332,26 +1434,93 @@ static void do_tarput() do { if (!fsize) { - switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) - { - case -2: /* something dodgy but not fatal about this */ - DEBUG(0, ("skipping %s...\n", finfo.name)); - bufferp+=TBLOCK; /* header - like a link */ - continue; - case -1: - DEBUG(0, ("abandoning restore\n")); - free(inbuf); free(outbuf); - return; - case 0: /* chksum is zero - we assume that one all zero - *header block will do for eof */ - DEBUG(0, - ("total of %d tar files restored to share\n", ntarf)); - free(inbuf); free(outbuf); - return; - default: - break; - } + int next_header = 1; /* Want at least one header */ + while (next_header) + { + if (bufferp >= endofbuffer) { + + bufread = read(tarhandle, tarbuf, tbufsiz); + bufferp = tarbuf; + + } + next_header = 0; /* Don't want the next one ... */ + switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) + { + case -2: /* something dodgy but not fatal about this */ + DEBUG(0, ("skipping %s...\n", finfo.name)); + bufferp+=TBLOCK; /* header - like a link */ + continue; + case -1: + DEBUG(0, ("abandoning restore, -1 from readtarheader\n")); + free(inbuf); free(outbuf); + return; + case 0: /* chksum is zero - we assume that one all zero + *header block will do for eof */ + DEBUG(0, + ("total of %d tar files restored to share\n", ntarf)); + free(inbuf); free(outbuf); + return; + default: + break; + } + + /* If we have a longname left from the last time through, + copy it into finfo.name and free it. + + The size of a pstring is the limiting factor on filenames + and directory names now. The total pathname length must be + less than sizeof(pstring) - 1, which is currently 1023. */ + + if (longname != NULL) { + + strncpy(finfo.name, longname, sizeof(pstring) - 1); + free(longname); + longname = NULL; + + } + + /* Check if a long-link. We do this before the clip checking + because clip-checking should clip on real name - RJS */ + + if (((union hblock *)bufferp) -> dbuf.linkflag == 'L') { + + /* Skip this header, but pick up length, get the name and + fix the name and skip the name. Hmmm, what about end of + buffer??? */ + + longname = malloc(finfo.size + strlen(cur_dir) + 1); + if (longname == NULL) { + + DEBUG(0, ("could not allocate buffer of size %d for longname\n", + finfo.size + strlen(cur_dir) + 1) + ); + free(inbuf); free(outbuf); + return; + } + + bufferp += TBLOCK; /* Skip that longlink header */ + /* This needs restructuring ... */ + + if (bufferp >= endofbuffer) { + + bufread = read(tarhandle, tarbuf, tbufsiz); + + bufferp = tarbuf; + + } + + strncpy(longname, cur_dir, strlen(cur_dir)); + unfixtarname(longname+strlen(cur_dir), bufferp, finfo.size); + + /* Next rounds up to next TBLOCK and takes care of us being right + on a TBLOCK boundary */ + + bufferp += (((finfo.size - 1)/TBLOCK)+1)*TBLOCK; + next_header = 1; /* Force read of next header */ + + } + } tskip=clipn && (clipfind(cliplist, clipn, finfo.name) ^ tar_excl); if (tskip) { @@ -1371,17 +1540,32 @@ static void do_tarput() } } + DEBUG(5, ("do_tarput: File is: %s\n", finfo.name)); + if (finfo.mode & aDIR) { - if (!smbchkpath(finfo.name, inbuf, outbuf) - && !smbmkdir(finfo.name, inbuf, outbuf)) + if (!ensurepath(finfo.name, inbuf, outbuf)) +/* if (!smbchkpath(finfo.name, inbuf, outbuf) + && !smbmkdir(finfo.name, inbuf, outbuf))*/ { - DEBUG(0, ("abandoning restore\n")); + DEBUG(0, ("abandoning restore, problems ensuring path\n")); free(inbuf); free(outbuf); return; } else { + /* Now we update the creation date ... */ + + DEBUG(5, ("Updating creation date on %s\n", finfo.name)); + + if (!do_setrtime(finfo.name, finfo.mtime)) { + + DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); + return; + + } + + ntarf++; bufferp+=TBLOCK; continue; } @@ -1397,9 +1581,17 @@ static void do_tarput() return; } - DEBUG(0,("restore tar file %s of size %d bytes\n", + DEBUG(0 ,("restore tar file %s of size %d bytes\n", finfo.name,finfo.size)); + if (!finfo.size) { + if (!smbshut(finfo, fnum, inbuf, outbuf)){ + DEBUG(0, ("Error closing remote file of length 0: %s\n", finfo.name)); + free(inbuf);free(outbuf); + return; + } + } + nread=0; if ((bufferp+=TBLOCK) >= endofbuffer) break; } /* if (!fsize) */ @@ -1430,7 +1622,7 @@ static void do_tarput() bufferp+=minichunk; nread+=minichunk; chunk-=minichunk; } - + if (nread>=fsize) { if (!smbshut(finfo, fnum, inbuf, outbuf)) @@ -1641,19 +1833,19 @@ int process_tar(char *inbuf, char *outbuf) strcpy(cur_dir, tarmac); *(strrchr(cur_dir, '\\')+1)='\0'; - do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse); + do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); strcpy(cur_dir,saved_dir); } else { strcpy(tarmac, cur_dir); strcat(tarmac, cliplist[i]); - do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse); + do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); } } } else { pstring mask; strcpy(mask,cur_dir); strcat(mask,"\\*"); - do_dir((char *)inbuf,(char *)outbuf,mask,attribute,do_tar,recurse); + do_dir((char *)inbuf,(char *)outbuf,mask,attribute,do_tar,recurse, True); } if (ntarf) dotareof(tarhandle); @@ -1774,8 +1966,38 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) tar_excl=tar_clipfl!='X'; if (Optind+1=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ -- cgit From cac6a060af598bf94e6414b06e7365ec51ca360e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Apr 1998 19:24:06 +0000 Subject: Changes to allow Samba to be compiled with -Wstrict-prototypes with gcc. (Not a big change although it looks like it :-). Jeremy. (This used to be commit cd2613c57261456485fe4eeecfda209ada70de8e) --- source3/client/clitar.c | 48 +++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 130c5e7a27..32731200b0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -86,21 +86,13 @@ int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); -static void do_atar(); -static void do_tar(); -static void oct_it(); -static void fixtarname(); -static int dotarbuf(); -static void dozerobuf(); -static void dotareof(); -static void initarbuf(); -static int do_setrattr(); - -/* restore functions */ -static long readtarheader(); -static long unoct(); -static void do_tarput(); -static void unfixtarname(); + +/* Forward references. */ +static void fixtarname(char *tptr, char *fp, int l); +static int dotarbuf(int f, char *b, int n); +static void oct_it (long value, int ndgs, char *p); +static long unoct(char *p, int ndgs); +static void unfixtarname(char *tptr, char *fp, int l); /* * tar specific utitlities @@ -306,7 +298,7 @@ static void dozerobuf(int f, int n) /**************************************************************************** Malloc tape buffer ****************************************************************************/ -static void initarbuf() +static void initarbuf(void) { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; @@ -373,7 +365,7 @@ static void fixtarname(char *tptr, char *fp, int l) /**************************************************************************** Convert from decimal to octal string ****************************************************************************/ -static void oct_it (register long value, register int ndgs, register char *p) +static void oct_it (long value, int ndgs, char *p) { /* Converts long to octal string, pads with leading zeros */ @@ -1353,21 +1345,7 @@ static void unfixtarname(char *tptr, char *fp, int l) } } -/**************************************************************************** -Move to the next block in the buffer, which may mean read in another set of -blocks. -****************************************************************************/ -int next_block(char *tarbuf, char *bufferp, int bufsiz) -{ - int bufread, total = 0; - - for (bufread = read(tarhandle, tarbuf, bufsiz); total += bufread; total < bufsiz) { - - } - -} - -static void do_tarput() +static void do_tarput(void) { file_info finfo; int nread=0, bufread; @@ -1653,7 +1631,7 @@ static void do_tarput() /**************************************************************************** Blocksize command ***************************************************************************/ -void cmd_block(void) +void cmd_block(char *dum_in, char *dum_out) { fstring buf; int block; @@ -1678,7 +1656,7 @@ void cmd_block(void) /**************************************************************************** command to set incremental / reset mode ***************************************************************************/ -void cmd_tarmode(void) +void cmd_tarmode(char *dum_in, char *dum_out) { fstring buf; @@ -1718,7 +1696,7 @@ void cmd_tarmode(void) /**************************************************************************** Feeble attrib command ***************************************************************************/ -void cmd_setmode(void) +void cmd_setmode(char *dum_in, char *dum_out) { char *q; fstring buf; -- cgit From 38b8e524ea2911384a193e230ab66b0c77519e25 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Tue, 5 May 1998 13:03:44 +0000 Subject: Added bug fixes to clitar to ensure proper longfile name restores occur. Also getting ready for setting directory dates correctly (This used to be commit fc0cad9035f9cbb5d8a5ee0221c342a3f90cf201) --- source3/client/clitar.c | 407 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 382 insertions(+), 25 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 32731200b0..3169c37962 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -27,13 +27,47 @@ directory creation times 3. tar now accepts both UNIX path names and DOS path names. I prefer those lovely /'s to those UGLY \'s :-) + 4. the files to exclude can be specified as a regular expression by adding + an r flag to the other tar flags. Eg: + -TcrX file.tar "*.(obj|exe)" + + will skip all .obj and .exe files */ #include "includes.h" #include "clitar.h" +#ifdef HAVE_REGEX_H #include +#endif + +typedef struct file_info_struct file_info2; + +struct file_info_struct +{ + int size; + int mode; + int uid; + int gid; + /* These times are normally kept in GMT */ + time_t mtime; + time_t atime; + time_t ctime; + char *name; /* This is dynamically allocate */ + + file_info2 *next, *prev; /* Used in the stack ... */ + +}; + +typedef struct +{ + file_info2 *top; + int items; + +} stack; + +stack dir_stack = {NULL, 0}; /* Want an empty stack */ extern BOOL recurse; @@ -60,6 +94,11 @@ BOOL tar_inc=False; BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ BOOL tar_excl=True; +/* use regular expressions for search on file names */ +BOOL tar_re_search=False; +#ifdef HAVE_REGEX_H +regex_t *preg; +#endif /* Dump files with System attribute */ BOOL tar_system=False; /* Dump files with Hidden attribute */ @@ -86,18 +125,85 @@ int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); - -/* Forward references. */ +static void do_atar(); +static void do_tar(); +static void oct_it(long value, int ndgs, char *p); static void fixtarname(char *tptr, char *fp, int l); static int dotarbuf(int f, char *b, int n); -static void oct_it (long value, int ndgs, char *p); +static void dozerobuf(); +static void dotareof(); +static void initarbuf(); +static int do_setrattr(); + +/* restore functions */ +static long readtarheader(); static long unoct(char *p, int ndgs); +static void do_tarput(); static void unfixtarname(char *tptr, char *fp, int l); /* * tar specific utitlities */ +/* + * Stack routines, push_dir, pop_dir, top_dir_name + */ + +BOOL push_dir(stack *dir_stack, file_info2 *dir) +{ + dir -> next = dir_stack -> top; + dir -> prev = NULL; + dir_stack -> items++; + dir_stack -> top = dir; + return(True); + +} + +file_info2 *pop_dir(stack *dir_stack) +{ + file_info2 *ptr; + + ptr = dir_stack -> top; + if (dir_stack -> top != NULL) { + + dir_stack -> top = dir_stack -> top -> next; + dir_stack -> items--; + + } + + return ptr; + +} + +char *top_dir_name(stack *dir_stack) +{ + + return(dir_stack -> top != NULL?dir_stack -> top -> name:NULL); + +} + +BOOL sub_dir(char *dir1, char *dir2) +{ + +} + +/* Create a string of size size+1 (for the null) */ +char * string_create_s(int size) +{ + char *tmp; + + tmp = (char *)malloc(size+1); + + if (tmp == NULL) { + + DEBUG(0, ("Out of memory in string_create_s\n")); + + } + + return(tmp); + +} + /**************************************************************************** Write a tar header to buffer ****************************************************************************/ @@ -108,7 +214,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, int i, chk, l; char *jp; - DEBUG(5, ("WriteTarHdr, Type = %c, Name = %s\n", ftype, aname)); + DEBUG(5, ("WriteTarHdr, Type = %c, Size= %i, Name = %s\n", ftype, size, aname)); memset(hb.dummy, 0, sizeof(hb.dummy)); @@ -125,6 +231,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l+1); i = strlen(b)+1; + DEBUG(5, ("File name in tar file: %s, size=%i, \n", b, strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); free(b); } @@ -158,7 +265,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, /**************************************************************************** Read a tar header into a hblock structure, and validate ***************************************************************************/ -static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) +static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) { long chk, fchk; int i; @@ -192,6 +299,13 @@ static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) return -1; } + if ((finfo->name = string_create_s(strlen(prefix) + strlen(hb -> dbuf.name) + 3)) == NULL) { + + DEBUG(0, ("Out of space creating file_info2 for %s\n", hb -> dbuf.name)); + return(-1); + + } + strcpy(finfo->name, prefix); /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ @@ -298,7 +412,7 @@ static void dozerobuf(int f, int n) /**************************************************************************** Malloc tape buffer ****************************************************************************/ -static void initarbuf(void) +static void initarbuf() { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; @@ -447,6 +561,8 @@ static int do_setrtime(char *fname, int mtime) char *inbuf, *outbuf, *p; char *name; + DEBUG(5, ("Setting time on: %s, fnlen=%i.\n", fname, strlen(fname))); + name = (char *)malloc(strlen(fname) + 1 + 1); if (name == NULL) { @@ -600,7 +716,7 @@ static int do_setrattr(char *fname, int attr, int setit) /**************************************************************************** Create a file on a share ***************************************************************************/ -static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) +static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) { char *p; /* *must* be called with buffer ready malloc'ed */ @@ -680,7 +796,7 @@ static BOOL smbwrite(int fnum, int n, int low, int high, int left, /**************************************************************************** Close a file on a share ***************************************************************************/ -static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) +static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) { /* *must* be called with buffer ready malloc'ed */ @@ -775,11 +891,21 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ - pstring partpath, ffname; + char *partpath, *ffname; char *p=fname, *basehack; DEBUG(5, ( "Ensurepath called with: %s\n", fname)); + partpath = string_create_s(strlen(fname)); + ffname = string_create_s(strlen(fname)); + + if ((partpath == NULL) || (ffname == NULL)){ + + DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); + return(False); + + } + *partpath = 0; /* fname copied to ffname so can strtok */ @@ -821,7 +947,7 @@ int padit(char *buf, int bufsize, int padsize) int berr= 0; int bytestowrite; - DEBUG(0, ("Padding with %d zeros\n", padsize)); + DEBUG(5, ("Padding with %d zeros\n", padsize)); memset(buf, 0, bufsize); while( !berr && padsize > 0 ) { bytestowrite= MIN(bufsize, padsize); @@ -965,7 +1091,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen = 0; } - DEBUG(2,("getting file %s of size %d bytes as a tar file %s", + DEBUG(3,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, lname)); @@ -1230,7 +1356,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_size += finfo.size; /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(2,("(%g kb/s) (average %g kb/s)\n", + DEBUG(3,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); if (tar_noisy) @@ -1265,7 +1391,14 @@ static void do_tar(file_info *finfo) strcat(exclaim, "\\"); strcat(exclaim, finfo->name); - if (clipfind(cliplist, clipn, exclaim)) { + DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); + + if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || +#ifdef HAVE_REGEX_H + (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { +#else + (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) { +#endif DEBUG(3,("Skipping file %s\n", exclaim)); return; } @@ -1345,9 +1478,178 @@ static void unfixtarname(char *tptr, char *fp, int l) } } -static void do_tarput(void) +/**************************************************************************** +Move to the next block in the buffer, which may mean read in another set of +blocks. +****************************************************************************/ +int next_block(char *tarbuf, char *bufferp, int bufsiz) { - file_info finfo; + int bufread, total = 0; + + if (bufferp >= (tarbuf + bufsiz)) { + + for (bufread = read(tarhandle, tarbuf, bufsiz); total += bufread; total < bufsiz) { + + if (bufread <= 0) { /* An error, return false */ + return (total > 0 ? -2 : bufread); + } + + } + + bufferp = tarbuf; + + } + else { + + bufferp += TBLOCK; + + } + +} + +int skip_file() +{ + +} + +int get_file(file_info2 finfo) +{ + + +} + +int get_dir(file_info2 finfo) +{ + +} + +char * get_longfilename(file_info2 finfo) +{ + +} + +static char * bufferp; + +static void do_tarput2() +{ + file_info2 finfo; + struct timeval tp_start; + char *inbuf, *outbuf, *longfilename = NULL; + int skip = False; + + GetTimeOfDay(&tp_start); + + bufferp = tarbuf + tbufsiz; /* init this to force first read */ + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) { + + DEBUG(0, ("Out of memory during allocate of inbuf and outbuf!\n")); + return; + + } + + if (next_block(tarbuf, bufferp, tbufsiz) <= 0) { + + DEBUG(0, ("Empty file or short tar file: %s\n", strerror(errno))); + + } + + /* Now read through those files ... */ + + while (True) { + + switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { + + case -2: /* Hmm, not good, but not fatal */ + DEBUG(0, ("Skipping %s...\n", finfo.name)); + if ((next_block(tarbuf, bufferp, tbufsiz) <= 0) && + !skip_file(finfo.size)) { + + DEBUG(0, ("Short file, bailing out...\n")); + free(inbuf); free(outbuf); + continue; + + } + + break; + + case -1: + DEBUG(0, ("abandoning restore, -1 from read tar header\n")); + free(inbuf); free(outbuf); + return; + + case 0: /* chksum is zero - looks like an EOF */ + DEBUG(0, ("total of %d tar files restored to share\n", ntarf)); + free(inbuf); free(outbuf); + return; /* Hmmm, bad here ... */ + + default: + break; + + } + + /* Now, do we have a long file name? */ + + if (longfilename != NULL) { + if (strlen(longfilename) < sizeof(finfo.name)) { /* if we have space */ + + strncpy(finfo.name, longfilename, sizeof(finfo.name) - 1); + free(longfilename); + longfilename = NULL; + + } + else { + + DEBUG(0, ("filename: %s too long, skipping\n", strlen(longfilename))); + skip = True; + + } + } + + /* Well, now we have a header, process the file ... */ + + /* Should we skip the file? */ + + if (skip) { + + skip_file(finfo); + continue; + + } + + /* We only get this far if we should process the file */ + + switch (((union hblock *)bufferp) -> dbuf.linkflag) { + + case '0': /* Should use symbolic names--FIXME */ + get_file(finfo); + break; + + case '5': + get_dir(finfo); + break; + + case 'L': + longfilename = get_longfilename(finfo); + break; + + default: + skip_file(finfo); /* Don't handle these yet */ + break; + + } + + } + + +} + +static void do_tarput() +{ + file_info2 finfo; int nread=0, bufread; char *inbuf,*outbuf, *longname = NULL; int fsize=0; @@ -1355,6 +1657,8 @@ static void do_tarput(void) struct timeval tp_start; BOOL tskip=False; /* We'll take each file as it comes */ + finfo.name = NULL; /* No name in here ... */ + GetTimeOfDay(&tp_start); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1422,6 +1726,13 @@ static void do_tarput(void) } next_header = 0; /* Don't want the next one ... */ + + if (finfo.name != NULL) { /* Free the space */ + + free(finfo.name); + finfo.name = NULL; + + } switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ @@ -1451,7 +1762,10 @@ static void do_tarput(void) if (longname != NULL) { - strncpy(finfo.name, longname, sizeof(pstring) - 1); + free(finfo.name); /* Free the name in the finfo */ + finfo.name = string_create_s(strlen(longname) + 2); + strncpy(finfo.name, longname, strlen(longname) + 1); + DEBUG(5, ("Long name = \"%s\", filename=\"%s\"\n", longname, finfo.name)); free(longname); longname = NULL; @@ -1466,6 +1780,7 @@ static void do_tarput(void) fix the name and skip the name. Hmmm, what about end of buffer??? */ + DEBUG(5, ("Buffer size = %i\n", finfo.size + strlen(cur_dir) +1)); longname = malloc(finfo.size + strlen(cur_dir) + 1); if (longname == NULL) { @@ -1488,8 +1803,9 @@ static void do_tarput(void) } - strncpy(longname, cur_dir, strlen(cur_dir)); + strncpy(longname, cur_dir, strlen(cur_dir) + 1); unfixtarname(longname+strlen(cur_dir), bufferp, finfo.size); + DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, bufferp)); /* Next rounds up to next TBLOCK and takes care of us being right on a TBLOCK boundary */ @@ -1500,7 +1816,12 @@ static void do_tarput(void) } } tskip=clipn - && (clipfind(cliplist, clipn, finfo.name) ^ tar_excl); + && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) +#ifdef HAVE_REGEX_H + || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); +#else + || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); +#endif if (tskip) { bufferp+=TBLOCK; if (finfo.mode & aDIR) @@ -1522,9 +1843,10 @@ static void do_tarput(void) if (finfo.mode & aDIR) { + + DEBUG(5, ("Creating directory: %s\n", finfo.name)); + if (!ensurepath(finfo.name, inbuf, outbuf)) -/* if (!smbchkpath(finfo.name, inbuf, outbuf) - && !smbmkdir(finfo.name, inbuf, outbuf))*/ { DEBUG(0, ("abandoning restore, problems ensuring path\n")); free(inbuf); free(outbuf); @@ -1534,7 +1856,7 @@ static void do_tarput(void) { /* Now we update the creation date ... */ - DEBUG(5, ("Updating creation date on %s\n", finfo.name)); + DEBUG(0, ("Updating creation date on %s\n", finfo.name)); if (!do_setrtime(finfo.name, finfo.mtime)) { @@ -1562,13 +1884,13 @@ static void do_tarput(void) DEBUG(0 ,("restore tar file %s of size %d bytes\n", finfo.name,finfo.size)); - if (!finfo.size) { + /* if (!finfo.size) { if (!smbshut(finfo, fnum, inbuf, outbuf)){ DEBUG(0, ("Error closing remote file of length 0: %s\n", finfo.name)); free(inbuf);free(outbuf); return; } - } + } */ nread=0; if ((bufferp+=TBLOCK) >= endofbuffer) break; @@ -1614,6 +1936,7 @@ static void do_tarput(void) (long) bufferp, (long)(bufferp - tarbuf))); ntarf++; fsize=0; + } } while (bufferp < endofbuffer); } @@ -1791,7 +2114,7 @@ int process_tar(char *inbuf, char *outbuf) pstring tarmac; for (i=0; i=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); -- cgit From 905261c53cfb57b7d1c69e2c8bda11a3958b5254 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 May 1998 18:11:24 +0000 Subject: Rolling clitar.c back to the previous rev 1.22 as the current one needs fixing (sorry). Jeremy. (This used to be commit 50f75b11465ac45f1944ed613a65524ca4e60594) --- source3/client/clitar.c | 407 +++--------------------------------------------- 1 file changed, 25 insertions(+), 382 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 3169c37962..32731200b0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -27,47 +27,13 @@ directory creation times 3. tar now accepts both UNIX path names and DOS path names. I prefer those lovely /'s to those UGLY \'s :-) - 4. the files to exclude can be specified as a regular expression by adding - an r flag to the other tar flags. Eg: - -TcrX file.tar "*.(obj|exe)" - - will skip all .obj and .exe files */ #include "includes.h" #include "clitar.h" -#ifdef HAVE_REGEX_H #include -#endif - -typedef struct file_info_struct file_info2; - -struct file_info_struct -{ - int size; - int mode; - int uid; - int gid; - /* These times are normally kept in GMT */ - time_t mtime; - time_t atime; - time_t ctime; - char *name; /* This is dynamically allocate */ - - file_info2 *next, *prev; /* Used in the stack ... */ - -}; - -typedef struct -{ - file_info2 *top; - int items; - -} stack; - -stack dir_stack = {NULL, 0}; /* Want an empty stack */ extern BOOL recurse; @@ -94,11 +60,6 @@ BOOL tar_inc=False; BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ BOOL tar_excl=True; -/* use regular expressions for search on file names */ -BOOL tar_re_search=False; -#ifdef HAVE_REGEX_H -regex_t *preg; -#endif /* Dump files with System attribute */ BOOL tar_system=False; /* Dump files with Hidden attribute */ @@ -125,85 +86,18 @@ int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); -static void do_atar(); -static void do_tar(); -static void oct_it(long value, int ndgs, char *p); + +/* Forward references. */ static void fixtarname(char *tptr, char *fp, int l); static int dotarbuf(int f, char *b, int n); -static void dozerobuf(); -static void dotareof(); -static void initarbuf(); -static int do_setrattr(); - -/* restore functions */ -static long readtarheader(); +static void oct_it (long value, int ndgs, char *p); static long unoct(char *p, int ndgs); -static void do_tarput(); static void unfixtarname(char *tptr, char *fp, int l); /* * tar specific utitlities */ -/* - * Stack routines, push_dir, pop_dir, top_dir_name - */ - -BOOL push_dir(stack *dir_stack, file_info2 *dir) -{ - dir -> next = dir_stack -> top; - dir -> prev = NULL; - dir_stack -> items++; - dir_stack -> top = dir; - return(True); - -} - -file_info2 *pop_dir(stack *dir_stack) -{ - file_info2 *ptr; - - ptr = dir_stack -> top; - if (dir_stack -> top != NULL) { - - dir_stack -> top = dir_stack -> top -> next; - dir_stack -> items--; - - } - - return ptr; - -} - -char *top_dir_name(stack *dir_stack) -{ - - return(dir_stack -> top != NULL?dir_stack -> top -> name:NULL); - -} - -BOOL sub_dir(char *dir1, char *dir2) -{ - -} - -/* Create a string of size size+1 (for the null) */ -char * string_create_s(int size) -{ - char *tmp; - - tmp = (char *)malloc(size+1); - - if (tmp == NULL) { - - DEBUG(0, ("Out of memory in string_create_s\n")); - - } - - return(tmp); - -} - /**************************************************************************** Write a tar header to buffer ****************************************************************************/ @@ -214,7 +108,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, int i, chk, l; char *jp; - DEBUG(5, ("WriteTarHdr, Type = %c, Size= %i, Name = %s\n", ftype, size, aname)); + DEBUG(5, ("WriteTarHdr, Type = %c, Name = %s\n", ftype, aname)); memset(hb.dummy, 0, sizeof(hb.dummy)); @@ -231,7 +125,6 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l+1); i = strlen(b)+1; - DEBUG(5, ("File name in tar file: %s, size=%i, \n", b, strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); free(b); } @@ -265,7 +158,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, /**************************************************************************** Read a tar header into a hblock structure, and validate ***************************************************************************/ -static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) +static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) { long chk, fchk; int i; @@ -299,13 +192,6 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) return -1; } - if ((finfo->name = string_create_s(strlen(prefix) + strlen(hb -> dbuf.name) + 3)) == NULL) { - - DEBUG(0, ("Out of space creating file_info2 for %s\n", hb -> dbuf.name)); - return(-1); - - } - strcpy(finfo->name, prefix); /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ @@ -412,7 +298,7 @@ static void dozerobuf(int f, int n) /**************************************************************************** Malloc tape buffer ****************************************************************************/ -static void initarbuf() +static void initarbuf(void) { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; @@ -561,8 +447,6 @@ static int do_setrtime(char *fname, int mtime) char *inbuf, *outbuf, *p; char *name; - DEBUG(5, ("Setting time on: %s, fnlen=%i.\n", fname, strlen(fname))); - name = (char *)malloc(strlen(fname) + 1 + 1); if (name == NULL) { @@ -716,7 +600,7 @@ static int do_setrattr(char *fname, int attr, int setit) /**************************************************************************** Create a file on a share ***************************************************************************/ -static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) +static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) { char *p; /* *must* be called with buffer ready malloc'ed */ @@ -796,7 +680,7 @@ static BOOL smbwrite(int fnum, int n, int low, int high, int left, /**************************************************************************** Close a file on a share ***************************************************************************/ -static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) +static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) { /* *must* be called with buffer ready malloc'ed */ @@ -891,21 +775,11 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ - char *partpath, *ffname; + pstring partpath, ffname; char *p=fname, *basehack; DEBUG(5, ( "Ensurepath called with: %s\n", fname)); - partpath = string_create_s(strlen(fname)); - ffname = string_create_s(strlen(fname)); - - if ((partpath == NULL) || (ffname == NULL)){ - - DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); - return(False); - - } - *partpath = 0; /* fname copied to ffname so can strtok */ @@ -947,7 +821,7 @@ int padit(char *buf, int bufsize, int padsize) int berr= 0; int bytestowrite; - DEBUG(5, ("Padding with %d zeros\n", padsize)); + DEBUG(0, ("Padding with %d zeros\n", padsize)); memset(buf, 0, bufsize); while( !berr && padsize > 0 ) { bytestowrite= MIN(bufsize, padsize); @@ -1091,7 +965,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen = 0; } - DEBUG(3,("getting file %s of size %d bytes as a tar file %s", + DEBUG(2,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, lname)); @@ -1356,7 +1230,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_size += finfo.size; /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(3,("(%g kb/s) (average %g kb/s)\n", + DEBUG(2,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); if (tar_noisy) @@ -1391,14 +1265,7 @@ static void do_tar(file_info *finfo) strcat(exclaim, "\\"); strcat(exclaim, finfo->name); - DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); - - if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || -#ifdef HAVE_REGEX_H - (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { -#else - (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) { -#endif + if (clipfind(cliplist, clipn, exclaim)) { DEBUG(3,("Skipping file %s\n", exclaim)); return; } @@ -1478,178 +1345,9 @@ static void unfixtarname(char *tptr, char *fp, int l) } } -/**************************************************************************** -Move to the next block in the buffer, which may mean read in another set of -blocks. -****************************************************************************/ -int next_block(char *tarbuf, char *bufferp, int bufsiz) -{ - int bufread, total = 0; - - if (bufferp >= (tarbuf + bufsiz)) { - - for (bufread = read(tarhandle, tarbuf, bufsiz); total += bufread; total < bufsiz) { - - if (bufread <= 0) { /* An error, return false */ - return (total > 0 ? -2 : bufread); - } - - } - - bufferp = tarbuf; - - } - else { - - bufferp += TBLOCK; - - } - -} - -int skip_file() -{ - -} - -int get_file(file_info2 finfo) -{ - - -} - -int get_dir(file_info2 finfo) -{ - -} - -char * get_longfilename(file_info2 finfo) -{ - -} - -static char * bufferp; - -static void do_tarput2() -{ - file_info2 finfo; - struct timeval tp_start; - char *inbuf, *outbuf, *longfilename = NULL; - int skip = False; - - GetTimeOfDay(&tp_start); - - bufferp = tarbuf + tbufsiz; /* init this to force first read */ - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) { - - DEBUG(0, ("Out of memory during allocate of inbuf and outbuf!\n")); - return; - - } - - if (next_block(tarbuf, bufferp, tbufsiz) <= 0) { - - DEBUG(0, ("Empty file or short tar file: %s\n", strerror(errno))); - - } - - /* Now read through those files ... */ - - while (True) { - - switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { - - case -2: /* Hmm, not good, but not fatal */ - DEBUG(0, ("Skipping %s...\n", finfo.name)); - if ((next_block(tarbuf, bufferp, tbufsiz) <= 0) && - !skip_file(finfo.size)) { - - DEBUG(0, ("Short file, bailing out...\n")); - free(inbuf); free(outbuf); - continue; - - } - - break; - - case -1: - DEBUG(0, ("abandoning restore, -1 from read tar header\n")); - free(inbuf); free(outbuf); - return; - - case 0: /* chksum is zero - looks like an EOF */ - DEBUG(0, ("total of %d tar files restored to share\n", ntarf)); - free(inbuf); free(outbuf); - return; /* Hmmm, bad here ... */ - - default: - break; - - } - - /* Now, do we have a long file name? */ - - if (longfilename != NULL) { - if (strlen(longfilename) < sizeof(finfo.name)) { /* if we have space */ - - strncpy(finfo.name, longfilename, sizeof(finfo.name) - 1); - free(longfilename); - longfilename = NULL; - - } - else { - - DEBUG(0, ("filename: %s too long, skipping\n", strlen(longfilename))); - skip = True; - - } - } - - /* Well, now we have a header, process the file ... */ - - /* Should we skip the file? */ - - if (skip) { - - skip_file(finfo); - continue; - - } - - /* We only get this far if we should process the file */ - - switch (((union hblock *)bufferp) -> dbuf.linkflag) { - - case '0': /* Should use symbolic names--FIXME */ - get_file(finfo); - break; - - case '5': - get_dir(finfo); - break; - - case 'L': - longfilename = get_longfilename(finfo); - break; - - default: - skip_file(finfo); /* Don't handle these yet */ - break; - - } - - } - - -} - -static void do_tarput() +static void do_tarput(void) { - file_info2 finfo; + file_info finfo; int nread=0, bufread; char *inbuf,*outbuf, *longname = NULL; int fsize=0; @@ -1657,8 +1355,6 @@ static void do_tarput() struct timeval tp_start; BOOL tskip=False; /* We'll take each file as it comes */ - finfo.name = NULL; /* No name in here ... */ - GetTimeOfDay(&tp_start); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1726,13 +1422,6 @@ static void do_tarput() } next_header = 0; /* Don't want the next one ... */ - - if (finfo.name != NULL) { /* Free the space */ - - free(finfo.name); - finfo.name = NULL; - - } switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ @@ -1762,10 +1451,7 @@ static void do_tarput() if (longname != NULL) { - free(finfo.name); /* Free the name in the finfo */ - finfo.name = string_create_s(strlen(longname) + 2); - strncpy(finfo.name, longname, strlen(longname) + 1); - DEBUG(5, ("Long name = \"%s\", filename=\"%s\"\n", longname, finfo.name)); + strncpy(finfo.name, longname, sizeof(pstring) - 1); free(longname); longname = NULL; @@ -1780,7 +1466,6 @@ static void do_tarput() fix the name and skip the name. Hmmm, what about end of buffer??? */ - DEBUG(5, ("Buffer size = %i\n", finfo.size + strlen(cur_dir) +1)); longname = malloc(finfo.size + strlen(cur_dir) + 1); if (longname == NULL) { @@ -1803,9 +1488,8 @@ static void do_tarput() } - strncpy(longname, cur_dir, strlen(cur_dir) + 1); + strncpy(longname, cur_dir, strlen(cur_dir)); unfixtarname(longname+strlen(cur_dir), bufferp, finfo.size); - DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, bufferp)); /* Next rounds up to next TBLOCK and takes care of us being right on a TBLOCK boundary */ @@ -1816,12 +1500,7 @@ static void do_tarput() } } tskip=clipn - && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) -#ifdef HAVE_REGEX_H - || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); -#else - || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); -#endif + && (clipfind(cliplist, clipn, finfo.name) ^ tar_excl); if (tskip) { bufferp+=TBLOCK; if (finfo.mode & aDIR) @@ -1843,10 +1522,9 @@ static void do_tarput() if (finfo.mode & aDIR) { - - DEBUG(5, ("Creating directory: %s\n", finfo.name)); - if (!ensurepath(finfo.name, inbuf, outbuf)) +/* if (!smbchkpath(finfo.name, inbuf, outbuf) + && !smbmkdir(finfo.name, inbuf, outbuf))*/ { DEBUG(0, ("abandoning restore, problems ensuring path\n")); free(inbuf); free(outbuf); @@ -1856,7 +1534,7 @@ static void do_tarput() { /* Now we update the creation date ... */ - DEBUG(0, ("Updating creation date on %s\n", finfo.name)); + DEBUG(5, ("Updating creation date on %s\n", finfo.name)); if (!do_setrtime(finfo.name, finfo.mtime)) { @@ -1884,13 +1562,13 @@ static void do_tarput() DEBUG(0 ,("restore tar file %s of size %d bytes\n", finfo.name,finfo.size)); - /* if (!finfo.size) { + if (!finfo.size) { if (!smbshut(finfo, fnum, inbuf, outbuf)){ DEBUG(0, ("Error closing remote file of length 0: %s\n", finfo.name)); free(inbuf);free(outbuf); return; } - } */ + } nread=0; if ((bufferp+=TBLOCK) >= endofbuffer) break; @@ -1936,7 +1614,6 @@ static void do_tarput() (long) bufferp, (long)(bufferp - tarbuf))); ntarf++; fsize=0; - } } while (bufferp < endofbuffer); } @@ -2114,7 +1791,7 @@ int process_tar(char *inbuf, char *outbuf) pstring tarmac; for (i=0; i=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); -- cgit From b59916ebf77814edca91683e3fe6f30799d29dd2 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 6 May 1998 02:35:56 +0000 Subject: Real fix for clitar.c problems. Have now made all the right things static, and have done a 'make proto; make clean; make'. Still get 54 compiler warnings under Digital UNIX cc. Honest. :-) (This used to be commit 47eb7e5be2f12206bd2de0670be478d80e1d84de) --- source3/client/clitar.c | 407 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 382 insertions(+), 25 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 32731200b0..b40e3ce9fe 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -27,13 +27,47 @@ directory creation times 3. tar now accepts both UNIX path names and DOS path names. I prefer those lovely /'s to those UGLY \'s :-) + 4. the files to exclude can be specified as a regular expression by adding + an r flag to the other tar flags. Eg: + -TcrX file.tar "*.(obj|exe)" + + will skip all .obj and .exe files */ #include "includes.h" #include "clitar.h" +#ifdef HAVE_REGEX_H #include +#endif + +typedef struct file_info_struct file_info2; + +struct file_info_struct +{ + int size; + int mode; + int uid; + int gid; + /* These times are normally kept in GMT */ + time_t mtime; + time_t atime; + time_t ctime; + char *name; /* This is dynamically allocate */ + + file_info2 *next, *prev; /* Used in the stack ... */ + +}; + +typedef struct +{ + file_info2 *top; + int items; + +} stack; + +stack dir_stack = {NULL, 0}; /* Want an empty stack */ extern BOOL recurse; @@ -60,6 +94,11 @@ BOOL tar_inc=False; BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ BOOL tar_excl=True; +/* use regular expressions for search on file names */ +BOOL tar_re_search=False; +#ifdef HAVE_REGEX_H +regex_t *preg; +#endif /* Dump files with System attribute */ BOOL tar_system=False; /* Dump files with Hidden attribute */ @@ -86,18 +125,85 @@ int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); - -/* Forward references. */ +static void do_atar(); +static void do_tar(); +static void oct_it(long value, int ndgs, char *p); static void fixtarname(char *tptr, char *fp, int l); static int dotarbuf(int f, char *b, int n); -static void oct_it (long value, int ndgs, char *p); +static void dozerobuf(); +static void dotareof(); +static void initarbuf(); +static int do_setrattr(); + +/* restore functions */ +static long readtarheader(); static long unoct(char *p, int ndgs); +static void do_tarput(); static void unfixtarname(char *tptr, char *fp, int l); /* * tar specific utitlities */ +/* + * Stack routines, push_dir, pop_dir, top_dir_name + */ + +static BOOL push_dir(stack *dir_stack, file_info2 *dir) +{ + dir -> next = dir_stack -> top; + dir -> prev = NULL; + dir_stack -> items++; + dir_stack -> top = dir; + return(True); + +} + +static file_info2 *pop_dir(stack *dir_stack) +{ + file_info2 *ptr; + + ptr = dir_stack -> top; + if (dir_stack -> top != NULL) { + + dir_stack -> top = dir_stack -> top -> next; + dir_stack -> items--; + + } + + return ptr; + +} + +static char *top_dir_name(stack *dir_stack) +{ + + return(dir_stack -> top != NULL?dir_stack -> top -> name:NULL); + +} + +static BOOL sub_dir(char *dir1, char *dir2) +{ + +} + +/* Create a string of size size+1 (for the null) */ +static char * string_create_s(int size) +{ + char *tmp; + + tmp = (char *)malloc(size+1); + + if (tmp == NULL) { + + DEBUG(0, ("Out of memory in string_create_s\n")); + + } + + return(tmp); + +} + /**************************************************************************** Write a tar header to buffer ****************************************************************************/ @@ -108,7 +214,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, int i, chk, l; char *jp; - DEBUG(5, ("WriteTarHdr, Type = %c, Name = %s\n", ftype, aname)); + DEBUG(5, ("WriteTarHdr, Type = %c, Size= %i, Name = %s\n", ftype, size, aname)); memset(hb.dummy, 0, sizeof(hb.dummy)); @@ -125,6 +231,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l+1); i = strlen(b)+1; + DEBUG(5, ("File name in tar file: %s, size=%i, \n", b, strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); free(b); } @@ -158,7 +265,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, /**************************************************************************** Read a tar header into a hblock structure, and validate ***************************************************************************/ -static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) +static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) { long chk, fchk; int i; @@ -192,6 +299,13 @@ static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) return -1; } + if ((finfo->name = string_create_s(strlen(prefix) + strlen(hb -> dbuf.name) + 3)) == NULL) { + + DEBUG(0, ("Out of space creating file_info2 for %s\n", hb -> dbuf.name)); + return(-1); + + } + strcpy(finfo->name, prefix); /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ @@ -298,7 +412,7 @@ static void dozerobuf(int f, int n) /**************************************************************************** Malloc tape buffer ****************************************************************************/ -static void initarbuf(void) +static void initarbuf() { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; @@ -447,6 +561,8 @@ static int do_setrtime(char *fname, int mtime) char *inbuf, *outbuf, *p; char *name; + DEBUG(5, ("Setting time on: %s, fnlen=%i.\n", fname, strlen(fname))); + name = (char *)malloc(strlen(fname) + 1 + 1); if (name == NULL) { @@ -600,7 +716,7 @@ static int do_setrattr(char *fname, int attr, int setit) /**************************************************************************** Create a file on a share ***************************************************************************/ -static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) +static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) { char *p; /* *must* be called with buffer ready malloc'ed */ @@ -680,7 +796,7 @@ static BOOL smbwrite(int fnum, int n, int low, int high, int left, /**************************************************************************** Close a file on a share ***************************************************************************/ -static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) +static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) { /* *must* be called with buffer ready malloc'ed */ @@ -775,11 +891,21 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ - pstring partpath, ffname; + char *partpath, *ffname; char *p=fname, *basehack; DEBUG(5, ( "Ensurepath called with: %s\n", fname)); + partpath = string_create_s(strlen(fname)); + ffname = string_create_s(strlen(fname)); + + if ((partpath == NULL) || (ffname == NULL)){ + + DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); + return(False); + + } + *partpath = 0; /* fname copied to ffname so can strtok */ @@ -821,7 +947,7 @@ int padit(char *buf, int bufsize, int padsize) int berr= 0; int bytestowrite; - DEBUG(0, ("Padding with %d zeros\n", padsize)); + DEBUG(5, ("Padding with %d zeros\n", padsize)); memset(buf, 0, bufsize); while( !berr && padsize > 0 ) { bytestowrite= MIN(bufsize, padsize); @@ -965,7 +1091,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen = 0; } - DEBUG(2,("getting file %s of size %d bytes as a tar file %s", + DEBUG(3,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, lname)); @@ -1230,7 +1356,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_size += finfo.size; /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(2,("(%g kb/s) (average %g kb/s)\n", + DEBUG(3,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); if (tar_noisy) @@ -1265,7 +1391,14 @@ static void do_tar(file_info *finfo) strcat(exclaim, "\\"); strcat(exclaim, finfo->name); - if (clipfind(cliplist, clipn, exclaim)) { + DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); + + if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || +#ifdef HAVE_REGEX_H + (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { +#else + (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) { +#endif DEBUG(3,("Skipping file %s\n", exclaim)); return; } @@ -1345,9 +1478,178 @@ static void unfixtarname(char *tptr, char *fp, int l) } } -static void do_tarput(void) +/**************************************************************************** +Move to the next block in the buffer, which may mean read in another set of +blocks. +****************************************************************************/ +static int next_block(char *tarbuf, char *bufferp, int bufsiz) { - file_info finfo; + int bufread, total = 0; + + if (bufferp >= (tarbuf + bufsiz)) { + + for (bufread = read(tarhandle, tarbuf, bufsiz); total += bufread; total < bufsiz) { + + if (bufread <= 0) { /* An error, return false */ + return (total > 0 ? -2 : bufread); + } + + } + + bufferp = tarbuf; + + } + else { + + bufferp += TBLOCK; + + } + +} + +static int skip_file() +{ + +} + +static int get_file(file_info2 finfo) +{ + + +} + +static int get_dir(file_info2 finfo) +{ + +} + +static char * get_longfilename(file_info2 finfo) +{ + +} + +static char * bufferp; + +static void do_tarput2() +{ + file_info2 finfo; + struct timeval tp_start; + char *inbuf, *outbuf, *longfilename = NULL; + int skip = False; + + GetTimeOfDay(&tp_start); + + bufferp = tarbuf + tbufsiz; /* init this to force first read */ + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) { + + DEBUG(0, ("Out of memory during allocate of inbuf and outbuf!\n")); + return; + + } + + if (next_block(tarbuf, bufferp, tbufsiz) <= 0) { + + DEBUG(0, ("Empty file or short tar file: %s\n", strerror(errno))); + + } + + /* Now read through those files ... */ + + while (True) { + + switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { + + case -2: /* Hmm, not good, but not fatal */ + DEBUG(0, ("Skipping %s...\n", finfo.name)); + if ((next_block(tarbuf, bufferp, tbufsiz) <= 0) && + !skip_file(finfo.size)) { + + DEBUG(0, ("Short file, bailing out...\n")); + free(inbuf); free(outbuf); + continue; + + } + + break; + + case -1: + DEBUG(0, ("abandoning restore, -1 from read tar header\n")); + free(inbuf); free(outbuf); + return; + + case 0: /* chksum is zero - looks like an EOF */ + DEBUG(0, ("total of %d tar files restored to share\n", ntarf)); + free(inbuf); free(outbuf); + return; /* Hmmm, bad here ... */ + + default: + break; + + } + + /* Now, do we have a long file name? */ + + if (longfilename != NULL) { + if (strlen(longfilename) < sizeof(finfo.name)) { /* if we have space */ + + strncpy(finfo.name, longfilename, sizeof(finfo.name) - 1); + free(longfilename); + longfilename = NULL; + + } + else { + + DEBUG(0, ("filename: %s too long, skipping\n", strlen(longfilename))); + skip = True; + + } + } + + /* Well, now we have a header, process the file ... */ + + /* Should we skip the file? */ + + if (skip) { + + skip_file(finfo); + continue; + + } + + /* We only get this far if we should process the file */ + + switch (((union hblock *)bufferp) -> dbuf.linkflag) { + + case '0': /* Should use symbolic names--FIXME */ + get_file(finfo); + break; + + case '5': + get_dir(finfo); + break; + + case 'L': + longfilename = get_longfilename(finfo); + break; + + default: + skip_file(finfo); /* Don't handle these yet */ + break; + + } + + } + + +} + +static void do_tarput() +{ + file_info2 finfo; int nread=0, bufread; char *inbuf,*outbuf, *longname = NULL; int fsize=0; @@ -1355,6 +1657,8 @@ static void do_tarput(void) struct timeval tp_start; BOOL tskip=False; /* We'll take each file as it comes */ + finfo.name = NULL; /* No name in here ... */ + GetTimeOfDay(&tp_start); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1422,6 +1726,13 @@ static void do_tarput(void) } next_header = 0; /* Don't want the next one ... */ + + if (finfo.name != NULL) { /* Free the space */ + + free(finfo.name); + finfo.name = NULL; + + } switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ @@ -1451,7 +1762,10 @@ static void do_tarput(void) if (longname != NULL) { - strncpy(finfo.name, longname, sizeof(pstring) - 1); + free(finfo.name); /* Free the name in the finfo */ + finfo.name = string_create_s(strlen(longname) + 2); + strncpy(finfo.name, longname, strlen(longname) + 1); + DEBUG(5, ("Long name = \"%s\", filename=\"%s\"\n", longname, finfo.name)); free(longname); longname = NULL; @@ -1466,6 +1780,7 @@ static void do_tarput(void) fix the name and skip the name. Hmmm, what about end of buffer??? */ + DEBUG(5, ("Buffer size = %i\n", finfo.size + strlen(cur_dir) +1)); longname = malloc(finfo.size + strlen(cur_dir) + 1); if (longname == NULL) { @@ -1488,8 +1803,9 @@ static void do_tarput(void) } - strncpy(longname, cur_dir, strlen(cur_dir)); + strncpy(longname, cur_dir, strlen(cur_dir) + 1); unfixtarname(longname+strlen(cur_dir), bufferp, finfo.size); + DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, bufferp)); /* Next rounds up to next TBLOCK and takes care of us being right on a TBLOCK boundary */ @@ -1500,7 +1816,12 @@ static void do_tarput(void) } } tskip=clipn - && (clipfind(cliplist, clipn, finfo.name) ^ tar_excl); + && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) +#ifdef HAVE_REGEX_H + || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); +#else + || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); +#endif if (tskip) { bufferp+=TBLOCK; if (finfo.mode & aDIR) @@ -1522,9 +1843,10 @@ static void do_tarput(void) if (finfo.mode & aDIR) { + + DEBUG(5, ("Creating directory: %s\n", finfo.name)); + if (!ensurepath(finfo.name, inbuf, outbuf)) -/* if (!smbchkpath(finfo.name, inbuf, outbuf) - && !smbmkdir(finfo.name, inbuf, outbuf))*/ { DEBUG(0, ("abandoning restore, problems ensuring path\n")); free(inbuf); free(outbuf); @@ -1534,7 +1856,7 @@ static void do_tarput(void) { /* Now we update the creation date ... */ - DEBUG(5, ("Updating creation date on %s\n", finfo.name)); + DEBUG(0, ("Updating creation date on %s\n", finfo.name)); if (!do_setrtime(finfo.name, finfo.mtime)) { @@ -1562,13 +1884,13 @@ static void do_tarput(void) DEBUG(0 ,("restore tar file %s of size %d bytes\n", finfo.name,finfo.size)); - if (!finfo.size) { + /* if (!finfo.size) { if (!smbshut(finfo, fnum, inbuf, outbuf)){ DEBUG(0, ("Error closing remote file of length 0: %s\n", finfo.name)); free(inbuf);free(outbuf); return; } - } + } */ nread=0; if ((bufferp+=TBLOCK) >= endofbuffer) break; @@ -1614,6 +1936,7 @@ static void do_tarput(void) (long) bufferp, (long)(bufferp - tarbuf))); ntarf++; fsize=0; + } } while (bufferp < endofbuffer); } @@ -1791,7 +2114,7 @@ int process_tar(char *inbuf, char *outbuf) pstring tarmac; for (i=0; i=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); -- cgit From 2b4d426726cad43db6ef2889c83d898b52a2018f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 6 May 1998 17:54:28 +0000 Subject: Rolling back again to the equivalent of revision 1.22, as the current CVS head branch will not compile. Jeremy. (This used to be commit 18a0a10dcb04733a2d7ba0e16d07ab7e6e2d54be) --- source3/client/clitar.c | 407 +++--------------------------------------------- 1 file changed, 25 insertions(+), 382 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index b40e3ce9fe..32731200b0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -27,47 +27,13 @@ directory creation times 3. tar now accepts both UNIX path names and DOS path names. I prefer those lovely /'s to those UGLY \'s :-) - 4. the files to exclude can be specified as a regular expression by adding - an r flag to the other tar flags. Eg: - -TcrX file.tar "*.(obj|exe)" - - will skip all .obj and .exe files */ #include "includes.h" #include "clitar.h" -#ifdef HAVE_REGEX_H #include -#endif - -typedef struct file_info_struct file_info2; - -struct file_info_struct -{ - int size; - int mode; - int uid; - int gid; - /* These times are normally kept in GMT */ - time_t mtime; - time_t atime; - time_t ctime; - char *name; /* This is dynamically allocate */ - - file_info2 *next, *prev; /* Used in the stack ... */ - -}; - -typedef struct -{ - file_info2 *top; - int items; - -} stack; - -stack dir_stack = {NULL, 0}; /* Want an empty stack */ extern BOOL recurse; @@ -94,11 +60,6 @@ BOOL tar_inc=False; BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ BOOL tar_excl=True; -/* use regular expressions for search on file names */ -BOOL tar_re_search=False; -#ifdef HAVE_REGEX_H -regex_t *preg; -#endif /* Dump files with System attribute */ BOOL tar_system=False; /* Dump files with Hidden attribute */ @@ -125,85 +86,18 @@ int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); -static void do_atar(); -static void do_tar(); -static void oct_it(long value, int ndgs, char *p); + +/* Forward references. */ static void fixtarname(char *tptr, char *fp, int l); static int dotarbuf(int f, char *b, int n); -static void dozerobuf(); -static void dotareof(); -static void initarbuf(); -static int do_setrattr(); - -/* restore functions */ -static long readtarheader(); +static void oct_it (long value, int ndgs, char *p); static long unoct(char *p, int ndgs); -static void do_tarput(); static void unfixtarname(char *tptr, char *fp, int l); /* * tar specific utitlities */ -/* - * Stack routines, push_dir, pop_dir, top_dir_name - */ - -static BOOL push_dir(stack *dir_stack, file_info2 *dir) -{ - dir -> next = dir_stack -> top; - dir -> prev = NULL; - dir_stack -> items++; - dir_stack -> top = dir; - return(True); - -} - -static file_info2 *pop_dir(stack *dir_stack) -{ - file_info2 *ptr; - - ptr = dir_stack -> top; - if (dir_stack -> top != NULL) { - - dir_stack -> top = dir_stack -> top -> next; - dir_stack -> items--; - - } - - return ptr; - -} - -static char *top_dir_name(stack *dir_stack) -{ - - return(dir_stack -> top != NULL?dir_stack -> top -> name:NULL); - -} - -static BOOL sub_dir(char *dir1, char *dir2) -{ - -} - -/* Create a string of size size+1 (for the null) */ -static char * string_create_s(int size) -{ - char *tmp; - - tmp = (char *)malloc(size+1); - - if (tmp == NULL) { - - DEBUG(0, ("Out of memory in string_create_s\n")); - - } - - return(tmp); - -} - /**************************************************************************** Write a tar header to buffer ****************************************************************************/ @@ -214,7 +108,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, int i, chk, l; char *jp; - DEBUG(5, ("WriteTarHdr, Type = %c, Size= %i, Name = %s\n", ftype, size, aname)); + DEBUG(5, ("WriteTarHdr, Type = %c, Name = %s\n", ftype, aname)); memset(hb.dummy, 0, sizeof(hb.dummy)); @@ -231,7 +125,6 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l+1); i = strlen(b)+1; - DEBUG(5, ("File name in tar file: %s, size=%i, \n", b, strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); free(b); } @@ -265,7 +158,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, /**************************************************************************** Read a tar header into a hblock structure, and validate ***************************************************************************/ -static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) +static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) { long chk, fchk; int i; @@ -299,13 +192,6 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) return -1; } - if ((finfo->name = string_create_s(strlen(prefix) + strlen(hb -> dbuf.name) + 3)) == NULL) { - - DEBUG(0, ("Out of space creating file_info2 for %s\n", hb -> dbuf.name)); - return(-1); - - } - strcpy(finfo->name, prefix); /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ @@ -412,7 +298,7 @@ static void dozerobuf(int f, int n) /**************************************************************************** Malloc tape buffer ****************************************************************************/ -static void initarbuf() +static void initarbuf(void) { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; @@ -561,8 +447,6 @@ static int do_setrtime(char *fname, int mtime) char *inbuf, *outbuf, *p; char *name; - DEBUG(5, ("Setting time on: %s, fnlen=%i.\n", fname, strlen(fname))); - name = (char *)malloc(strlen(fname) + 1 + 1); if (name == NULL) { @@ -716,7 +600,7 @@ static int do_setrattr(char *fname, int attr, int setit) /**************************************************************************** Create a file on a share ***************************************************************************/ -static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) +static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) { char *p; /* *must* be called with buffer ready malloc'ed */ @@ -796,7 +680,7 @@ static BOOL smbwrite(int fnum, int n, int low, int high, int left, /**************************************************************************** Close a file on a share ***************************************************************************/ -static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) +static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) { /* *must* be called with buffer ready malloc'ed */ @@ -891,21 +775,11 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ - char *partpath, *ffname; + pstring partpath, ffname; char *p=fname, *basehack; DEBUG(5, ( "Ensurepath called with: %s\n", fname)); - partpath = string_create_s(strlen(fname)); - ffname = string_create_s(strlen(fname)); - - if ((partpath == NULL) || (ffname == NULL)){ - - DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); - return(False); - - } - *partpath = 0; /* fname copied to ffname so can strtok */ @@ -947,7 +821,7 @@ int padit(char *buf, int bufsize, int padsize) int berr= 0; int bytestowrite; - DEBUG(5, ("Padding with %d zeros\n", padsize)); + DEBUG(0, ("Padding with %d zeros\n", padsize)); memset(buf, 0, bufsize); while( !berr && padsize > 0 ) { bytestowrite= MIN(bufsize, padsize); @@ -1091,7 +965,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen = 0; } - DEBUG(3,("getting file %s of size %d bytes as a tar file %s", + DEBUG(2,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, lname)); @@ -1356,7 +1230,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_size += finfo.size; /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(3,("(%g kb/s) (average %g kb/s)\n", + DEBUG(2,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); if (tar_noisy) @@ -1391,14 +1265,7 @@ static void do_tar(file_info *finfo) strcat(exclaim, "\\"); strcat(exclaim, finfo->name); - DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); - - if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || -#ifdef HAVE_REGEX_H - (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { -#else - (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) { -#endif + if (clipfind(cliplist, clipn, exclaim)) { DEBUG(3,("Skipping file %s\n", exclaim)); return; } @@ -1478,178 +1345,9 @@ static void unfixtarname(char *tptr, char *fp, int l) } } -/**************************************************************************** -Move to the next block in the buffer, which may mean read in another set of -blocks. -****************************************************************************/ -static int next_block(char *tarbuf, char *bufferp, int bufsiz) -{ - int bufread, total = 0; - - if (bufferp >= (tarbuf + bufsiz)) { - - for (bufread = read(tarhandle, tarbuf, bufsiz); total += bufread; total < bufsiz) { - - if (bufread <= 0) { /* An error, return false */ - return (total > 0 ? -2 : bufread); - } - - } - - bufferp = tarbuf; - - } - else { - - bufferp += TBLOCK; - - } - -} - -static int skip_file() -{ - -} - -static int get_file(file_info2 finfo) -{ - - -} - -static int get_dir(file_info2 finfo) -{ - -} - -static char * get_longfilename(file_info2 finfo) -{ - -} - -static char * bufferp; - -static void do_tarput2() -{ - file_info2 finfo; - struct timeval tp_start; - char *inbuf, *outbuf, *longfilename = NULL; - int skip = False; - - GetTimeOfDay(&tp_start); - - bufferp = tarbuf + tbufsiz; /* init this to force first read */ - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) { - - DEBUG(0, ("Out of memory during allocate of inbuf and outbuf!\n")); - return; - - } - - if (next_block(tarbuf, bufferp, tbufsiz) <= 0) { - - DEBUG(0, ("Empty file or short tar file: %s\n", strerror(errno))); - - } - - /* Now read through those files ... */ - - while (True) { - - switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { - - case -2: /* Hmm, not good, but not fatal */ - DEBUG(0, ("Skipping %s...\n", finfo.name)); - if ((next_block(tarbuf, bufferp, tbufsiz) <= 0) && - !skip_file(finfo.size)) { - - DEBUG(0, ("Short file, bailing out...\n")); - free(inbuf); free(outbuf); - continue; - - } - - break; - - case -1: - DEBUG(0, ("abandoning restore, -1 from read tar header\n")); - free(inbuf); free(outbuf); - return; - - case 0: /* chksum is zero - looks like an EOF */ - DEBUG(0, ("total of %d tar files restored to share\n", ntarf)); - free(inbuf); free(outbuf); - return; /* Hmmm, bad here ... */ - - default: - break; - - } - - /* Now, do we have a long file name? */ - - if (longfilename != NULL) { - if (strlen(longfilename) < sizeof(finfo.name)) { /* if we have space */ - - strncpy(finfo.name, longfilename, sizeof(finfo.name) - 1); - free(longfilename); - longfilename = NULL; - - } - else { - - DEBUG(0, ("filename: %s too long, skipping\n", strlen(longfilename))); - skip = True; - - } - } - - /* Well, now we have a header, process the file ... */ - - /* Should we skip the file? */ - - if (skip) { - - skip_file(finfo); - continue; - - } - - /* We only get this far if we should process the file */ - - switch (((union hblock *)bufferp) -> dbuf.linkflag) { - - case '0': /* Should use symbolic names--FIXME */ - get_file(finfo); - break; - - case '5': - get_dir(finfo); - break; - - case 'L': - longfilename = get_longfilename(finfo); - break; - - default: - skip_file(finfo); /* Don't handle these yet */ - break; - - } - - } - - -} - -static void do_tarput() +static void do_tarput(void) { - file_info2 finfo; + file_info finfo; int nread=0, bufread; char *inbuf,*outbuf, *longname = NULL; int fsize=0; @@ -1657,8 +1355,6 @@ static void do_tarput() struct timeval tp_start; BOOL tskip=False; /* We'll take each file as it comes */ - finfo.name = NULL; /* No name in here ... */ - GetTimeOfDay(&tp_start); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1726,13 +1422,6 @@ static void do_tarput() } next_header = 0; /* Don't want the next one ... */ - - if (finfo.name != NULL) { /* Free the space */ - - free(finfo.name); - finfo.name = NULL; - - } switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ @@ -1762,10 +1451,7 @@ static void do_tarput() if (longname != NULL) { - free(finfo.name); /* Free the name in the finfo */ - finfo.name = string_create_s(strlen(longname) + 2); - strncpy(finfo.name, longname, strlen(longname) + 1); - DEBUG(5, ("Long name = \"%s\", filename=\"%s\"\n", longname, finfo.name)); + strncpy(finfo.name, longname, sizeof(pstring) - 1); free(longname); longname = NULL; @@ -1780,7 +1466,6 @@ static void do_tarput() fix the name and skip the name. Hmmm, what about end of buffer??? */ - DEBUG(5, ("Buffer size = %i\n", finfo.size + strlen(cur_dir) +1)); longname = malloc(finfo.size + strlen(cur_dir) + 1); if (longname == NULL) { @@ -1803,9 +1488,8 @@ static void do_tarput() } - strncpy(longname, cur_dir, strlen(cur_dir) + 1); + strncpy(longname, cur_dir, strlen(cur_dir)); unfixtarname(longname+strlen(cur_dir), bufferp, finfo.size); - DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, bufferp)); /* Next rounds up to next TBLOCK and takes care of us being right on a TBLOCK boundary */ @@ -1816,12 +1500,7 @@ static void do_tarput() } } tskip=clipn - && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) -#ifdef HAVE_REGEX_H - || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); -#else - || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); -#endif + && (clipfind(cliplist, clipn, finfo.name) ^ tar_excl); if (tskip) { bufferp+=TBLOCK; if (finfo.mode & aDIR) @@ -1843,10 +1522,9 @@ static void do_tarput() if (finfo.mode & aDIR) { - - DEBUG(5, ("Creating directory: %s\n", finfo.name)); - if (!ensurepath(finfo.name, inbuf, outbuf)) +/* if (!smbchkpath(finfo.name, inbuf, outbuf) + && !smbmkdir(finfo.name, inbuf, outbuf))*/ { DEBUG(0, ("abandoning restore, problems ensuring path\n")); free(inbuf); free(outbuf); @@ -1856,7 +1534,7 @@ static void do_tarput() { /* Now we update the creation date ... */ - DEBUG(0, ("Updating creation date on %s\n", finfo.name)); + DEBUG(5, ("Updating creation date on %s\n", finfo.name)); if (!do_setrtime(finfo.name, finfo.mtime)) { @@ -1884,13 +1562,13 @@ static void do_tarput() DEBUG(0 ,("restore tar file %s of size %d bytes\n", finfo.name,finfo.size)); - /* if (!finfo.size) { + if (!finfo.size) { if (!smbshut(finfo, fnum, inbuf, outbuf)){ DEBUG(0, ("Error closing remote file of length 0: %s\n", finfo.name)); free(inbuf);free(outbuf); return; } - } */ + } nread=0; if ((bufferp+=TBLOCK) >= endofbuffer) break; @@ -1936,7 +1614,6 @@ static void do_tarput() (long) bufferp, (long)(bufferp - tarbuf))); ntarf++; fsize=0; - } } while (bufferp < endofbuffer); } @@ -2114,7 +1791,7 @@ int process_tar(char *inbuf, char *outbuf) pstring tarmac; for (i=0; i=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); -- cgit From bb8706f4076ca1e0ba11b62014ebfc85a357e931 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 8 May 1998 13:51:17 +0000 Subject: Se-submitting clitar.c/ I now only have one warning in my code which is the result of some code I have started working on but am not yet using in the code, along with a warning that is caused by one of the include files (a nested comment). I used -Wall -Wshadow -Wstrict-prototypes (This used to be commit 7b98fd5b69282320af700833c2d2720c42a382d8) --- source3/client/clitar.c | 486 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 433 insertions(+), 53 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 32731200b0..c0325c37e5 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -27,13 +27,44 @@ directory creation times 3. tar now accepts both UNIX path names and DOS path names. I prefer those lovely /'s to those UGLY \'s :-) + 4. the files to exclude can be specified as a regular expression by adding + an r flag to the other tar flags. Eg: + -TcrX file.tar "*.(obj|exe)" + + will skip all .obj and .exe files */ #include "includes.h" #include "clitar.h" -#include + +typedef struct file_info_struct file_info2; + +struct file_info_struct +{ + int size; + int mode; + int uid; + int gid; + /* These times are normally kept in GMT */ + time_t mtime; + time_t atime; + time_t ctime; + char *name; /* This is dynamically allocate */ + + file_info2 *next, *prev; /* Used in the stack ... */ + +}; + +typedef struct +{ + file_info2 *top; + int items; + +} stack; + +stack dir_stack = {NULL, 0}; /* Want an empty stack */ extern BOOL recurse; @@ -60,6 +91,11 @@ BOOL tar_inc=False; BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ BOOL tar_excl=True; +/* use regular expressions for search on file names */ +BOOL tar_re_search=False; +#ifdef HAVE_REGEX_H +regex_t *preg; +#endif /* Dump files with System attribute */ BOOL tar_system=False; /* Dump files with Hidden attribute */ @@ -86,18 +122,87 @@ int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); - -/* Forward references. */ +static void do_atar(char *rname,char *lname,file_info *finfo1); +static void do_tar(file_info *finfo); +static void oct_it(long value, int ndgs, char *p); static void fixtarname(char *tptr, char *fp, int l); static int dotarbuf(int f, char *b, int n); -static void oct_it (long value, int ndgs, char *p); +static void dozerobuf(int f, int n); +static void dotareof(int f); +static void initarbuf(void); +static int do_setrattr(char *fname, int attr, int setit); + +/* restore functions */ +static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix); static long unoct(char *p, int ndgs); +static void do_tarput(void); static void unfixtarname(char *tptr, char *fp, int l); /* * tar specific utitlities */ +/* + * Stack routines, push_dir, pop_dir, top_dir_name + */ + +static BOOL push_dir(stack *tar_dir_stack, file_info2 *dir) +{ + dir -> next = tar_dir_stack -> top; + dir -> prev = NULL; + tar_dir_stack -> items++; + tar_dir_stack -> top = dir; + return(True); + +} + +static file_info2 *pop_dir(stack *tar_dir_stack) +{ + file_info2 *ptr; + + ptr = tar_dir_stack -> top; + if (tar_dir_stack -> top != NULL) { + + tar_dir_stack -> top = tar_dir_stack -> top -> next; + tar_dir_stack -> items--; + + } + + return ptr; + +} + +static char *top_dir_name(stack *tar_dir_stack) +{ + + return(tar_dir_stack -> top != NULL?tar_dir_stack -> top -> name:NULL); + +} + +static BOOL sub_dir(char *dir1, char *dir2) +{ + + return(True); + +} + +/* Create a string of size size+1 (for the null) */ +static char * string_create_s(int size) +{ + char *tmp; + + tmp = (char *)malloc(size+1); + + if (tmp == NULL) { + + DEBUG(0, ("Out of memory in string_create_s\n")); + + } + + return(tmp); + +} + /**************************************************************************** Write a tar header to buffer ****************************************************************************/ @@ -108,7 +213,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, int i, chk, l; char *jp; - DEBUG(5, ("WriteTarHdr, Type = %c, Name = %s\n", ftype, aname)); + DEBUG(5, ("WriteTarHdr, Type = %c, Size= %i, Name = %s\n", ftype, size, aname)); memset(hb.dummy, 0, sizeof(hb.dummy)); @@ -125,6 +230,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l+1); i = strlen(b)+1; + DEBUG(5, ("File name in tar file: %s, size=%i, \n", b, strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); free(b); } @@ -158,7 +264,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, /**************************************************************************** Read a tar header into a hblock structure, and validate ***************************************************************************/ -static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) +static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) { long chk, fchk; int i; @@ -192,6 +298,13 @@ static long readtarheader(union hblock *hb, file_info *finfo, char *prefix) return -1; } + if ((finfo->name = string_create_s(strlen(prefix) + strlen(hb -> dbuf.name) + 3)) == NULL) { + + DEBUG(0, ("Out of space creating file_info2 for %s\n", hb -> dbuf.name)); + return(-1); + + } + strcpy(finfo->name, prefix); /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ @@ -298,7 +411,7 @@ static void dozerobuf(int f, int n) /**************************************************************************** Malloc tape buffer ****************************************************************************/ -static void initarbuf(void) +static void initarbuf() { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; @@ -447,6 +560,8 @@ static int do_setrtime(char *fname, int mtime) char *inbuf, *outbuf, *p; char *name; + DEBUG(5, ("Setting time on: %s, fnlen=%i.\n", fname, strlen(fname))); + name = (char *)malloc(strlen(fname) + 1 + 1); if (name == NULL) { @@ -600,7 +715,7 @@ static int do_setrattr(char *fname, int attr, int setit) /**************************************************************************** Create a file on a share ***************************************************************************/ -static BOOL smbcreat(file_info finfo, int *fnum, char *inbuf, char *outbuf) +static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) { char *p; /* *must* be called with buffer ready malloc'ed */ @@ -680,7 +795,7 @@ static BOOL smbwrite(int fnum, int n, int low, int high, int left, /**************************************************************************** Close a file on a share ***************************************************************************/ -static BOOL smbshut(file_info finfo, int fnum, char *inbuf, char *outbuf) +static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) { /* *must* be called with buffer ready malloc'ed */ @@ -775,11 +890,21 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ - pstring partpath, ffname; + char *partpath, *ffname; char *p=fname, *basehack; DEBUG(5, ( "Ensurepath called with: %s\n", fname)); + partpath = string_create_s(strlen(fname)); + ffname = string_create_s(strlen(fname)); + + if ((partpath == NULL) || (ffname == NULL)){ + + DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); + return(False); + + } + *partpath = 0; /* fname copied to ffname so can strtok */ @@ -821,7 +946,7 @@ int padit(char *buf, int bufsize, int padsize) int berr= 0; int bytestowrite; - DEBUG(0, ("Padding with %d zeros\n", padsize)); + DEBUG(5, ("Padding with %d zeros\n", padsize)); memset(buf, 0, bufsize); while( !berr && padsize > 0 ) { bytestowrite= MIN(bufsize, padsize); @@ -965,7 +1090,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen = 0; } - DEBUG(2,("getting file %s of size %d bytes as a tar file %s", + DEBUG(3,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, lname)); @@ -1230,7 +1355,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_size += finfo.size; /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(2,("(%g kb/s) (average %g kb/s)\n", + DEBUG(3,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); if (tar_noisy) @@ -1265,7 +1390,14 @@ static void do_tar(file_info *finfo) strcat(exclaim, "\\"); strcat(exclaim, finfo->name); - if (clipfind(cliplist, clipn, exclaim)) { + DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); + + if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || +#ifdef HAVE_REGEX_H + (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { +#else + (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) { +#endif DEBUG(3,("Skipping file %s\n", exclaim)); return; } @@ -1345,9 +1477,197 @@ static void unfixtarname(char *tptr, char *fp, int l) } } -static void do_tarput(void) +/**************************************************************************** +Move to the next block in the buffer, which may mean read in another set of +blocks. +****************************************************************************/ +static int next_block(char *ltarbuf, char *bufferp, int bufsiz) { - file_info finfo; + int bufread, total = 0; + + if (bufferp >= (ltarbuf + bufsiz)) { + + for (bufread = read(tarhandle, ltarbuf, bufsiz); total < bufsiz; total += bufread) { + + if (bufread <= 0) { /* An error, return false */ + return (total > 0 ? -2 : bufread); + } + + } + + bufferp = ltarbuf; + + } + else { + + bufferp += TBLOCK; + + } + + return(0); + +} + +static int skip_file(int skip) +{ + + return(0); +} + +static int get_file(file_info2 finfo) +{ + + return(0); + +} + +static int get_dir(file_info2 finfo) +{ + + return(0); + +} + +static char * get_longfilename(file_info2 finfo) +{ + + return(NULL); + +} + +static char * bufferp; + +static void do_tarput2(void) +{ + file_info2 finfo, *finfo2; + struct timeval tp_start; + char *inbuf, *outbuf, *longfilename = NULL; + int skip = False; + + GetTimeOfDay(&tp_start); + + bufferp = tarbuf + tbufsiz; /* init this to force first read */ + + if (push_dir(&dir_stack, &finfo)) { + + finfo2 = pop_dir(&dir_stack); + inbuf = top_dir_name(&dir_stack); /* FIXME */ + if (sub_dir(inbuf, finfo2 -> name)){ + + DEBUG(0, ("")); + + } + } + + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); + + if (!inbuf || !outbuf) { + + DEBUG(0, ("Out of memory during allocate of inbuf and outbuf!\n")); + return; + + } + + if (next_block(tarbuf, bufferp, tbufsiz) <= 0) { + + DEBUG(0, ("Empty file or short tar file: %s\n", strerror(errno))); + + } + + /* Now read through those files ... */ + + while (True) { + + switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { + + case -2: /* Hmm, not good, but not fatal */ + DEBUG(0, ("Skipping %s...\n", finfo.name)); + if ((next_block(tarbuf, bufferp, tbufsiz) <= 0) && + !skip_file(finfo.size)) { + + DEBUG(0, ("Short file, bailing out...\n")); + free(inbuf); free(outbuf); + continue; + + } + + break; + + case -1: + DEBUG(0, ("abandoning restore, -1 from read tar header\n")); + free(inbuf); free(outbuf); + return; + + case 0: /* chksum is zero - looks like an EOF */ + DEBUG(0, ("total of %d tar files restored to share\n", ntarf)); + free(inbuf); free(outbuf); + return; /* Hmmm, bad here ... */ + + default: + break; + + } + + /* Now, do we have a long file name? */ + + if (longfilename != NULL) { + if (strlen(longfilename) < sizeof(finfo.name)) { /* if we have space */ + + strncpy(finfo.name, longfilename, sizeof(finfo.name) - 1); + free(longfilename); + longfilename = NULL; + + } + else { + + DEBUG(0, ("filename: %s too long, skipping\n", strlen(longfilename))); + skip = True; + + } + } + + /* Well, now we have a header, process the file ... */ + + /* Should we skip the file? */ + + if (skip) { + + skip_file(finfo.size); + continue; + + } + + /* We only get this far if we should process the file */ + + switch (((union hblock *)bufferp) -> dbuf.linkflag) { + + case '0': /* Should use symbolic names--FIXME */ + get_file(finfo); + break; + + case '5': + get_dir(finfo); + break; + + case 'L': + longfilename = get_longfilename(finfo); + break; + + default: + skip_file(finfo.size); /* Don't handle these yet */ + break; + + } + + } + + +} + +static void do_tarput() +{ + file_info2 finfo; int nread=0, bufread; char *inbuf,*outbuf, *longname = NULL; int fsize=0; @@ -1355,6 +1675,8 @@ static void do_tarput(void) struct timeval tp_start; BOOL tskip=False; /* We'll take each file as it comes */ + finfo.name = NULL; /* No name in here ... */ + GetTimeOfDay(&tp_start); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1372,7 +1694,7 @@ static void do_tarput(void) /* These should be the only reads in clitar.c */ while ((bufread=read(tarhandle, tarbuf, tbufsiz))>0) { - char *bufferp, *endofbuffer; + char *buffer_p, *endofbuffer; int chunk; /* Code to handle a short read. @@ -1394,13 +1716,13 @@ static void do_tarput(void) if (lread<=0) break; } - bufferp=tarbuf; + buffer_p=tarbuf; endofbuffer=tarbuf+bufread; if (tskip) { if (fsize= endofbuffer) { + if (buffer_p >= endofbuffer) { bufread = read(tarhandle, tarbuf, tbufsiz); - bufferp = tarbuf; + buffer_p = tarbuf; } next_header = 0; /* Don't want the next one ... */ - switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) + + if (finfo.name != NULL) { /* Free the space */ + + free(finfo.name); + finfo.name = NULL; + + } + switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ DEBUG(0, ("skipping %s...\n", finfo.name)); - bufferp+=TBLOCK; /* header - like a link */ + buffer_p+=TBLOCK; /* header - like a link */ continue; case -1: DEBUG(0, ("abandoning restore, -1 from readtarheader\n")); @@ -1451,7 +1780,10 @@ static void do_tarput(void) if (longname != NULL) { - strncpy(finfo.name, longname, sizeof(pstring) - 1); + free(finfo.name); /* Free the name in the finfo */ + finfo.name = string_create_s(strlen(longname) + 2); + strncpy(finfo.name, longname, strlen(longname) + 1); + DEBUG(5, ("Long name = \"%s\", filename=\"%s\"\n", longname, finfo.name)); free(longname); longname = NULL; @@ -1460,12 +1792,13 @@ static void do_tarput(void) /* Check if a long-link. We do this before the clip checking because clip-checking should clip on real name - RJS */ - if (((union hblock *)bufferp) -> dbuf.linkflag == 'L') { + if (((union hblock *)buffer_p) -> dbuf.linkflag == 'L') { /* Skip this header, but pick up length, get the name and fix the name and skip the name. Hmmm, what about end of buffer??? */ + DEBUG(5, ("Buffer size = %i\n", finfo.size + strlen(cur_dir) +1)); longname = malloc(finfo.size + strlen(cur_dir) + 1); if (longname == NULL) { @@ -1476,44 +1809,50 @@ static void do_tarput(void) return; } - bufferp += TBLOCK; /* Skip that longlink header */ + buffer_p += TBLOCK; /* Skip that longlink header */ /* This needs restructuring ... */ - if (bufferp >= endofbuffer) { + if (buffer_p >= endofbuffer) { bufread = read(tarhandle, tarbuf, tbufsiz); - bufferp = tarbuf; + buffer_p = tarbuf; } - strncpy(longname, cur_dir, strlen(cur_dir)); - unfixtarname(longname+strlen(cur_dir), bufferp, finfo.size); + strncpy(longname, cur_dir, strlen(cur_dir) + 1); + unfixtarname(longname+strlen(cur_dir), buffer_p, finfo.size); + DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, buffer_p)); /* Next rounds up to next TBLOCK and takes care of us being right on a TBLOCK boundary */ - bufferp += (((finfo.size - 1)/TBLOCK)+1)*TBLOCK; + buffer_p += (((finfo.size - 1)/TBLOCK)+1)*TBLOCK; next_header = 1; /* Force read of next header */ } } tskip=clipn - && (clipfind(cliplist, clipn, finfo.name) ^ tar_excl); + && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) +#ifdef HAVE_REGEX_H + || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); +#else + || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); +#endif if (tskip) { - bufferp+=TBLOCK; + buffer_p+=TBLOCK; if (finfo.mode & aDIR) continue; else if ((fsize=finfo.size) % TBLOCK) { fsize+=TBLOCK-(fsize%TBLOCK); } - if (fsize= endofbuffer) break; + if ((buffer_p+=TBLOCK) >= endofbuffer) break; } /* if (!fsize) */ /* write out the file in chunk sized chunks - don't * go past end of buffer though */ - chunk=(fsize-nread < endofbuffer - bufferp) - ? fsize - nread : endofbuffer - bufferp; + chunk=(fsize-nread < endofbuffer - buffer_p) + ? fsize - nread : endofbuffer - buffer_p; while (chunk > 0) { int minichunk=MIN(chunk, max_xmit-200); @@ -1587,7 +1927,7 @@ static void do_tarput(void) nread, /* offset low */ 0, /* offset high - not implemented */ fsize-nread, /* left - only hint to server */ - bufferp, + buffer_p, inbuf, outbuf)) { @@ -1597,7 +1937,7 @@ static void do_tarput(void) } DEBUG(5, ("chunk writing fname=%s fnum=%d nread=%d minichunk=%d chunk=%d size=%d\n", finfo.name, fnum, nread, minichunk, chunk, fsize)); - bufferp+=minichunk; nread+=minichunk; + buffer_p+=minichunk; nread+=minichunk; chunk-=minichunk; } @@ -1609,13 +1949,14 @@ static void do_tarput(void) free(inbuf);free(outbuf); return; } - if (fsize % TBLOCK) bufferp+=TBLOCK - (fsize % TBLOCK); - DEBUG(5, ("bufferp is now %d (psn=%d)\n", - (long) bufferp, (long)(bufferp - tarbuf))); + if (fsize % TBLOCK) buffer_p+=TBLOCK - (fsize % TBLOCK); + DEBUG(5, ("buffer_p is now %d (psn=%d)\n", + (long) buffer_p, (long)(buffer_p - tarbuf))); ntarf++; fsize=0; + } - } while (bufferp < endofbuffer); + } while (buffer_p < endofbuffer); } DEBUG(0, ("premature eof on tar file ?\n")); @@ -1780,7 +2121,12 @@ int process_tar(char *inbuf, char *outbuf) initarbuf(); switch(tar_type) { case 'x': + +#ifdef 0 + do_tarput2(); +#else do_tarput(); +#endif free(tarbuf); close(tarhandle); break; @@ -1791,7 +2137,7 @@ int process_tar(char *inbuf, char *outbuf) pstring tarmac; for (i=0; i=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); -- cgit From 9f57f01b144b030274cc5d116b864b3c27f251ef Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 8 May 1998 16:59:30 +0000 Subject: clitar.c: #ifdef'ed out all the bits that were giving 'defined but not used' messages. nttrans.c: More updates. smb.h: Removed stuff that didn't belong in the smb_passwd struct. Persuaded Luke to use a new structure. web/swat.c: Fixed gcc complaints about shadowing global 'string'. Jeremy. (This used to be commit 61c1dbb9785ed1e6fe40f93c7cc65024884df6f5) --- source3/client/clitar.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c0325c37e5..98364b77ed 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -142,6 +142,8 @@ static void unfixtarname(char *tptr, char *fp, int l); * tar specific utitlities */ +#if 0 /* Removed to get around gcc 'defined but not used' error. */ + /* * Stack routines, push_dir, pop_dir, top_dir_name */ @@ -186,6 +188,8 @@ static BOOL sub_dir(char *dir1, char *dir2) } +#endif /* Removed to get around gcc 'defined but not used' error. */ + /* Create a string of size size+1 (for the null) */ static char * string_create_s(int size) { @@ -1477,6 +1481,8 @@ static void unfixtarname(char *tptr, char *fp, int l) } } +#if 0 /* Removed to get around gcc 'defined but not used' error. */ + /**************************************************************************** Move to the next block in the buffer, which may mean read in another set of blocks. @@ -1664,6 +1670,7 @@ static void do_tarput2(void) } +#endif /* Removed to get around gcc 'defined but not used' error. */ static void do_tarput() { -- cgit From 3dfc0c847240ac7e12c39f4ed9c31a888949ade1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 May 1998 06:38:36 +0000 Subject: changed to use slprintf() instead of sprintf() just about everywhere. I've implemented slprintf() as a bounds checked sprintf() using mprotect() and a non-writeable page. This should prevent any sprintf based security holes. (This used to be commit ee09e9dadb69aaba5a751dd20ccc6d587d841bd6) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 98364b77ed..69a8c9823b 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -2129,7 +2129,7 @@ int process_tar(char *inbuf, char *outbuf) switch(tar_type) { case 'x': -#ifdef 0 +#if 0 do_tarput2(); #else do_tarput(); -- cgit From f888868f46a5418bac9ab528497136c152895305 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 00:55:32 +0000 Subject: This is a security audit change of the main source. It removed all ocurrences of the following functions : sprintf strcpy strcat The replacements are slprintf, safe_strcpy and safe_strcat. It should not be possible to use code in Samba that uses sprintf, strcpy or strcat, only the safe_equivalents. Once Andrew has fixed the slprintf implementation then this code will be moved back to the 1.9.18 code stream. Jeremy. (This used to be commit 2d774454005f0b54e5684cf618da7060594dfcbb) --- source3/client/clitar.c | 84 ++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 69a8c9823b..04d435eca7 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -248,7 +248,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, /* write out a "standard" tar format header */ hb.dbuf.name[NAMSIZ-1]='\0'; - strcpy(hb.dbuf.mode, amode); + fstrcpy(hb.dbuf.mode, amode); oct_it(0L, 8, hb.dbuf.uid); oct_it(0L, 8, hb.dbuf.gid); oct_it((long) size, 13, hb.dbuf.size); @@ -309,7 +309,7 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) } - strcpy(finfo->name, prefix); + pstrcpy(finfo->name, prefix); /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ unfixtarname(finfo->name + strlen(prefix), hb->dbuf.name, @@ -574,9 +574,9 @@ static int do_setrtime(char *fname, int mtime) } - strcpy(name, fname); - strcpy(fname, "\\"); - strcat(fname, name); + pstrcpy(name, fname); + pstrcpy(fname, "\\"); + pstrcat(fname, name); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -599,7 +599,7 @@ static int do_setrtime(char *fname, int mtime) p = smb_buf(outbuf); *p++ = 4; - strcpy(p, fname); + pstrcpy(p, fname); p+= (strlen(fname)+1); *p++ = 4; @@ -634,9 +634,9 @@ static int do_setrattr(char *fname, int attr, int setit) pstring name; int fattr; - strcpy(name,fname); - strcpy(fname,"\\"); - strcat(fname,name); + pstrcpy(name,fname); + pstrcpy(fname,"\\"); + pstrcat(fname,name); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -657,7 +657,7 @@ static int do_setrattr(char *fname, int attr, int setit) p = smb_buf(outbuf); *p++ = 4; - strcpy(p,fname); + pstrcpy(p,fname); p += (strlen(fname)+1); *p++ = 4; @@ -695,7 +695,7 @@ static int do_setrattr(char *fname, int attr, int setit) p = smb_buf(outbuf); *p++ = 4; - strcpy(p,fname); + pstrcpy(p,fname); p += (strlen(fname)+1); *p++ = 4; @@ -736,7 +736,7 @@ static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) p = smb_buf(outbuf); *p++ = 4; - strcpy(p,finfo.name); + pstrcpy(p,finfo.name); send_smb(Client,outbuf); client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); @@ -844,7 +844,7 @@ static BOOL smbchkpath(char *fname, char *inbuf, char *outbuf) p = smb_buf(outbuf); *p++ = 4; - strcpy(p,fname); + pstrcpy(p,fname); send_smb(Client,outbuf); client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); @@ -871,7 +871,7 @@ static BOOL smbmkdir(char *fname, char *inbuf, char *outbuf) p = smb_buf(outbuf); *p++ = 4; - strcpy(p,fname); + pstrcpy(p,fname); send_smb(Client,outbuf); client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); @@ -913,7 +913,7 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) /* fname copied to ffname so can strtok */ - strcpy(ffname, fname); + pstrcpy(ffname, fname); /* do a `basename' on ffname, so don't try and make file name directory */ if ((basehack=strrchr(ffname, '\\')) == NULL) @@ -925,7 +925,7 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) while (p) { - strcat(partpath, p); + pstrcat(partpath, p); if (!smbchkpath(partpath, inbuf, outbuf)) { if (!smbmkdir(partpath, inbuf, outbuf)) @@ -938,7 +938,7 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) } - strcat(partpath, "\\"); + pstrcat(partpath, "\\"); p = strtok(NULL,"/\\"); } @@ -1014,7 +1014,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) SSVAL(outbuf,smb_vwv8,1); p = smb_buf(outbuf); - strcpy(p,rname); + pstrcpy(p,rname); p = skip_string(p,1); dos_clean_name(rname); @@ -1052,7 +1052,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) return; } - strcpy(finfo.name,rname); + pstrcpy(finfo.name,rname); if (!finfo1) { finfo.mode = SVAL(inbuf,smb_vwv3); @@ -1388,11 +1388,11 @@ static void do_tar(file_info *finfo) if (!tar_excl && clipn) { pstring exclaim; - strcpy(exclaim, cur_dir); + pstrcpy(exclaim, cur_dir); *(exclaim+strlen(exclaim)-1)='\0'; - strcat(exclaim, "\\"); - strcat(exclaim, finfo->name); + pstrcat(exclaim, "\\"); + pstrcat(exclaim, finfo->name); DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); @@ -1422,10 +1422,10 @@ static void do_tar(file_info *finfo) return; } - strcpy(saved_curdir,cur_dir); + pstrcpy(saved_curdir,cur_dir); - strcat(cur_dir,finfo->name); - strcat(cur_dir,"\\"); + pstrcat(cur_dir,finfo->name); + pstrcat(cur_dir,"\\"); DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); @@ -1433,16 +1433,16 @@ static void do_tar(file_info *finfo) * 40755 */ writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); ntarf++; /* Make sure we have a file on there */ - strcpy(mtar_mask,cur_dir); - strcat(mtar_mask,"*"); + pstrcpy(mtar_mask,cur_dir); + pstrcat(mtar_mask,"*"); /* do_dir((char *)inbuf,(char *)outbuf,mtar_mask,attribute,do_tar,recurse,True); */ - strcpy(cur_dir,saved_curdir); + pstrcpy(cur_dir,saved_curdir); free(inbuf);free(outbuf); } else { - strcpy(rname,cur_dir); - strcat(rname,finfo->name); + pstrcpy(rname,cur_dir); + pstrcat(rname,finfo->name); do_atar(rname,finfo->name,finfo); } } @@ -2060,8 +2060,8 @@ void cmd_setmode(char *dum_in, char *dum_out) return; } - strcpy(fname, cur_dir); - strcat(fname, buf); + pstrcpy(fname, cur_dir); + pstrcat(fname, buf); while (next_token(NULL,buf,NULL)) { q=buf; @@ -2153,29 +2153,29 @@ int process_tar(char *inbuf, char *outbuf) if (strrchr(cliplist[i], '\\')) { pstring saved_dir; - strcpy(saved_dir, cur_dir); + pstrcpy(saved_dir, cur_dir); if (*cliplist[i]=='\\') { - strcpy(tarmac, cliplist[i]); + pstrcpy(tarmac, cliplist[i]); } else { - strcpy(tarmac, cur_dir); - strcat(tarmac, cliplist[i]); + pstrcpy(tarmac, cur_dir); + pstrcat(tarmac, cliplist[i]); } - strcpy(cur_dir, tarmac); + pstrcpy(cur_dir, tarmac); *(strrchr(cur_dir, '\\')+1)='\0'; do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); - strcpy(cur_dir,saved_dir); + pstrcpy(cur_dir,saved_dir); } else { - strcpy(tarmac, cur_dir); - strcat(tarmac, cliplist[i]); + pstrcpy(tarmac, cur_dir); + pstrcat(tarmac, cliplist[i]); do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); } } } else { pstring mask; - strcpy(mask,cur_dir); - strcat(mask,"\\*"); + pstrcpy(mask,cur_dir); + pstrcat(mask,"\\*"); do_dir((char *)inbuf,(char *)outbuf,mask,attribute,do_tar,recurse, True); } -- cgit From bbd7ca65e706457f5dbc046e83b4bd8cdde5be8f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Jun 1998 18:25:36 +0000 Subject: clientgen: Added USE_SSL for client shutdown. clitar.c: Added 'Samba style' comments before string_create_s(). loadparm.c: Fixed missing comma in SSL code. util.c: Removed string_create_s(). Currently it's only called from clitar.c and having it here as well as a static in clitar causes the compile to break (Richard, please decide where you want this function). lib/rpc/parse/parse_net.c: Fix from to stop coredump on missing parameter. Jeremy. (This used to be commit d23b44322570cb9a7aa2b86407bf4f91010a237b) --- source3/client/clitar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 04d435eca7..bd42c2677a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -190,7 +190,9 @@ static BOOL sub_dir(char *dir1, char *dir2) #endif /* Removed to get around gcc 'defined but not used' error. */ -/* Create a string of size size+1 (for the null) */ +/******************************************************************* +Create a string of size size+1 (for the null) +*******************************************************************/ static char * string_create_s(int size) { char *tmp; -- cgit From c47cce6dd9553990a5b715befde94b99df7163c6 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 17 Jun 1998 01:52:57 +0000 Subject: Re-submit changes for CLITAR. Have fixed the location of create_string_s back to clitar.c, and have added Jay Berkenbilt's changes. Have used safe_strcpy and safe_strcat everywhere and have tested with long file names extensively, but have not yet been able to check that it works OK on Solaris. (This used to be commit daf239a1881d5be4669759e972fbbf07e8e38893) --- source3/client/clitar.c | 375 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 291 insertions(+), 84 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index bd42c2677a..412af8fa83 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -3,6 +3,7 @@ Version 1.9. Tar Extensions Copyright (C) Ricky Poulten 1995-1998 + Copyright (C) Richard Sharpe 1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,8 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* The following changes developed by Richard Sharpe for Canon Information - Systems Research Australia (CISRA) are Copyright (C) 1998 by CISRA and are - made available under the terms of the GPL as listed above: + Systems Research Australia (CISRA) 1. Restore can now restore files with long file names 2. Save now saves directory information so that we can restore @@ -97,7 +97,7 @@ BOOL tar_re_search=False; regex_t *preg; #endif /* Dump files with System attribute */ -BOOL tar_system=False; +BOOL tar_system=True; /* Dump files with Hidden attribute */ BOOL tar_hidden=True; /* Be noisy - make a catalogue */ @@ -106,6 +106,7 @@ BOOL tar_noisy=True; char tar_type='\0'; static char **cliplist=NULL; static int clipn=0; +static BOOL must_free_cliplist = False; extern file_info def_finfo; extern BOOL lowercase; @@ -136,7 +137,7 @@ static int do_setrattr(char *fname, int attr, int setit); static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix); static long unoct(char *p, int ndgs); static void do_tarput(void); -static void unfixtarname(char *tptr, char *fp, int l); +static void unfixtarname(char *tptr, char *fp, int l, BOOL first); /* * tar specific utitlities @@ -193,7 +194,7 @@ static BOOL sub_dir(char *dir1, char *dir2) /******************************************************************* Create a string of size size+1 (for the null) *******************************************************************/ -static char * string_create_s(int size) +static char *string_create_s(int size) { char *tmp; @@ -234,7 +235,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, } writetarheader(f, "/./@LongLink", l+1, 0, " 0 \0", 'L'); memset(b, 0, l+TBLOCK+100); - fixtarname(b, aname, l+1); + fixtarname(b, aname, l); i = strlen(b)+1; DEBUG(5, ("File name in tar file: %s, size=%i, \n", b, strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); @@ -250,7 +251,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, /* write out a "standard" tar format header */ hb.dbuf.name[NAMSIZ-1]='\0'; - fstrcpy(hb.dbuf.mode, amode); + safe_strcpy(hb.dbuf.mode, amode, strlen(amode)); oct_it(0L, 8, hb.dbuf.uid); oct_it(0L, 8, hb.dbuf.gid); oct_it((long) size, 13, hb.dbuf.size); @@ -301,6 +302,12 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) if (fchk != chk) { DEBUG(0, ("checksums don't match %d %d\n", fchk, chk)); + for (i = 0; i < sizeof(hb -> dummy); i++) { + fprintf(stdout, "%2X ", hb -> dummy[i]); + } + fprintf(stdout, "\n"); + fprintf(stdout, "%s\n", hb -> dummy); + fprintf(stdout, "Tarbuf = %X, hb = %X\n", tarbuf, hb); return -1; } @@ -311,11 +318,11 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) } - pstrcpy(finfo->name, prefix); + safe_strcpy(finfo->name, prefix, strlen(prefix) + strlen(hb -> dbuf.name) + 3); /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ unfixtarname(finfo->name + strlen(prefix), hb->dbuf.name, - strlen(hb->dbuf.name) + 1); + strlen(hb->dbuf.name) + 1, True); /* can't handle some links at present */ if ((hb->dbuf.linkflag != '0') && (hb -> dbuf.linkflag != '5')) { @@ -576,9 +583,8 @@ static int do_setrtime(char *fname, int mtime) } - pstrcpy(name, fname); - pstrcpy(fname, "\\"); - pstrcat(fname, name); + safe_strcpy(name, "\\", strlen(fname) + 1); + safe_strcat(name, fname, strlen(fname) + 1); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -586,12 +592,13 @@ static int do_setrtime(char *fname, int mtime) if (!inbuf || !outbuf) { DEBUG(0, ("Could not allocate memory for inbuf or outbuf while changing time on: %s\n", fname)); + free(name); return False; } memset(outbuf, 0, smb_size); - set_message(outbuf, 8, 4 + strlen(fname), True); + set_message(outbuf, 8, 4 + strlen(name), True); CVAL(outbuf, smb_com) = SMBsetatr; SSVAL(outbuf, smb_tid, cnum); cli_setup_pkt(outbuf); @@ -601,7 +608,7 @@ static int do_setrtime(char *fname, int mtime) p = smb_buf(outbuf); *p++ = 4; - pstrcpy(p, fname); + safe_strcpy(p, name, strlen(name)); p+= (strlen(fname)+1); *p++ = 4; @@ -614,10 +621,11 @@ static int do_setrtime(char *fname, int mtime) { DEBUG(0,("%s setting attributes on file %s\n", smb_errstr(inbuf), fname)); - free(inbuf);free(outbuf); + free(name);free(inbuf);free(outbuf); return(False); } + free(name); free(inbuf);free(outbuf); return(True); @@ -633,12 +641,19 @@ static int do_setrattr(char *fname, int attr, int setit) */ char *inbuf,*outbuf; char *p; - pstring name; + char *name; int fattr; - pstrcpy(name,fname); - pstrcpy(fname,"\\"); - pstrcat(fname,name); + name = (char *)malloc(strlen(fname) + 1 + 1); + if (name == NULL) { + + DEBUG(0, ("Failed to allocate space in do_setrattr while setting time on file: %s", fname)); + return False; + + } + + safe_strcpy(name, "\\", strlen(fname) + 1); + safe_strcat(name, fname, strlen(fname) + 1); inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -646,6 +661,7 @@ static int do_setrattr(char *fname, int attr, int setit) if (!inbuf || !outbuf) { DEBUG(0,("out of memory\n")); + free(name); return False; } @@ -659,8 +675,8 @@ static int do_setrattr(char *fname, int attr, int setit) p = smb_buf(outbuf); *p++ = 4; - pstrcpy(p,fname); - p += (strlen(fname)+1); + safe_strcpy(p,name, strlen(name)); + p += (strlen(name)+1); *p++ = 4; *p++ = 0; @@ -688,7 +704,7 @@ static int do_setrattr(char *fname, int attr, int setit) /* clear out buffer and start again */ memset(outbuf,0,smb_size); - set_message(outbuf,8,4 + strlen(fname),True); + set_message(outbuf,8,4 + strlen(name),True); CVAL(outbuf,smb_com) = SMBsetatr; SSVAL(outbuf,smb_tid,cnum); cli_setup_pkt(outbuf); @@ -697,8 +713,8 @@ static int do_setrattr(char *fname, int attr, int setit) p = smb_buf(outbuf); *p++ = 4; - pstrcpy(p,fname); - p += (strlen(fname)+1); + safe_strcpy(p,name, strlen(name)); + p += (strlen(name)+1); *p++ = 4; *p++ = 0; @@ -709,11 +725,12 @@ static int do_setrattr(char *fname, int attr, int setit) if (CVAL(inbuf,smb_rcls) != 0) { DEBUG(0,("%s setting attributes on file %s\n", - smb_errstr(inbuf), fname)); - free(inbuf);free(outbuf); + smb_errstr(inbuf), name)); + free(name);free(inbuf);free(outbuf); return(False); } + free(name); free(inbuf);free(outbuf); return(True); } @@ -738,7 +755,7 @@ static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) p = smb_buf(outbuf); *p++ = 4; - pstrcpy(p,finfo.name); + safe_strcpy(p,finfo.name, strlen(finfo.name)); send_smb(Client,outbuf); client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); @@ -846,7 +863,7 @@ static BOOL smbchkpath(char *fname, char *inbuf, char *outbuf) p = smb_buf(outbuf); *p++ = 4; - pstrcpy(p,fname); + safe_strcpy(p,fname, strlen(fname)); send_smb(Client,outbuf); client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); @@ -873,7 +890,7 @@ static BOOL smbmkdir(char *fname, char *inbuf, char *outbuf) p = smb_buf(outbuf); *p++ = 4; - pstrcpy(p,fname); + safe_strcpy(p,fname, strlen(fname)); send_smb(Client,outbuf); client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); @@ -915,7 +932,7 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) /* fname copied to ffname so can strtok */ - pstrcpy(ffname, fname); + safe_strcpy(ffname, fname, strlen(fname)); /* do a `basename' on ffname, so don't try and make file name directory */ if ((basehack=strrchr(ffname, '\\')) == NULL) @@ -927,7 +944,7 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) while (p) { - pstrcat(partpath, p); + safe_strcat(partpath, p, strlen(fname) + 1); if (!smbchkpath(partpath, inbuf, outbuf)) { if (!smbmkdir(partpath, inbuf, outbuf)) @@ -940,7 +957,7 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) } - pstrcat(partpath, "\\"); + safe_strcat(partpath, "\\", strlen(fname) + 1); p = strtok(NULL,"/\\"); } @@ -975,7 +992,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) uint32 nread=0; char *p, ftype; char *inbuf,*outbuf; - file_info finfo; + file_info2 finfo; BOOL close_done = False; BOOL shallitime=True; BOOL ignore_close_error = False; @@ -987,10 +1004,25 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) ftype = '0'; /* An ordinary file ... */ - if (finfo1) - finfo = *finfo1; - else - finfo = def_finfo; + if (finfo1) { + finfo.size = finfo1 -> size; + finfo.mode = finfo1 -> mode; + finfo.uid = finfo1 -> uid; + finfo.gid = finfo1 -> gid; + finfo.mtime = finfo1 -> mtime; + finfo.atime = finfo1 -> atime; + finfo.ctime = finfo1 -> ctime; + } + 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; + } + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1016,7 +1048,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) SSVAL(outbuf,smb_vwv8,1); p = smb_buf(outbuf); - pstrcpy(p,rname); + safe_strcpy(p, rname, strlen(rname)); p = skip_string(p,1); dos_clean_name(rname); @@ -1054,7 +1086,16 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) return; } - pstrcpy(finfo.name,rname); + finfo.name = string_create_s(strlen(rname)); + if (finfo.name == NULL) { + + DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); + free(inbuf); free(outbuf); + return; + + } + + safe_strcpy(finfo.name,rname, strlen(rname)); if (!finfo1) { finfo.mode = SVAL(inbuf,smb_vwv3); @@ -1390,11 +1431,13 @@ static void do_tar(file_info *finfo) if (!tar_excl && clipn) { pstring exclaim; - pstrcpy(exclaim, cur_dir); + DEBUG(5, ("Excl: strlen(cur_dir) = %i\n", strlen(cur_dir))); + + safe_strcpy(exclaim, cur_dir, sizeof(pstring)); *(exclaim+strlen(exclaim)-1)='\0'; - pstrcat(exclaim, "\\"); - pstrcat(exclaim, finfo->name); + safe_strcat(exclaim, "\\", sizeof(pstring)); + safe_strcat(exclaim, finfo->name, sizeof(exclaim)); DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); @@ -1424,27 +1467,34 @@ static void do_tar(file_info *finfo) return; } - pstrcpy(saved_curdir,cur_dir); + safe_strcpy(saved_curdir, cur_dir, sizeof(saved_curdir)); + + DEBUG(5, ("Sizeof(cur_dir)=%i, strlen(cur_dir)=%i, strlen(finfo->name)=%i\nname=%s,cur_dir=%s\n", sizeof(cur_dir), strlen(cur_dir), strlen(finfo->name), finfo->name, cur_dir)); - pstrcat(cur_dir,finfo->name); - pstrcat(cur_dir,"\\"); + safe_strcat(cur_dir,finfo->name, sizeof(cur_dir)); + safe_strcat(cur_dir,"\\", sizeof(cur_dir)); DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); /* write a tar directory, don't bother with mode - just set it to * 40755 */ writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); + if (tar_noisy) { + + printf(" directory %s\n", cur_dir); + + } ntarf++; /* Make sure we have a file on there */ - pstrcpy(mtar_mask,cur_dir); - pstrcat(mtar_mask,"*"); + safe_strcpy(mtar_mask,cur_dir, sizeof(pstring)); + safe_strcat(mtar_mask,"*", sizeof(pstring)); /* do_dir((char *)inbuf,(char *)outbuf,mtar_mask,attribute,do_tar,recurse,True); */ - pstrcpy(cur_dir,saved_curdir); + safe_strcpy(cur_dir,saved_curdir, sizeof(pstring)); free(inbuf);free(outbuf); } else { - pstrcpy(rname,cur_dir); - pstrcat(rname,finfo->name); + safe_strcpy(rname,cur_dir, sizeof(pstring)); + safe_strcat(rname,finfo->name, sizeof(pstring)); do_atar(rname,finfo->name,finfo); } } @@ -1452,14 +1502,24 @@ static void do_tar(file_info *finfo) /**************************************************************************** Convert from UNIX to DOS file names ***************************************************************************/ -static void unfixtarname(char *tptr, char *fp, int l) +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. + * dos \'s in path. Kill any absolute path names. But only if first! */ - if (*fp == '.') fp++; - if (*fp == '\\' || *fp == '/') fp++; + DEBUG(5, ("firstb=%X, secondb=%X, len=%i\n", tptr, fp, l)); + + if (first) { + if (*fp == '.') { + fp++; + l--; + } + if (*fp == '\\' || *fp == '/') { + fp++; + l--; + } + } while (l > 0) { int skip; @@ -1760,6 +1820,7 @@ static void do_tarput() finfo.name = NULL; } + DEBUG(5, ("Tarbuf=%X, buffer=%X, endofbuf=%X\n", tarbuf, buffer_p, endofbuffer)); switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ @@ -1802,12 +1863,12 @@ static void do_tarput() because clip-checking should clip on real name - RJS */ if (((union hblock *)buffer_p) -> dbuf.linkflag == 'L') { + int file_len, first = 0; char *cp; /* Skip this header, but pick up length, get the name and fix the name and skip the name. Hmmm, what about end of buffer??? */ - DEBUG(5, ("Buffer size = %i\n", finfo.size + strlen(cur_dir) +1)); longname = malloc(finfo.size + strlen(cur_dir) + 1); if (longname == NULL) { @@ -1822,24 +1883,30 @@ static void do_tarput() /* This needs restructuring ... */ - if (buffer_p >= endofbuffer) { + strncpy(longname, cur_dir, strlen(cur_dir) + 1); + cp = longname + strlen(cur_dir); + file_len = finfo.size; - bufread = read(tarhandle, tarbuf, tbufsiz); + while (file_len > 0) { - buffer_p = tarbuf; + if (buffer_p >= endofbuffer) { - } + bufread = read(tarhandle, tarbuf, tbufsiz); - strncpy(longname, cur_dir, strlen(cur_dir) + 1); - unfixtarname(longname+strlen(cur_dir), buffer_p, finfo.size); - DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, buffer_p)); + buffer_p = tarbuf; - /* Next rounds up to next TBLOCK and takes care of us being right - on a TBLOCK boundary */ + } - buffer_p += (((finfo.size - 1)/TBLOCK)+1)*TBLOCK; - next_header = 1; /* Force read of next header */ + unfixtarname(cp, buffer_p, file_len >= TBLOCK?TBLOCK:file_len, first == 0); + first++; /* Not the first anymore */ + cp = cp + strlen(cp); /* Move to end of string */ + buffer_p += TBLOCK; + file_len -= TBLOCK; + + next_header = 1; /* Force read of next header */ + + } } } tskip=clipn @@ -1872,6 +1939,8 @@ static void do_tarput() { DEBUG(5, ("Creating directory: %s\n", finfo.name)); + DEBUG(0, ("restore tar dir %s of size %d bytes\n", + finfo.name, finfo.size)); if (!ensurepath(finfo.name, inbuf, outbuf)) { @@ -1883,7 +1952,7 @@ static void do_tarput() { /* Now we update the creation date ... */ - DEBUG(0, ("Updating creation date on %s\n", finfo.name)); + DEBUG(5, ("Updating creation date on %s\n", finfo.name)); if (!do_setrtime(finfo.name, finfo.mtime)) { @@ -1909,7 +1978,7 @@ static void do_tarput() } DEBUG(0 ,("restore tar file %s of size %d bytes\n", - finfo.name,finfo.size)); + finfo.name, finfo.size)); /* if (!finfo.size) { if (!smbshut(finfo, fnum, inbuf, outbuf)){ @@ -2062,8 +2131,8 @@ void cmd_setmode(char *dum_in, char *dum_out) return; } - pstrcpy(fname, cur_dir); - pstrcat(fname, buf); + safe_strcpy(fname, cur_dir, sizeof(pstring)); + safe_strcat(fname, buf, sizeof(pstring)); while (next_token(NULL,buf,NULL)) { q=buf; @@ -2155,29 +2224,29 @@ int process_tar(char *inbuf, char *outbuf) if (strrchr(cliplist[i], '\\')) { pstring saved_dir; - pstrcpy(saved_dir, cur_dir); + safe_strcpy(saved_dir, cur_dir, sizeof(pstring)); if (*cliplist[i]=='\\') { - pstrcpy(tarmac, cliplist[i]); + safe_strcpy(tarmac, cliplist[i], sizeof(pstring)); } else { - pstrcpy(tarmac, cur_dir); - pstrcat(tarmac, cliplist[i]); + safe_strcpy(tarmac, cur_dir, sizeof(pstring)); + safe_strcat(tarmac, cliplist[i], sizeof(pstring)); } - pstrcpy(cur_dir, tarmac); + safe_strcpy(cur_dir, tarmac, sizeof(pstring)); *(strrchr(cur_dir, '\\')+1)='\0'; do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); - pstrcpy(cur_dir,saved_dir); + safe_strcpy(cur_dir,saved_dir, sizeof(pstring)); } else { - pstrcpy(tarmac, cur_dir); - pstrcat(tarmac, cliplist[i]); + safe_strcpy(tarmac, cur_dir, sizeof(pstring)); + safe_strcat(tarmac, cliplist[i], sizeof(pstring)); do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); } } } else { pstring mask; - pstrcpy(mask,cur_dir); - pstrcat(mask,"\\*"); + safe_strcpy(mask,cur_dir, sizeof(pstring)); + safe_strcat(mask,"\\*", sizeof(pstring)); do_dir((char *)inbuf,(char *)outbuf,mask,attribute,do_tar,recurse, True); } @@ -2190,6 +2259,17 @@ int process_tar(char *inbuf, char *outbuf) break; } + if (must_free_cliplist) { + int i; + for (i = 0; i < clipn; ++i) { + free(cliplist[i]); + } + free(cliplist); + cliplist = NULL; + clipn = 0; + must_free_cliplist = False; + } + return(0); } @@ -2215,6 +2295,115 @@ int clipfind(char **aret, int ret, char *tok) return 0; } +/**************************************************************************** +Read list of files to include from the file and initialize cliplist +accordingly. +***************************************************************************/ +static int read_inclusion_file(char *filename) +{ + FILE *inclusion = NULL; + char buf[MAXPATHLEN + 1]; + char *inclusion_buffer = NULL; + int inclusion_buffer_size = 0; + int inclusion_buffer_sofar = 0; + char *p; + char *tmpstr; + int i; + int result = 0; + int error = 0; + + clipn = 0; + buf[MAXPATHLEN] = '\0'; /* guarantee null-termination */ + if ((inclusion = 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. + */ + DEBUG(0,("Unable to open inclusion file %s\n", filename)); + return 0; + } + + while ((! error) && (fgets(buf, sizeof(buf)-1, inclusion))) { + if (inclusion_buffer == NULL) { + inclusion_buffer_size = 1024; + if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) { + DEBUG(0,("failure allocating buffer to read inclusion file\n")); + error = 1; + break; + } + } + + if (buf[strlen(buf)-1] == '\n') { + buf[strlen(buf)-1] = '\0'; + } + + if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) { + inclusion_buffer_size *= 2; + inclusion_buffer = Realloc(inclusion_buffer,inclusion_buffer_size); + if (! inclusion_buffer) { + DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", + inclusion_buffer_size)); + error = 1; + break; + } + } + + safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar); + inclusion_buffer_sofar += strlen(buf) + 1; + clipn++; + } + fclose(inclusion); + + if (! error) { + /* Allocate an array of clipn + 1 char*'s for cliplist */ + cliplist = malloc((clipn + 1) * sizeof(char *)); + if (cliplist == NULL) { + DEBUG(0,("failure allocating memory for cliplist\n")); + error = 1; + } else { + cliplist[clipn] = NULL; + p = inclusion_buffer; + for (i = 0; (! error) && (i < clipn); i++) { + /* set current item to NULL so array will be null-terminated even if + * malloc fails below. */ + cliplist[i] = NULL; + if ((tmpstr = (char *)malloc(strlen(p)+1)) == NULL) { + DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i)); + error = 1; + } else { + unfixtarname(tmpstr, p, strlen(p) + 1, True); + cliplist[i] = tmpstr; + if ((p = strchr(p, '\000')) == NULL) { + DEBUG(0,("INTERNAL ERROR: inclusion_buffer is of unexpected contents.\n")); + abort(); + } + } + ++p; + } + must_free_cliplist = True; + } + } + + if (inclusion_buffer) { + free(inclusion_buffer); + } + if (error) { + if (cliplist) { + char **p; + /* We know cliplist is always null-terminated */ + for (p = cliplist; *p; ++p) { + free(*p); + } + free(cliplist); + cliplist = NULL; + must_free_cliplist = False; + } + return 0; + } + + /* cliplist and its elements are freed at the end of process_tar. */ + return 1; +} + /**************************************************************************** Parse tar arguments. Sets tar_type, tar_excl, etc. ***************************************************************************/ @@ -2275,18 +2464,25 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) break; case 'I': if (tar_clipfl) { - DEBUG(0,("Only one of I,X must be specified\n")); + DEBUG(0,("Only one of I,X,F must be specified\n")); return 0; } tar_clipfl='I'; break; case 'X': if (tar_clipfl) { - DEBUG(0,("Only one of I,X must be specified\n")); + DEBUG(0,("Only one of I,X,F must be specified\n")); return 0; } tar_clipfl='X'; break; + case 'F': + if (tar_clipfl) { + DEBUG(0,("Only one of I,X,F must be specified\n")); + return 0; + } + tar_clipfl='F'; + break; case 'r': DEBUG(0, ("tar_re_search set\n")); tar_re_search = True; @@ -2301,9 +2497,19 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) return 0; } + /* tar_excl is true if cliplist lists files to be included. + * Both 'I' and 'F' mean include. */ tar_excl=tar_clipfl!='X'; - if (Optind+1 Date: Sat, 20 Jun 1998 10:06:26 +0000 Subject: clitar.c: Fixed minor gcc -pedantic-error compile warnings. passdb.c: Fixed stupid bug in read_sid_from_file(). Jeremy. (This used to be commit e65efe3f78240a4fa1ed7931e96c6fb698d9d8c8) --- source3/client/clitar.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 412af8fa83..b06b5b2d37 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -307,7 +307,7 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) } fprintf(stdout, "\n"); fprintf(stdout, "%s\n", hb -> dummy); - fprintf(stdout, "Tarbuf = %X, hb = %X\n", tarbuf, hb); + fprintf(stdout, "Tarbuf = %X, hb = %X\n", (int)tarbuf, (int)hb); return -1; } @@ -2309,7 +2309,6 @@ static int read_inclusion_file(char *filename) char *p; char *tmpstr; int i; - int result = 0; int error = 0; clipn = 0; @@ -2388,10 +2387,10 @@ static int read_inclusion_file(char *filename) } if (error) { if (cliplist) { - char **p; + char **pp; /* We know cliplist is always null-terminated */ - for (p = cliplist; *p; ++p) { - free(*p); + for (pp = cliplist; *pp; ++pp) { + free(*pp); } free(cliplist); cliplist = NULL; -- cgit From 8afebcdd7e055cd6c6f9eb69f9ba652b4e1ab591 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sun, 21 Jun 1998 12:44:34 +0000 Subject: Remove the copyright to Canon Information Systems Australia, as we don't want them to have the copyright. Added a new DOSERR response code that Win95 returns, unimp, unimplemented. Added code to ignore errors on setting remote time, as Win 95 does not like the time being changed on a directory. Win NT and Samba are OK at this. This is the next to last clean-ups here. Next is to properly handle restore times on directories (except for Win95--see above). Now have Jay's changes in and have fixed a bug reported by Tim Lee. (This used to be commit dc9436bae4493b71ba92970d6cc49dbb33cd55cd) --- source3/client/clitar.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index b06b5b2d37..d7d47fc903 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -102,6 +102,7 @@ BOOL tar_system=True; BOOL tar_hidden=True; /* Be noisy - make a catalogue */ BOOL tar_noisy=True; +BOOL tar_real_noisy=True; char tar_type='\0'; static char **cliplist=NULL; @@ -568,7 +569,7 @@ static int strslashcmp(char *s1, char *s2) do_setrtime, set time on a file or dir ... **********************************************************************/ -static int do_setrtime(char *fname, int mtime) +static int do_setrtime(char *fname, int mtime, BOOL err_silent) { char *inbuf, *outbuf, *p; char *name; @@ -583,9 +584,15 @@ static int do_setrtime(char *fname, int mtime) } - safe_strcpy(name, "\\", strlen(fname) + 1); + if (*fname != '\\') + safe_strcpy(name, "\\", strlen(fname) + 1); + else + safe_strcpy(name, "", strlen(fname) + 1); safe_strcat(name, fname, strlen(fname) + 1); + if (fname[strlen(name) - 1] == '\\') + name[strlen(name) - 1] = '\0'; + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -619,8 +626,10 @@ static int do_setrtime(char *fname, int mtime) if (CVAL(inbuf,smb_rcls) != 0) { - DEBUG(0,("%s setting attributes on file %s\n", - smb_errstr(inbuf), fname)); + if (!err_silent) { + DEBUG(0,("%s setting attributes on file %s\n", + smb_errstr(inbuf), fname)); + } free(name);free(inbuf);free(outbuf); return(False); } @@ -1954,10 +1963,12 @@ static void do_tarput() DEBUG(5, ("Updating creation date on %s\n", finfo.name)); - if (!do_setrtime(finfo.name, finfo.mtime)) { + if (!do_setrtime(finfo.name, finfo.mtime, True)) { - DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); - return; + if (tar_real_noisy) { + DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); + } + /*return; /* Win 95 does not like setting time on dirs */ } -- cgit From 9d001d5c959d8fb5b4f14529e73ed2453035283b Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Mon, 22 Jun 1998 06:31:39 +0000 Subject: Arrrgh, one more fix. Restores of long file names were broken ... Added a bzero of the buffer the names went into ... Seems OK now ... Richard Sharpe (This used to be commit c749c8d0460feddafaa68654d8a4bec33f97cc8c) --- source3/client/clitar.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index d7d47fc903..eba82ba217 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1888,14 +1888,19 @@ static void do_tarput() return; } + + bzero(longname, finfo.size + strlen(cur_dir) +1); + buffer_p += TBLOCK; /* Skip that longlink header */ /* This needs restructuring ... */ - strncpy(longname, cur_dir, strlen(cur_dir) + 1); + safe_strcpy(longname, cur_dir, strlen(cur_dir) + 1); cp = longname + strlen(cur_dir); file_len = finfo.size; + DEBUG(5, ("longname=%0X, cp=%0X, file_len=%i\n", longname, cp, file_len)); + while (file_len > 0) { if (buffer_p >= endofbuffer) { @@ -1912,7 +1917,7 @@ static void do_tarput() cp = cp + strlen(cp); /* Move to end of string */ buffer_p += TBLOCK; file_len -= TBLOCK; - + DEBUG(5, ("cp=%0X, file_len=%i\n", cp, file_len)); next_header = 1; /* Force read of next header */ } -- cgit From bc39cff279ef3df174c1d1408f90e88666e64237 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 25 Jun 1998 23:51:28 +0000 Subject: clitar.c: Fixed gcc warning with comment in /* */ code. nmbd_winsserver.c: Remember to free packet in multi-homed register code. Use correct query_name_from_wins_server call instead of query_name call in multihomed code. Jeremy. (This used to be commit 6e995802fecb4474003db55a69c9e1663737aade) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index eba82ba217..d286477d7d 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1973,7 +1973,7 @@ static void do_tarput() if (tar_real_noisy) { DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); } - /*return; /* Win 95 does not like setting time on dirs */ + /*return; - Win 95 does not like setting time on dirs */ } -- cgit From 4fa20ebdc051083b02c790ff8a1c0a1094bd5e53 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Mon, 3 Aug 1998 10:35:00 +0000 Subject: Fixing clitar.c so that tar to stdout works correctly. Replaced printfs with DEBUG(0. Tested ... Works. Hope I didn't disturb the autoconf code ... It feels great to be able to run configure for Samba at long last! Regards Richard Sharpe (This used to be commit b968aa31ba15742a9eadc010e03781583feb6455) --- source3/client/clitar.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index d286477d7d..1f453da492 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -303,12 +303,12 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) if (fchk != chk) { DEBUG(0, ("checksums don't match %d %d\n", fchk, chk)); - for (i = 0; i < sizeof(hb -> dummy); i++) { +/* for (i = 0; i < sizeof(hb -> dummy); i++) { fprintf(stdout, "%2X ", hb -> dummy[i]); } fprintf(stdout, "\n"); fprintf(stdout, "%s\n", hb -> dummy); - fprintf(stdout, "Tarbuf = %X, hb = %X\n", (int)tarbuf, (int)hb); + fprintf(stdout, "Tarbuf = %X, hb = %X\n", (int)tarbuf, (int)hb);*/ return -1; } @@ -1410,17 +1410,17 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) get_total_time_ms += this_time; get_total_size += finfo.size; - /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(3,("(%g kb/s) (average %g kb/s)\n", - finfo.size / MAX(0.001, (1.024*this_time)), - get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); if (tar_noisy) { - printf("%10d (%7.1f kb/s) %s\n", + DEBUG(0, ("%10d (%7.1f kb/s) %s\n", finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), - finfo.name); + finfo.name)); } + /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ + DEBUG(3,("(%g kb/s) (average %g kb/s)\n", + finfo.size / MAX(0.001, (1.024*this_time)), + get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); } free(inbuf);free(outbuf); @@ -1490,7 +1490,7 @@ static void do_tar(file_info *finfo) writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); if (tar_noisy) { - printf(" directory %s\n", cur_dir); + DEBUG(0, (" directory %s\n", cur_dir)); } ntarf++; /* Make sure we have a file on there */ -- cgit From b9623ab59e813131b1ed3f51616a46e719d59c21 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 Aug 1998 17:38:29 +0000 Subject: this is the bug change to using connection_struct* instead of cnum. Connections[] is now a local array in server.c I might have broken something with this change. In particular the oplock code is suspect and some .dll files aren't being oplocked when I expected them to be. I'll look at it after I've got some sleep. (This used to be commit c7ee025ead4a85b6fa44a832047b878451845fb6) --- source3/client/clitar.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 1f453da492..035e4f7607 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -297,12 +297,12 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) fchk=unoct(hb->dbuf.chksum, sizeof(hb->dbuf.chksum)); - DEBUG(5, ("checksum totals chk=%d fchk=%d chksum=%s\n", + DEBUG(5, ("checksum totals chk=%ld fchk=%ld chksum=%s\n", chk, fchk, hb->dbuf.chksum)); if (fchk != chk) { - DEBUG(0, ("checksums don't match %d %d\n", fchk, chk)); + DEBUG(0, ("checksums don't match %ld %ld\n", fchk, chk)); /* for (i = 0; i < sizeof(hb -> dummy); i++) { fprintf(stdout, "%2X ", hb -> dummy[i]); } @@ -840,7 +840,7 @@ static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) SSVAL(outbuf,smb_vwv0,fnum); put_dos_date3(outbuf,smb_vwv1,finfo.mtime); - DEBUG(3,("Setting date to %s (0x%X)", + DEBUG(3,("Setting date to %s (0x%lX)", asctime(LocalTime(&finfo.mtime)), finfo.mtime)); @@ -1517,7 +1517,7 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) * dos \'s in path. Kill any absolute path names. But only if first! */ - DEBUG(5, ("firstb=%X, secondb=%X, len=%i\n", tptr, fp, l)); + DEBUG(5, ("firstb=%lX, secondb=%lX, len=%i\n", tptr, fp, l)); if (first) { if (*fp == '.') { @@ -1829,7 +1829,8 @@ static void do_tarput() finfo.name = NULL; } - DEBUG(5, ("Tarbuf=%X, buffer=%X, endofbuf=%X\n", tarbuf, buffer_p, endofbuffer)); + DEBUG(5, ("Tarbuf=%X, buffer=%X, endofbuf=%X\n", + (int)tarbuf, (int)buffer_p, (int)endofbuffer)); switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { case -2: /* something dodgy but not fatal about this */ @@ -1899,7 +1900,8 @@ static void do_tarput() cp = longname + strlen(cur_dir); file_len = finfo.size; - DEBUG(5, ("longname=%0X, cp=%0X, file_len=%i\n", longname, cp, file_len)); + DEBUG(5, ("longname=%0X, cp=%0X, file_len=%i\n", + (int)longname, (int)cp, file_len)); while (file_len > 0) { @@ -1917,7 +1919,7 @@ static void do_tarput() cp = cp + strlen(cp); /* Move to end of string */ buffer_p += TBLOCK; file_len -= TBLOCK; - DEBUG(5, ("cp=%0X, file_len=%i\n", cp, file_len)); + DEBUG(5, ("cp=%0X, file_len=%i\n", (int)cp, file_len)); next_header = 1; /* Force read of next header */ } @@ -2045,7 +2047,7 @@ static void do_tarput() } if (fsize % TBLOCK) buffer_p+=TBLOCK - (fsize % TBLOCK); DEBUG(5, ("buffer_p is now %d (psn=%d)\n", - (long) buffer_p, (long)(buffer_p - tarbuf))); + (int) buffer_p, (int)(buffer_p - tarbuf))); ntarf++; fsize=0; -- cgit From e13aeea928dd89373cfaf3916c96f853c1227884 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Aug 1998 01:19:26 +0000 Subject: configure: Changes for extra headers. configure.in: Source for header changes. client/clitar.c: Fixed isXXX macros & debugs for gcc pedantic compile. include/config.h.in: Added MEMSET, BZERO, MEMORY, RPCSVC_YPCLNT, STRINGS headers. include/includes.h: Headers for the above. include/smb.h: Made SIGNAL_CAST POSIX by default void (*)(int). lib/access.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/charset.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/debug.c: Fixed signal functs. lib/kanji.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/smbrun.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/util.c: Fixed isXXX macros & debugs for gcc pedantic compile. libsmb/namequery.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem_sysv.c: Fixed error messages in sysV stuff. nmbd/asyncdns.c: Fixed signal functs. nmbd/nmbd.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/passdb.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/smbpassfile.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/chgpasswd.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/ipc.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/nttrans.c: Fixed fsp code path. smbd/password.c: fixed HAVE_YP_GET_DEFAULT_DOMAIN problem. smbd/printing.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/reply.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/server.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/trans2.c: Fixed core dump bug. smbd/uid.c: Fixed isXXX macros & debugs for gcc pedantic compile. Jeremy. (This used to be commit 1b9cbcd02e575dc0a95fa589f720df30a4acc46b) --- source3/client/clitar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 035e4f7607..395f31edcf 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -522,7 +522,7 @@ static long unoct(char *p, int ndgs) while (--ndgs) { - if (isdigit(*p)) + if (isdigit((int)*p)) value = (value << 3) | (long) (*p - '0'); p++; @@ -1517,7 +1517,7 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) * dos \'s in path. Kill any absolute path names. But only if first! */ - DEBUG(5, ("firstb=%lX, secondb=%lX, len=%i\n", tptr, fp, l)); + DEBUG(5, ("firstb=%lX, secondb=%lX, len=%i\n", (long)tptr, (long)fp, l)); if (first) { if (*fp == '.') { -- cgit From 61b5fd6f32e9ccb612df1354a3e3b3bed5f2b808 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Aug 1998 03:11:42 +0000 Subject: bounds check next_token() to prevent possible buffer overflows (This used to be commit 3eade55dc7c842bdc50205c330802d211fae54d3) --- source3/client/clitar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 395f31edcf..47903d20be 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -2073,7 +2073,7 @@ void cmd_block(char *dum_in, char *dum_out) fstring buf; int block; - if (!next_token(NULL,buf,NULL)) + if (!next_token(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("blocksize \n")); return; @@ -2097,7 +2097,7 @@ void cmd_tarmode(char *dum_in, char *dum_out) { fstring buf; - while (next_token(NULL,buf,NULL)) { + while (next_token(NULL,buf,NULL,sizeof(buf))) { if (strequal(buf, "full")) tar_inc=False; else if (strequal(buf, "inc")) @@ -2143,7 +2143,7 @@ void cmd_setmode(char *dum_in, char *dum_out) attra[0] = attra[1] = 0; - if (!next_token(NULL,buf,NULL)) + if (!next_token(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("setmode \n")); return; @@ -2152,7 +2152,7 @@ void cmd_setmode(char *dum_in, char *dum_out) safe_strcpy(fname, cur_dir, sizeof(pstring)); safe_strcat(fname, buf, sizeof(pstring)); - while (next_token(NULL,buf,NULL)) { + while (next_token(NULL,buf,NULL,sizeof(buf))) { q=buf; while(*q) @@ -2194,7 +2194,7 @@ void cmd_tar(char *inbuf, char *outbuf) char **argl; int argcl; - if (!next_token(NULL,buf,NULL)) + if (!next_token(NULL,buf,NULL,sizeof(buf))) { DEBUG(0,("tar [IXbga] \n")); return; -- cgit From 18556274139cc5a00593471bd745354d98a35303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Sep 1998 20:11:54 +0000 Subject: More abstraction of file system data types, to move to a 64 bit file interface for the NT SMB's. Created a new define, SMB_STRUCT_STAT that currently is defined to be struct stat - this wil change to a user defined type containing 64 bit info when the correct wrappers are written for 64 bit stat(), fstat() and lstat() calls. Also changed all sys_xxxx() calls that were previously just wrappers to the same call prefixed by a dos_to_unix() call into dos_xxxx() calls. This makes it explicit when a pathname translation is being done, and when it is not. Now, all sys_xxx() calls are meant to be wrappers to mask OS differences, and not silently converting filenames on the fly. Jeremy. (This used to be commit 28aa182dbffaa4ffd86047e608400de4b26e80eb) --- source3/client/clitar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 47903d20be..6642154683 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -440,7 +440,7 @@ Write two zero blocks at end of file ****************************************************************************/ static void dotareof(int f) { - struct stat stbuf; + SMB_STRUCT_STAT stbuf; /* Two zero blocks at end of file, write out full buffer */ (void) dozerobuf(f, TBLOCK); @@ -2462,10 +2462,10 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) DEBUG(0,("Option N must be followed by valid file name\n")); return 0; } else { - struct stat stbuf; + SMB_STRUCT_STAT stbuf; extern time_t newer_than; - if (sys_stat(argv[Optind], &stbuf) == 0) { + if (dos_stat(argv[Optind], &stbuf) == 0) { newer_than = stbuf.st_mtime; DEBUG(1,("Getting files newer than %s", asctime(LocalTime(&newer_than)))); -- cgit From 7bb86c1b132bce31a006ea9768a54db7a45fe1a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Sep 1998 18:40:31 +0000 Subject: Ok - this is the 64 bit widening check in. It changes the configure to check for stat64 and friends, and then changes much of Samba to use the data type SMB_OFF_T for file size information. stat/fstat/lstat/lseek/ftruncate have now become sys_stat etc. to hide the 64 bit calls if needed. Note that this still does not expose 64 bit functionality to the client, as the changes to the reply_xxx smb's are not yet done. This code change should make these changes possible. Still to do before full 64 bit-ness to the client: fcntl lock code. statfs code widening of dev_t and ino_t (now possible due to SMB_DEV_T and SMB_OFF_T types being in place). Let me know if wierd things happen after this check-in and I'll fix them :-). Jeremy. (This used to be commit 14500936c321d15995c963766aac67bf1f4e3824) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 6642154683..502a867f60 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -446,7 +446,7 @@ static void dotareof(int f) (void) dozerobuf(f, TBLOCK); (void) dozerobuf(f, TBLOCK); - if (fstat(f, &stbuf) == -1) + if (sys_fstat(f, &stbuf) == -1) { DEBUG(0, ("Couldn't stat file handle\n")); return; -- cgit From e9ea36e4d2270bd7d32da12ef6d6e2299641582d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Sep 1998 05:07:05 +0000 Subject: tridge the destroyer returns! prompted by the interpret_security() dead code that Jean-Francois pointed out I added a make target "finddead" that finds potentially dead (ie. unused) code. It spat out 304 function names ... I went through these are deleted many of them, making others static (finddead also reports functions that are used only in the local file). in doing this I have almost certainly deleted some useful code. I may have even prevented compilation with some compile options. I apologise. I decided it was better to get rid of this code now and add back the one or two functions that are needed than to keep all this baggage. So, if I have done a bit too much "destroying" then let me know. Keep the swearing to a minimum :) One bit I didn't do is the ubibt code. Chris, can you look at that? Heaps of unused functions there. Can they be made static? (This used to be commit 2204475c87f3024ea8fd1fbd7385b2def617a46f) --- source3/client/clitar.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 502a867f60..376d3aeac6 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -39,6 +39,8 @@ #include "includes.h" #include "clitar.h" +static int clipfind(char **aret, int ret, char *tok); + typedef struct file_info_struct file_info2; struct file_info_struct @@ -973,7 +975,7 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) return True; } -int padit(char *buf, int bufsize, int padsize) +static int padit(char *buf, int bufsize, int padsize) { int berr= 0; int bytestowrite; @@ -2294,7 +2296,7 @@ int process_tar(char *inbuf, char *outbuf) /**************************************************************************** Find a token (filename) in a clip list ***************************************************************************/ -int clipfind(char **aret, int ret, char *tok) +static int clipfind(char **aret, int ret, char *tok) { if (aret==NULL) return 0; -- cgit From 9b20e5bac2a7b83f8e3dfdf3a274a1ce12dbd92c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Sep 1998 21:42:18 +0000 Subject: Ok so with this bugfix 64 bit file access actually seems to work :-). Problems were just dumb bugs like (defining sys_lseek to return 'int' DOH !). Jeremy. (This used to be commit 54dd51176fbab18af0b21bdee71b53f8f86573a8) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 376d3aeac6..1ca8c1a4dc 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1071,7 +1071,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) SSVAL(outbuf,smb_vwv1,PTR_DIFF(p,outbuf) - 4); memset(p,0,200); p -= smb_wct; - SSVAL(p,smb_wct,10); + SCVAL(p,smb_wct,10); SSVAL(p,smb_vwv0,0xFF); SSVAL(p,smb_vwv5,MIN(max_xmit-500,finfo.size)); SSVAL(p,smb_vwv9,MIN(0xFFFF,finfo.size)); -- cgit From c198d4c8be6b1a4f042151714107ff37fc446471 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 18 Sep 1998 12:47:46 +0000 Subject: Adding rewritten restore code ... Old code is still there surrounded by a OLD_DOTARPUT. (This used to be commit 00ba54d4ee9ad875c5cfbee09d4b745df5f116ab) --- source3/client/clitar.c | 286 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 234 insertions(+), 52 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 1ca8c1a4dc..c38f9fdec9 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -85,7 +85,7 @@ static int attribute = aDIR | aSYSTEM | aHIDDEN; #define CLIENT_TIMEOUT (30*1000) #endif -static char *tarbuf; +static char *tarbuf, *buffer_p; static int tp, ntarf, tbufsiz, ttarf; /* Incremental mode */ BOOL tar_inc=False; @@ -1554,18 +1554,26 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) } } -#if 0 /* Removed to get around gcc 'defined but not used' error. */ +#ifndef OLD_DOTARPUT /**************************************************************************** Move to the next block in the buffer, which may mean read in another set of -blocks. +blocks. FIXME, we should allow more than one block to be skipped. ****************************************************************************/ -static int next_block(char *ltarbuf, char *bufferp, int bufsiz) +static int next_block(char *ltarbuf, char **bufferp, int bufsiz) { int bufread, total = 0; - if (bufferp >= (ltarbuf + bufsiz)) { - + DEBUG(5, ("Advancing to next block: %0X\n", *bufferp)); + *bufferp += TBLOCK; + total = TBLOCK; + + if (*bufferp >= (ltarbuf + bufsiz)) { + + DEBUG(5, ("Reading more data into ltarbuf ...\n")); + + total = 0; + for (bufread = read(tarhandle, ltarbuf, bufsiz); total < bufsiz; total += bufread) { if (bufread <= 0) { /* An error, return false */ @@ -1574,49 +1582,192 @@ static int next_block(char *ltarbuf, char *bufferp, int bufsiz) } - bufferp = ltarbuf; - - } - else { + DEBUG(5, ("Total bytes read ... %i\n", total)); - bufferp += TBLOCK; + *bufferp = ltarbuf; } - return(0); + return(total); } -static int skip_file(int skip) +/* Skip a file, even if it includes a long file name? */ +static int skip_file(int skipsize) { + int dsize = skipsize; - return(0); + DEBUG(5, ("Skiping file. Size = %i\n", skipsize)); + + /* FIXME, we should skip more than one block at a time */ + + while (dsize > 0) { + + if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { + + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return(False); + + } + + dsize -= TBLOCK; + + } + + return(True); } -static int get_file(file_info2 finfo) +/* We get a file from the tar file and store it */ +static int get_file(file_info2 finfo, char * inbuf, char * outbuf) { + int fsize = finfo.size; + int fnum, pos = 0, dsize = 0, wsize = 0, rsize = 0; - return(0); + DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, fsize)); + + if (ensurepath(finfo.name, inbuf, outbuf) && + !smbcreat(finfo, &fnum, inbuf, outbuf)) + { + DEBUG(0, ("abandoning restore\n")); + return(False); + } + + DEBUG(0, ("restore tar file %s of size %d bytes\n", + finfo.name, finfo.size)); + + /* read the blocks from the tar file and write to the remote file */ + + rsize = fsize; + + while (rsize > 0) { + + dsize = MIN(tbufsiz - (buffer_p - tarbuf), rsize); /* Calculate the size to write */ + + DEBUG(5, ("writing %i bytes ...\n", dsize)); + + if (!smbwrite(fnum, dsize, pos, 0, fsize - pos, buffer_p, inbuf, outbuf)) { + + DEBUG(0, ("Error writing remote file\n")); + return 0; + + } + + rsize -= dsize; + + /* Now figure out how much to move in the buffer */ + + /* FIXME, we should skip more than one block at a time */ + + while (dsize > 0) { + + if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { + + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return False; + + } + + dsize -= TBLOCK; + + } + + } + + /* Now close the file ... */ + + if (!smbshut(finfo, fnum, inbuf, outbuf)) { + + DEBUG(0, ("Error closing remote file\n")); + return(False); + + } + + /* Now we update the creation date ... */ + + DEBUG(5, ("Updating creation date on %s\n", finfo.name)); + + if (!do_setrtime(finfo.name, finfo.mtime)) { + + DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); + /*return(False); */ /* Ignore, as Win95 does not allow changes */ + + } + + ntarf++; + return(True); } -static int get_dir(file_info2 finfo) +/* Create a directory. We just ensure that the path exists and return as there + is no file associated with a directory +*/ +static int get_dir(file_info2 finfo, char * inbuf, char * outbuf) { - return(0); + DEBUG(5, ("Creating directory: %s\n", finfo.name)); -} + if (!ensurepath(finfo.name, inbuf, outbuf)) { + + DEBUG(0, ("Problems creating directory\n")); + return(False); + + } + return(True); +} +/* Get a file with a long file name ... first file has file name, next file + has the data. We only want the long file name, as the loop in do_tarput + will deal with the rest. +*/ static char * get_longfilename(file_info2 finfo) { + int namesize = finfo.size + strlen(cur_dir) + 2; + char *longname = malloc(namesize); + char *xxx; + int offset = 0, left = finfo.size; - return(NULL); + DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); + DEBUG(5, ("Len = %i\n", finfo.size)); + fflush(stderr); -} + if (longname == NULL) { + + DEBUG(0, ("could not allocate buffer of size %d for longname\n", + finfo.size + strlen(cur_dir) + 2)); + return(NULL); + } + + /* First, add cur_dir to the long file name */ + + if (strlen(cur_dir) > 0) { + strncpy(longname, cur_dir, namesize); + offset = strlen(cur_dir); + } + + /* Loop through the blocks picking up the name */ + + while (left > 0) { + + if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { + + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return(NULL); + + } + + unfixtarname(longname + offset, buffer_p, MIN(TBLOCK, finfo.size)); + DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, buffer_p)); -static char * bufferp; + offset += TBLOCK; + left -= TBLOCK; -static void do_tarput2(void) + } + + return(longname); + +} + +static void do_tarput(void) { file_info2 finfo, *finfo2; struct timeval tp_start; @@ -1625,8 +1776,11 @@ static void do_tarput2(void) GetTimeOfDay(&tp_start); - bufferp = tarbuf + tbufsiz; /* init this to force first read */ + DEBUG(5, ("RJS do_tarput called ...\n")); + + buffer_p = tarbuf + tbufsiz; /* init this to force first read */ +#ifdef 0 /* Fix later ... */ if (push_dir(&dir_stack, &finfo)) { finfo2 = pop_dir(&dir_stack); @@ -1637,6 +1791,7 @@ static void do_tarput2(void) } } +#endif inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1648,21 +1803,27 @@ static void do_tarput2(void) } - if (next_block(tarbuf, bufferp, tbufsiz) <= 0) { + /* Now read through those files ... */ + + while (True) { - DEBUG(0, ("Empty file or short tar file: %s\n", strerror(errno))); + /* Get us to the next block, or the first block first time around */ - } + if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { - /* Now read through those files ... */ + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); - while (True) { + return; + + } - switch (readtarheader((union hblock *) bufferp, &finfo, cur_dir)) { + DEBUG(5, ("Reading the next header ...\n")); + fflush(stdout); + switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { case -2: /* Hmm, not good, but not fatal */ DEBUG(0, ("Skipping %s...\n", finfo.name)); - if ((next_block(tarbuf, bufferp, tbufsiz) <= 0) && + if ((next_block(tarbuf, &buffer_p, tbufsiz) <= 0) && !skip_file(finfo.size)) { DEBUG(0, ("Short file, bailing out...\n")); @@ -1691,46 +1852,65 @@ static void do_tarput2(void) /* Now, do we have a long file name? */ if (longfilename != NULL) { - if (strlen(longfilename) < sizeof(finfo.name)) { /* if we have space */ - strncpy(finfo.name, longfilename, sizeof(finfo.name) - 1); - free(longfilename); - longfilename = NULL; + free(finfo.name); /* Free the space already allocated */ + finfo.name = longfilename; + longfilename = NULL; - } - else { + } - DEBUG(0, ("filename: %s too long, skipping\n", strlen(longfilename))); - skip = True; + /* Well, now we have a header, process the file ... */ - } - } + /* Should we skip the file? We have the long name as well here */ - /* Well, now we have a header, process the file ... */ + skip = clipn && + ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) +#ifdef HAVE_REGEX_H + || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); +#else + || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); +#endif - /* Should we skip the file? */ + DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, cliplist[0], finfo.name)); - if (skip) { + if (skip) { - skip_file(finfo.size); - continue; + skip_file(finfo.size); + continue; - } + } /* We only get this far if we should process the file */ - switch (((union hblock *)bufferp) -> dbuf.linkflag) { + switch (((union hblock *)buffer_p) -> dbuf.linkflag) { case '0': /* Should use symbolic names--FIXME */ - get_file(finfo); + if (!get_file(finfo, inbuf, outbuf)) { + + free(inbuf); free(outbuf); + DEBUG(0, ("Abandoning restore\n")); + return; + + } break; case '5': - get_dir(finfo); + if (!get_dir(finfo, inbuf, outbuf)) { + free(inbuf); free(outbuf); + DEBUG(0, ("Abandoning restore \n")); + return; + } break; case 'L': longfilename = get_longfilename(finfo); + if (!longfilename) { + free(inbuf); free(outbuf); + DEBUG(0, ("abandoning restore\n")); + return; + + } + DEBUG(5, ("Long file name: %s\n", longfilename)); break; default: @@ -1743,7 +1923,8 @@ static void do_tarput2(void) } -#endif /* Removed to get around gcc 'defined but not used' error. */ + +#else static void do_tarput() { @@ -1774,7 +1955,7 @@ static void do_tarput() /* These should be the only reads in clitar.c */ while ((bufread=read(tarhandle, tarbuf, tbufsiz))>0) { - char *buffer_p, *endofbuffer; + char *endofbuffer; int chunk; /* Code to handle a short read. @@ -2062,6 +2243,7 @@ static void do_tarput() free(inbuf); free(outbuf); } +#endif /* * samba interactive commands -- cgit From 717f538e2efdce231f6b9255be998cc4495337df Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Sep 1998 17:32:35 +0000 Subject: Fixed compile errors in new code. Jeremy. (This used to be commit dbd8ce8a7053b6ea051e9bbdd0ddc27f1e0cb7c2) --- source3/client/clitar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c38f9fdec9..9cb71b10a2 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1686,7 +1686,7 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) DEBUG(5, ("Updating creation date on %s\n", finfo.name)); - if (!do_setrtime(finfo.name, finfo.mtime)) { + if (!do_setrtime(finfo.name, finfo.mtime, True)) { DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); /*return(False); */ /* Ignore, as Win95 does not allow changes */ @@ -1755,7 +1755,7 @@ static char * get_longfilename(file_info2 finfo) } - unfixtarname(longname + offset, buffer_p, MIN(TBLOCK, finfo.size)); + unfixtarname(longname + offset, buffer_p, MIN(TBLOCK, finfo.size),False); DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, buffer_p)); offset += TBLOCK; @@ -1780,7 +1780,7 @@ static void do_tarput(void) buffer_p = tarbuf + tbufsiz; /* init this to force first read */ -#ifdef 0 /* Fix later ... */ +#if 0 /* Fix later ... */ if (push_dir(&dir_stack, &finfo)) { finfo2 = pop_dir(&dir_stack); -- cgit From b65bbdeefc5397f321d86146086ab495bf5d4657 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 19 Sep 1998 04:25:10 +0000 Subject: Fixed changes in clitar.c that Jeremey noted. One change was correct, the other needed slightly changing. Now to test it is all OK :-) (This used to be commit d54c91598c24e89a999936f446be134137df5dea) --- source3/client/clitar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 9cb71b10a2..e7ab180836 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1725,6 +1725,7 @@ static char * get_longfilename(file_info2 finfo) char *longname = malloc(namesize); char *xxx; int offset = 0, left = finfo.size; + BOOL first = True; DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); DEBUG(5, ("Len = %i\n", finfo.size)); @@ -1755,7 +1756,7 @@ static char * get_longfilename(file_info2 finfo) } - unfixtarname(longname + offset, buffer_p, MIN(TBLOCK, finfo.size),False); + unfixtarname(longname + offset, buffer_p, MIN(TBLOCK, finfo.size), first--); DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, buffer_p)); offset += TBLOCK; -- cgit From 81babe9b0def6dcddeb811b0d9f1e8ff1bac3bd2 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Mon, 21 Sep 1998 08:45:11 +0000 Subject: implemented du and tar -n (This used to be commit 23484508a86a59a71e54a1bcac3766ec3858142a) --- source3/client/clitar.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index e7ab180836..0ce5c205fa 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -98,6 +98,8 @@ BOOL tar_re_search=False; #ifdef HAVE_REGEX_H regex_t *preg; #endif +/* Do not dump anything, just calculate sizes */ +BOOL dry_run=False; /* Dump files with System attribute */ BOOL tar_system=True; /* Dump files with Hidden attribute */ @@ -374,6 +376,9 @@ static int dotarbuf(int f, char *b, int n) { int fail=1, writ=n; + if (dry_run) { + return writ; + } /* This routine and the next one should be the only ones that do write()s */ if (tp + n >= tbufsiz) { @@ -410,6 +415,9 @@ static void dozerobuf(int f, int n) * used to round files to nearest block * and to do tar EOFs */ + if (dry_run) + return; + if (n+tp >= tbufsiz) { memset(tarbuf+tp, 0, tbufsiz-tp); @@ -445,6 +453,9 @@ static void dotareof(int f) SMB_STRUCT_STAT stbuf; /* Two zero blocks at end of file, write out full buffer */ + if (dry_run) + return; + (void) dozerobuf(f, TBLOCK); (void) dozerobuf(f, TBLOCK); @@ -1034,7 +1045,17 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) finfo.ctime = def_finfo.ctime; } - + if (dry_run) + { + DEBUG(3,("skipping file %s of size %d bytes\n", + finfo.name, + finfo.size)); + shallitime=0; + ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); + ntarf++; + return; + } + inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); @@ -1403,7 +1424,8 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) int this_time; /* if shallitime is true then we didn't skip */ - if (tar_reset) (void) do_setrattr(finfo.name, aARCH, ATTRRESET); + if (tar_reset && !dry_run) + (void) do_setrattr(finfo.name, aARCH, ATTRRESET); GetTimeOfDay(&tp_end); this_time = @@ -2381,7 +2403,7 @@ void cmd_tar(char *inbuf, char *outbuf) if (!next_token(NULL,buf,NULL,sizeof(buf))) { - DEBUG(0,("tar [IXbga] \n")); + DEBUG(0,("tar [IXbgan] \n")); return; } @@ -2618,6 +2640,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) */ tar_type='\0'; tar_excl=True; + dry_run=False; while (*Optarg) switch(*Optarg++) { @@ -2689,6 +2712,15 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) DEBUG(0, ("tar_re_search set\n")); tar_re_search = True; break; + case 'n': + if (tar_type == 'c') { + DEBUG(0, ("dry_run set\n")); + dry_run = True; + } else { + DEBUG(0, ("n is only meaningful when creating a tar-file\n")); + return 0; + } + break; default: DEBUG(0,("Unknown tar option\n")); return 0; @@ -2779,6 +2811,14 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); } else { + if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) + { + if (!dry_run) { + DEBUG(0,("Output is /dev/null, assuming dry_run")); + dry_run = True; + } + tarhandle=-1; + } else if ((tar_type=='x' && (tarhandle = open(argv[Optind], O_RDONLY)) == -1) || (tar_type=='c' && (tarhandle=creat(argv[Optind], 0644)) < 0)) { -- cgit From 242d068297b79af46c00a94d0e737c79e908a498 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 23 Sep 1998 00:57:34 +0000 Subject: Fixed up warnings in new client code. Note to coders. If using gcc please use the compiler flags : -Wall -Werror -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual *before* checking anything in to ensure a clean compile. Jeremy. (This used to be commit 1daf424da6c5a346f672121d4b6fe5753250f464) --- source3/client/clitar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0ce5c205fa..7df6417ae1 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1586,7 +1586,7 @@ static int next_block(char *ltarbuf, char **bufferp, int bufsiz) { int bufread, total = 0; - DEBUG(5, ("Advancing to next block: %0X\n", *bufferp)); + DEBUG(5, ("Advancing to next block: %0x\n", (unsigned int)*bufferp)); *bufferp += TBLOCK; total = TBLOCK; @@ -1643,7 +1643,7 @@ static int skip_file(int skipsize) static int get_file(file_info2 finfo, char * inbuf, char * outbuf) { int fsize = finfo.size; - int fnum, pos = 0, dsize = 0, wsize = 0, rsize = 0; + int fnum, pos = 0, dsize = 0, rsize = 0; DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, fsize)); @@ -1745,7 +1745,6 @@ static char * get_longfilename(file_info2 finfo) { int namesize = finfo.size + strlen(cur_dir) + 2; char *longname = malloc(namesize); - char *xxx; int offset = 0, left = finfo.size; BOOL first = True; @@ -1792,7 +1791,7 @@ static char * get_longfilename(file_info2 finfo) static void do_tarput(void) { - file_info2 finfo, *finfo2; + file_info2 finfo; struct timeval tp_start; char *inbuf, *outbuf, *longfilename = NULL; int skip = False; @@ -1805,6 +1804,7 @@ static void do_tarput(void) #if 0 /* Fix later ... */ if (push_dir(&dir_stack, &finfo)) { + file_info2 *finfo2; finfo2 = pop_dir(&dir_stack); inbuf = top_dir_name(&dir_stack); /* FIXME */ -- cgit From 474110e3e047fb207c306a0d5fa4f8b7969791f7 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 23 Sep 1998 14:37:01 +0000 Subject: Fixed data corruption bugs in clitar.c with restores. Have tested against samba with clitar using a hard-coded max_xmit of 2920, since max smit = 2920 does not seem to work in the smb.conf file. Will have to test correctly against Win95 and WinNT now. Have also compiled with -WJeremy'sFlags and get no more warnings after I removed an unused variable. (This used to be commit f24bbaccda48810fd7ef3fea5621c1e1d3009b01) --- source3/client/clitar.c | 75 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 17 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 7df6417ae1..aadb485301 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -329,7 +329,7 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) unfixtarname(finfo->name + strlen(prefix), hb->dbuf.name, strlen(hb->dbuf.name) + 1, True); -/* can't handle some links at present */ + /* can't handle some links at present */ if ((hb->dbuf.linkflag != '0') && (hb -> dbuf.linkflag != '5')) { if (hb->dbuf.linkflag == 0) { DEBUG(6, ("Warning: NULL link flag (gnu tar archive ?) %s\n", @@ -1643,7 +1643,7 @@ static int skip_file(int skipsize) static int get_file(file_info2 finfo, char * inbuf, char * outbuf) { int fsize = finfo.size; - int fnum, pos = 0, dsize = 0, rsize = 0; + int fnum, pos = 0, dsize = 0, rsize = 0, bpos = 0; DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, fsize)); @@ -1654,20 +1654,19 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) return(False); } - DEBUG(0, ("restore tar file %s of size %d bytes\n", - finfo.name, finfo.size)); - /* read the blocks from the tar file and write to the remote file */ - rsize = fsize; + rsize = fsize; /* This is how much to write */ while (rsize > 0) { - dsize = MIN(tbufsiz - (buffer_p - tarbuf), rsize); /* Calculate the size to write */ + /* We can only write up to the end of the buffer */ - DEBUG(5, ("writing %i bytes ...\n", dsize)); + dsize = MIN(tbufsiz - (buffer_p - tarbuf) - bpos, max_xmit - 50); /* Calculate the size to write */ + dsize = MIN(dsize, rsize); /* Should be only what is left */ + DEBUG(5, ("writing %i bytes, max_xmit = %i, bpos = %i ...\n", dsize, max_xmit, bpos)); - if (!smbwrite(fnum, dsize, pos, 0, fsize - pos, buffer_p, inbuf, outbuf)) { + if (!smbwrite(fnum, dsize, pos, 0, fsize - pos, buffer_p + bpos, inbuf, outbuf)) { DEBUG(0, ("Error writing remote file\n")); return 0; @@ -1675,12 +1674,29 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) } rsize -= dsize; + pos += dsize; /* Now figure out how much to move in the buffer */ /* FIXME, we should skip more than one block at a time */ - while (dsize > 0) { + /* First, skip any initial part of the part written that is left over */ + /* from the end of the first TBLOCK */ + + if ((bpos + dsize) >= TBLOCK) { + + dsize -= (TBLOCK - bpos); /* Get rid of the end of the first block */ + bpos = 0; + + if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { /* and skip the block */ + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return False; + + } + + } + + while (dsize >= TBLOCK) { if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { @@ -1693,6 +1709,17 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) } + /* if (dsize > 0) { + if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { + + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return False; + + } + }*/ + + bpos = dsize; + } /* Now close the file ... */ @@ -1716,6 +1743,9 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) } ntarf++; + + DEBUG(0, ("restore tar file %s of size %d bytes\n", finfo.name, finfo.size)); + return(True); } @@ -1750,7 +1780,6 @@ static char * get_longfilename(file_info2 finfo) DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); DEBUG(5, ("Len = %i\n", finfo.size)); - fflush(stderr); if (longname == NULL) { @@ -1793,7 +1822,7 @@ static void do_tarput(void) { file_info2 finfo; struct timeval tp_start; - char *inbuf, *outbuf, *longfilename = NULL; + char *inbuf, *outbuf, *longfilename = NULL, linkflag; int skip = False; GetTimeOfDay(&tp_start); @@ -1841,7 +1870,7 @@ static void do_tarput(void) } DEBUG(5, ("Reading the next header ...\n")); - fflush(stdout); + switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { case -2: /* Hmm, not good, but not fatal */ @@ -1851,7 +1880,7 @@ static void do_tarput(void) DEBUG(0, ("Short file, bailing out...\n")); free(inbuf); free(outbuf); - continue; + return; } @@ -1867,7 +1896,9 @@ static void do_tarput(void) free(inbuf); free(outbuf); return; /* Hmmm, bad here ... */ - default: + default: + /* No action */ + break; } @@ -1894,7 +1925,7 @@ static void do_tarput(void) || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); #endif - DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, cliplist[0], finfo.name)); + DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, (cliplist?cliplist[0]:NULL), finfo.name)); if (skip) { @@ -1904,10 +1935,20 @@ static void do_tarput(void) } /* We only get this far if we should process the file */ + linkflag = ((union hblock *)buffer_p) -> dbuf.linkflag; - switch (((union hblock *)buffer_p) -> dbuf.linkflag) { + switch (linkflag) { case '0': /* Should use symbolic names--FIXME */ + + /* Skip to the next block first, so we can get the file, FIXME, should + be in get_file ... */ + + if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { + DEBUG(0, ("Short file, bailing out...\n")); + free(inbuf); free(outbuf); + return; + } if (!get_file(finfo, inbuf, outbuf)) { free(inbuf); free(outbuf); -- cgit From 921b171acfcc7e55c1770bf095d9137e815199b5 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Thu, 24 Sep 1998 13:43:36 +0000 Subject: Added a minor fix to clitar.c for a bug. Could not check that it compiles clean with Jeremy's -Wflags because someone loaded some changes to reply.c that break in the locking area :-( (This used to be commit b18cd03c0bf3b7a6815d69a9bbeba7d1b076765c) --- source3/client/clitar.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index aadb485301..4d7a2cf043 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -307,12 +307,7 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) if (fchk != chk) { DEBUG(0, ("checksums don't match %ld %ld\n", fchk, chk)); -/* for (i = 0; i < sizeof(hb -> dummy); i++) { - fprintf(stdout, "%2X ", hb -> dummy[i]); - } - fprintf(stdout, "\n"); - fprintf(stdout, "%s\n", hb -> dummy); - fprintf(stdout, "Tarbuf = %X, hb = %X\n", (int)tarbuf, (int)hb);*/ + dump_data(5, (char *)hb - TBLOCK, TBLOCK *3); return -1; } @@ -1683,7 +1678,7 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) /* First, skip any initial part of the part written that is left over */ /* from the end of the first TBLOCK */ - if ((bpos + dsize) >= TBLOCK) { + if ((bpos) && ((bpos + dsize) >= TBLOCK)) { dsize -= (TBLOCK - bpos); /* Get rid of the end of the first block */ bpos = 0; @@ -1709,15 +1704,6 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) } - /* if (dsize > 0) { - if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { - - DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); - return False; - - } - }*/ - bpos = dsize; } -- cgit From 1ea570da834fa72c88dd35a86fdf68ae5ecbeb19 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 26 Sep 1998 00:41:20 +0000 Subject: Small update to clitar.c to omit warnings about servers not letting us change the date unless tar_real_noisy is True. Also updated a few places where variables are declared but not set. (This used to be commit b46f1024c939ee9ecb8deb9c844acbd4b5f109c6) --- source3/client/clitar.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 4d7a2cf043..afcd4b9f1d 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -106,7 +106,7 @@ BOOL tar_system=True; BOOL tar_hidden=True; /* Be noisy - make a catalogue */ BOOL tar_noisy=True; -BOOL tar_real_noisy=True; +BOOL tar_real_noisy=False; /* Don't want to be really noisy by default */ char tar_type='\0'; static char **cliplist=NULL; @@ -1723,9 +1723,10 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) if (!do_setrtime(finfo.name, finfo.mtime, True)) { - DEBUG(0, ("Could not set time on file: %s\n", finfo.name)); - /*return(False); */ /* Ignore, as Win95 does not allow changes */ - + 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 */ + } } ntarf++; -- cgit From cf3a9741dc7427efb97eff09a3c197a906ce6767 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Sep 1998 21:43:48 +0000 Subject: Changes to test in configure if capabilities are enabled on a system. Changes to get Samba to compile cleanly with the IRIX compiler with the options : -fullwarn -woff 1209,1174 (the -woff options are to turn off warnings about unused function parameters and controlling loop expressions being constants). Split prototype generation as we hit a limit in IRIX nawk. Removed "." code in smbd/filename.c (yet again :-). Jeremy. (This used to be commit e0567433bd72aec17bf5a54cc292701095d25f09) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index afcd4b9f1d..0f3d54fcc0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -430,7 +430,7 @@ static void dozerobuf(int f, int n) /**************************************************************************** Malloc tape buffer ****************************************************************************/ -static void initarbuf() +static void initarbuf(void) { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; -- cgit From f82217a589ba72d6321a13b04e312f35916f920d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 29 Sep 1998 22:52:38 +0000 Subject: Fixed extern definition of cnum in clitar.c Jeremy (This used to be commit 6c08f3b81c8039e458e0b27d6649060bf6cf6c13) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0f3d54fcc0..0a9b7fd1a8 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -115,7 +115,7 @@ static BOOL must_free_cliplist = False; extern file_info def_finfo; extern BOOL lowercase; -extern int cnum; +extern uint16 cnum; extern BOOL readbraw_supported; extern int max_xmit; extern pstring cur_dir; -- cgit From 832ca93117e4dca90080c3117e26c5c9b81f930f Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sun, 4 Oct 1998 07:09:38 +0000 Subject: Added E Jay Berkenbilt's fixes (This used to be commit fcdc9bc2089822b02b30cd55054a60ed4e696e70) --- source3/client/clitar.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0a9b7fd1a8..c841ff982c 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -2715,6 +2715,9 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) case 'a': tar_reset=True; break; + case 'q': + tar_noisy=False; + break; case 'I': if (tar_clipfl) { DEBUG(0,("Only one of I,X,F must be specified\n")); -- cgit From fe2681dd4bbc296de371c7140cd8cee172397777 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Oct 1998 12:34:43 +0000 Subject: fixed a cast warning (This used to be commit 4093bb16d20b0057e07085f061bdcfb372c679c1) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c841ff982c..e9b79baa71 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1581,7 +1581,7 @@ static int next_block(char *ltarbuf, char **bufferp, int bufsiz) { int bufread, total = 0; - DEBUG(5, ("Advancing to next block: %0x\n", (unsigned int)*bufferp)); + DEBUG(5, ("Advancing to next block: %0lx\n", (unsigned long)*bufferp)); *bufferp += TBLOCK; total = TBLOCK; -- cgit From 8c62b28e0ef1e012ebb0713701916d82ffc7661e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 9 Nov 1998 03:45:49 +0000 Subject: converted smbclient to use clientgen.c rather than clientutil.c I did this when I saw yet another bug report complaining about smbclient intermittently missing files. Rather than applying more patches to smbclient it was better to move to the more robust clientgen.c code. The conversion wasn't perfect, I probably lost some features of smbclient while doing it, but at least smbclient should be consistent now. It if fails it should _always_ fail rather than giving people the false impression of a reliable utility. the tar stuff seems to work, but hasn't had much testing as I never use it myself. I'm sure someone will find bugs in my conversion of smbtar.c. It was quite tricky as it did a lot of its own SMB calls. It now uses clientgen.c exclusively. smbclient is still quite messy, but at least it doesn't build its own SMB packets. I haven't touched smbmount as I never use it. Mike, do you want to convert smbmount to use clientgen.c? (This used to be commit e14ca7765ace1b721dad8eca4a527a4e4a8f1ab8) --- source3/client/clitar.c | 1249 +++++------------------------------------------ 1 file changed, 112 insertions(+), 1137 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index e9b79baa71..8ebe9dc853 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -68,11 +68,9 @@ typedef struct stack dir_stack = {NULL, 0}; /* Want an empty stack */ -extern BOOL recurse; - #define SEPARATORS " \t\n\r" extern int DEBUGLEVEL; -extern int Client; +extern struct cli_state *cli; /* These defines are for the do_setrattr routine, to indicate * setting and reseting of file attributes in the function call */ @@ -136,7 +134,6 @@ static int dotarbuf(int f, char *b, int n); static void dozerobuf(int f, int n); static void dotareof(int f); static void initarbuf(void); -static int do_setrattr(char *fname, int attr, int setit); /* restore functions */ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix); @@ -148,54 +145,6 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first); * tar specific utitlities */ -#if 0 /* Removed to get around gcc 'defined but not used' error. */ - -/* - * Stack routines, push_dir, pop_dir, top_dir_name - */ - -static BOOL push_dir(stack *tar_dir_stack, file_info2 *dir) -{ - dir -> next = tar_dir_stack -> top; - dir -> prev = NULL; - tar_dir_stack -> items++; - tar_dir_stack -> top = dir; - return(True); - -} - -static file_info2 *pop_dir(stack *tar_dir_stack) -{ - file_info2 *ptr; - - ptr = tar_dir_stack -> top; - if (tar_dir_stack -> top != NULL) { - - tar_dir_stack -> top = tar_dir_stack -> top -> next; - tar_dir_stack -> items--; - - } - - return ptr; - -} - -static char *top_dir_name(stack *tar_dir_stack) -{ - - return(tar_dir_stack -> top != NULL?tar_dir_stack -> top -> name:NULL); - -} - -static BOOL sub_dir(char *dir1, char *dir2) -{ - - return(True); - -} - -#endif /* Removed to get around gcc 'defined but not used' error. */ - /******************************************************************* Create a string of size size+1 (for the null) *******************************************************************/ @@ -570,362 +519,11 @@ static int strslashcmp(char *s1, char *s2) return *s1-*s2; } -/* - * general smb utility functions - */ -/********************************************************************** -do_setrtime, set time on a file or dir ... -**********************************************************************/ - -static int do_setrtime(char *fname, int mtime, BOOL err_silent) -{ - char *inbuf, *outbuf, *p; - char *name; - - DEBUG(5, ("Setting time on: %s, fnlen=%i.\n", fname, strlen(fname))); - - name = (char *)malloc(strlen(fname) + 1 + 1); - if (name == NULL) { - - DEBUG(0, ("Failed to allocate space while setting time on file: %s", fname)); - return False; - - } - - if (*fname != '\\') - safe_strcpy(name, "\\", strlen(fname) + 1); - else - safe_strcpy(name, "", strlen(fname) + 1); - safe_strcat(name, fname, strlen(fname) + 1); - - if (fname[strlen(name) - 1] == '\\') - name[strlen(name) - 1] = '\0'; - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) { - - DEBUG(0, ("Could not allocate memory for inbuf or outbuf while changing time on: %s\n", fname)); - free(name); - return False; - - } - - memset(outbuf, 0, smb_size); - set_message(outbuf, 8, 4 + strlen(name), True); - CVAL(outbuf, smb_com) = SMBsetatr; - SSVAL(outbuf, smb_tid, cnum); - cli_setup_pkt(outbuf); - - SSVAL(outbuf, smb_vwv0, 0); - put_dos_date3(outbuf, smb_vwv1, mtime); - - p = smb_buf(outbuf); - *p++ = 4; - safe_strcpy(p, name, strlen(name)); - p+= (strlen(fname)+1); - - *p++ = 4; - *p++ = 0; - - send_smb(Client, outbuf); - client_receive_smb(Client, inbuf, CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - if (!err_silent) { - DEBUG(0,("%s setting attributes on file %s\n", - smb_errstr(inbuf), fname)); - } - free(name);free(inbuf);free(outbuf); - return(False); - } - - free(name); - free(inbuf);free(outbuf); - return(True); - -} - -/**************************************************************************** -Set DOS file attributes -***************************************************************************/ -static int do_setrattr(char *fname, int attr, int setit) -{ - /* - * First get the existing attribs from existing file - */ - char *inbuf,*outbuf; - char *p; - char *name; - int fattr; - - name = (char *)malloc(strlen(fname) + 1 + 1); - if (name == NULL) { - - DEBUG(0, ("Failed to allocate space in do_setrattr while setting time on file: %s", fname)); - return False; - - } - - safe_strcpy(name, "\\", strlen(fname) + 1); - safe_strcat(name, fname, strlen(fname) + 1); - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) - { - DEBUG(0,("out of memory\n")); - free(name); - return False; - } - - /* send an smb getatr message */ - - memset(outbuf,0,smb_size); - set_message(outbuf,0,2 + strlen(fname),True); - CVAL(outbuf,smb_com) = SMBgetatr; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - p = smb_buf(outbuf); - *p++ = 4; - safe_strcpy(p,name, strlen(name)); - p += (strlen(name)+1); - - *p++ = 4; - *p++ = 0; - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - DEBUG(5,("getatr: %s\n",smb_errstr(inbuf))); - else - { - DEBUG(5,("\nattr 0x%X time %d size %d\n", - (int)CVAL(inbuf,smb_vwv0), - SVAL(inbuf,smb_vwv1), - SVAL(inbuf,smb_vwv3))); - } - - fattr=CVAL(inbuf,smb_vwv0); - - /* combine found attributes with bits to be set or reset */ - - attr=setit ? (fattr | attr) : (fattr & ~attr); - - /* now try and set attributes by sending smb reset message */ - - /* clear out buffer and start again */ - memset(outbuf,0,smb_size); - set_message(outbuf,8,4 + strlen(name),True); - CVAL(outbuf,smb_com) = SMBsetatr; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - SSVAL(outbuf,smb_vwv0,attr); - - p = smb_buf(outbuf); - *p++ = 4; - safe_strcpy(p,name, strlen(name)); - p += (strlen(name)+1); - - *p++ = 4; - *p++ = 0; - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("%s setting attributes on file %s\n", - smb_errstr(inbuf), name)); - free(name);free(inbuf);free(outbuf); - return(False); - } - - free(name); - free(inbuf);free(outbuf); - return(True); -} - -/**************************************************************************** -Create a file on a share -***************************************************************************/ -static BOOL smbcreat(file_info2 finfo, int *fnum, char *inbuf, char *outbuf) -{ - char *p; - /* *must* be called with buffer ready malloc'ed */ - /* open remote file */ - - memset(outbuf,0,smb_size); - set_message(outbuf,3,2 + strlen(finfo.name),True); - CVAL(outbuf,smb_com) = SMBcreate; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - SSVAL(outbuf,smb_vwv0,finfo.mode); - put_dos_date3(outbuf,smb_vwv1,finfo.mtime); - - p = smb_buf(outbuf); - *p++ = 4; - safe_strcpy(p,finfo.name, strlen(finfo.name)); - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("%s opening remote file %s\n",smb_errstr(inbuf), - finfo.name)); - return 0; - } - - *fnum = SVAL(inbuf,smb_vwv0); - return True; -} - -/**************************************************************************** -Write a file to a share -***************************************************************************/ -static BOOL smbwrite(int fnum, int n, int low, int high, int left, - char *bufferp, char *inbuf, char *outbuf) -{ - /* *must* be called with buffer ready malloc'ed */ - - memset(outbuf,0,smb_size); - set_message(outbuf,5,n + 3,True); - - memcpy(smb_buf(outbuf)+3, bufferp, n); - - set_message(outbuf,5,n + 3, False); - CVAL(outbuf,smb_com) = SMBwrite; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - SSVAL(outbuf,smb_vwv0,fnum); - SSVAL(outbuf,smb_vwv1,n); - SIVAL(outbuf,smb_vwv2,low); - SSVAL(outbuf,smb_vwv4,left); - CVAL(smb_buf(outbuf),0) = 1; - SSVAL(smb_buf(outbuf),1,n); - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("%s writing remote file\n",smb_errstr(inbuf))); - return False; - } - - if (n != SVAL(inbuf,smb_vwv0)) - { - DEBUG(0,("Error: only wrote %d bytes out of %d\n", - SVAL(inbuf,smb_vwv0), n)); - return False; - } - - return True; -} - -/**************************************************************************** -Close a file on a share -***************************************************************************/ -static BOOL smbshut(file_info2 finfo, int fnum, char *inbuf, char *outbuf) -{ - /* *must* be called with buffer ready malloc'ed */ - - memset(outbuf,0,smb_size); - set_message(outbuf,3,0,True); - CVAL(outbuf,smb_com) = SMBclose; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - SSVAL(outbuf,smb_vwv0,fnum); - put_dos_date3(outbuf,smb_vwv1,finfo.mtime); - - DEBUG(3,("Setting date to %s (0x%lX)", - asctime(LocalTime(&finfo.mtime)), - finfo.mtime)); - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("%s closing remote file %s\n",smb_errstr(inbuf), - finfo.name)); - return False; - } - - return True; -} - -/**************************************************************************** -Verify existence of path on share -***************************************************************************/ -static BOOL smbchkpath(char *fname, char *inbuf, char *outbuf) -{ - char *p; - - memset(outbuf,0,smb_size); - set_message(outbuf,0,4 + strlen(fname),True); - CVAL(outbuf,smb_com) = SMBchkpth; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - p = smb_buf(outbuf); - *p++ = 4; - safe_strcpy(p,fname, strlen(fname)); - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - DEBUG(5,("smbchkpath: %s\n",smb_errstr(inbuf))); - - return(CVAL(inbuf,smb_rcls) == 0); -} - -/**************************************************************************** -Make a directory on share -***************************************************************************/ -static BOOL smbmkdir(char *fname, char *inbuf, char *outbuf) -{ - /* *must* be called with buffer ready malloc'ed */ - char *p; - - memset(outbuf,0,smb_size); - set_message(outbuf,0,2 + strlen(fname),True); - - CVAL(outbuf,smb_com) = SMBmkdir; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - p = smb_buf(outbuf); - *p++ = 4; - safe_strcpy(p,fname, strlen(fname)); - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("%s making remote directory %s\n", - smb_errstr(inbuf),fname)); - return(False); - } - - return(True); -} /**************************************************************************** Ensure a remote path exists (make if necessary) ***************************************************************************/ -static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) +static BOOL ensurepath(char *fname) { /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ @@ -963,8 +561,8 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) { safe_strcat(partpath, p, strlen(fname) + 1); - if (!smbchkpath(partpath, inbuf, outbuf)) { - if (!smbmkdir(partpath, inbuf, outbuf)) + if (!cli_chkpath(cli, partpath)) { + if (!cli_mkdir(cli, partpath)) { DEBUG(0, ("Error mkdirhiering\n")); return False; @@ -983,23 +581,40 @@ static BOOL ensurepath(char *fname, char *inbuf, char *outbuf) static int padit(char *buf, int bufsize, int padsize) { - int berr= 0; - int bytestowrite; + int berr= 0; + int bytestowrite; - DEBUG(5, ("Padding with %d zeros\n", padsize)); - memset(buf, 0, bufsize); - while( !berr && padsize > 0 ) { - bytestowrite= MIN(bufsize, padsize); - berr = dotarbuf(tarhandle, buf, bytestowrite) != bytestowrite; - padsize -= bytestowrite; - } + DEBUG(5, ("Padding with %d zeros\n", padsize)); + memset(buf, 0, bufsize); + while( !berr && padsize > 0 ) { + bytestowrite= MIN(bufsize, padsize); + berr = dotarbuf(tarhandle, buf, bytestowrite) != bytestowrite; + padsize -= bytestowrite; + } - return berr; + return berr; } -/* - * smbclient functions - */ + +static void do_setrattr(char *name, int attr, int set) +{ + int oldattr; + time_t t; + + if (!cli_getatr(cli, name, &oldattr, NULL, &t)) return; + + if (set == ATTRSET) { + attr |= oldattr; + } else { + attr = oldattr & ~attr; + } + + if (!cli_setatr(cli, name, attr, t)) { + DEBUG(1,("setatr failed: %s\n", cli_errstr(cli))); + } +} + + /**************************************************************************** append one remote file to the tar file ***************************************************************************/ @@ -1008,12 +623,11 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) int fnum; uint32 nread=0; char *p, ftype; - char *inbuf,*outbuf; file_info2 finfo; BOOL close_done = False; BOOL shallitime=True; - BOOL ignore_close_error = False; - char *dataptr=NULL; + char data[65520]; + int read_size = 65520; int datalen=0; struct timeval tp_start; @@ -1050,91 +664,34 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) ntarf++; return; } - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) - { - DEBUG(0,("out of memory\n")); - return; - } - - memset(outbuf,0,smb_size); - set_message(outbuf,15,1 + strlen(rname),True); - - CVAL(outbuf,smb_com) = SMBopenX; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - SSVAL(outbuf,smb_vwv0,0xFF); - SSVAL(outbuf,smb_vwv2,1); - SSVAL(outbuf,smb_vwv3,(DENY_NONE<<4)); - SSVAL(outbuf,smb_vwv4,aSYSTEM | aHIDDEN); - SSVAL(outbuf,smb_vwv5,aSYSTEM | aHIDDEN); - SSVAL(outbuf,smb_vwv8,1); - - p = smb_buf(outbuf); - safe_strcpy(p, rname, strlen(rname)); - p = skip_string(p,1); + fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); dos_clean_name(rname); - /* do a chained openX with a readX? */ - if (finfo.size > 0) - { - SSVAL(outbuf,smb_vwv0,SMBreadX); - SSVAL(outbuf,smb_vwv1,PTR_DIFF(p,outbuf) - 4); - memset(p,0,200); - p -= smb_wct; - SCVAL(p,smb_wct,10); - SSVAL(p,smb_vwv0,0xFF); - SSVAL(p,smb_vwv5,MIN(max_xmit-500,finfo.size)); - SSVAL(p,smb_vwv9,MIN(0xFFFF,finfo.size)); - smb_setlen(outbuf,smb_len(outbuf)+11*2+1); - } - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - if (CVAL(inbuf,smb_rcls) == ERRSRV && - SVAL(inbuf,smb_err) == ERRnoresource && - cli_reopen_connection(inbuf,outbuf)) - { - do_atar(rname,lname,finfo1); - free(inbuf);free(outbuf); + if (fnum == -1) { + DEBUG(0,("%s opening remote file %s (%s)\n", + cli_errstr(cli),rname, cur_dir)); return; - } - - DEBUG(0,("%s opening remote file %s\n",smb_errstr(inbuf),rname)); - free(inbuf);free(outbuf); - return; - } + } finfo.name = string_create_s(strlen(rname)); if (finfo.name == NULL) { - - DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); - free(inbuf); free(outbuf); - return; - + DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); + return; } safe_strcpy(finfo.name,rname, strlen(rname)); - if (!finfo1) - { - finfo.mode = SVAL(inbuf,smb_vwv3); - finfo.size = IVAL(inbuf,smb_vwv4); - finfo.mtime = make_unix_date3(inbuf+smb_vwv6); - finfo.atime = finfo.ctime = finfo.mtime; - } + if (!finfo1) { + if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &finfo.atime, &finfo.mtime)) { + DEBUG(0, ("getattrE: %s\n", cli_errstr(cli))); + return; + } + finfo.ctime = finfo.mtime; + } DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); - fnum = SVAL(inbuf,smb_vwv2); - if (tar_inc && !(finfo.mode & aARCH)) { DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name)); @@ -1152,18 +709,6 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) } else { - if (SVAL(inbuf,smb_vwv0) == SMBreadX) - { - p = (inbuf+4+SVAL(inbuf,smb_vwv1)) - smb_wct; - datalen = SVAL(p,smb_vwv5); - dataptr = inbuf + 4 + SVAL(p,smb_vwv6); - } - else - { - dataptr = NULL; - datalen = 0; - } - DEBUG(3,("getting file %s of size %d bytes as a tar file %s", finfo.name, finfo.size, @@ -1171,217 +716,41 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) /* write a tar header, don't bother with mode - just set to 100644 */ writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); - - while (nread < finfo.size && !close_done) - { - int method = -1; - static BOOL can_chain_close=True; - - p=NULL; - - DEBUG(3,("nread=%d\n",nread)); - - /* 3 possible read types. readbraw if a large block is required. - readX + close if not much left and read if neither is supported */ - /* we might have already read some data from a chained readX */ - if (dataptr && datalen>0) - method=3; - - /* if we can finish now then readX+close */ - if (method<0 && can_chain_close && (Protocol >= PROTOCOL_LANMAN1) && - ((finfo.size - nread) < - (max_xmit - (2*smb_size + 13*SIZEOFWORD + 300)))) - method = 0; - - /* if we support readraw then use that */ - if (method<0 && readbraw_supported) - method = 1; - - /* if we can then use readX */ - if (method<0 && (Protocol >= PROTOCOL_LANMAN1)) - method = 2; - - - switch (method) - { - /* use readX */ - case 0: - case 2: - if (method == 0) - close_done = True; - - /* use readX + close */ - memset(outbuf,0,smb_size); - set_message(outbuf,10,0,True); - CVAL(outbuf,smb_com) = SMBreadX; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - if (close_done) - { - CVAL(outbuf,smb_vwv0) = SMBclose; - SSVAL(outbuf,smb_vwv1,PTR_DIFF(smb_buf(outbuf),outbuf) - 4); - } - else - CVAL(outbuf,smb_vwv0) = 0xFF; - - - SSVAL(outbuf,smb_vwv2,fnum); - SIVAL(outbuf,smb_vwv3,nread); - SSVAL(outbuf,smb_vwv5,MIN(max_xmit-200,finfo.size - nread)); - SSVAL(outbuf,smb_vwv6,0); - SIVAL(outbuf,smb_vwv7,0); - SSVAL(outbuf,smb_vwv9,MIN(0xFFFF,finfo.size-nread)); - - if (close_done) - { - p = smb_buf(outbuf); - memset(p,0,9); - - CVAL(p,0) = 3; - SSVAL(p,1,fnum); - SIVALS(p,3,-1); - - /* now set the total packet length */ - smb_setlen(outbuf,smb_len(outbuf)+9); - } + while (nread < finfo.size && !close_done) { + p=NULL; - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); + DEBUG(3,("nread=%d\n",nread)); - if (CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("Error %s reading remote file\n",smb_errstr(inbuf))); - break; - } + datalen = cli_read(cli, fnum, data, nread, read_size); - if (close_done && - SVAL(inbuf,smb_vwv0) != SMBclose) - { - /* NOTE: WfWg sometimes just ignores the chained - command! This seems to break the spec? */ - DEBUG(3,("Rejected chained close?\n")); - close_done = False; - can_chain_close = False; - ignore_close_error = True; - } - - datalen = SVAL(inbuf,smb_vwv5); - dataptr = inbuf + 4 + SVAL(inbuf,smb_vwv6); - break; + if (datalen == -1) { + DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli))); + break; + } + /* add received bits of file to buffer - dotarbuf will + * write out in 512 byte intervals */ + if (dotarbuf(tarhandle,data,datalen) != datalen) { + DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); + break; + } - /* use readbraw */ - case 1: - { - static int readbraw_size = 0xFFFF; - - extern int Client; - memset(outbuf,0,smb_size); - set_message(outbuf,8,0,True); - CVAL(outbuf,smb_com) = SMBreadbraw; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - SSVAL(outbuf,smb_vwv0,fnum); - SIVAL(outbuf,smb_vwv1,nread); - SSVAL(outbuf,smb_vwv3,MIN(finfo.size-nread,readbraw_size)); - SSVAL(outbuf,smb_vwv4,0); - SIVALS(outbuf,smb_vwv5,-1); - send_smb(Client,outbuf); - - /* Now read the raw data into the buffer and write it */ - if(read_smb_length(Client,inbuf,0) == -1) { - DEBUG(0,("Failed to read length in readbraw\n")); - exit(1); - } - - /* Even though this is not an smb message, smb_len - returns the generic length of an smb message */ - datalen = smb_len(inbuf); - - if (datalen == 0) - { - /* we got a readbraw error */ - DEBUG(4,("readbraw error - reducing size\n")); - readbraw_size = (readbraw_size * 9) / 10; - - if (readbraw_size < max_xmit) - { - DEBUG(0,("disabling readbraw\n")); - readbraw_supported = False; - } - - dataptr=NULL; - continue; - } - - if(read_data(Client,inbuf,datalen) != datalen) { - DEBUG(0,("Failed to read data in readbraw\n")); - exit(1); - } - dataptr = inbuf; + nread += datalen; + if (datalen == 0) { + DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); + break; } - break; - case 3: - /* we've already read some data with a chained readX */ - break; - - default: - /* use plain read */ - memset(outbuf,0,smb_size); - set_message(outbuf,5,0,True); - CVAL(outbuf,smb_com) = SMBread; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - SSVAL(outbuf,smb_vwv0,fnum); - SSVAL(outbuf,smb_vwv1,MIN(max_xmit-200,finfo.size - nread)); - SIVAL(outbuf,smb_vwv2,nread); - SSVAL(outbuf,smb_vwv4,finfo.size - nread); - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("Error %s reading remote file\n",smb_errstr(inbuf))); - break; - } - - datalen = SVAL(inbuf,smb_vwv0); - dataptr = smb_buf(inbuf) + 3; - break; - } - - - /* add received bits of file to buffer - dotarbuf will - * write out in 512 byte intervals */ - if (dotarbuf(tarhandle,dataptr,datalen) != datalen) - { - DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); - break; - } - - nread += datalen; - if (datalen == 0) - { - DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); - break; - } - - dataptr=NULL; - datalen=0; - } + datalen=0; + } - /* pad tar file with zero's if we couldn't get entire file */ - if (nread < finfo.size) - { - DEBUG(0, ("Didn't get entire file. size=%d, nread=%d\n", finfo.size, nread)); - if (padit(inbuf, BUFFER_SIZE, finfo.size - nread)) - DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); - } + /* pad tar file with zero's if we couldn't get entire file */ + if (nread < finfo.size) { + DEBUG(0, ("Didn't get entire file. size=%d, nread=%d\n", finfo.size, nread)); + if (padit(data, sizeof(data), finfo.size - nread)) + DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); + } /* round tar file to nearest block */ if (finfo.size % TBLOCK) @@ -1391,27 +760,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) ntarf++; } - if (!close_done) - { - memset(outbuf,0,smb_size); - set_message(outbuf,3,0,True); - CVAL(outbuf,smb_com) = SMBclose; - SSVAL(outbuf,smb_tid,cnum); - cli_setup_pkt(outbuf); - - SSVAL(outbuf,smb_vwv0,fnum); - SIVALS(outbuf,smb_vwv1,-1); - - send_smb(Client,outbuf); - client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); - - if (!ignore_close_error && CVAL(inbuf,smb_rcls) != 0) - { - DEBUG(0,("Error %s closing remote file\n",smb_errstr(inbuf))); - free(inbuf);free(outbuf); - return; - } - } + cli_close(cli, fnum); if (shallitime) { @@ -1441,8 +790,6 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); } - - free(inbuf);free(outbuf); } /**************************************************************************** @@ -1452,7 +799,7 @@ static void do_tar(file_info *finfo) { pstring rname; - if (strequal(finfo->name,"..")) + if (strequal(finfo->name,"..") || strequal(finfo->name,".")) return; /* Is it on the exclude list ? */ @@ -1484,16 +831,6 @@ static void do_tar(file_info *finfo) { pstring saved_curdir; pstring mtar_mask; - char *inbuf,*outbuf; - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) - { - DEBUG(0,("out of memory\n")); - return; - } safe_strcpy(saved_curdir, cur_dir, sizeof(saved_curdir)); @@ -1508,16 +845,13 @@ static void do_tar(file_info *finfo) * 40755 */ writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); if (tar_noisy) { - - DEBUG(0, (" directory %s\n", cur_dir)); - + DEBUG(0,(" directory %s\n", cur_dir)); } ntarf++; /* Make sure we have a file on there */ safe_strcpy(mtar_mask,cur_dir, sizeof(pstring)); - safe_strcat(mtar_mask,"*", sizeof(pstring)); - /* do_dir((char *)inbuf,(char *)outbuf,mtar_mask,attribute,do_tar,recurse,True); */ + safe_strcat(mtar_mask,"*.*", sizeof(pstring)); + do_list(mtar_mask, attribute, do_tar, False, True); safe_strcpy(cur_dir,saved_curdir, sizeof(pstring)); - free(inbuf);free(outbuf); } else { @@ -1571,7 +905,6 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) } } -#ifndef OLD_DOTARPUT /**************************************************************************** Move to the next block in the buffer, which may mean read in another set of @@ -1635,15 +968,15 @@ static int skip_file(int skipsize) } /* We get a file from the tar file and store it */ -static int get_file(file_info2 finfo, char * inbuf, char * outbuf) +static int get_file(file_info2 finfo) { int fsize = finfo.size; int fnum, pos = 0, dsize = 0, rsize = 0, bpos = 0; DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, fsize)); - if (ensurepath(finfo.name, inbuf, outbuf) && - !smbcreat(finfo, &fnum, inbuf, outbuf)) + if (ensurepath(finfo.name) && + (fnum=cli_open(cli, finfo.name, O_WRONLY|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { DEBUG(0, ("abandoning restore\n")); return(False); @@ -1657,15 +990,13 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) /* We can only write up to the end of the buffer */ - dsize = MIN(tbufsiz - (buffer_p - tarbuf) - bpos, max_xmit - 50); /* Calculate the size to write */ + dsize = MIN(tbufsiz - (buffer_p - tarbuf) - bpos, 65520); /* Calculate the size to write */ dsize = MIN(dsize, rsize); /* Should be only what is left */ - DEBUG(5, ("writing %i bytes, max_xmit = %i, bpos = %i ...\n", dsize, max_xmit, bpos)); - - if (!smbwrite(fnum, dsize, pos, 0, fsize - pos, buffer_p + bpos, inbuf, outbuf)) { - - DEBUG(0, ("Error writing remote file\n")); - return 0; + DEBUG(5, ("writing %i bytes, bpos = %i ...\n", dsize, bpos)); + if (cli_write(cli, fnum, 0, buffer_p + bpos, pos, dsize) != dsize) { + DEBUG(0, ("Error writing remote file\n")); + return 0; } rsize -= dsize; @@ -1710,23 +1041,20 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) /* Now close the file ... */ - if (!smbshut(finfo, fnum, inbuf, outbuf)) { - - DEBUG(0, ("Error closing remote file\n")); - return(False); - + if (!cli_close(cli, fnum)) { + DEBUG(0, ("Error closing remote file\n")); + return(False); } /* Now we update the creation date ... */ DEBUG(5, ("Updating creation date on %s\n", finfo.name)); - if (!do_setrtime(finfo.name, finfo.mtime, True)) { - - 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 */ - } + if (!cli_setatr(cli, 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 */ + } } ntarf++; @@ -1734,18 +1062,17 @@ static int get_file(file_info2 finfo, char * inbuf, char * outbuf) DEBUG(0, ("restore tar file %s of size %d bytes\n", finfo.name, finfo.size)); return(True); - } /* Create a directory. We just ensure that the path exists and return as there is no file associated with a directory */ -static int get_dir(file_info2 finfo, char * inbuf, char * outbuf) +static int get_dir(file_info2 finfo) { DEBUG(5, ("Creating directory: %s\n", finfo.name)); - if (!ensurepath(finfo.name, inbuf, outbuf)) { + if (!ensurepath(finfo.name)) { DEBUG(0, ("Problems creating directory\n")); return(False); @@ -1809,7 +1136,7 @@ static void do_tarput(void) { file_info2 finfo; struct timeval tp_start; - char *inbuf, *outbuf, *longfilename = NULL, linkflag; + char *longfilename = NULL, linkflag; int skip = False; GetTimeOfDay(&tp_start); @@ -1818,30 +1145,6 @@ static void do_tarput(void) buffer_p = tarbuf + tbufsiz; /* init this to force first read */ -#if 0 /* Fix later ... */ - if (push_dir(&dir_stack, &finfo)) { - file_info2 *finfo2; - - finfo2 = pop_dir(&dir_stack); - inbuf = top_dir_name(&dir_stack); /* FIXME */ - if (sub_dir(inbuf, finfo2 -> name)){ - - DEBUG(0, ("")); - - } - } -#endif - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) { - - DEBUG(0, ("Out of memory during allocate of inbuf and outbuf!\n")); - return; - - } - /* Now read through those files ... */ while (True) { @@ -1866,7 +1169,6 @@ static void do_tarput(void) !skip_file(finfo.size)) { DEBUG(0, ("Short file, bailing out...\n")); - free(inbuf); free(outbuf); return; } @@ -1875,12 +1177,10 @@ static void do_tarput(void) case -1: DEBUG(0, ("abandoning restore, -1 from read tar header\n")); - free(inbuf); free(outbuf); return; case 0: /* chksum is zero - looks like an EOF */ DEBUG(0, ("total of %d tar files restored to share\n", ntarf)); - free(inbuf); free(outbuf); return; /* Hmmm, bad here ... */ default: @@ -1933,12 +1233,9 @@ static void do_tarput(void) if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { DEBUG(0, ("Short file, bailing out...\n")); - free(inbuf); free(outbuf); return; } - if (!get_file(finfo, inbuf, outbuf)) { - - free(inbuf); free(outbuf); + if (!get_file(finfo)) { DEBUG(0, ("Abandoning restore\n")); return; @@ -1946,8 +1243,7 @@ static void do_tarput(void) break; case '5': - if (!get_dir(finfo, inbuf, outbuf)) { - free(inbuf); free(outbuf); + if (!get_dir(finfo)) { DEBUG(0, ("Abandoning restore \n")); return; } @@ -1956,7 +1252,6 @@ static void do_tarput(void) case 'L': longfilename = get_longfilename(finfo); if (!longfilename) { - free(inbuf); free(outbuf); DEBUG(0, ("abandoning restore\n")); return; @@ -1975,326 +1270,6 @@ static void do_tarput(void) } -#else - -static void do_tarput() -{ - file_info2 finfo; - int nread=0, bufread; - char *inbuf,*outbuf, *longname = NULL; - int fsize=0; - int fnum; - struct timeval tp_start; - BOOL tskip=False; /* We'll take each file as it comes */ - - finfo.name = NULL; /* No name in here ... */ - - GetTimeOfDay(&tp_start); - - inbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - outbuf = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN); - - if (!inbuf || !outbuf) - { - DEBUG(0,("out of memory\n")); - return; - } - - /* - * Must read in tbufsiz dollops - */ - - /* These should be the only reads in clitar.c */ - while ((bufread=read(tarhandle, tarbuf, tbufsiz))>0) { - char *endofbuffer; - int chunk; - - /* Code to handle a short read. - * We always need a TBLOCK full of stuff - */ - if (bufread % TBLOCK) { - int lchunk=TBLOCK-(bufread % TBLOCK); - int lread; - - /* It's a shorty - a short read that is */ - DEBUG(3, ("Short read, read %d so far (need %d)\n", bufread, lchunk)); - - while ((lread=read(tarhandle, tarbuf+bufread, lchunk))>0) { - bufread+=lread; - if (!(lchunk-=lread)) break; - } - - /* If we've reached EOF then that must be a short file */ - if (lread<=0) break; - } - - buffer_p=tarbuf; - endofbuffer=tarbuf+bufread; - - if (tskip) { - if (fsize= endofbuffer) { - - bufread = read(tarhandle, tarbuf, tbufsiz); - buffer_p = tarbuf; - - } - next_header = 0; /* Don't want the next one ... */ - - if (finfo.name != NULL) { /* Free the space */ - - free(finfo.name); - finfo.name = NULL; - - } - DEBUG(5, ("Tarbuf=%X, buffer=%X, endofbuf=%X\n", - (int)tarbuf, (int)buffer_p, (int)endofbuffer)); - switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) - { - case -2: /* something dodgy but not fatal about this */ - DEBUG(0, ("skipping %s...\n", finfo.name)); - buffer_p+=TBLOCK; /* header - like a link */ - continue; - case -1: - DEBUG(0, ("abandoning restore, -1 from readtarheader\n")); - free(inbuf); free(outbuf); - return; - case 0: /* chksum is zero - we assume that one all zero - *header block will do for eof */ - DEBUG(0, - ("total of %d tar files restored to share\n", ntarf)); - free(inbuf); free(outbuf); - return; - default: - break; - } - - /* If we have a longname left from the last time through, - copy it into finfo.name and free it. - - The size of a pstring is the limiting factor on filenames - and directory names now. The total pathname length must be - less than sizeof(pstring) - 1, which is currently 1023. */ - - if (longname != NULL) { - - free(finfo.name); /* Free the name in the finfo */ - finfo.name = string_create_s(strlen(longname) + 2); - strncpy(finfo.name, longname, strlen(longname) + 1); - DEBUG(5, ("Long name = \"%s\", filename=\"%s\"\n", longname, finfo.name)); - free(longname); - longname = NULL; - - } - - /* Check if a long-link. We do this before the clip checking - because clip-checking should clip on real name - RJS */ - - if (((union hblock *)buffer_p) -> dbuf.linkflag == 'L') { - int file_len, first = 0; char *cp; - - /* Skip this header, but pick up length, get the name and - fix the name and skip the name. Hmmm, what about end of - buffer??? */ - - longname = malloc(finfo.size + strlen(cur_dir) + 1); - if (longname == NULL) { - - DEBUG(0, ("could not allocate buffer of size %d for longname\n", - finfo.size + strlen(cur_dir) + 1) - ); - free(inbuf); free(outbuf); - return; - } - - - bzero(longname, finfo.size + strlen(cur_dir) +1); - - buffer_p += TBLOCK; /* Skip that longlink header */ - - /* This needs restructuring ... */ - - safe_strcpy(longname, cur_dir, strlen(cur_dir) + 1); - cp = longname + strlen(cur_dir); - file_len = finfo.size; - - DEBUG(5, ("longname=%0X, cp=%0X, file_len=%i\n", - (int)longname, (int)cp, file_len)); - - while (file_len > 0) { - - if (buffer_p >= endofbuffer) { - - bufread = read(tarhandle, tarbuf, tbufsiz); - - buffer_p = tarbuf; - - } - - unfixtarname(cp, buffer_p, file_len >= TBLOCK?TBLOCK:file_len, first == 0); - - first++; /* Not the first anymore */ - cp = cp + strlen(cp); /* Move to end of string */ - buffer_p += TBLOCK; - file_len -= TBLOCK; - DEBUG(5, ("cp=%0X, file_len=%i\n", (int)cp, file_len)); - next_header = 1; /* Force read of next header */ - - } - } - } - tskip=clipn - && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) -#ifdef HAVE_REGEX_H - || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); -#else - || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); -#endif - if (tskip) { - buffer_p+=TBLOCK; - if (finfo.mode & aDIR) - continue; - else if ((fsize=finfo.size) % TBLOCK) { - fsize+=TBLOCK-(fsize%TBLOCK); - } - if (fsize= endofbuffer) break; - } /* if (!fsize) */ - - /* write out the file in chunk sized chunks - don't - * go past end of buffer though */ - chunk=(fsize-nread < endofbuffer - buffer_p) - ? fsize - nread : endofbuffer - buffer_p; - - while (chunk > 0) { - int minichunk=MIN(chunk, max_xmit-200); - - if (!smbwrite(fnum, /* file descriptor */ - minichunk, /* n */ - nread, /* offset low */ - 0, /* offset high - not implemented */ - fsize-nread, /* left - only hint to server */ - buffer_p, - inbuf, - outbuf)) - { - DEBUG(0, ("Error writing remote file\n")); - free(inbuf); free(outbuf); - return; - } - DEBUG(5, ("chunk writing fname=%s fnum=%d nread=%d minichunk=%d chunk=%d size=%d\n", finfo.name, fnum, nread, minichunk, chunk, fsize)); - - buffer_p+=minichunk; nread+=minichunk; - chunk-=minichunk; - } - - if (nread>=fsize) - { - if (!smbshut(finfo, fnum, inbuf, outbuf)) - { - DEBUG(0, ("Error closing remote file\n")); - free(inbuf);free(outbuf); - return; - } - if (fsize % TBLOCK) buffer_p+=TBLOCK - (fsize % TBLOCK); - DEBUG(5, ("buffer_p is now %d (psn=%d)\n", - (int) buffer_p, (int)(buffer_p - tarbuf))); - ntarf++; - fsize=0; - - } - } while (buffer_p < endofbuffer); - } - - DEBUG(0, ("premature eof on tar file ?\n")); - DEBUG(0,("total of %d tar files restored to share\n", ntarf)); - - free(inbuf); free(outbuf); -} -#endif /* * samba interactive commands @@ -2303,7 +1278,7 @@ static void do_tarput() /**************************************************************************** Blocksize command ***************************************************************************/ -void cmd_block(char *dum_in, char *dum_out) +void cmd_block(void) { fstring buf; int block; @@ -2328,7 +1303,7 @@ void cmd_block(char *dum_in, char *dum_out) /**************************************************************************** command to set incremental / reset mode ***************************************************************************/ -void cmd_tarmode(char *dum_in, char *dum_out) +void cmd_tarmode(void) { fstring buf; @@ -2368,7 +1343,7 @@ void cmd_tarmode(char *dum_in, char *dum_out) /**************************************************************************** Feeble attrib command ***************************************************************************/ -void cmd_setmode(char *dum_in, char *dum_out) +void cmd_setmode(void) { char *q; fstring buf; @@ -2423,7 +1398,7 @@ void cmd_setmode(char *dum_in, char *dum_out) /**************************************************************************** Principal command for creating / extracting ***************************************************************************/ -void cmd_tar(char *inbuf, char *outbuf) +void cmd_tar(void) { fstring buf; char **argl; @@ -2439,7 +1414,7 @@ void cmd_tar(char *inbuf, char *outbuf) if (!tar_parseargs(argcl, argl, buf, 0)) return; - process_tar(inbuf, outbuf); + process_tar(); free(argl); } @@ -2447,7 +1422,7 @@ void cmd_tar(char *inbuf, char *outbuf) /**************************************************************************** Command line (option) version ***************************************************************************/ -int process_tar(char *inbuf, char *outbuf) +int process_tar(void) { initarbuf(); switch(tar_type) { @@ -2488,19 +1463,19 @@ int process_tar(char *inbuf, char *outbuf) safe_strcpy(cur_dir, tarmac, sizeof(pstring)); *(strrchr(cur_dir, '\\')+1)='\0'; - do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); + do_list(tarmac,attribute,do_tar, False, True); safe_strcpy(cur_dir,saved_dir, sizeof(pstring)); } else { safe_strcpy(tarmac, cur_dir, sizeof(pstring)); safe_strcat(tarmac, cliplist[i], sizeof(pstring)); - do_dir((char *)inbuf,(char *)outbuf,tarmac,attribute,do_tar,recurse, True); + do_list(tarmac,attribute,do_tar, False, True); } } } else { pstring mask; safe_strcpy(mask,cur_dir, sizeof(pstring)); - safe_strcat(mask,"\\*", sizeof(pstring)); - do_dir((char *)inbuf,(char *)outbuf,mask,attribute,do_tar,recurse, True); + safe_strcat(mask,"\\*.*", sizeof(pstring)); + do_list(mask,attribute,do_tar,False, True); } if (ntarf) dotareof(tarhandle); -- cgit From e4f974c611c179a5e7827ec8325e01811db6540b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Nov 1998 20:33:37 +0000 Subject: Makefile.in: Removed rpc_server/srv_ldap_helpers.c per J.F.'s instructions. client/client.c: client/clitar.c: include/client.h: smbwrapper/smbw_dir.c: smbwrapper/smbw_stat.c: smbwrapper/smbw.c: lib/util.c: Converted all use of 'mode' to uint16. smbd/quotas.c: Fixed stupid comment bug I put in there :-(. printing/printing.c: Fix from J.F. to new code. Jeremy. (This used to be commit bacd3e9d2036a804e73644a28fc498f229c8446c) --- source3/client/clitar.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 8ebe9dc853..aade8fcb6f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -45,8 +45,8 @@ typedef struct file_info_struct file_info2; struct file_info_struct { - int size; - int mode; + size_t size; + uint16 mode; int uid; int gid; /* These times are normally kept in GMT */ @@ -77,7 +77,7 @@ extern struct cli_state *cli; #define ATTRSET 1 #define ATTRRESET 0 -static int attribute = aDIR | aSYSTEM | aHIDDEN; +static uint16 attribute = aDIR | aSYSTEM | aHIDDEN; #ifndef CLIENT_TIMEOUT #define CLIENT_TIMEOUT (30*1000) @@ -596,9 +596,9 @@ static int padit(char *buf, int bufsize, int padsize) } -static void do_setrattr(char *name, int attr, int set) +static void do_setrattr(char *name, uint16 attr, int set) { - int oldattr; + uint16 oldattr; time_t t; if (!cli_getatr(cli, name, &oldattr, NULL, &t)) return; @@ -622,7 +622,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) { int fnum; uint32 nread=0; - char *p, ftype; + char ftype; file_info2 finfo; BOOL close_done = False; BOOL shallitime=True; @@ -718,7 +718,6 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); while (nread < finfo.size && !close_done) { - p=NULL; DEBUG(3,("nread=%d\n",nread)); @@ -1348,7 +1347,7 @@ void cmd_setmode(void) char *q; fstring buf; pstring fname; - int attra[2]; + uint16 attra[2]; int direct=1; attra[0] = attra[1] = 0; -- cgit From 8fc1504ff8204dd1ca735f31c769f6dadf0f88cb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Nov 1998 21:41:01 +0000 Subject: Makefile.in configure configure.in include/config.h.in: Changes for DGUX and UNIXWARE. groupdb/aliasdb.c groupdb/aliasfile.c groupdb/groupfile.c: Don't use snprinf, use slprintf. include/includes.h: Fix YP problem. include/smb.h: Fix ZERO_STRUCTP. lib/util_sock.c: Added strerror() in debugs. passdb/ldap.c: Don't use snprinf, use slprintf. rpc_client/cli_lsarpc.c rpc_client/cli_pipe.c rpc_parse/parse_sec.c rpc_server/srv_pipe.c: Don't use snprinf, use slprintf. script/installman.sh: DGUX changes. smbd/open.c smbd/oplock.c: Fixed gcc warnings. web/swat.c: Changes USER to SWAT_USER. (This used to be commit 4c2b5a00983501e5d4aad1456ba8b5ab0dfd9b4c) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index aade8fcb6f..e7ddfc5fa0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -970,7 +970,7 @@ static int skip_file(int skipsize) static int get_file(file_info2 finfo) { int fsize = finfo.size; - int fnum, pos = 0, dsize = 0, rsize = 0, bpos = 0; + int fnum = -1, pos = 0, dsize = 0, rsize = 0, bpos = 0; DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, fsize)); -- cgit From fedc62d17a971650f0dc18c7a1fd1185bf6e9905 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Nov 1998 03:53:24 +0000 Subject: - handle servers that don't support getattrE (ie. NT) - use * in clitar instead of *.* (This used to be commit 2d9335fe2a6fc3bb6687360c99d8fc69cb2d555a) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index e7ddfc5fa0..49b076b5e6 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -848,7 +848,7 @@ static void do_tar(file_info *finfo) } ntarf++; /* Make sure we have a file on there */ safe_strcpy(mtar_mask,cur_dir, sizeof(pstring)); - safe_strcat(mtar_mask,"*.*", sizeof(pstring)); + safe_strcat(mtar_mask,"*", sizeof(pstring)); do_list(mtar_mask, attribute, do_tar, False, True); safe_strcpy(cur_dir,saved_curdir, sizeof(pstring)); } -- cgit From c57ab7807d28e642fcbf3315bcb336db03cc0625 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Nov 1998 04:08:19 +0000 Subject: fixed setmode in smbclient (This used to be commit c58f4965100692d8edcd613a341df9e2ad88cfa0) --- source3/client/clitar.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 49b076b5e6..e7915d1066 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -599,9 +599,8 @@ static int padit(char *buf, int bufsize, int padsize) static void do_setrattr(char *name, uint16 attr, int set) { uint16 oldattr; - time_t t; - if (!cli_getatr(cli, name, &oldattr, NULL, &t)) return; + if (!cli_getatr(cli, name, &oldattr, NULL, NULL)) return; if (set == ATTRSET) { attr |= oldattr; @@ -609,7 +608,7 @@ static void do_setrattr(char *name, uint16 attr, int set) attr = oldattr & ~attr; } - if (!cli_setatr(cli, name, attr, t)) { + if (!cli_setatr(cli, name, attr, 0)) { DEBUG(1,("setatr failed: %s\n", cli_errstr(cli))); } } @@ -1354,7 +1353,7 @@ void cmd_setmode(void) if (!next_token(NULL,buf,NULL,sizeof(buf))) { - DEBUG(0, ("setmode \n")); + DEBUG(0, ("setmode <[+|-]rsha>\n")); return; } @@ -1385,13 +1384,13 @@ void cmd_setmode(void) if (attra[ATTRSET]==0 && attra[ATTRRESET]==0) { - DEBUG(0, ("setmode \n")); + DEBUG(0, ("setmode <[+|-]rsha>\n")); return; } DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); - (void) do_setrattr(fname, attra[ATTRSET], ATTRSET); - (void) do_setrattr(fname, attra[ATTRRESET], ATTRRESET); + do_setrattr(fname, attra[ATTRSET], ATTRSET); + do_setrattr(fname, attra[ATTRRESET], ATTRRESET); } /**************************************************************************** -- cgit From 768761820e8d7481c586c4e0ab4ac7cb36d18c4b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 17 Nov 1998 20:50:07 +0000 Subject: Added the same open()/fopen()/creat()/mmap() -> sys_XXX calls. Tidied up some of the mess (no other word for it). Still doesn't compile cleanly. There are calls with incorrect parameters that don't seem to be doing the right thing. This code still needs surgery :-(. Jeremy. (This used to be commit 18ff93a9abbf68ee8c59c0af3e57c63e4a015dac) --- source3/client/clitar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index e7915d1066..a2b23817f5 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1539,7 +1539,7 @@ static int read_inclusion_file(char *filename) clipn = 0; buf[MAXPATHLEN] = '\0'; /* guarantee null-termination */ - if ((inclusion = fopen(filename, "r")) == 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. */ @@ -1823,8 +1823,8 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) } tarhandle=-1; } else - if ((tar_type=='x' && (tarhandle = open(argv[Optind], O_RDONLY)) == -1) - || (tar_type=='c' && (tarhandle=creat(argv[Optind], 0644)) < 0)) + if ((tar_type=='x' && (tarhandle = sys_open(argv[Optind], O_RDONLY, 0)) == -1) + || (tar_type=='c' && (tarhandle=sys_creat(argv[Optind], 0644)) < 0)) { DEBUG(0,("Error opening local file %s - %s\n", argv[Optind], strerror(errno))); -- cgit From d5791b826dfefcb34789dc68a8f00f0653123e70 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Dec 1998 22:44:56 +0000 Subject: Fixed tar recurse bug. Jeremy. (This used to be commit 7be5c8e8f734a2bd8f4e3c38b7f94c501ad35a19) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index a2b23817f5..6e9f8bcd03 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1472,7 +1472,7 @@ int process_tar(void) } else { pstring mask; safe_strcpy(mask,cur_dir, sizeof(pstring)); - safe_strcat(mask,"\\*.*", sizeof(pstring)); + safe_strcat(mask,"\\*", sizeof(pstring)); do_list(mask,attribute,do_tar,False, True); } -- cgit From a7e4be0e782dc4dd9b3d5e3e3af9e49ef93ed08a Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 19 Dec 1998 01:43:24 +0000 Subject: Added some debugging to clitar ... (This used to be commit b75af70990c3a9eaed9e3537b79e8e66a0ae8286) --- source3/client/clitar.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 6e9f8bcd03..f3379a3119 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -848,6 +848,7 @@ static void do_tar(file_info *finfo) ntarf++; /* Make sure we have a file on there */ safe_strcpy(mtar_mask,cur_dir, sizeof(pstring)); safe_strcat(mtar_mask,"*", sizeof(pstring)); + DEBUG(5, ("Doing list with mtar_mask: %s\n, mtar_mask)); do_list(mtar_mask, attribute, do_tar, False, True); safe_strcpy(cur_dir,saved_curdir, sizeof(pstring)); } @@ -1461,17 +1462,20 @@ int process_tar(void) safe_strcpy(cur_dir, tarmac, sizeof(pstring)); *(strrchr(cur_dir, '\\')+1)='\0'; + DEBUG(5, "process_tar, do_list with tarmac: %s\n", tarmac); do_list(tarmac,attribute,do_tar, False, True); safe_strcpy(cur_dir,saved_dir, sizeof(pstring)); } else { safe_strcpy(tarmac, cur_dir, sizeof(pstring)); safe_strcat(tarmac, cliplist[i], sizeof(pstring)); + DEBUG(5, "process_tar, do_list with tarmac: %s\n", tarmac); do_list(tarmac,attribute,do_tar, False, True); } } } else { pstring mask; safe_strcpy(mask,cur_dir, sizeof(pstring)); + DEBUG(5, process_tar, do_list with mask: $s\n", mask); safe_strcat(mask,"\\*", sizeof(pstring)); do_list(mask,attribute,do_tar,False, True); } -- cgit From ddfe1d35fcd383fd13ab6a23617d73e8921337f4 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sat, 19 Dec 1998 02:08:35 +0000 Subject: Fixed problems in debug code because I did not compile first :-( (This used to be commit 47e36bed8fc3cec3a63087f30d680f2431bcfe55) --- source3/client/clitar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f3379a3119..4978a4dec1 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -848,7 +848,7 @@ static void do_tar(file_info *finfo) ntarf++; /* Make sure we have a file on there */ safe_strcpy(mtar_mask,cur_dir, sizeof(pstring)); safe_strcat(mtar_mask,"*", sizeof(pstring)); - DEBUG(5, ("Doing list with mtar_mask: %s\n, mtar_mask)); + DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask)); do_list(mtar_mask, attribute, do_tar, False, True); safe_strcpy(cur_dir,saved_curdir, sizeof(pstring)); } @@ -1462,20 +1462,20 @@ int process_tar(void) safe_strcpy(cur_dir, tarmac, sizeof(pstring)); *(strrchr(cur_dir, '\\')+1)='\0'; - DEBUG(5, "process_tar, do_list with tarmac: %s\n", tarmac); + DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); safe_strcpy(cur_dir,saved_dir, sizeof(pstring)); } else { safe_strcpy(tarmac, cur_dir, sizeof(pstring)); safe_strcat(tarmac, cliplist[i], sizeof(pstring)); - DEBUG(5, "process_tar, do_list with tarmac: %s\n", tarmac); + DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); } } } else { pstring mask; safe_strcpy(mask,cur_dir, sizeof(pstring)); - DEBUG(5, process_tar, do_list with mask: $s\n", mask); + DEBUG(5, ("process_tar, do_list with mask: $s\n", mask)); safe_strcat(mask,"\\*", sizeof(pstring)); do_list(mask,attribute,do_tar,False, True); } -- cgit From 8dac09c5a15bbf17cf69975bff84106eba6147e9 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sun, 17 Jan 1999 01:03:52 +0000 Subject: A small change to clitar.c (really, I promise :-) If we are writing the tar file to stdout, set dbf to stderr so that we do not screw up tar output with log info etc. Compiles clean and tested with 38MB backup. Honest :-) (This used to be commit 57301a3eb4723d0790822d3409da788fec4d8378) --- source3/client/clitar.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 4978a4dec1..dcc176b9d1 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -71,6 +71,7 @@ stack dir_stack = {NULL, 0}; /* Want an empty stack */ #define SEPARATORS " \t\n\r" extern int DEBUGLEVEL; 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 */ @@ -1818,6 +1819,12 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) if (Optind>=argc || !strcmp(argv[Optind], "-")) { /* Sets tar handle to either 0 or 1, as appropriate */ tarhandle=(tar_type=='c'); + /* + * Make sure that dbf points to stderr if we are using stdout for + * tar output + */ + if (tarhandle == 1) + dbf = stderr; } else { if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) { -- cgit From 91403ea47dc6a23bd17c45ed0e5d6b61b3f8b531 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 3 Feb 1999 16:30:54 +0000 Subject: %s not $s (This used to be commit 62118e15fed8c9a7e13705842d0ae59669a2dd8f) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index dcc176b9d1..fd43d37abb 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1476,7 +1476,7 @@ int process_tar(void) } else { pstring mask; safe_strcpy(mask,cur_dir, sizeof(pstring)); - DEBUG(5, ("process_tar, do_list with mask: $s\n", mask)); + DEBUG(5, ("process_tar, do_list with mask: %s\n", mask)); safe_strcat(mask,"\\*", sizeof(pstring)); do_list(mask,attribute,do_tar,False, True); } -- cgit From 1db113b0a2a81a0f37c55aa49517dc64f0578474 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Thu, 25 Mar 1999 20:21:01 +0000 Subject: * client/client.c (dir_total): use SMB_BIG_UINT * client/clitar.c (ttarf): ditto * * lib/snprintf.c: support long longs; adapted from Cloyce D. Spradling's patch (This used to be commit 29581f8486e221f41669c2ca268c282f36a496ce) --- source3/client/clitar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index fd43d37abb..b655b2d325 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -85,7 +85,8 @@ static uint16 attribute = aDIR | aSYSTEM | aHIDDEN; #endif static char *tarbuf, *buffer_p; -static int tp, ntarf, tbufsiz, ttarf; +static int tp, ntarf, tbufsiz; +static SMB_BIG_UINT ttarf; /* Incremental mode */ BOOL tar_inc=False; /* Reset archive bit */ @@ -1486,7 +1487,7 @@ int process_tar(void) free(tarbuf); DEBUG(0, ("tar: dumped %d tar files\n", ntarf)); - DEBUG(0, ("Total bytes written: %d\n", ttarf)); + DEBUG(0, ("Total bytes written: %llu\n", ttarf)); break; } -- cgit From d963fb524c00a6721a3f40fa843785e912a6c487 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Tue, 30 Mar 1999 10:25:20 +0000 Subject: use double instead of SMB_BIG_UINT for dir_total and ttarf (by tridge, merged from branch) (This used to be commit b482ac8fc4948ead79be8dd08c8386449f12e5f6) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index b655b2d325..a7586fcb5e 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1487,7 +1487,7 @@ int process_tar(void) free(tarbuf); DEBUG(0, ("tar: dumped %d tar files\n", ntarf)); - DEBUG(0, ("Total bytes written: %llu\n", ttarf)); + DEBUG(0, ("Total bytes written: %.0f\n", (double)ttarf)); break; } -- cgit From a8aff598f42a7479a2c43cbd04064cbbcf150599 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Tue, 30 Mar 1999 10:41:07 +0000 Subject: declare ttarf as double, as in client.c (This used to be commit dfcfeb743a7667c9dedf3d2b04587c497af12893) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index a7586fcb5e..0b7cf6f54d 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -86,7 +86,7 @@ static uint16 attribute = aDIR | aSYSTEM | aHIDDEN; static char *tarbuf, *buffer_p; static int tp, ntarf, tbufsiz; -static SMB_BIG_UINT ttarf; +static double ttarf; /* Incremental mode */ BOOL tar_inc=False; /* Reset archive bit */ -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/client/clitar.c | 92 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 32 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0b7cf6f54d..76b6ff94d5 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -193,7 +193,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l); i = strlen(b)+1; - DEBUG(5, ("File name in tar file: %s, size=%i, \n", b, strlen(b))); + DEBUG(5, ("File name in tar file: %s, size=%d, \n", b, (int)strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); free(b); } @@ -659,7 +659,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) { DEBUG(3,("skipping file %s of size %d bytes\n", finfo.name, - finfo.size)); + (int)finfo.size)); shallitime=0; ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); ntarf++; @@ -712,7 +712,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) { DEBUG(3,("getting file %s of size %d bytes as a tar file %s", finfo.name, - finfo.size, + (int)finfo.size, lname)); /* write a tar header, don't bother with mode - just set to 100644 */ @@ -747,7 +747,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) /* pad tar file with zero's if we couldn't get entire file */ if (nread < finfo.size) { - DEBUG(0, ("Didn't get entire file. size=%d, nread=%d\n", finfo.size, nread)); + DEBUG(0, ("Didn't get entire file. size=%d, nread=%d\n", (int)finfo.size, (int)nread)); if (padit(data, sizeof(data), finfo.size - nread)) DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); } @@ -781,7 +781,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) if (tar_noisy) { DEBUG(0, ("%10d (%7.1f kb/s) %s\n", - finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), + (int)finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), finfo.name)); } @@ -806,7 +806,7 @@ static void do_tar(file_info *finfo) if (!tar_excl && clipn) { pstring exclaim; - DEBUG(5, ("Excl: strlen(cur_dir) = %i\n", strlen(cur_dir))); + DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir))); safe_strcpy(exclaim, cur_dir, sizeof(pstring)); *(exclaim+strlen(exclaim)-1)='\0'; @@ -834,7 +834,7 @@ static void do_tar(file_info *finfo) safe_strcpy(saved_curdir, cur_dir, sizeof(saved_curdir)); - DEBUG(5, ("Sizeof(cur_dir)=%i, strlen(cur_dir)=%i, strlen(finfo->name)=%i\nname=%s,cur_dir=%s\n", sizeof(cur_dir), strlen(cur_dir), strlen(finfo->name), finfo->name, cur_dir)); + DEBUG(5, ("Sizeof(cur_dir)=%d, strlen(cur_dir)=%d, strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", (int)sizeof(cur_dir), (int)strlen(cur_dir), (int)strlen(finfo->name), finfo->name, cur_dir)); safe_strcat(cur_dir,finfo->name, sizeof(cur_dir)); safe_strcat(cur_dir,"\\", sizeof(cur_dir)); @@ -923,14 +923,27 @@ static int next_block(char *ltarbuf, char **bufferp, int bufsiz) DEBUG(5, ("Reading more data into ltarbuf ...\n")); - total = 0; + /* + * Bugfix from Bob Boehmer + * Fixes bug where read can return short if coming from + * a pipe. + */ - for (bufread = read(tarhandle, ltarbuf, bufsiz); total < bufsiz; total += bufread) { + bufread = read(tarhandle, ltarbuf, bufsiz); + total = bufread; - if (bufread <= 0) { /* An error, return false */ - return (total > 0 ? -2 : bufread); + while (total < bufsiz) { + if (bufread < 0) { /* An error, return false */ + return (total > 0 ? -2 : bufread); } - + if (bufread == 0) { + if (total <= 0) { + return -2; + } + break; + } + bufread = read(tarhandle, <arbuf[total], bufsiz - total); + total += bufread; } DEBUG(5, ("Total bytes read ... %i\n", total)); @@ -968,24 +981,27 @@ static int skip_file(int skipsize) return(True); } -/* We get a file from the tar file and store it */ +/************************************************************* + Get a file from the tar file and store it. + When this is called, tarbuf already contains the first + file block. This is a bit broken & needs fixing. +**************************************************************/ + static int get_file(file_info2 finfo) { - int fsize = finfo.size; int fnum = -1, pos = 0, dsize = 0, rsize = 0, bpos = 0; - DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, fsize)); + DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, (int)finfo.size)); if (ensurepath(finfo.name) && - (fnum=cli_open(cli, finfo.name, O_WRONLY|O_CREAT|O_TRUNC, DENY_NONE)) == -1) - { + (fnum=cli_open(cli, finfo.name, O_WRONLY|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { DEBUG(0, ("abandoning restore\n")); return(False); - } + } /* read the blocks from the tar file and write to the remote file */ - rsize = fsize; /* This is how much to write */ + rsize = finfo.size; /* This is how much to write */ while (rsize > 0) { @@ -1023,17 +1039,23 @@ static int get_file(file_info2 finfo) } - while (dsize >= TBLOCK) { + /* + * Bugfix from Bob Boehmer . + * If the file being extracted is an exact multiple of + * TBLOCK bytes then we don't want to extract the next + * block from the tarfile here, as it will be done in + * the caller of get_file(). + */ - if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { + while (((rsize != 0) && (dsize >= TBLOCK)) || + ((rsize == 0) && (dsize > TBLOCK))) { + if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); return False; - } dsize -= TBLOCK; - } bpos = dsize; @@ -1060,7 +1082,7 @@ static int get_file(file_info2 finfo) ntarf++; - DEBUG(0, ("restore tar file %s of size %d bytes\n", finfo.name, finfo.size)); + DEBUG(0, ("restore tar file %s of size %d bytes\n", finfo.name, (int)finfo.size)); return(True); } @@ -1071,7 +1093,7 @@ static int get_file(file_info2 finfo) static int get_dir(file_info2 finfo) { - DEBUG(5, ("Creating directory: %s\n", finfo.name)); + DEBUG(0, ("restore directory %s\n", finfo.name)); if (!ensurepath(finfo.name)) { @@ -1079,6 +1101,8 @@ static int get_dir(file_info2 finfo) return(False); } + + ntarf++; return(True); } @@ -1094,12 +1118,12 @@ static char * get_longfilename(file_info2 finfo) BOOL first = True; DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); - DEBUG(5, ("Len = %i\n", finfo.size)); + DEBUG(5, ("Len = %d\n", (int)finfo.size)); if (longname == NULL) { DEBUG(0, ("could not allocate buffer of size %d for longname\n", - finfo.size + strlen(cur_dir) + 2)); + (int)(finfo.size + strlen(cur_dir) + 2))); return(NULL); } @@ -1181,7 +1205,7 @@ static void do_tarput(void) return; case 0: /* chksum is zero - looks like an EOF */ - DEBUG(0, ("total of %d tar files restored to share\n", ntarf)); + DEBUG(0, ("tar: restored %d files and directories\n", ntarf)); return; /* Hmmm, bad here ... */ default: @@ -1229,10 +1253,14 @@ static void do_tarput(void) case '0': /* Should use symbolic names--FIXME */ - /* Skip to the next block first, so we can get the file, FIXME, should - be in get_file ... */ + /* + * Skip to the next block first, so we can get the file, FIXME, should + * be in get_file ... + * The 'finfo.size != 0' fix is from Bob Boehmer + * Fixes bug where file size in tarfile is zero. + */ - if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { + if ((finfo.size != 0) && next_block(tarbuf, &buffer_p, tbufsiz) <=0) { DEBUG(0, ("Short file, bailing out...\n")); return; } @@ -1486,7 +1514,7 @@ int process_tar(void) close(tarhandle); free(tarbuf); - DEBUG(0, ("tar: dumped %d tar files\n", ntarf)); + DEBUG(0, ("tar: dumped %d files and directories\n", ntarf)); DEBUG(0, ("Total bytes written: %.0f\n", (double)ttarf)); break; } -- cgit From e8b5cb45155536107a71e1106ad4a624eb559496 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Jan 2000 10:15:53 +0000 Subject: cli_open() wasn't handling DENY_FCB or O_WRONLY correctly. After fixing that I needed to use O_RDWR instead of O_WRONLY in several places to avoid the silly bug in MS servers that doesn't allow getattrE on a file opened with O_WRONLY (This used to be commit e21aa4cb088f348139309d29c85c48c8b777cff5) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 76b6ff94d5..f50c4b4288 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -994,7 +994,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, finfo.name, O_WRONLY|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { + (fnum=cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { DEBUG(0, ("abandoning restore\n")); return(False); } -- cgit From d867b86721e988dee56d5e9382b32c870ccb2790 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 26 Jan 2000 00:12:35 +0000 Subject: Second set of inline optimisation fixes from Ying Chen . Stop makeing function calls for every use of skip_multibyte_char. This function is called several *million* times during a NetBench run :-). Jeremy. (This used to be commit e5a3deba46ea2d4cb49a6c4b73edd766fe8b5a5c) --- source3/client/clitar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f50c4b4288..d71eff1c9e 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -427,8 +427,8 @@ static void fixtarname(char *tptr, char *fp, int l) *tptr++='.'; while (l > 0) { - int skip; - if((skip = skip_multibyte_char( *fp)) != 0) { + int skip = get_character_len(*fp); + if(skip != 0) { if (skip == 2) { *tptr++ = *fp++; *tptr++ = *fp++; @@ -885,8 +885,8 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) } while (l > 0) { - int skip; - if(( skip = skip_multibyte_char( *fp )) != 0) { + int skip = get_character_len(*fp); + if(skip != 0) { if (skip == 2) { *tptr++ = *fp++; *tptr++ = *fp++; -- cgit From 700f72453ed8dfd356a5591b9447127b5066ac4b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Apr 2000 11:04:28 +0000 Subject: - removed all our old wildcard matching code and replaced it with a call to ms_fnmatch(). This also removes all the Win9X semantics stuff and a bunch of other associated cruft. - moved the stat cache code into statcache.c - fixed the uint16 alignment requirements of ascii_to_unistr() and unistr_to_ascii() - trans2 SMB_FIND_FILE_BOTH_DIRECTORY_INFO returns the short name as unicode always (at least thats what NT4 does) - fixed some errors in the in-memory tdb code. Still ugly, but doesn't crash as much (This used to be commit 03e9cea004bbba72161a5323cf3b4556c94aed8e) --- source3/client/clitar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index d71eff1c9e..efa4fa8815 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -820,7 +820,7 @@ static void do_tar(file_info *finfo) #ifdef HAVE_REGEX_H (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { #else - (tar_re_search && mask_match(exclaim, cliplist[0], True, False))) { + (tar_re_search && mask_match(exclaim, cliplist[0], True))) { #endif DEBUG(3,("Skipping file %s\n", exclaim)); return; @@ -1234,7 +1234,7 @@ static void do_tarput(void) #ifdef HAVE_REGEX_H || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); #else - || (tar_re_search && mask_match(finfo.name, cliplist[0], True, False))); + || (tar_re_search && mask_match(finfo.name, cliplist[0], True))); #endif DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, (cliplist?cliplist[0]:NULL), finfo.name)); -- cgit From 8d26523e90ff76adf6195d938fa1b8bc2b747dc1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 22 Nov 2000 23:06:29 +0000 Subject: Tar fixes from Craig Barratt craig@arraycomm.com. Jeremy. (This used to be commit cf05709ec394d6cac14577c033d658bdc4506208) --- source3/client/clitar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index efa4fa8815..fe0fc83e4c 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -181,7 +181,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, memset(hb.dummy, 0, sizeof(hb.dummy)); l=strlen(aname); - if (l >= NAMSIZ) { + if (l >= NAMSIZ - 1) { /* write a GNU tar style long header */ char *b; b = (char *)malloc(l+TBLOCK+100); @@ -189,7 +189,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, DEBUG(0,("out of memory\n")); exit(1); } - writetarheader(f, "/./@LongLink", l+1, 0, " 0 \0", 'L'); + writetarheader(f, "/./@LongLink", l+2, 0, " 0 \0", 'L'); memset(b, 0, l+TBLOCK+100); fixtarname(b, aname, l); i = strlen(b)+1; -- cgit From 4e35283a8b2c4b816b7aec821c719378a1ef10a6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 26 Mar 2001 22:34:25 +0000 Subject: Fix for smbtar race condition from Glenn Burkhardt . Jeremy. (This used to be commit 0c9a92a0557b2595e520cbaf2feaa587f9e7502d) --- source3/client/clitar.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index fe0fc83e4c..f6e0423025 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -729,6 +729,17 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) break; } + nread += datalen; + + /* if file size has increased since we made file size query, truncate + read so tar header for this file will be correct. + */ + + if (nread > finfo.size) { + datalen -= nread - finfo.size; + DEBUG(0,("File size change - truncating %s to %d bytes\n", finfo.name, (int)finfo.size)); + } + /* add received bits of file to buffer - dotarbuf will * write out in 512 byte intervals */ if (dotarbuf(tarhandle,data,datalen) != datalen) { @@ -736,7 +747,6 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) break; } - nread += datalen; if (datalen == 0) { DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); break; -- cgit From 91b8a8d1d21b810b6aca44ce647837669efd6dcf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 21 Jun 2001 09:10:42 +0000 Subject: next_token() was supposed to be a reentrant replacement for strtok(), but the code suffered from bitrot and is not now reentrant. That means we can get bizarre behaviour i've fixed this by making next_token() reentrant and creating a next_token_nr() that is a small non-reentrant wrapper for those lumps of code (mostly smbclient) that have come to rely on the non-reentrant behaviour (This used to be commit 674ee2f1d12b0afc164a9e9072758fd1c5e54df7) --- source3/client/clitar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f6e0423025..3c35e41155 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1322,7 +1322,7 @@ void cmd_block(void) fstring buf; int block; - if (!next_token(NULL,buf,NULL,sizeof(buf))) + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("blocksize \n")); return; @@ -1346,7 +1346,7 @@ void cmd_tarmode(void) { fstring buf; - while (next_token(NULL,buf,NULL,sizeof(buf))) { + while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { if (strequal(buf, "full")) tar_inc=False; else if (strequal(buf, "inc")) @@ -1392,7 +1392,7 @@ void cmd_setmode(void) attra[0] = attra[1] = 0; - if (!next_token(NULL,buf,NULL,sizeof(buf))) + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("setmode <[+|-]rsha>\n")); return; @@ -1401,7 +1401,7 @@ void cmd_setmode(void) safe_strcpy(fname, cur_dir, sizeof(pstring)); safe_strcat(fname, buf, sizeof(pstring)); - while (next_token(NULL,buf,NULL,sizeof(buf))) { + while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { q=buf; while(*q) @@ -1443,7 +1443,7 @@ void cmd_tar(void) char **argl; int argcl; - if (!next_token(NULL,buf,NULL,sizeof(buf))) + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { DEBUG(0,("tar [IXbgan] \n")); return; -- cgit From 87fbb7092b8f8b2f0db0f361c3d625e19de57cd9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:15:53 +0000 Subject: The big character set handling changeover! This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a) --- source3/client/clitar.c | 87 ++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 62 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 3c35e41155..8f935da4e0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -421,31 +421,12 @@ 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++='.'; - - 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--; - } - } + /* 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, '\\', '/'); } /**************************************************************************** @@ -877,43 +858,25 @@ 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! + */ + + 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--; - } - } + safe_strcpy(tptr, fp, l); + string_replace(tptr, '/', '\\'); } @@ -1718,7 +1681,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) SMB_STRUCT_STAT stbuf; extern time_t newer_than; - if (dos_stat(argv[Optind], &stbuf) == 0) { + if (sys_stat(argv[Optind], &stbuf) == 0) { newer_than = stbuf.st_mtime; DEBUG(1,("Getting files newer than %s", asctime(LocalTime(&newer_than)))); -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/client/clitar.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 8f935da4e0..d28e652b35 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -533,7 +533,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(ffname, '\\')) == NULL) + if ((basehack=strrchr_m(ffname, '\\')) == NULL) return True; else *basehack='\0'; @@ -1451,7 +1451,7 @@ int process_tar(void) *(cliplist[i]+strlen(cliplist[i])-1)='\0'; } - if (strrchr(cliplist[i], '\\')) { + if (strrchr_m(cliplist[i], '\\')) { pstring saved_dir; safe_strcpy(saved_dir, cur_dir, sizeof(pstring)); @@ -1463,7 +1463,7 @@ int process_tar(void) safe_strcat(tarmac, cliplist[i], sizeof(pstring)); } safe_strcpy(cur_dir, tarmac, sizeof(pstring)); - *(strrchr(cur_dir, '\\')+1)='\0'; + *(strrchr_m(cur_dir, '\\')+1)='\0'; DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); @@ -1514,13 +1514,13 @@ static int clipfind(char **aret, int ret, char *tok) if (aret==NULL) return 0; /* ignore leading slashes or dots in token */ - while(strchr("/\\.", *tok)) tok++; + while(strchr_m("/\\.", *tok)) tok++; while(ret--) { char *pkey=*aret++; /* ignore leading slashes or dots in list */ - while(strchr("/\\.", *pkey)) pkey++; + while(strchr_m("/\\.", *pkey)) pkey++; if (!strslashcmp(pkey, tok)) return 1; } @@ -1604,7 +1604,7 @@ static int read_inclusion_file(char *filename) } else { unfixtarname(tmpstr, p, strlen(p) + 1, True); cliplist[i] = tmpstr; - if ((p = strchr(p, '\000')) == NULL) { + if ((p = strchr_m(p, '\000')) == NULL) { DEBUG(0,("INTERNAL ERROR: inclusion_buffer is of unexpected contents.\n")); abort(); } -- cgit From 2e783a47076bd0994b6ce86df7ec967bc1c2da63 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 12 Aug 2001 17:30:01 +0000 Subject: this is a big global fix for the ptr = Realloc(ptr, size) bug. many possible mem leaks, and segfaults fixed. someone should port this fix to 2.2 also. (This used to be commit fa8e55b8b465114ce209344965c1ca0333b84db9) --- source3/client/clitar.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index d28e652b35..3ae4cafc18 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1569,14 +1569,16 @@ static int read_inclusion_file(char *filename) } if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) { + char *ib; inclusion_buffer_size *= 2; - inclusion_buffer = Realloc(inclusion_buffer,inclusion_buffer_size); - if (! inclusion_buffer) { + 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; } safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar); -- cgit From 11ce0f4d2d493702386c0bd49c8e2dd2aad84d56 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Aug 2001 05:15:26 +0000 Subject: a bunch of fixes from the sflight to seattle in particular: - fixed NT status code for a bunch of ops - fixed handling of protocol levels in ms_fnmatch (This used to be commit 3eba9606f71f90bfd9820af26f8676277ed22390) --- source3/client/clitar.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 3ae4cafc18..8ce73f6645 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -121,7 +121,6 @@ extern int max_xmit; extern pstring cur_dir; extern int get_total_time_ms; extern int get_total_size; -extern int Protocol; int blocksize=20; int tarhandle; -- cgit From b30e75692d68233448b3ad3d7ddd4b4ac423d3ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 11:08:57 +0000 Subject: replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down replacemnt of stdio that doesn't suffer from the 8-bit filedescriptor limit that we hit with nasty consequences on some systems I would eventually prefer us to have a configure test to see if we need to replace stdio, but for now this code needs to be tested widely so I'm enabling it by default. (This used to be commit 1af8bf34f1caa3e7ec312d8109c07d32a945a448) --- source3/client/clitar.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 8ce73f6645..6169c9af46 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -71,7 +71,7 @@ stack dir_stack = {NULL, 0}; /* Want an empty stack */ #define SEPARATORS " \t\n\r" extern int DEBUGLEVEL; extern struct cli_state *cli; -extern FILE *dbf; +extern XFILE *dbf; /* These defines are for the do_setrattr routine, to indicate * setting and reseting of file attributes in the function call */ @@ -1533,7 +1533,7 @@ accordingly. ***************************************************************************/ static int read_inclusion_file(char *filename) { - FILE *inclusion = NULL; + XFILE *inclusion = NULL; char buf[MAXPATHLEN + 1]; char *inclusion_buffer = NULL; int inclusion_buffer_size = 0; @@ -1545,7 +1545,7 @@ static int read_inclusion_file(char *filename) clipn = 0; buf[MAXPATHLEN] = '\0'; /* guarantee null-termination */ - if ((inclusion = sys_fopen(filename, "r")) == NULL) { + if ((inclusion = x_fopen(filename, O_RDONLY, 0)) == NULL) { /* XXX It would be better to include a reason for failure, but without * autoconf, it's hard to use strerror, sys_errlist, etc. */ @@ -1553,7 +1553,7 @@ static int read_inclusion_file(char *filename) return 0; } - while ((! error) && (fgets(buf, sizeof(buf)-1, inclusion))) { + while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) { if (inclusion_buffer == NULL) { inclusion_buffer_size = 1024; if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) { @@ -1584,7 +1584,7 @@ static int read_inclusion_file(char *filename) inclusion_buffer_sofar += strlen(buf) + 1; clipn++; } - fclose(inclusion); + x_fclose(inclusion); if (! error) { /* Allocate an array of clipn + 1 char*'s for cliplist */ @@ -1827,7 +1827,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) * tar output */ if (tarhandle == 1) - dbf = stderr; + dbf = x_stderr; } else { if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) { -- cgit From b12a4dd9b655485420d5c67dd143d8f49ac28a40 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 12:14:18 +0000 Subject: declare dbf in one spot (This used to be commit f41c3bb80f1e498a9d27f6e236b0ff3a742764c9) --- source3/client/clitar.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 6169c9af46..49ea5edf47 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -71,7 +71,6 @@ stack dir_stack = {NULL, 0}; /* Want an empty stack */ #define SEPARATORS " \t\n\r" extern int DEBUGLEVEL; extern struct cli_state *cli; -extern XFILE *dbf; /* These defines are for the do_setrattr routine, to indicate * setting and reseting of file attributes in the function call */ -- cgit From 77bdea1b95f0169c32ba13a4434e9cfb4089b7d3 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 00:52:47 +0000 Subject: move to SAFE_FREE() (This used to be commit 29db6ef7a7c4df51adf964c0aecb1164e4ab7dee) --- source3/client/clitar.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 49ea5edf47..39c31625b4 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -193,7 +193,7 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, i = strlen(b)+1; DEBUG(5, ("File name in tar file: %s, size=%d, \n", b, (int)strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); - free(b); + SAFE_FREE(b); } /* use l + 1 to do the null too */ @@ -1190,7 +1190,7 @@ static void do_tarput(void) if (longfilename != NULL) { - free(finfo.name); /* Free the space already allocated */ + SAFE_FREE(finfo.name); /* Free the space already allocated */ finfo.name = longfilename; longfilename = NULL; @@ -1416,7 +1416,7 @@ void cmd_tar(void) process_tar(); - free(argl); + SAFE_FREE(argl); } /**************************************************************************** @@ -1433,7 +1433,7 @@ int process_tar(void) #else do_tarput(); #endif - free(tarbuf); + SAFE_FREE(tarbuf); close(tarhandle); break; case 'r': @@ -1483,7 +1483,7 @@ int process_tar(void) if (ntarf) dotareof(tarhandle); close(tarhandle); - free(tarbuf); + SAFE_FREE(tarbuf); DEBUG(0, ("tar: dumped %d files and directories\n", ntarf)); DEBUG(0, ("Total bytes written: %.0f\n", (double)ttarf)); @@ -1493,9 +1493,9 @@ int process_tar(void) if (must_free_cliplist) { int i; for (i = 0; i < clipn; ++i) { - free(cliplist[i]); + SAFE_FREE(cliplist[i]); } - free(cliplist); + SAFE_FREE(cliplist); cliplist = NULL; clipn = 0; must_free_cliplist = False; @@ -1615,17 +1615,15 @@ static int read_inclusion_file(char *filename) } } - if (inclusion_buffer) { - free(inclusion_buffer); - } + SAFE_FREE(inclusion_buffer); if (error) { if (cliplist) { char **pp; /* We know cliplist is always null-terminated */ for (pp = cliplist; *pp; ++pp) { - free(*pp); + SAFE_FREE(*pp); } - free(cliplist); + SAFE_FREE(cliplist); cliplist = NULL; must_free_cliplist = False; } -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/client/clitar.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 39c31625b4..f2f373ffba 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -69,7 +69,6 @@ typedef struct stack dir_stack = {NULL, 0}; /* Want an empty stack */ #define SEPARATORS " \t\n\r" -extern int DEBUGLEVEL; extern struct cli_state *cli; /* These defines are for the do_setrattr routine, to indicate -- cgit From 52341e94a86420368b479acd2c760468444fef72 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 9 Oct 2001 19:12:18 +0000 Subject: initial support to error report in smbclient, useful when using smbclient -c in scripts. Thanks to Claudio Cicali aka FleXer for the initial patch (This used to be commit 53b95b3c0fd087b1cade95fd8de849547ac3bfcb) --- source3/client/clitar.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f2f373ffba..0c99359dc3 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1277,7 +1277,7 @@ static void do_tarput(void) /**************************************************************************** Blocksize command ***************************************************************************/ -void cmd_block(void) +int cmd_block(void) { fstring buf; int block; @@ -1285,24 +1285,26 @@ void cmd_block(void) if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("blocksize \n")); - return; + return 1; } block=atoi(buf); if (block < 0 || block > 65535) { DEBUG(0, ("blocksize out of range")); - return; + return 1; } blocksize=block; DEBUG(2,("blocksize is now %d\n", blocksize)); + + return 0; } /**************************************************************************** command to set incremental / reset mode ***************************************************************************/ -void cmd_tarmode(void) +int cmd_tarmode(void) { fstring buf; @@ -1337,12 +1339,13 @@ void cmd_tarmode(void) tar_reset ? "reset" : "noreset", tar_noisy ? "verbose" : "quiet")); + return 0; } /**************************************************************************** Feeble attrib command ***************************************************************************/ -void cmd_setmode(void) +int cmd_setmode(void) { char *q; fstring buf; @@ -1355,7 +1358,7 @@ void cmd_setmode(void) if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { DEBUG(0, ("setmode <[+|-]rsha>\n")); - return; + return 1; } safe_strcpy(fname, cur_dir, sizeof(pstring)); @@ -1386,18 +1389,20 @@ void cmd_setmode(void) if (attra[ATTRSET]==0 && attra[ATTRRESET]==0) { DEBUG(0, ("setmode <[+|-]rsha>\n")); - return; + return 1; } 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 ***************************************************************************/ -void cmd_tar(void) +int cmd_tar(void) { fstring buf; char **argl; @@ -1406,16 +1411,18 @@ void cmd_tar(void) if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { DEBUG(0,("tar [IXbgan] \n")); - return; + return 1; } argl=toktocliplist(&argcl, NULL); if (!tar_parseargs(argcl, argl, buf, 0)) - return; + return 1; process_tar(); SAFE_FREE(argl); + + return 0; } /**************************************************************************** -- cgit From 8cec5cf35f17568009c70d37bb8b2a1f360d3422 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 11 Oct 2001 08:40:42 +0000 Subject: first step in converting the head branch to use lang_tdb.c instead of gettext for internationalisation support. There is more to do (This used to be commit ab7f67677a1ade4669e5c2750d0a38422ea616a9) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0c99359dc3..64b035a89e 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1382,7 +1382,7 @@ int cmd_setmode(void) case 'a': attra[direct]|=aARCH; break; default: DEBUG(0, ("setmode \n")); - return; + return 1; } } -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/client/clitar.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 64b035a89e..9fa3750b0c 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. Tar Extensions Copyright (C) Ricky Poulten 1995-1998 Copyright (C) Richard Sharpe 1998 -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/client/clitar.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 9fa3750b0c..43b0ef44bc 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -37,6 +37,7 @@ #include "includes.h" #include "clitar.h" +#include "../client/client_proto.h" static int clipfind(char **aret, int ret, char *tok); @@ -65,8 +66,6 @@ typedef struct } stack; -stack dir_stack = {NULL, 0}; /* Want an empty stack */ - #define SEPARATORS " \t\n\r" extern struct cli_state *cli; @@ -85,25 +84,25 @@ static char *tarbuf, *buffer_p; static int tp, ntarf, tbufsiz; static double ttarf; /* Incremental mode */ -BOOL tar_inc=False; +static BOOL tar_inc=False; /* Reset archive bit */ -BOOL tar_reset=False; +static BOOL tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ -BOOL tar_excl=True; +static BOOL tar_excl=True; /* use regular expressions for search on file names */ -BOOL tar_re_search=False; +static BOOL tar_re_search=False; #ifdef HAVE_REGEX_H regex_t *preg; #endif /* Do not dump anything, just calculate sizes */ -BOOL dry_run=False; +static BOOL dry_run=False; /* Dump files with System attribute */ -BOOL tar_system=True; +static BOOL tar_system=True; /* Dump files with Hidden attribute */ -BOOL tar_hidden=True; +static BOOL tar_hidden=True; /* Be noisy - make a catalogue */ -BOOL tar_noisy=True; -BOOL tar_real_noisy=False; /* Don't want to be really noisy by default */ +static BOOL tar_noisy=True; +static BOOL tar_real_noisy=False; /* Don't want to be really noisy by default */ char tar_type='\0'; static char **cliplist=NULL; @@ -119,8 +118,8 @@ extern pstring cur_dir; extern int get_total_time_ms; extern int get_total_size; -int blocksize=20; -int tarhandle; +static int blocksize=20; +static int tarhandle; static void writetarheader(int f, char *aname, int size, time_t mtime, char *amode, unsigned char ftype); -- cgit From b2edf254eda92f775e7d3d9b6793b4d77f9000b6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 17:00:51 +0000 Subject: sync 3.0 branch with head (This used to be commit 3928578b52cfc949be5e0ef444fce1558d75f290) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 43b0ef44bc..c453cfbb54 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -492,7 +492,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 == '\\') return 0; + if ((*s2 == '/' || *s2 == '\\') && !*s1) return 0; return *s1-*s2; } -- cgit From e76f1ffa7e5da5bc391c923e7cada44b77e01da9 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Mon, 16 Dec 2002 21:32:32 +0000 Subject: merge smbtar fix from 2.2 (This used to be commit 41188337c3fa8c716dc7a4721ee5c31e5ddd928d) --- source3/client/clitar.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c453cfbb54..bf26beb652 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -45,10 +45,10 @@ typedef struct file_info_struct file_info2; struct file_info_struct { - size_t size; + SMB_BIG_UINT size; uint16 mode; - int uid; - int gid; + uid_t uid; + gid_t gid; /* These times are normally kept in GMT */ time_t mtime; time_t atime; @@ -620,6 +620,7 @@ 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; } else { finfo.size = def_finfo.size; @@ -629,13 +630,14 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) finfo.mtime = def_finfo.mtime; finfo.atime = def_finfo.atime; finfo.ctime = def_finfo.ctime; + finfo.name = def_finfo.name; } if (dry_run) { - DEBUG(3,("skipping file %s of size %d bytes\n", + DEBUG(3,("skipping file %s of size %12.0f bytes\n", finfo.name, - (int)finfo.size)); + (double)finfo.size)); shallitime=0; ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); ntarf++; @@ -1833,7 +1835,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) { if (!dry_run) { - DEBUG(0,("Output is /dev/null, assuming dry_run")); + DEBUG(0,("Output is /dev/null, assuming dry_run\n")); dry_run = True; } tarhandle=-1; -- cgit From 41969738a4d5244b73864dd882d214ff8824365b Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 19 Dec 2002 20:26:44 +0000 Subject: merge from 2.2 fix for smbclient large files (This used to be commit 17f685fdbf5d36f82e3da0a09457f5e248b3f109) --- source3/client/clitar.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index bf26beb652..bf4b6e592a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -121,11 +121,11 @@ extern int get_total_size; static int blocksize=20; static int tarhandle; -static void writetarheader(int f, char *aname, int size, time_t mtime, +static void writetarheader(int f, char *aname, SMB_BIG_UINT size, time_t mtime, char *amode, unsigned char ftype); static void do_atar(char *rname,char *lname,file_info *finfo1); static void do_tar(file_info *finfo); -static void oct_it(long value, int ndgs, char *p); +static void oct_it(SMB_BIG_UINT value, int ndgs, char *p); static void fixtarname(char *tptr, char *fp, int l); static int dotarbuf(int f, char *b, int n); static void dozerobuf(int f, int n); @@ -164,14 +164,14 @@ static char *string_create_s(int size) /**************************************************************************** Write a tar header to buffer ****************************************************************************/ -static void writetarheader(int f, char *aname, int size, time_t mtime, +static void writetarheader(int f, char *aname, SMB_BIG_UINT size, time_t mtime, char *amode, unsigned char ftype) { union hblock hb; int i, chk, l; char *jp; - DEBUG(5, ("WriteTarHdr, Type = %c, Size= %i, Name = %s\n", ftype, size, aname)); + DEBUG(5, ("WriteTarHdr, Type = %c, Size= %.0f, Name = %s\n", ftype, (double)size, aname)); memset(hb.dummy, 0, sizeof(hb.dummy)); @@ -203,17 +203,17 @@ static void writetarheader(int f, char *aname, int size, time_t mtime, hb.dbuf.name[NAMSIZ-1]='\0'; safe_strcpy(hb.dbuf.mode, amode, strlen(amode)); - oct_it(0L, 8, hb.dbuf.uid); - oct_it(0L, 8, hb.dbuf.gid); - oct_it((long) size, 13, hb.dbuf.size); - oct_it((long) mtime, 13, hb.dbuf.mtime); + 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); 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((long) chk, 8, hb.dbuf.chksum); + oct_it((SMB_BIG_UINT) chk, 8, hb.dbuf.chksum); hb.dbuf.chksum[6] = '\0'; (void) dotarbuf(f, hb.dummy, sizeof(hb.dummy)); @@ -427,7 +427,7 @@ static void fixtarname(char *tptr, char *fp, int l) /**************************************************************************** Convert from decimal to octal string ****************************************************************************/ -static void oct_it (long value, int ndgs, char *p) +static void oct_it (SMB_BIG_UINT value, int ndgs, char *p) { /* Converts long to octal string, pads with leading zeros */ @@ -598,7 +598,7 @@ append one remote file to the tar file static void do_atar(char *rname,char *lname,file_info *finfo1) { int fnum; - uint32 nread=0; + SMB_BIG_UINT nread=0; char ftype; file_info2 finfo; BOOL close_done = False; @@ -688,9 +688,9 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) } else { - DEBUG(3,("getting file %s of size %d bytes as a tar file %s", + DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", finfo.name, - (int)finfo.size, + (double)finfo.size, lname)); /* write a tar header, don't bother with mode - just set to 100644 */ @@ -698,7 +698,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) while (nread < finfo.size && !close_done) { - DEBUG(3,("nread=%d\n",nread)); + DEBUG(3,("nread=%.0f\n",(double)nread)); datalen = cli_read(cli, fnum, data, nread, read_size); @@ -715,7 +715,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) if (nread > finfo.size) { datalen -= nread - finfo.size; - DEBUG(0,("File size change - truncating %s to %d bytes\n", finfo.name, (int)finfo.size)); + DEBUG(0,("File size change - truncating %s to %.0f bytes\n", finfo.name, (double)finfo.size)); } /* add received bits of file to buffer - dotarbuf will @@ -735,7 +735,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) /* pad tar file with zero's if we couldn't get entire file */ if (nread < finfo.size) { - DEBUG(0, ("Didn't get entire file. size=%d, nread=%d\n", (int)finfo.size, (int)nread)); + DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", (double)finfo.size, (int)nread)); if (padit(data, sizeof(data), finfo.size - nread)) DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); } @@ -768,8 +768,8 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) if (tar_noisy) { - DEBUG(0, ("%10d (%7.1f kb/s) %s\n", - (int)finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), + DEBUG(0, ("%12.0f (%7.1f kb/s) %s\n", + (double)finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), finfo.name)); } -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/client/clitar.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index bf4b6e592a..e8be5e04e7 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -121,12 +121,12 @@ extern int get_total_size; static int blocksize=20; static int tarhandle; -static void writetarheader(int f, char *aname, SMB_BIG_UINT size, time_t mtime, - char *amode, unsigned char ftype); +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 do_tar(file_info *finfo); static void oct_it(SMB_BIG_UINT value, int ndgs, char *p); -static void fixtarname(char *tptr, char *fp, int l); +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); static void dotareof(int f); @@ -164,8 +164,8 @@ static char *string_create_s(int size) /**************************************************************************** Write a tar header to buffer ****************************************************************************/ -static void writetarheader(int f, char *aname, SMB_BIG_UINT size, time_t mtime, - char *amode, unsigned char ftype) +static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t mtime, + const char *amode, unsigned char ftype) { union hblock hb; int i, chk, l; @@ -414,7 +414,7 @@ static void dotareof(int f) /**************************************************************************** (Un)mangle DOS pathname, make nonabsolute ****************************************************************************/ -static void fixtarname(char *tptr, char *fp, int l) +static void fixtarname(char *tptr, const char *fp, int l) { /* add a '.' to start of file name, convert from ugly dos \'s in path * to lovely unix /'s :-} */ -- cgit From e3fdd289f58505f258f9617e1b8618694703bea2 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Mon, 3 Mar 2003 23:00:22 +0000 Subject: More janitorial duties, fixing the BIG_UINT changes for large offsets. (This used to be commit 1af39523cc3b2313f3e8acd4f2e5338182ec0b13) --- source3/client/clitar.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index e8be5e04e7..612a383ce0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -959,9 +959,10 @@ static int skip_file(int skipsize) static int get_file(file_info2 finfo) { - int fnum = -1, pos = 0, dsize = 0, rsize = 0, bpos = 0; + int fnum = -1, pos = 0, dsize = 0, bpos = 0; + SMB_BIG_UINT rsize = 0; - DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, (int)finfo.size)); + DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size)); if (ensurepath(finfo.name) && (fnum=cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { @@ -1052,7 +1053,7 @@ static int get_file(file_info2 finfo) ntarf++; - DEBUG(0, ("restore tar file %s of size %d bytes\n", finfo.name, (int)finfo.size)); + DEBUG(0, ("restore tar file %s of size %.0f bytes\n", finfo.name, (double)finfo.size)); return(True); } @@ -1082,7 +1083,7 @@ static int get_dir(file_info2 finfo) */ static char * get_longfilename(file_info2 finfo) { - int namesize = finfo.size + strlen(cur_dir) + 2; + int namesize = strlen(finfo.name) + strlen(cur_dir) + 2; char *longname = malloc(namesize); int offset = 0, left = finfo.size; BOOL first = True; @@ -1093,7 +1094,7 @@ static char * get_longfilename(file_info2 finfo) if (longname == NULL) { DEBUG(0, ("could not allocate buffer of size %d for longname\n", - (int)(finfo.size + strlen(cur_dir) + 2))); + namesize)); return(NULL); } -- cgit From d5ee9b2f480ddbda0b8f69409698d27c99384f9c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 18 Mar 2003 11:22:52 +0000 Subject: Jeremy merged across my string parinoia fixes, but forgot to enable them! :-) This patch catches up on the rest of the work - as much string checking as is possible is done at compile time, and the rest at runtime. Lots of code converted to pstrcpy() etc, and other code reworked to correctly call sizeof(). Andrew Bartlett (This used to be commit c5b604e2ee67d74241ae2fa07ae904647d35a2be) --- source3/client/clitar.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 612a383ce0..579110f75f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -202,7 +202,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m /* write out a "standard" tar format header */ hb.dbuf.name[NAMSIZ-1]='\0'; - safe_strcpy(hb.dbuf.mode, amode, strlen(amode)); + safe_strcpy(hb.dbuf.mode, amode, sizeof(hb.dbuf.mode)-1); 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); @@ -796,11 +796,11 @@ static void do_tar(file_info *finfo) DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir))); - safe_strcpy(exclaim, cur_dir, sizeof(pstring)); + pstrcpy(exclaim, cur_dir); *(exclaim+strlen(exclaim)-1)='\0'; - safe_strcat(exclaim, "\\", sizeof(pstring)); - safe_strcat(exclaim, finfo->name, sizeof(exclaim)); + pstrcat(exclaim, "\\"); + pstrcat(exclaim, finfo->name); DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); @@ -820,12 +820,12 @@ static void do_tar(file_info *finfo) pstring saved_curdir; pstring mtar_mask; - safe_strcpy(saved_curdir, cur_dir, sizeof(saved_curdir)); + pstrcpy(saved_curdir, cur_dir); DEBUG(5, ("Sizeof(cur_dir)=%d, strlen(cur_dir)=%d, strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", (int)sizeof(cur_dir), (int)strlen(cur_dir), (int)strlen(finfo->name), finfo->name, cur_dir)); - safe_strcat(cur_dir,finfo->name, sizeof(cur_dir)); - safe_strcat(cur_dir,"\\", sizeof(cur_dir)); + pstrcat(cur_dir,finfo->name); + pstrcat(cur_dir,"\\"); DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); @@ -836,16 +836,16 @@ static void do_tar(file_info *finfo) DEBUG(0,(" directory %s\n", cur_dir)); } ntarf++; /* Make sure we have a file on there */ - safe_strcpy(mtar_mask,cur_dir, sizeof(pstring)); - safe_strcat(mtar_mask,"*", sizeof(pstring)); + pstrcpy(mtar_mask,cur_dir); + pstrcat(mtar_mask,"*"); DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask)); do_list(mtar_mask, attribute, do_tar, False, True); - safe_strcpy(cur_dir,saved_curdir, sizeof(pstring)); + pstrcpy(cur_dir,saved_curdir); } else { - safe_strcpy(rname,cur_dir, sizeof(pstring)); - safe_strcat(rname,finfo->name, sizeof(pstring)); + pstrcpy(rname,cur_dir); + pstrcat(rname,finfo->name); do_atar(rname,finfo->name,finfo); } } @@ -1362,8 +1362,8 @@ int cmd_setmode(void) return 1; } - safe_strcpy(fname, cur_dir, sizeof(pstring)); - safe_strcat(fname, buf, sizeof(pstring)); + pstrcpy(fname, cur_dir); + pstrcat(fname, buf); while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { q=buf; @@ -1459,32 +1459,32 @@ int process_tar(void) if (strrchr_m(cliplist[i], '\\')) { pstring saved_dir; - safe_strcpy(saved_dir, cur_dir, sizeof(pstring)); + pstrcpy(saved_dir, cur_dir); if (*cliplist[i]=='\\') { - safe_strcpy(tarmac, cliplist[i], sizeof(pstring)); + pstrcpy(tarmac, cliplist[i]); } else { - safe_strcpy(tarmac, cur_dir, sizeof(pstring)); - safe_strcat(tarmac, cliplist[i], sizeof(pstring)); + pstrcpy(tarmac, cur_dir); + pstrcat(tarmac, cliplist[i]); } - safe_strcpy(cur_dir, tarmac, sizeof(pstring)); + pstrcpy(cur_dir, tarmac); *(strrchr_m(cur_dir, '\\')+1)='\0'; DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); - safe_strcpy(cur_dir,saved_dir, sizeof(pstring)); + pstrcpy(cur_dir,saved_dir); } else { - safe_strcpy(tarmac, cur_dir, sizeof(pstring)); - safe_strcat(tarmac, cliplist[i], sizeof(pstring)); + pstrcpy(tarmac, cur_dir); + pstrcat(tarmac, cliplist[i]); DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); } } } else { pstring mask; - safe_strcpy(mask,cur_dir, sizeof(pstring)); + pstrcpy(mask,cur_dir); DEBUG(5, ("process_tar, do_list with mask: %s\n", mask)); - safe_strcat(mask,"\\*", sizeof(pstring)); + pstrcat(mask,"\\*"); do_list(mask,attribute,do_tar,False, True); } -- cgit From 9cfa77ae1537ec96479f71dc93097ebb4c83ea01 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Apr 2003 04:03:39 +0000 Subject: Merge: - "Fix lingering large offset problems in smbtar etc." (This used to be commit ba53df64cab5dc0ea9f2b7d82007bf655f85bc67) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 579110f75f..dfda997ca2 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1089,7 +1089,7 @@ static char * get_longfilename(file_info2 finfo) BOOL first = True; DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); - DEBUG(5, ("Len = %d\n", (int)finfo.size)); + DEBUG(5, ("Len = %.0f\n", (double)finfo.size)); if (longname == NULL) { -- cgit From ce72beb2b558d86fb49063c6b1fa00e07952ce56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Jul 2003 19:11:31 +0000 Subject: Removed strupper/strlower macros that automatically map to strupper_m/strlower_m. I really want people to think about when they're using multibyte strings. Jeremy. (This used to be commit ff222716a08af65d26ad842ce4c2841cc6540959) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index dfda997ca2..2ef2832e50 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -197,7 +197,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m fixtarname(hb.dbuf.name, aname, (l >= NAMSIZ) ? NAMSIZ : l + 1); if (lowercase) - strlower(hb.dbuf.name); + strlower_m(hb.dbuf.name); /* write out a "standard" tar format header */ -- cgit From bd9a42fa8df5eb37af9f23ff4498c4747f084131 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 16 Jul 2003 00:13:40 +0000 Subject: Fix from Dragan Krnic for handling files in tar archives > 8GB. Fixes bug 102. (This used to be commit b54183a7b23d1046faad0890de3fdda3df0fec88) --- source3/client/clitar.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 2ef2832e50..765bc2a659 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -206,6 +206,16 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m 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); + if (size > (SMB_BIG_UINT)077777777777LL) { + + /* This is a non-POSIX compatible extention to store files + greater than 8GB. */ + + memset(hb.dbuf.size, 0, 4); + hb.dbuf.size[0]=128; + for (i = 8, jp=(char*)&size; i; i--) + hb.dbuf.size[i+3] = *(jp++); + } oct_it((SMB_BIG_UINT) mtime, 13, hb.dbuf.mtime); memcpy(hb.dbuf.chksum, " ", sizeof(hb.dbuf.chksum)); memset(hb.dbuf.linkname, 0, NAMSIZ); -- cgit From 14f207be92ca8afbf0cf19d69508d63ddbd29bbb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Aug 2003 00:41:57 +0000 Subject: Reformat clitar option processing - getting ready to fix it for popt... Jeremy. (This used to be commit 94b30e7b4a4f71d3aa2fefee60b9ea8ead2acccd) --- source3/client/clitar.c | 359 ++++++++++++++++++++++++------------------------ 1 file changed, 176 insertions(+), 183 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 765bc2a659..97b27136f4 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1654,211 +1654,204 @@ static int read_inclusion_file(char *filename) /**************************************************************************** Parse tar arguments. Sets tar_type, tar_excl, etc. ***************************************************************************/ + int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) { - char tar_clipfl='\0'; + char tar_clipfl='\0'; - /* Reset back to defaults - could be from interactive version - * reset mode and archive mode left as they are though - */ - tar_type='\0'; - tar_excl=True; - dry_run=False; - - while (*Optarg) - switch(*Optarg++) { - case 'c': - tar_type='c'; - break; - case 'x': - if (tar_type=='c') { - printf("Tar must be followed by only one of c or x.\n"); - return 0; - } - tar_type='x'; - break; - case 'b': - if (Optind>=argc || !(blocksize=atoi(argv[Optind]))) { - DEBUG(0,("Option b must be followed by valid blocksize\n")); - return 0; - } else { - Optind++; - } - break; - case 'g': - tar_inc=True; - break; - case 'N': - if (Optind>=argc) { - DEBUG(0,("Option N must be followed by valid file name\n")); - return 0; - } else { - SMB_STRUCT_STAT stbuf; - extern time_t newer_than; + /* Reset back to defaults - could be from interactive version + * reset mode and archive mode left as they are though + */ + tar_type='\0'; + tar_excl=True; + dry_run=False; + + while (*Optarg) { + switch(*Optarg++) { + case 'c': + tar_type='c'; + break; + case 'x': + if (tar_type=='c') { + printf("Tar must be followed by only one of c or x.\n"); + return 0; + } + tar_type='x'; + break; + case 'b': + if (Optind>=argc || !(blocksize=atoi(argv[Optind]))) { + DEBUG(0,("Option b must be followed by valid blocksize\n")); + return 0; + } else { + Optind++; + } + break; + case 'g': + tar_inc=True; + break; + case 'N': + if (Optind>=argc) { + DEBUG(0,("Option N must be followed by valid file name\n")); + return 0; + } else { + SMB_STRUCT_STAT stbuf; + extern time_t newer_than; - if (sys_stat(argv[Optind], &stbuf) == 0) { - newer_than = stbuf.st_mtime; - DEBUG(1,("Getting files newer than %s", - asctime(LocalTime(&newer_than)))); - Optind++; - } else { - DEBUG(0,("Error setting newer-than time\n")); - return 0; + if (sys_stat(argv[Optind], &stbuf) == 0) { + newer_than = stbuf.st_mtime; + DEBUG(1,("Getting files newer than %s", + asctime(LocalTime(&newer_than)))); + Optind++; + } else { + DEBUG(0,("Error setting newer-than time\n")); + return 0; + } + } + break; + case 'a': + tar_reset=True; + break; + case 'q': + tar_noisy=False; + break; + case 'I': + if (tar_clipfl) { + DEBUG(0,("Only one of I,X,F must be specified\n")); + return 0; + } + tar_clipfl='I'; + break; + case 'X': + if (tar_clipfl) { + DEBUG(0,("Only one of I,X,F must be specified\n")); + return 0; + } + tar_clipfl='X'; + break; + case 'F': + if (tar_clipfl) { + DEBUG(0,("Only one of I,X,F must be specified\n")); + return 0; + } + tar_clipfl='F'; + break; + case 'r': + DEBUG(0, ("tar_re_search set\n")); + tar_re_search = True; + break; + case 'n': + if (tar_type == 'c') { + DEBUG(0, ("dry_run set\n")); + dry_run = True; + } else { + DEBUG(0, ("n is only meaningful when creating a tar-file\n")); + return 0; + } + break; + default: + DEBUG(0,("Unknown tar option\n")); + return 0; + } } - } - break; - case 'a': - tar_reset=True; - break; - case 'q': - tar_noisy=False; - break; - case 'I': - if (tar_clipfl) { - DEBUG(0,("Only one of I,X,F must be specified\n")); - return 0; - } - tar_clipfl='I'; - break; - case 'X': - if (tar_clipfl) { - DEBUG(0,("Only one of I,X,F must be specified\n")); - return 0; - } - tar_clipfl='X'; - break; - case 'F': - if (tar_clipfl) { - DEBUG(0,("Only one of I,X,F must be specified\n")); - return 0; - } - tar_clipfl='F'; - break; - case 'r': - DEBUG(0, ("tar_re_search set\n")); - tar_re_search = True; - break; - case 'n': - if (tar_type == 'c') { - DEBUG(0, ("dry_run set\n")); - dry_run = True; - } else { - DEBUG(0, ("n is only meaningful when creating a tar-file\n")); - return 0; - } - break; - default: - DEBUG(0,("Unknown tar option\n")); - return 0; - } - if (!tar_type) { - printf("Option T must be followed by one of c or x.\n"); - return 0; - } + if (!tar_type) { + printf("Option T must be followed by one of c or x.\n"); + return 0; + } - /* tar_excl is true if cliplist lists files to be included. - * Both 'I' and 'F' mean include. */ - tar_excl=tar_clipfl!='X'; + /* tar_excl is true if cliplist lists files to be included. + * Both 'I' and 'F' mean include. */ + tar_excl=tar_clipfl!='X'; - if (tar_clipfl=='F') { - if (argc-Optind-1 != 1) { - DEBUG(0,("Option F must be followed by exactly one filename.\n")); - return 0; - } - if (! read_inclusion_file(argv[Optind+1])) { - return 0; - } - } else if (Optind+1=argc || !strcmp(argv[Optind], "-")) { - /* Sets tar handle to either 0 or 1, as appropriate */ - tarhandle=(tar_type=='c'); - /* - * Make sure that dbf points to stderr if we are using stdout for - * tar output - */ - if (tarhandle == 1) - dbf = x_stderr; - } else { - if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) - { - if (!dry_run) { - DEBUG(0,("Output is /dev/null, assuming dry_run\n")); - dry_run = True; + if (Optind>=argc || !strcmp(argv[Optind], "-")) { + /* Sets tar handle to either 0 or 1, as appropriate */ + tarhandle=(tar_type=='c'); + /* + * Make sure that dbf points to stderr if we are using stdout for + * tar output + */ + if (tarhandle == 1) { + dbf = x_stderr; + } + } else { + if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) { + if (!dry_run) { + DEBUG(0,("Output is /dev/null, assuming dry_run\n")); + dry_run = True; + } + 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)) { + DEBUG(0,("Error opening local file %s - %s\n", argv[Optind], strerror(errno))); + return(0); + } } - 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)) - { - DEBUG(0,("Error opening local file %s - %s\n", - argv[Optind], strerror(errno))); - return(0); - } - } - return 1; + return 1; } -- cgit From 7e39e87ce0a83a08a8bf2b27f7264bc3c12a9aee Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Aug 2003 01:03:05 +0000 Subject: Reformat lots of clitar code as I hate the style so much :-). Jeremy. (This used to be commit 77f2a91549c8b61e74e2088faef2b61612803aed) --- source3/client/clitar.c | 1103 +++++++++++++++++++++++------------------------ 1 file changed, 540 insertions(+), 563 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 97b27136f4..68f78e497f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -43,27 +43,23 @@ static int clipfind(char **aret, int ret, char *tok); typedef struct file_info_struct file_info2; -struct file_info_struct -{ - SMB_BIG_UINT size; - uint16 mode; - uid_t uid; - gid_t gid; - /* These times are normally kept in GMT */ - time_t mtime; - time_t atime; - time_t ctime; - char *name; /* This is dynamically allocate */ - - file_info2 *next, *prev; /* Used in the stack ... */ - +struct file_info_struct { + SMB_BIG_UINT size; + uint16 mode; + uid_t uid; + gid_t gid; + /* These times are normally kept in GMT */ + time_t mtime; + time_t atime; + time_t ctime; + char *name; /* This is dynamically allocate */ + + file_info2 *next, *prev; /* Used in the stack ... */ }; -typedef struct -{ - file_info2 *top; - int items; - +typedef struct { + file_info2 *top; + int items; } stack; #define SEPARATORS " \t\n\r" @@ -145,285 +141,284 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first); /******************************************************************* Create a string of size size+1 (for the null) *******************************************************************/ + static char *string_create_s(int size) { - char *tmp; - - tmp = (char *)malloc(size+1); - - if (tmp == NULL) { + char *tmp; - DEBUG(0, ("Out of memory in string_create_s\n")); + tmp = (char *)malloc(size+1); - } - - return(tmp); + if (tmp == NULL) { + DEBUG(0, ("Out of memory in string_create_s\n")); + } + return(tmp); } /**************************************************************************** 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) { - union hblock hb; - int i, chk, l; - char *jp; + union hblock hb; + int i, chk, l; + char *jp; - DEBUG(5, ("WriteTarHdr, Type = %c, Size= %.0f, Name = %s\n", ftype, (double)size, aname)); + DEBUG(5, ("WriteTarHdr, Type = %c, Size= %.0f, Name = %s\n", ftype, (double)size, aname)); - memset(hb.dummy, 0, sizeof(hb.dummy)); + memset(hb.dummy, 0, sizeof(hb.dummy)); - l=strlen(aname); - if (l >= NAMSIZ - 1) { - /* write a GNU tar style long header */ - char *b; - b = (char *)malloc(l+TBLOCK+100); - if (!b) { - DEBUG(0,("out of memory\n")); - exit(1); - } - writetarheader(f, "/./@LongLink", l+2, 0, " 0 \0", 'L'); - memset(b, 0, l+TBLOCK+100); - fixtarname(b, aname, l); - i = strlen(b)+1; - DEBUG(5, ("File name in tar file: %s, size=%d, \n", b, (int)strlen(b))); - dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); - SAFE_FREE(b); - } + l=strlen(aname); + if (l >= NAMSIZ - 1) { + /* write a GNU tar style long header */ + char *b; + b = (char *)malloc(l+TBLOCK+100); + if (!b) { + DEBUG(0,("out of memory\n")); + exit(1); + } + writetarheader(f, "/./@LongLink", l+2, 0, " 0 \0", 'L'); + memset(b, 0, l+TBLOCK+100); + fixtarname(b, aname, l); + i = strlen(b)+1; + DEBUG(5, ("File name in tar file: %s, size=%d, \n", b, (int)strlen(b))); + dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); + SAFE_FREE(b); + } - /* use l + 1 to do the null too */ - fixtarname(hb.dbuf.name, aname, (l >= NAMSIZ) ? NAMSIZ : l + 1); + /* use l + 1 to do the null too */ + fixtarname(hb.dbuf.name, aname, (l >= NAMSIZ) ? NAMSIZ : l + 1); - if (lowercase) - strlower_m(hb.dbuf.name); + if (lowercase) + strlower_m(hb.dbuf.name); - /* write out a "standard" tar format header */ + /* write out a "standard" tar format header */ - hb.dbuf.name[NAMSIZ-1]='\0'; - safe_strcpy(hb.dbuf.mode, amode, sizeof(hb.dbuf.mode)-1); - 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); - if (size > (SMB_BIG_UINT)077777777777LL) { + hb.dbuf.name[NAMSIZ-1]='\0'; + safe_strcpy(hb.dbuf.mode, amode, sizeof(hb.dbuf.mode)-1); + 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); + if (size > (SMB_BIG_UINT)077777777777LL) { - /* This is a non-POSIX compatible extention to store files - greater than 8GB. */ + /* This is a non-POSIX compatible extention to store files + greater than 8GB. */ - memset(hb.dbuf.size, 0, 4); - hb.dbuf.size[0]=128; - for (i = 8, jp=(char*)&size; i; i--) - hb.dbuf.size[i+3] = *(jp++); - } - oct_it((SMB_BIG_UINT) mtime, 13, hb.dbuf.mtime); - memcpy(hb.dbuf.chksum, " ", sizeof(hb.dbuf.chksum)); - memset(hb.dbuf.linkname, 0, NAMSIZ); - hb.dbuf.linkflag=ftype; + memset(hb.dbuf.size, 0, 4); + hb.dbuf.size[0]=128; + for (i = 8, jp=(char*)&size; i; i--) + hb.dbuf.size[i+3] = *(jp++); + } + oct_it((SMB_BIG_UINT) 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++); + 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); - hb.dbuf.chksum[6] = '\0'; + oct_it((SMB_BIG_UINT) chk, 8, hb.dbuf.chksum); + hb.dbuf.chksum[6] = '\0'; - (void) dotarbuf(f, hb.dummy, sizeof(hb.dummy)); + (void) dotarbuf(f, hb.dummy, sizeof(hb.dummy)); } /**************************************************************************** Read a tar header into a hblock structure, and validate ***************************************************************************/ + static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) { - long chk, fchk; - int i; - char *jp; + long chk, fchk; + int i; + char *jp; - /* - * read in a "standard" tar format header - we're not that interested - * in that many fields, though - */ + /* + * read in a "standard" tar format header - we're not that interested + * in that many fields, though + */ - /* check the checksum */ - for (chk=0, i=sizeof(hb->dummy), jp=hb->dummy; --i>=0;) chk+=(0xFF & *jp++); + /* check the checksum */ + for (chk=0, i=sizeof(hb->dummy), jp=hb->dummy; --i>=0;) + chk+=(0xFF & *jp++); - if (chk == 0) - return chk; + if (chk == 0) + return chk; - /* compensate for blanks in chksum header */ - for (i=sizeof(hb->dbuf.chksum), jp=hb->dbuf.chksum; --i>=0;) - chk-=(0xFF & *jp++); + /* compensate for blanks in chksum header */ + for (i=sizeof(hb->dbuf.chksum), jp=hb->dbuf.chksum; --i>=0;) + chk-=(0xFF & *jp++); - chk += ' ' * sizeof(hb->dbuf.chksum); + chk += ' ' * sizeof(hb->dbuf.chksum); - fchk=unoct(hb->dbuf.chksum, sizeof(hb->dbuf.chksum)); + fchk=unoct(hb->dbuf.chksum, sizeof(hb->dbuf.chksum)); - DEBUG(5, ("checksum totals chk=%ld fchk=%ld chksum=%s\n", - chk, fchk, hb->dbuf.chksum)); + DEBUG(5, ("checksum totals chk=%ld fchk=%ld chksum=%s\n", + chk, fchk, hb->dbuf.chksum)); - if (fchk != chk) - { - DEBUG(0, ("checksums don't match %ld %ld\n", fchk, chk)); - dump_data(5, (char *)hb - TBLOCK, TBLOCK *3); - return -1; - } + if (fchk != chk) { + DEBUG(0, ("checksums don't match %ld %ld\n", fchk, chk)); + dump_data(5, (char *)hb - TBLOCK, TBLOCK *3); + return -1; + } - if ((finfo->name = string_create_s(strlen(prefix) + strlen(hb -> dbuf.name) + 3)) == NULL) { + if ((finfo->name = string_create_s(strlen(prefix) + strlen(hb -> dbuf.name) + 3)) == NULL) { + DEBUG(0, ("Out of space creating file_info2 for %s\n", hb -> dbuf.name)); + return(-1); + } - DEBUG(0, ("Out of space creating file_info2 for %s\n", hb -> dbuf.name)); - return(-1); + safe_strcpy(finfo->name, prefix, strlen(prefix) + strlen(hb -> dbuf.name) + 3); + + /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ + unfixtarname(finfo->name + strlen(prefix), hb->dbuf.name, + strlen(hb->dbuf.name) + 1, True); + + /* can't handle some links at present */ + if ((hb->dbuf.linkflag != '0') && (hb -> dbuf.linkflag != '5')) { + if (hb->dbuf.linkflag == 0) { + DEBUG(6, ("Warning: NULL link flag (gnu tar archive ?) %s\n", + finfo->name)); + } else { + if (hb -> dbuf.linkflag == 'L') { /* We have a longlink */ + /* Do nothing here at the moment. do_tarput will handle this + as long as the longlink gets back to it, as it has to advance + the buffer pointer, etc */ + } else { + DEBUG(0, ("this tar file appears to contain some kind \ +of link other than a GNUtar Longlink - ignoring\n")); + return -2; + } + } + } + + if ((unoct(hb->dbuf.mode, sizeof(hb->dbuf.mode)) & S_IFDIR) || + (*(finfo->name+strlen(finfo->name)-1) == '\\')) { + finfo->mode=aDIR; + } else { + finfo->mode=0; /* we don't care about mode at the moment, we'll + * just make it a regular file */ + } - } + /* + * Bug fix by richard@sj.co.uk + * + * REC: restore times correctly (as does tar) + * We only get the modification time of the file; set the creation time + * from the mod. time, and the access time to current time + */ + finfo->mtime = finfo->ctime = strtol(hb->dbuf.mtime, NULL, 8); + finfo->atime = time(NULL); + finfo->size = unoct(hb->dbuf.size, sizeof(hb->dbuf.size)); - safe_strcpy(finfo->name, prefix, strlen(prefix) + strlen(hb -> dbuf.name) + 3); - - /* use l + 1 to do the null too; do prefix - prefcnt to zap leading slash */ - unfixtarname(finfo->name + strlen(prefix), hb->dbuf.name, - strlen(hb->dbuf.name) + 1, True); - - /* can't handle some links at present */ - if ((hb->dbuf.linkflag != '0') && (hb -> dbuf.linkflag != '5')) { - if (hb->dbuf.linkflag == 0) { - DEBUG(6, ("Warning: NULL link flag (gnu tar archive ?) %s\n", - finfo->name)); - } else { - if (hb -> dbuf.linkflag == 'L') { /* We have a longlink */ - /* Do nothing here at the moment. do_tarput will handle this - as long as the longlink gets back to it, as it has to advance - the buffer pointer, etc */ - - } else { - DEBUG(0, ("this tar file appears to contain some kind of link other than a GNUtar Longlink - ignoring\n")); - return -2; - } - } - } - - if ((unoct(hb->dbuf.mode, sizeof(hb->dbuf.mode)) & S_IFDIR) - || (*(finfo->name+strlen(finfo->name)-1) == '\\')) - { - finfo->mode=aDIR; - } - else - finfo->mode=0; /* we don't care about mode at the moment, we'll - * just make it a regular file */ - /* - * Bug fix by richard@sj.co.uk - * - * REC: restore times correctly (as does tar) - * We only get the modification time of the file; set the creation time - * from the mod. time, and the access time to current time - */ - finfo->mtime = finfo->ctime = strtol(hb->dbuf.mtime, NULL, 8); - finfo->atime = time(NULL); - finfo->size = unoct(hb->dbuf.size, sizeof(hb->dbuf.size)); - - return True; + return True; } /**************************************************************************** Write out the tar buffer to tape or wherever ****************************************************************************/ + static int dotarbuf(int f, char *b, int n) { - int fail=1, writ=n; + int fail=1, writ=n; - if (dry_run) { - return writ; - } - /* This routine and the next one should be the only ones that do write()s */ - if (tp + n >= tbufsiz) - { - int diff; - - diff=tbufsiz-tp; - memcpy(tarbuf + tp, b, diff); - fail=fail && (1+write(f, tarbuf, tbufsiz)); - n-=diff; - b+=diff; - tp=0; - - while (n >= tbufsiz) - { - fail=fail && (1 + write(f, b, tbufsiz)); - n-=tbufsiz; - b+=tbufsiz; + if (dry_run) { + return writ; + } + /* This routine and the next one should be the only ones that do write()s */ + if (tp + n >= tbufsiz) { + int diff; + + diff=tbufsiz-tp; + memcpy(tarbuf + tp, b, diff); + fail=fail && (1+write(f, tarbuf, tbufsiz)); + n-=diff; + b+=diff; + tp=0; + + while (n >= tbufsiz) { + fail=fail && (1 + write(f, b, tbufsiz)); + n-=tbufsiz; + b+=tbufsiz; + } + } + + if (n>0) { + memcpy(tarbuf+tp, b, n); + tp+=n; } - } - if (n>0) { - memcpy(tarbuf+tp, b, n); - tp+=n; - } - return(fail ? writ : 0); + return(fail ? writ : 0); } /**************************************************************************** Write zeros to buffer / tape ****************************************************************************/ + static void dozerobuf(int f, int n) { - /* short routine just to write out n zeros to buffer - - * used to round files to nearest block - * and to do tar EOFs */ + /* short routine just to write out n zeros to buffer - + * used to round files to nearest block + * and to do tar EOFs */ - if (dry_run) - return; + if (dry_run) + return; - if (n+tp >= tbufsiz) - { - memset(tarbuf+tp, 0, tbufsiz-tp); - - write(f, tarbuf, tbufsiz); - memset(tarbuf, 0, (tp+=n-tbufsiz)); - } - else - { - memset(tarbuf+tp, 0, n); - tp+=n; - } + if (n+tp >= tbufsiz) { + memset(tarbuf+tp, 0, tbufsiz-tp); + write(f, tarbuf, tbufsiz); + memset(tarbuf, 0, (tp+=n-tbufsiz)); + } else { + memset(tarbuf+tp, 0, n); + tp+=n; + } } /**************************************************************************** Malloc tape buffer ****************************************************************************/ + static void initarbuf(void) { - /* initialize tar buffer */ - tbufsiz=blocksize*TBLOCK; - tarbuf=malloc(tbufsiz); /* FIXME: We might not get the buffer */ + /* initialize tar buffer */ + tbufsiz=blocksize*TBLOCK; + tarbuf=malloc(tbufsiz); /* FIXME: We might not get the buffer */ - /* reset tar buffer pointer and tar file counter and total dumped */ - tp=0; ntarf=0; ttarf=0; + /* reset tar buffer pointer and tar file counter and total dumped */ + tp=0; ntarf=0; ttarf=0; } /**************************************************************************** Write two zero blocks at end of file ****************************************************************************/ + static void dotareof(int f) { - SMB_STRUCT_STAT stbuf; - /* Two zero blocks at end of file, write out full buffer */ + SMB_STRUCT_STAT stbuf; + /* Two zero blocks at end of file, write out full buffer */ - if (dry_run) - return; + if (dry_run) + return; - (void) dozerobuf(f, TBLOCK); - (void) dozerobuf(f, TBLOCK); + (void) dozerobuf(f, TBLOCK); + (void) dozerobuf(f, TBLOCK); - if (sys_fstat(f, &stbuf) == -1) - { - DEBUG(0, ("Couldn't stat file handle\n")); - return; - } + if (sys_fstat(f, &stbuf) == -1) { + DEBUG(0, ("Couldn't stat file handle\n")); + return; + } - /* Could be a pipe, in which case S_ISREG should fail, - * and we should write out at full size */ - if (tp > 0) write(f, tarbuf, S_ISREG(stbuf.st_mode) ? tp : tbufsiz); + /* Could be a pipe, in which case S_ISREG should fail, + * and we should write out at full size */ + if (tp > 0) + write(f, tarbuf, S_ISREG(stbuf.st_mode) ? tp : tbufsiz); } /**************************************************************************** (Un)mangle DOS pathname, make nonabsolute ****************************************************************************/ + static void fixtarname(char *tptr, const char *fp, int l) { /* add a '.' to start of file name, convert from ugly dos \'s in path @@ -437,43 +432,43 @@ 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) { - /* Converts long to octal string, pads with leading zeros */ + /* Converts long to octal string, pads with leading zeros */ - /* skip final null, but do final space */ - --ndgs; - p[--ndgs] = ' '; + /* skip final null, but do final space */ + --ndgs; + p[--ndgs] = ' '; - /* Loop does at least one digit */ - do { - p[--ndgs] = '0' + (char) (value & 7); - value >>= 3; - } - while (ndgs > 0 && value != 0); + /* Loop does at least one digit */ + do { + p[--ndgs] = '0' + (char) (value & 7); + value >>= 3; + } while (ndgs > 0 && value != 0); - /* Do leading zeros */ - while (ndgs > 0) - p[--ndgs] = '0'; + /* Do leading zeros */ + while (ndgs > 0) + p[--ndgs] = '0'; } /**************************************************************************** Convert from octal string to long ***************************************************************************/ + static long unoct(char *p, int ndgs) { - long value=0; - /* Converts octal string to long, ignoring any non-digit */ + long value=0; + /* Converts octal string to long, ignoring any non-digit */ - while (--ndgs) - { - if (isdigit((int)*p)) - value = (value << 3) | (long) (*p - '0'); + while (--ndgs) { + if (isdigit((int)*p)) + value = (value << 3) | (long) (*p - '0'); - p++; - } + p++; + } - return value; + return value; } /**************************************************************************** @@ -481,90 +476,86 @@ Compare two strings in a slash insensitive way, allowing s1 to match s2 if s1 is an "initial" string (up to directory marker). Thus, if s2 is a file in any subdirectory of s1, declare a match. ***************************************************************************/ + static int strslashcmp(char *s1, char *s2) { - char *s1_0=s1; - - while(*s1 && *s2 && - (*s1 == *s2 - || tolower(*s1) == tolower(*s2) - || (*s1 == '\\' && *s2=='/') - || (*s1 == '/' && *s2=='\\'))) { - s1++; s2++; - } + char *s1_0=s1; - /* if s1 has a trailing slash, it compared equal, so s1 is an "initial" - string of s2. - */ - if (!*s1 && s1 != s1_0 && (*(s1-1) == '/' || *(s1-1) == '\\')) return 0; + while(*s1 && *s2 && (*s1 == *s2 || tolower(*s1) == tolower(*s2) || + (*s1 == '\\' && *s2=='/') || (*s1 == '/' && *s2=='\\'))) { + s1++; s2++; + } - /* ignore trailing slash on s1 */ - if (!*s2 && (*s1 == '/' || *s1 == '\\') && !*(s1+1)) return 0; + /* if s1 has a trailing slash, it compared equal, so s1 is an "initial" + string of s2. + */ + if (!*s1 && s1 != s1_0 && (*(s1-1) == '/' || *(s1-1) == '\\')) + return 0; - /* check for s1 is an "initial" string of s2 */ - if ((*s2 == '/' || *s2 == '\\') && !*s1) return 0; + /* ignore trailing slash on s1 */ + if (!*s2 && (*s1 == '/' || *s1 == '\\') && !*(s1+1)) + return 0; - return *s1-*s2; -} + /* check for s1 is an "initial" string of s2 */ + if ((*s2 == '/' || *s2 == '\\') && !*s1) + return 0; + return *s1-*s2; +} /**************************************************************************** Ensure a remote path exists (make if necessary) ***************************************************************************/ + static BOOL ensurepath(char *fname) { - /* *must* be called with buffer ready malloc'ed */ - /* ensures path exists */ + /* *must* be called with buffer ready malloc'ed */ + /* ensures path exists */ - char *partpath, *ffname; - char *p=fname, *basehack; + char *partpath, *ffname; + char *p=fname, *basehack; - DEBUG(5, ( "Ensurepath called with: %s\n", fname)); + DEBUG(5, ( "Ensurepath called with: %s\n", fname)); - partpath = string_create_s(strlen(fname)); - ffname = string_create_s(strlen(fname)); - - if ((partpath == NULL) || (ffname == NULL)){ - - DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); - return(False); + partpath = string_create_s(strlen(fname)); + ffname = string_create_s(strlen(fname)); - } + if ((partpath == NULL) || (ffname == NULL)){ + DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); + return(False); + } - *partpath = 0; + *partpath = 0; - /* fname copied to ffname so can strtok */ + /* fname copied to ffname so can strtok */ - safe_strcpy(ffname, fname, strlen(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) - return True; - else - *basehack='\0'; + /* do a `basename' on ffname, so don't try and make file name directory */ + if ((basehack=strrchr_m(ffname, '\\')) == NULL) + return True; + else + *basehack='\0'; - p=strtok(ffname, "\\"); + p=strtok(ffname, "\\"); - while (p) - { - safe_strcat(partpath, p, strlen(fname) + 1); - - if (!cli_chkpath(cli, partpath)) { - if (!cli_mkdir(cli, partpath)) - { - DEBUG(0, ("Error mkdirhiering\n")); - return False; - } - else - DEBUG(3, ("mkdirhiering %s\n", partpath)); + while (p) { + safe_strcat(partpath, p, strlen(fname) + 1); - } + if (!cli_chkpath(cli, partpath)) { + if (!cli_mkdir(cli, partpath)) { + DEBUG(0, ("Error mkdirhiering\n")); + return False; + } else { + DEBUG(3, ("mkdirhiering %s\n", partpath)); + } + } - safe_strcat(partpath, "\\", strlen(fname) + 1); - p = strtok(NULL,"/\\"); - } + safe_strcat(partpath, "\\", strlen(fname) + 1); + p = strtok(NULL,"/\\"); + } - return True; + return True; } static int padit(char *buf, int bufsize, int padsize) @@ -583,7 +574,6 @@ static int padit(char *buf, int bufsize, int padsize) return berr; } - static void do_setrattr(char *name, uint16 attr, int set) { uint16 oldattr; @@ -601,268 +591,258 @@ 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) { - int fnum; - SMB_BIG_UINT nread=0; - char ftype; - file_info2 finfo; - BOOL close_done = False; - BOOL shallitime=True; - char data[65520]; - int read_size = 65520; - int datalen=0; - - struct timeval tp_start; - GetTimeOfDay(&tp_start); - - ftype = '0'; /* An ordinary file ... */ - - if (finfo1) { - finfo.size = finfo1 -> size; - finfo.mode = finfo1 -> mode; - finfo.uid = finfo1 -> uid; - finfo.gid = finfo1 -> gid; - finfo.mtime = finfo1 -> mtime; - finfo.atime = finfo1 -> atime; - finfo.ctime = finfo1 -> ctime; - finfo.name = 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; - } - - if (dry_run) - { - DEBUG(3,("skipping file %s of size %12.0f bytes\n", - finfo.name, - (double)finfo.size)); - shallitime=0; - ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); - ntarf++; - return; - } + int fnum; + SMB_BIG_UINT nread=0; + char ftype; + file_info2 finfo; + BOOL close_done = False; + BOOL shallitime=True; + char data[65520]; + int read_size = 65520; + int datalen=0; + + struct timeval tp_start; + + GetTimeOfDay(&tp_start); + + ftype = '0'; /* An ordinary file ... */ + + if (finfo1) { + finfo.size = finfo1 -> size; + finfo.mode = finfo1 -> mode; + finfo.uid = finfo1 -> uid; + finfo.gid = finfo1 -> gid; + finfo.mtime = finfo1 -> mtime; + finfo.atime = finfo1 -> atime; + finfo.ctime = finfo1 -> ctime; + finfo.name = 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; + } - fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); + if (dry_run) { + DEBUG(3,("skipping file %s of size %12.0f bytes\n", finfo.name, + (double)finfo.size)); + shallitime=0; + ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); + ntarf++; + return; + } - dos_clean_name(rname); + fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); - if (fnum == -1) { - DEBUG(0,("%s opening remote file %s (%s)\n", - cli_errstr(cli),rname, cur_dir)); - return; - } + dos_clean_name(rname); - finfo.name = string_create_s(strlen(rname)); - if (finfo.name == NULL) { - DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); - return; - } + if (fnum == -1) { + DEBUG(0,("%s opening remote file %s (%s)\n", + cli_errstr(cli),rname, cur_dir)); + return; + } - safe_strcpy(finfo.name,rname, strlen(rname)); - if (!finfo1) { - if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &finfo.atime, &finfo.mtime)) { - DEBUG(0, ("getattrE: %s\n", cli_errstr(cli))); - return; - } - finfo.ctime = finfo.mtime; - } + finfo.name = string_create_s(strlen(rname)); + if (finfo.name == NULL) { + DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); + return; + } - DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); + safe_strcpy(finfo.name,rname, strlen(rname)); + if (!finfo1) { + if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &finfo.atime, &finfo.mtime)) { + DEBUG(0, ("getattrE: %s\n", cli_errstr(cli))); + return; + } + finfo.ctime = finfo.mtime; + } - if (tar_inc && !(finfo.mode & aARCH)) - { - DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name)); - shallitime=0; - } - else if (!tar_system && (finfo.mode & aSYSTEM)) - { - DEBUG(4, ("skipping %s - system bit is set\n", finfo.name)); - shallitime=0; - } - else if (!tar_hidden && (finfo.mode & aHIDDEN)) - { - DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name)); - shallitime=0; - } - else - { - DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", - finfo.name, - (double)finfo.size, - lname)); + DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); + + if (tar_inc && !(finfo.mode & aARCH)) { + DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name)); + shallitime=0; + } else if (!tar_system && (finfo.mode & aSYSTEM)) { + DEBUG(4, ("skipping %s - system bit is set\n", finfo.name)); + shallitime=0; + } else if (!tar_hidden && (finfo.mode & aHIDDEN)) { + DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name)); + shallitime=0; + } else { + DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", + finfo.name, (double)finfo.size, lname)); - /* write a tar header, don't bother with mode - just set to 100644 */ - writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); + /* write a tar header, don't bother with mode - just set to 100644 */ + writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); - while (nread < finfo.size && !close_done) { + while (nread < finfo.size && !close_done) { - DEBUG(3,("nread=%.0f\n",(double)nread)); + DEBUG(3,("nread=%.0f\n",(double)nread)); - datalen = cli_read(cli, fnum, data, nread, read_size); + datalen = cli_read(cli, fnum, data, nread, read_size); - if (datalen == -1) { - DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli))); - break; - } + if (datalen == -1) { + DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli))); + break; + } - nread += datalen; - - /* if file size has increased since we made file size query, truncate - read so tar header for this file will be correct. - */ - - if (nread > finfo.size) { - datalen -= nread - finfo.size; - DEBUG(0,("File size change - truncating %s to %.0f bytes\n", finfo.name, (double)finfo.size)); - } - - /* add received bits of file to buffer - dotarbuf will - * write out in 512 byte intervals */ - if (dotarbuf(tarhandle,data,datalen) != datalen) { - DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); - break; - } + nread += datalen; + + /* if file size has increased since we made file size query, truncate + read so tar header for this file will be correct. + */ + + if (nread > finfo.size) { + datalen -= nread - finfo.size; + DEBUG(0,("File size change - truncating %s to %.0f bytes\n", + finfo.name, (double)finfo.size)); + } + + /* add received bits of file to buffer - dotarbuf will + * write out in 512 byte intervals */ + + if (dotarbuf(tarhandle,data,datalen) != datalen) { + DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); + break; + } - if (datalen == 0) { - DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); - break; - } + if (datalen == 0) { + DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); + break; + } - datalen=0; - } + datalen=0; + } - /* pad tar file with zero's if we couldn't get entire file */ - if (nread < finfo.size) { - DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", (double)finfo.size, (int)nread)); - if (padit(data, sizeof(data), finfo.size - nread)) - DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); - } + /* pad tar file with zero's if we couldn't get entire file */ + if (nread < finfo.size) { + DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", + (double)finfo.size, (int)nread)); + if (padit(data, sizeof(data), finfo.size - nread)) + DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); + } - /* round tar file to nearest block */ - if (finfo.size % TBLOCK) - dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); + /* round tar file to nearest block */ + if (finfo.size % TBLOCK) + dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); - ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); - ntarf++; - } + ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); + ntarf++; + } - cli_close(cli, fnum); + cli_close(cli, fnum); - if (shallitime) - { - struct timeval tp_end; - int this_time; + if (shallitime) { + struct timeval tp_end; + int this_time; - /* if shallitime is true then we didn't skip */ - if (tar_reset && !dry_run) - (void) do_setrattr(finfo.name, aARCH, ATTRRESET); + /* if shallitime is true then we didn't skip */ + if (tar_reset && !dry_run) + (void) do_setrattr(finfo.name, aARCH, ATTRRESET); - GetTimeOfDay(&tp_end); - this_time = - (tp_end.tv_sec - tp_start.tv_sec)*1000 + - (tp_end.tv_usec - tp_start.tv_usec)/1000; - get_total_time_ms += this_time; - get_total_size += finfo.size; - - if (tar_noisy) - { - DEBUG(0, ("%12.0f (%7.1f kb/s) %s\n", - (double)finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), - finfo.name)); - } + GetTimeOfDay(&tp_end); + this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_usec - tp_start.tv_usec)/1000; + get_total_time_ms += this_time; + get_total_size += finfo.size; + + if (tar_noisy) { + DEBUG(0, ("%12.0f (%7.1f kb/s) %s\n", + (double)finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), + finfo.name)); + } - /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ - DEBUG(3,("(%g kb/s) (average %g kb/s)\n", - finfo.size / MAX(0.001, (1.024*this_time)), - get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); - } + /* Thanks to Carel-Jan Engel (ease@mail.wirehub.nl) for this one */ + DEBUG(3,("(%g kb/s) (average %g kb/s)\n", + finfo.size / MAX(0.001, (1.024*this_time)), + get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); + } } /**************************************************************************** Append single file to tar file (or not) ***************************************************************************/ + static void do_tar(file_info *finfo) { - pstring rname; + pstring rname; - if (strequal(finfo->name,"..") || strequal(finfo->name,".")) - return; + if (strequal(finfo->name,"..") || strequal(finfo->name,".")) + return; - /* Is it on the exclude list ? */ - if (!tar_excl && clipn) { - pstring exclaim; + /* Is it on the exclude list ? */ + if (!tar_excl && clipn) { + pstring exclaim; - DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir))); + DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir))); - pstrcpy(exclaim, cur_dir); - *(exclaim+strlen(exclaim)-1)='\0'; + pstrcpy(exclaim, cur_dir); + *(exclaim+strlen(exclaim)-1)='\0'; - pstrcat(exclaim, "\\"); - pstrcat(exclaim, finfo->name); + pstrcat(exclaim, "\\"); + pstrcat(exclaim, finfo->name); - DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); + DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); - if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || + if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || #ifdef HAVE_REGEX_H - (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { + (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { #else - (tar_re_search && mask_match(exclaim, cliplist[0], True))) { + (tar_re_search && mask_match(exclaim, cliplist[0], True))) { #endif - DEBUG(3,("Skipping file %s\n", exclaim)); - return; - } - } + DEBUG(3,("Skipping file %s\n", exclaim)); + return; + } + } - if (finfo->mode & aDIR) - { - pstring saved_curdir; - pstring mtar_mask; + if (finfo->mode & aDIR) { + pstring saved_curdir; + pstring mtar_mask; - pstrcpy(saved_curdir, cur_dir); + pstrcpy(saved_curdir, cur_dir); - DEBUG(5, ("Sizeof(cur_dir)=%d, strlen(cur_dir)=%d, strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", (int)sizeof(cur_dir), (int)strlen(cur_dir), (int)strlen(finfo->name), finfo->name, cur_dir)); + DEBUG(5, ("Sizeof(cur_dir)=%d, strlen(cur_dir)=%d, \ +strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", + (int)sizeof(cur_dir), (int)strlen(cur_dir), + (int)strlen(finfo->name), finfo->name, cur_dir)); - pstrcat(cur_dir,finfo->name); - pstrcat(cur_dir,"\\"); + pstrcat(cur_dir,finfo->name); + pstrcat(cur_dir,"\\"); - DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); + DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); - /* write a tar directory, don't bother with mode - just set it to - * 40755 */ - writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); - if (tar_noisy) { - DEBUG(0,(" directory %s\n", cur_dir)); - } - ntarf++; /* Make sure we have a file on there */ - pstrcpy(mtar_mask,cur_dir); - pstrcat(mtar_mask,"*"); - DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask)); - do_list(mtar_mask, attribute, do_tar, False, True); - pstrcpy(cur_dir,saved_curdir); - } - else - { - pstrcpy(rname,cur_dir); - pstrcat(rname,finfo->name); - do_atar(rname,finfo->name,finfo); - } + /* write a tar directory, don't bother with mode - just set it to + * 40755 */ + writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); + if (tar_noisy) { + DEBUG(0,(" directory %s\n", cur_dir)); + } + ntarf++; /* Make sure we have a file on there */ + pstrcpy(mtar_mask,cur_dir); + pstrcat(mtar_mask,"*"); + DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask)); + do_list(mtar_mask, attribute, do_tar, False, True); + pstrcpy(cur_dir,saved_curdir); + } else { + pstrcpy(rname,cur_dir); + pstrcat(rname,finfo->name); + do_atar(rname,finfo->name,finfo); + } } /**************************************************************************** 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 @@ -886,79 +866,72 @@ static void unfixtarname(char *tptr, char *fp, int l, BOOL first) string_replace(tptr, '/', '\\'); } - /**************************************************************************** Move to the next block in the buffer, which may mean read in another set of blocks. FIXME, we should allow more than one block to be skipped. ****************************************************************************/ + static int next_block(char *ltarbuf, char **bufferp, int bufsiz) { - int bufread, total = 0; + int bufread, total = 0; - DEBUG(5, ("Advancing to next block: %0lx\n", (unsigned long)*bufferp)); - *bufferp += TBLOCK; - total = TBLOCK; + DEBUG(5, ("Advancing to next block: %0lx\n", (unsigned long)*bufferp)); + *bufferp += TBLOCK; + total = TBLOCK; - if (*bufferp >= (ltarbuf + bufsiz)) { + if (*bufferp >= (ltarbuf + bufsiz)) { - DEBUG(5, ("Reading more data into ltarbuf ...\n")); + DEBUG(5, ("Reading more data into ltarbuf ...\n")); - /* - * Bugfix from Bob Boehmer - * Fixes bug where read can return short if coming from - * a pipe. - */ - - bufread = read(tarhandle, ltarbuf, bufsiz); - total = bufread; - - while (total < bufsiz) { - if (bufread < 0) { /* An error, return false */ - return (total > 0 ? -2 : bufread); - } - if (bufread == 0) { - if (total <= 0) { - return -2; - } - break; - } - bufread = read(tarhandle, <arbuf[total], bufsiz - total); - total += bufread; - } + /* + * Bugfix from Bob Boehmer + * Fixes bug where read can return short if coming from + * a pipe. + */ - DEBUG(5, ("Total bytes read ... %i\n", total)); + bufread = read(tarhandle, ltarbuf, bufsiz); + total = bufread; - *bufferp = ltarbuf; + while (total < bufsiz) { + if (bufread < 0) { /* An error, return false */ + return (total > 0 ? -2 : bufread); + } + if (bufread == 0) { + if (total <= 0) { + return -2; + } + break; + } + bufread = read(tarhandle, <arbuf[total], bufsiz - total); + total += bufread; + } - } + DEBUG(5, ("Total bytes read ... %i\n", total)); - return(total); + *bufferp = ltarbuf; + } + return(total); } /* Skip a file, even if it includes a long file name? */ static int skip_file(int skipsize) { - int dsize = skipsize; - - DEBUG(5, ("Skiping file. Size = %i\n", skipsize)); - - /* FIXME, we should skip more than one block at a time */ - - while (dsize > 0) { + int dsize = skipsize; - if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { - - DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); - return(False); + DEBUG(5, ("Skiping file. Size = %i\n", skipsize)); - } + /* FIXME, we should skip more than one block at a time */ - dsize -= TBLOCK; - - } + while (dsize > 0) { + if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return(False); + } + dsize -= TBLOCK; + } - return(True); + return(True); } /************************************************************* @@ -1288,28 +1261,27 @@ static void do_tarput(void) /**************************************************************************** Blocksize command ***************************************************************************/ + int cmd_block(void) { - fstring buf; - int block; + fstring buf; + int block; - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) - { - DEBUG(0, ("blocksize \n")); - return 1; - } + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + DEBUG(0, ("blocksize \n")); + return 1; + } - block=atoi(buf); - if (block < 0 || block > 65535) - { - DEBUG(0, ("blocksize out of range")); - return 1; - } + block=atoi(buf); + if (block < 0 || block > 65535) { + DEBUG(0, ("blocksize out of range")); + return 1; + } - blocksize=block; - DEBUG(2,("blocksize is now %d\n", blocksize)); + blocksize=block; + DEBUG(2,("blocksize is now %d\n", blocksize)); - return 0; + return 0; } /**************************************************************************** @@ -1356,6 +1328,7 @@ int cmd_tarmode(void) /**************************************************************************** Feeble attrib command ***************************************************************************/ + int cmd_setmode(void) { char *q; @@ -1413,6 +1386,7 @@ int cmd_setmode(void) /**************************************************************************** Principal command for creating / extracting ***************************************************************************/ + int cmd_tar(void) { fstring buf; @@ -1439,6 +1413,7 @@ int cmd_tar(void) /**************************************************************************** Command line (option) version ***************************************************************************/ + int process_tar(void) { initarbuf(); @@ -1524,6 +1499,7 @@ int process_tar(void) /**************************************************************************** Find a token (filename) in a clip list ***************************************************************************/ + static int clipfind(char **aret, int ret, char *tok) { if (aret==NULL) return 0; @@ -1547,6 +1523,7 @@ static int clipfind(char **aret, int ret, char *tok) Read list of files to include from the file and initialize cliplist accordingly. ***************************************************************************/ + static int read_inclusion_file(char *filename) { XFILE *inclusion = NULL; -- cgit From d574b612e48780b31367fe2da399469990aae633 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Aug 2003 06:29:16 +0000 Subject: Finish reformatting. Jeremy. (This used to be commit 5ef75fa36620a87e8fd8567b854ea0770d8125ea) --- source3/client/clitar.c | 983 +++++++++++++++++++++++------------------------- 1 file changed, 467 insertions(+), 516 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 68f78e497f..5e8414e083 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -942,103 +942,94 @@ static int skip_file(int skipsize) static int get_file(file_info2 finfo) { - int fnum = -1, pos = 0, dsize = 0, bpos = 0; - SMB_BIG_UINT rsize = 0; + int fnum = -1, pos = 0, dsize = 0, bpos = 0; + SMB_BIG_UINT rsize = 0; - DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size)); + DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size)); - if (ensurepath(finfo.name) && - (fnum=cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { - DEBUG(0, ("abandoning restore\n")); - return(False); - } - - /* read the blocks from the tar file and write to the remote file */ - - rsize = finfo.size; /* This is how much to write */ - - while (rsize > 0) { - - /* We can only write up to the end of the buffer */ - - dsize = MIN(tbufsiz - (buffer_p - tarbuf) - bpos, 65520); /* Calculate the size to write */ - dsize = MIN(dsize, rsize); /* Should be only what is left */ - DEBUG(5, ("writing %i bytes, bpos = %i ...\n", dsize, bpos)); - - if (cli_write(cli, fnum, 0, buffer_p + bpos, pos, dsize) != dsize) { - DEBUG(0, ("Error writing remote file\n")); - return 0; - } - - rsize -= dsize; - pos += dsize; - - /* Now figure out how much to move in the buffer */ + if (ensurepath(finfo.name) && + (fnum=cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { + DEBUG(0, ("abandoning restore\n")); + return(False); + } - /* FIXME, we should skip more than one block at a time */ + /* read the blocks from the tar file and write to the remote file */ - /* First, skip any initial part of the part written that is left over */ - /* from the end of the first TBLOCK */ + rsize = finfo.size; /* This is how much to write */ - if ((bpos) && ((bpos + dsize) >= TBLOCK)) { + while (rsize > 0) { - dsize -= (TBLOCK - bpos); /* Get rid of the end of the first block */ - bpos = 0; + /* We can only write up to the end of the buffer */ + dsize = MIN(tbufsiz - (buffer_p - tarbuf) - bpos, 65520); /* Calculate the size to write */ + dsize = MIN(dsize, rsize); /* Should be only what is left */ + DEBUG(5, ("writing %i bytes, bpos = %i ...\n", dsize, bpos)); - if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { /* and skip the block */ - DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); - return False; + if (cli_write(cli, fnum, 0, buffer_p + bpos, pos, dsize) != dsize) { + DEBUG(0, ("Error writing remote file\n")); + return 0; + } - } + rsize -= dsize; + pos += dsize; - } + /* Now figure out how much to move in the buffer */ - /* - * Bugfix from Bob Boehmer . - * If the file being extracted is an exact multiple of - * TBLOCK bytes then we don't want to extract the next - * block from the tarfile here, as it will be done in - * the caller of get_file(). - */ + /* FIXME, we should skip more than one block at a time */ - while (((rsize != 0) && (dsize >= TBLOCK)) || - ((rsize == 0) && (dsize > TBLOCK))) { + /* First, skip any initial part of the part written that is left over */ + /* from the end of the first TBLOCK */ - if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { - DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); - return False; - } + if ((bpos) && ((bpos + dsize) >= TBLOCK)) { + dsize -= (TBLOCK - bpos); /* Get rid of the end of the first block */ + bpos = 0; - dsize -= TBLOCK; - } + if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { /* and skip the block */ + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return False; + } + } - bpos = dsize; + /* + * Bugfix from Bob Boehmer . + * If the file being extracted is an exact multiple of + * TBLOCK bytes then we don't want to extract the next + * block from the tarfile here, as it will be done in + * the caller of get_file(). + */ - } + while (((rsize != 0) && (dsize >= TBLOCK)) || + ((rsize == 0) && (dsize > TBLOCK))) { - /* Now close the file ... */ + if (next_block(tarbuf, &buffer_p, tbufsiz) <=0) { + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return False; + } - if (!cli_close(cli, fnum)) { - DEBUG(0, ("Error closing remote file\n")); - return(False); - } + dsize -= TBLOCK; + } + bpos = dsize; + } - /* Now we update the creation date ... */ + /* Now close the file ... */ - DEBUG(5, ("Updating creation date on %s\n", finfo.name)); + if (!cli_close(cli, fnum)) { + DEBUG(0, ("Error closing remote file\n")); + return(False); + } - if (!cli_setatr(cli, 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 */ - } - } + /* Now we update the creation date ... */ + DEBUG(5, ("Updating creation date on %s\n", finfo.name)); - ntarf++; + if (!cli_setatr(cli, 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 */ + } + } - DEBUG(0, ("restore tar file %s of size %.0f bytes\n", finfo.name, (double)finfo.size)); - - return(True); + ntarf++; + DEBUG(0, ("restore tar file %s of size %.0f bytes\n", finfo.name, (double)finfo.size)); + return(True); } /* Create a directory. We just ensure that the path exists and return as there @@ -1046,214 +1037,167 @@ static int get_file(file_info2 finfo) */ static int get_dir(file_info2 finfo) { + DEBUG(0, ("restore directory %s\n", finfo.name)); - DEBUG(0, ("restore directory %s\n", finfo.name)); - - if (!ensurepath(finfo.name)) { - - DEBUG(0, ("Problems creating directory\n")); - return(False); - - } - - ntarf++; - return(True); - + if (!ensurepath(finfo.name)) { + DEBUG(0, ("Problems creating directory\n")); + return(False); + } + ntarf++; + return(True); } + /* Get a file with a long file name ... first file has file name, next file has the data. We only want the long file name, as the loop in do_tarput will deal with the rest. */ static char * get_longfilename(file_info2 finfo) { - int namesize = strlen(finfo.name) + strlen(cur_dir) + 2; - char *longname = malloc(namesize); - int offset = 0, left = finfo.size; - BOOL first = True; - - DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); - DEBUG(5, ("Len = %.0f\n", (double)finfo.size)); - - if (longname == NULL) { - - DEBUG(0, ("could not allocate buffer of size %d for longname\n", - namesize)); - return(NULL); - } - - /* First, add cur_dir to the long file name */ + int namesize = strlen(finfo.name) + strlen(cur_dir) + 2; + char *longname = malloc(namesize); + int offset = 0, left = finfo.size; + BOOL first = True; - if (strlen(cur_dir) > 0) { - strncpy(longname, cur_dir, namesize); - offset = strlen(cur_dir); - } + DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); + DEBUG(5, ("Len = %.0f\n", (double)finfo.size)); - /* Loop through the blocks picking up the name */ - - while (left > 0) { - - if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { + if (longname == NULL) { + DEBUG(0, ("could not allocate buffer of size %d for longname\n", namesize)); + return(NULL); + } - DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); - return(NULL); + /* First, add cur_dir to the long file name */ - } + if (strlen(cur_dir) > 0) { + strncpy(longname, cur_dir, namesize); + offset = strlen(cur_dir); + } - unfixtarname(longname + offset, buffer_p, MIN(TBLOCK, finfo.size), first--); - DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, buffer_p)); + /* Loop through the blocks picking up the name */ - offset += TBLOCK; - left -= TBLOCK; + while (left > 0) { + if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return(NULL); + } - } + unfixtarname(longname + offset, buffer_p, MIN(TBLOCK, finfo.size), first--); + DEBUG(5, ("UnfixedName: %s, buffer: %s\n", longname, buffer_p)); - return(longname); + offset += TBLOCK; + left -= TBLOCK; + } + return(longname); } static void do_tarput(void) { - file_info2 finfo; - struct timeval tp_start; - char *longfilename = NULL, linkflag; - int skip = False; - - GetTimeOfDay(&tp_start); - - DEBUG(5, ("RJS do_tarput called ...\n")); - - buffer_p = tarbuf + tbufsiz; /* init this to force first read */ - - /* Now read through those files ... */ - - while (True) { - - /* Get us to the next block, or the first block first time around */ - - if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { - - DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); - - return; - - } - - DEBUG(5, ("Reading the next header ...\n")); - - switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { - - case -2: /* Hmm, not good, but not fatal */ - DEBUG(0, ("Skipping %s...\n", finfo.name)); - if ((next_block(tarbuf, &buffer_p, tbufsiz) <= 0) && - !skip_file(finfo.size)) { - - DEBUG(0, ("Short file, bailing out...\n")); - return; - - } - - break; - - case -1: - DEBUG(0, ("abandoning restore, -1 from read tar header\n")); - return; - - case 0: /* chksum is zero - looks like an EOF */ - DEBUG(0, ("tar: restored %d files and directories\n", ntarf)); - return; /* Hmmm, bad here ... */ + file_info2 finfo; + struct timeval tp_start; + char *longfilename = NULL, linkflag; + int skip = False; - default: - /* No action */ + GetTimeOfDay(&tp_start); + DEBUG(5, ("RJS do_tarput called ...\n")); - break; + buffer_p = tarbuf + tbufsiz; /* init this to force first read */ - } + /* Now read through those files ... */ + while (True) { + /* Get us to the next block, or the first block first time around */ + if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { + DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + return; + } - /* Now, do we have a long file name? */ + DEBUG(5, ("Reading the next header ...\n")); - if (longfilename != NULL) { + switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { + case -2: /* Hmm, not good, but not fatal */ + DEBUG(0, ("Skipping %s...\n", finfo.name)); + if ((next_block(tarbuf, &buffer_p, tbufsiz) <= 0) && !skip_file(finfo.size)) { + DEBUG(0, ("Short file, bailing out...\n")); + return; + } + break; - SAFE_FREE(finfo.name); /* Free the space already allocated */ - finfo.name = longfilename; - longfilename = NULL; + case -1: + DEBUG(0, ("abandoning restore, -1 from read tar header\n")); + return; - } + case 0: /* chksum is zero - looks like an EOF */ + DEBUG(0, ("tar: restored %d files and directories\n", ntarf)); + return; /* Hmmm, bad here ... */ - /* Well, now we have a header, process the file ... */ + default: + /* No action */ + break; + } - /* Should we skip the file? We have the long name as well here */ + /* Now, do we have a long file name? */ + if (longfilename != NULL) { + SAFE_FREE(finfo.name); /* Free the space already allocated */ + finfo.name = longfilename; + longfilename = NULL; + } - skip = clipn && - ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) + /* Well, now we have a header, process the file ... */ + /* Should we skip the file? We have the long name as well here */ + skip = clipn && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) || #ifdef HAVE_REGEX_H - || (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); + (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); #else - || (tar_re_search && mask_match(finfo.name, cliplist[0], True))); + (tar_re_search && mask_match(finfo.name, cliplist[0], True))); #endif - DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, (cliplist?cliplist[0]:NULL), finfo.name)); - - if (skip) { - - skip_file(finfo.size); - continue; - - } - - /* We only get this far if we should process the file */ - linkflag = ((union hblock *)buffer_p) -> dbuf.linkflag; - - switch (linkflag) { - - case '0': /* Should use symbolic names--FIXME */ - - /* - * Skip to the next block first, so we can get the file, FIXME, should - * be in get_file ... - * The 'finfo.size != 0' fix is from Bob Boehmer - * Fixes bug where file size in tarfile is zero. - */ - - if ((finfo.size != 0) && next_block(tarbuf, &buffer_p, tbufsiz) <=0) { - DEBUG(0, ("Short file, bailing out...\n")); - return; - } - if (!get_file(finfo)) { - DEBUG(0, ("Abandoning restore\n")); - return; - - } - break; - - case '5': - if (!get_dir(finfo)) { - DEBUG(0, ("Abandoning restore \n")); - return; - } - break; - - case 'L': - longfilename = get_longfilename(finfo); - if (!longfilename) { - DEBUG(0, ("abandoning restore\n")); - return; - - } - DEBUG(5, ("Long file name: %s\n", longfilename)); - break; - - default: - skip_file(finfo.size); /* Don't handle these yet */ - break; - - } - - } + DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, (cliplist?cliplist[0]:NULL), finfo.name)); + if (skip) { + skip_file(finfo.size); + continue; + } + /* We only get this far if we should process the file */ + linkflag = ((union hblock *)buffer_p) -> dbuf.linkflag; + switch (linkflag) { + case '0': /* Should use symbolic names--FIXME */ + /* + * Skip to the next block first, so we can get the file, FIXME, should + * be in get_file ... + * The 'finfo.size != 0' fix is from Bob Boehmer + * Fixes bug where file size in tarfile is zero. + */ + if ((finfo.size != 0) && next_block(tarbuf, &buffer_p, tbufsiz) <=0) { + DEBUG(0, ("Short file, bailing out...\n")); + return; + } + if (!get_file(finfo)) { + DEBUG(0, ("Abandoning restore\n")); + return; + } + break; + case '5': + if (!get_dir(finfo)) { + DEBUG(0, ("Abandoning restore \n")); + return; + } + break; + case 'L': + longfilename = get_longfilename(finfo); + if (!longfilename) { + DEBUG(0, ("abandoning restore\n")); + return; + } + DEBUG(5, ("Long file name: %s\n", longfilename)); + break; + default: + skip_file(finfo.size); /* Don't handle these yet */ + break; + } + } } - /* * samba interactive commands */ @@ -1287,42 +1231,43 @@ int cmd_block(void) /**************************************************************************** command to set incremental / reset mode ***************************************************************************/ + int cmd_tarmode(void) { - fstring buf; - - while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { - if (strequal(buf, "full")) - tar_inc=False; - else if (strequal(buf, "inc")) - tar_inc=True; - else if (strequal(buf, "reset")) - tar_reset=True; - else if (strequal(buf, "noreset")) - tar_reset=False; - else if (strequal(buf, "system")) - tar_system=True; - else if (strequal(buf, "nosystem")) - tar_system=False; - else if (strequal(buf, "hidden")) - tar_hidden=True; - else if (strequal(buf, "nohidden")) - tar_hidden=False; - else if (strequal(buf, "verbose") || strequal(buf, "noquiet")) - tar_noisy=True; - else if (strequal(buf, "quiet") || strequal(buf, "noverbose")) - tar_noisy=False; - else DEBUG(0, ("tarmode: unrecognised option %s\n", buf)); - } - - DEBUG(0, ("tarmode is now %s, %s, %s, %s, %s\n", - tar_inc ? "incremental" : "full", - tar_system ? "system" : "nosystem", - tar_hidden ? "hidden" : "nohidden", - tar_reset ? "reset" : "noreset", - tar_noisy ? "verbose" : "quiet")); - - return 0; + fstring buf; + + while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { + if (strequal(buf, "full")) + tar_inc=False; + else if (strequal(buf, "inc")) + tar_inc=True; + else if (strequal(buf, "reset")) + tar_reset=True; + else if (strequal(buf, "noreset")) + tar_reset=False; + else if (strequal(buf, "system")) + tar_system=True; + else if (strequal(buf, "nosystem")) + tar_system=False; + else if (strequal(buf, "hidden")) + tar_hidden=True; + else if (strequal(buf, "nohidden")) + tar_hidden=False; + else if (strequal(buf, "verbose") || strequal(buf, "noquiet")) + tar_noisy=True; + else if (strequal(buf, "quiet") || strequal(buf, "noverbose")) + tar_noisy=False; + else + DEBUG(0, ("tarmode: unrecognised option %s\n", buf)); + } + + DEBUG(0, ("tarmode is now %s, %s, %s, %s, %s\n", + tar_inc ? "incremental" : "full", + tar_system ? "system" : "nosystem", + tar_hidden ? "hidden" : "nohidden", + tar_reset ? "reset" : "noreset", + tar_noisy ? "verbose" : "quiet")); + return 0; } /**************************************************************************** @@ -1331,56 +1276,61 @@ Feeble attrib command int cmd_setmode(void) { - char *q; - fstring buf; - pstring fname; - uint16 attra[2]; - int direct=1; - - attra[0] = attra[1] = 0; - - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) - { - DEBUG(0, ("setmode <[+|-]rsha>\n")); - return 1; - } - - pstrcpy(fname, cur_dir); - pstrcat(fname, buf); - - while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { - q=buf; - - while(*q) - switch (*q++) { - case '+': direct=1; - break; - case '-': direct=0; - break; - case 'r': attra[direct]|=aRONLY; - break; - case 'h': attra[direct]|=aHIDDEN; - break; - case 's': attra[direct]|=aSYSTEM; - break; - case 'a': attra[direct]|=aARCH; - break; - default: DEBUG(0, ("setmode \n")); - return 1; - } - } + char *q; + fstring buf; + pstring fname; + uint16 attra[2]; + int direct=1; - if (attra[ATTRSET]==0 && attra[ATTRRESET]==0) - { - DEBUG(0, ("setmode <[+|-]rsha>\n")); - return 1; - } + attra[0] = attra[1] = 0; + + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + DEBUG(0, ("setmode <[+|-]rsha>\n")); + return 1; + } + + pstrcpy(fname, cur_dir); + pstrcat(fname, buf); + + while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { + q=buf; + + while(*q) { + switch (*q++) { + case '+': + direct=1; + break; + case '-': + direct=0; + break; + case 'r': + attra[direct]|=aRONLY; + break; + case 'h': + attra[direct]|=aHIDDEN; + break; + case 's': + attra[direct]|=aSYSTEM; + break; + case 'a': + attra[direct]|=aARCH; + break; + default: + DEBUG(0, ("setmode \n")); + return 1; + } + } + } - DEBUG(2, ("\nperm set %d %d\n", attra[ATTRSET], attra[ATTRRESET])); - do_setrattr(fname, attra[ATTRSET], ATTRSET); - do_setrattr(fname, attra[ATTRRESET], ATTRRESET); + if (attra[ATTRSET]==0 && attra[ATTRRESET]==0) { + DEBUG(0, ("setmode <[+|-]rsha>\n")); + return 1; + } - return 0; + 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; } /**************************************************************************** @@ -1389,25 +1339,22 @@ Principal command for creating / extracting int cmd_tar(void) { - fstring buf; - char **argl; - int argcl; - - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) - { - DEBUG(0,("tar [IXbgan] \n")); - return 1; - } - - argl=toktocliplist(&argcl, NULL); - if (!tar_parseargs(argcl, argl, buf, 0)) - return 1; + fstring buf; + char **argl; + int argcl; - process_tar(); + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + DEBUG(0,("tar [IXbgan] \n")); + return 1; + } - SAFE_FREE(argl); + argl=toktocliplist(&argcl, NULL); + if (!tar_parseargs(argcl, argl, buf, 0)) + return 1; - return 0; + process_tar(); + SAFE_FREE(argl); + return 0; } /**************************************************************************** @@ -1416,84 +1363,84 @@ Command line (option) version int process_tar(void) { - initarbuf(); - switch(tar_type) { - case 'x': + initarbuf(); + switch(tar_type) { + case 'x': #if 0 - do_tarput2(); + do_tarput2(); #else - do_tarput(); + do_tarput(); #endif - SAFE_FREE(tarbuf); - close(tarhandle); - break; - case 'r': - case 'c': - if (clipn && tar_excl) { - int i; - pstring tarmac; - - for (i=0; i= inclusion_buffer_size) { - char *ib; - 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; - } + if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) { + char *ib; + 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; + } + } - safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar); - inclusion_buffer_sofar += strlen(buf) + 1; - clipn++; - } - x_fclose(inclusion); - - if (! error) { - /* Allocate an array of clipn + 1 char*'s for cliplist */ - cliplist = malloc((clipn + 1) * sizeof(char *)); - if (cliplist == NULL) { - DEBUG(0,("failure allocating memory for cliplist\n")); - error = 1; - } else { - cliplist[clipn] = NULL; - p = inclusion_buffer; - for (i = 0; (! error) && (i < clipn); i++) { - /* set current item to NULL so array will be null-terminated even if - * malloc fails below. */ - cliplist[i] = NULL; - if ((tmpstr = (char *)malloc(strlen(p)+1)) == NULL) { - DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i)); - error = 1; - } else { - unfixtarname(tmpstr, p, strlen(p) + 1, True); - cliplist[i] = tmpstr; - if ((p = strchr_m(p, '\000')) == NULL) { - DEBUG(0,("INTERNAL ERROR: inclusion_buffer is of unexpected contents.\n")); - abort(); - } + safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar); + inclusion_buffer_sofar += strlen(buf) + 1; + clipn++; + } + x_fclose(inclusion); + + if (! error) { + /* Allocate an array of clipn + 1 char*'s for cliplist */ + cliplist = malloc((clipn + 1) * sizeof(char *)); + if (cliplist == NULL) { + DEBUG(0,("failure allocating memory for cliplist\n")); + error = 1; + } else { + cliplist[clipn] = NULL; + p = inclusion_buffer; + for (i = 0; (! error) && (i < clipn); i++) { + /* set current item to NULL so array will be null-terminated even if + * malloc fails below. */ + cliplist[i] = NULL; + if ((tmpstr = (char *)malloc(strlen(p)+1)) == NULL) { + DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i)); + error = 1; + } else { + unfixtarname(tmpstr, p, strlen(p) + 1, True); + cliplist[i] = tmpstr; + if ((p = strchr_m(p, '\000')) == NULL) { + DEBUG(0,("INTERNAL ERROR: inclusion_buffer is of unexpected contents.\n")); + abort(); + } + } + ++p; + } + must_free_cliplist = True; + } + } + + SAFE_FREE(inclusion_buffer); + if (error) { + if (cliplist) { + char **pp; + /* We know cliplist is always null-terminated */ + for (pp = cliplist; *pp; ++pp) { + SAFE_FREE(*pp); + } + SAFE_FREE(cliplist); + cliplist = NULL; + must_free_cliplist = False; + } + return 0; } - ++p; - } - must_free_cliplist = True; - } - } - - SAFE_FREE(inclusion_buffer); - if (error) { - if (cliplist) { - char **pp; - /* We know cliplist is always null-terminated */ - for (pp = cliplist; *pp; ++pp) { - SAFE_FREE(*pp); - } - SAFE_FREE(cliplist); - cliplist = NULL; - must_free_cliplist = False; - } - return 0; - } - /* cliplist and its elements are freed at the end of process_tar. */ - return 1; + /* cliplist and its elements are freed at the end of process_tar. */ + return 1; } /**************************************************************************** -- cgit From 72a8b313036092d3133c010257218ab60c1ca808 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Aug 2003 21:09:10 +0000 Subject: Fix the option processing for smbtar. Does no one check this ! Jeremy. (This used to be commit c4af1ec73584656fb9d2b372461da4748e1643f1) --- source3/client/clitar.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 5e8414e083..5295de8010 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1585,6 +1585,7 @@ Parse tar arguments. Sets tar_type, tar_excl, etc. int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) { + int newOptind = Optind; char tar_clipfl='\0'; /* Reset back to defaults - could be from interactive version @@ -1612,6 +1613,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) return 0; } else { Optind++; + newOptind++; } break; case 'g': @@ -1629,6 +1631,7 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) newer_than = stbuf.st_mtime; DEBUG(1,("Getting files newer than %s", asctime(LocalTime(&newer_than)))); + newOptind++; Optind++; } else { DEBUG(0,("Error setting newer-than time\n")); @@ -1696,7 +1699,9 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) DEBUG(0,("Option F must be followed by exactly one filename.\n")); return 0; } - if (! read_inclusion_file(argv[Optind+1])) { + newOptind++; + Optind++; + if (! read_inclusion_file(argv[Optind])) { return 0; } } else if (Optind+1=argc || !strcmp(argv[Optind], "-")) { @@ -1767,6 +1775,10 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) if (tarhandle == 1) { dbf = x_stderr; } + if (!strcmp(argv[Optind], "-")) { + newOptind++; + } + } else { if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) { if (!dry_run) { @@ -1779,7 +1791,8 @@ int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) DEBUG(0,("Error opening local file %s - %s\n", argv[Optind], strerror(errno))); return(0); } + newOptind++; } - return 1; + return newOptind; } -- cgit From 17a713d1b9eb00e28036fe9028c09c202340504f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 6 Aug 2003 19:30:42 +0000 Subject: Get rid of MAXPATHLEN, move to standard PATH_MAX. Jeremy. (This used to be commit 455ed2d51d86f39ce0fa6e6abca31a5425d2ea17) --- source3/client/clitar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 5295de8010..15c6ea3076 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1477,7 +1477,7 @@ accordingly. static int read_inclusion_file(char *filename) { XFILE *inclusion = NULL; - char buf[MAXPATHLEN + 1]; + char buf[MAX_PATH + 1]; char *inclusion_buffer = NULL; int inclusion_buffer_size = 0; int inclusion_buffer_sofar = 0; @@ -1487,7 +1487,7 @@ static int read_inclusion_file(char *filename) int error = 0; clipn = 0; - buf[MAXPATHLEN] = '\0'; /* guarantee null-termination */ + buf[MAX_PATH] = '\0'; /* guarantee null-termination */ if ((inclusion = x_fopen(filename, O_RDONLY, 0)) == NULL) { /* XXX It would be better to include a reason for failure, but without * autoconf, it's hard to use strerror, sys_errlist, etc. -- cgit From e602bca52fc50f2b126d5edbd7afd019bf96bbcc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 6 Aug 2003 21:31:11 +0000 Subject: Reversed replacement. Oops. Jeremy. (This used to be commit 520bee397d946766cef8ab9f0d7d89064106f510) --- source3/client/clitar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 15c6ea3076..7e0efc7947 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1477,7 +1477,7 @@ accordingly. static int read_inclusion_file(char *filename) { XFILE *inclusion = NULL; - char buf[MAX_PATH + 1]; + char buf[PATH_MAX + 1]; char *inclusion_buffer = NULL; int inclusion_buffer_size = 0; int inclusion_buffer_sofar = 0; @@ -1487,7 +1487,7 @@ static int read_inclusion_file(char *filename) int error = 0; clipn = 0; - buf[MAX_PATH] = '\0'; /* guarantee null-termination */ + buf[PATH_MAX] = '\0'; /* guarantee null-termination */ if ((inclusion = x_fopen(filename, O_RDONLY, 0)) == NULL) { /* XXX It would be better to include a reason for failure, but without * autoconf, it's hard to use strerror, sys_errlist, etc. -- cgit From a757fe10b1e00521862ff3217964d01eeaa77c05 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 12 Aug 2003 21:30:28 +0000 Subject: Apply a little const (This used to be commit e3b36906c53bd4a9231c2efb007cec234e52a78f) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 7e0efc7947..5e20c3e11b 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1583,7 +1583,7 @@ static int read_inclusion_file(char *filename) Parse tar arguments. Sets tar_type, tar_excl, etc. ***************************************************************************/ -int tar_parseargs(int argc, char *argv[], char *Optarg, int Optind) +int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) { int newOptind = Optind; char tar_clipfl='\0'; -- cgit From 64ca3346961650d089515b81ca3887fa499c1ef3 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 27 Aug 2003 07:39:26 +0000 Subject: Print an error instead of crashing if no argument is specified for smbclient -T Fixes bug 345. (This used to be commit a46e58e2b6e3d9526012d6a2d903163a3373fa59) --- source3/client/clitar.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 5e20c3e11b..f7a292dbbf 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1775,6 +1775,10 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) if (tarhandle == 1) { dbf = x_stderr; } + if (!argv[Optind]) { + DEBUG(0,("Must specify tar filename\n")); + return 0; + } if (!strcmp(argv[Optind], "-")) { newOptind++; } -- cgit From a7e8e39b91c661ac0058929a7e46c9d4da2763f2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 Sep 2003 23:58:39 +0000 Subject: Proposed patch for #308. Needs testing. Jeremy (This used to be commit e2b73477e772ac2f527719df0d3d64c67649bb1c) --- source3/client/clitar.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f7a292dbbf..b01de5b8e7 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -122,7 +122,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t static void do_atar(char *rname,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 fixtarname(char *tptr, const char *fp, int l); +static void fixtarname(char *tptr, const char *fp, size_t l); static int dotarbuf(int f, char *b, int n); static void dozerobuf(int f, int n); static void dotareof(int f); @@ -171,7 +171,10 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m memset(hb.dummy, 0, sizeof(hb.dummy)); l=strlen(aname); - if (l >= NAMSIZ - 1) { + /* We will be prepending a '.' in fixtarheader so use +2 to + * take care of the . and terminating zero. JRA. + */ + if (l+2 >= NAMSIZ) { /* write a GNU tar style long header */ char *b; b = (char *)malloc(l+TBLOCK+100); @@ -181,15 +184,14 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m } writetarheader(f, "/./@LongLink", l+2, 0, " 0 \0", 'L'); memset(b, 0, l+TBLOCK+100); - fixtarname(b, aname, l); + fixtarname(b, aname, l+2); i = strlen(b)+1; DEBUG(5, ("File name in tar file: %s, size=%d, \n", b, (int)strlen(b))); dotarbuf(f, b, TBLOCK*(((i-1)/TBLOCK)+1)); SAFE_FREE(b); } - /* use l + 1 to do the null too */ - fixtarname(hb.dbuf.name, aname, (l >= NAMSIZ) ? NAMSIZ : l + 1); + fixtarname(hb.dbuf.name, aname, (l+2 >= NAMSIZ) ? NAMSIZ : l + 2); if (lowercase) strlower_m(hb.dbuf.name); @@ -419,13 +421,14 @@ static void dotareof(int f) (Un)mangle DOS pathname, make nonabsolute ****************************************************************************/ -static void fixtarname(char *tptr, const char *fp, int l) +static void fixtarname(char *tptr, const char *fp, size_t l) { /* add a '.' to start of file name, convert from ugly dos \'s in path * to lovely unix /'s :-} */ *tptr++='.'; + l--; - safe_strcpy(tptr, fp, l); + StrnCpy(tptr, fp, l-1); string_replace(tptr, '\\', '/'); } -- cgit From a4e5e3f3a5d80673a6b4ee2d9bd4f00a325bb4fb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 12 Sep 2003 01:25:35 +0000 Subject: Fix from Craig Barratt to fix restore with filenames > 100 chars. Jeremy. (This used to be commit aa40a86cbe797cba4e281cb8dc09b2ae67e93dc2) --- source3/client/clitar.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index b01de5b8e7..f38d6fe91a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1054,9 +1054,11 @@ static int get_dir(file_info2 finfo) has the data. We only want the long file name, as the loop in do_tarput will deal with the rest. */ -static char * get_longfilename(file_info2 finfo) +static char *get_longfilename(file_info2 finfo) { - int namesize = strlen(finfo.name) + strlen(cur_dir) + 2; + /* finfo.size here is the length of the filename as written by the "/./@LongLink" name + * header call. */ + int namesize = finfo.size + strlen(cur_dir) + 2; char *longname = malloc(namesize); int offset = 0, left = finfo.size; BOOL first = True; -- cgit From 7942c2826b9f1f16246ef284009572427ec44909 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Mar 2004 23:45:15 +0000 Subject: Merge from HEAD for Amanda group. Apply Craig Barratt's fixes to allow multiple exlusion files and patterns. Jeremy. (This used to be commit 0272fac8ca40b3d4ea4de8ac8a2e371d450d12e6) --- source3/client/clitar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f38d6fe91a..e43b3e4cc5 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -800,7 +800,7 @@ static void do_tar(file_info *finfo) #ifdef HAVE_REGEX_H (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { #else - (tar_re_search && mask_match(exclaim, cliplist[0], True))) { + (tar_re_search && mask_match_list(exclaim, cliplist, clipn, True))) { #endif DEBUG(3,("Skipping file %s\n", exclaim)); return; @@ -1153,7 +1153,7 @@ static void do_tarput(void) #ifdef HAVE_REGEX_H (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); #else - (tar_re_search && mask_match(finfo.name, cliplist[0], True))); + (tar_re_search && mask_match_list(finfo.name, cliplist, clipn, True))); #endif DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, (cliplist?cliplist[0]:NULL), finfo.name)); -- cgit From 3382b0a21af393b4b40956c139224867daf4c848 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 1 Jul 2004 20:20:06 +0000 Subject: r1320: Return an error when the last command read from stdin fails in smbclient + prepare for better error checking in tar.. (This used to be commit 374f00b56b7e9bff08e70ee2d93538b2c7fde7b7) --- source3/client/clitar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index e43b3e4cc5..64c194b54d 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1357,9 +1357,8 @@ int cmd_tar(void) if (!tar_parseargs(argcl, argl, buf, 0)) return 1; - process_tar(); SAFE_FREE(argl); - return 0; + return process_tar(); } /**************************************************************************** @@ -1368,6 +1367,7 @@ Command line (option) version int process_tar(void) { + int rc = 0; initarbuf(); switch(tar_type) { case 'x': @@ -1445,7 +1445,7 @@ int process_tar(void) clipn = 0; must_free_cliplist = False; } - return(0); + return rc; } /**************************************************************************** -- cgit From 3ef0710fa4f487e8887a8c16714c6443009e4a47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Sep 2004 22:49:23 +0000 Subject: r2361: Fix the appalling toktocliplist() fn. Bug found by Luis Benvenutto. Jeremy. (This used to be commit d434d8e2b47bc8553ee04bd7211f622e3fcbb7fb) --- source3/client/clitar.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 64c194b54d..4cadef558d 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1345,8 +1345,9 @@ Principal command for creating / extracting int cmd_tar(void) { fstring buf; - char **argl; - int argcl; + char **argl = NULL; + int argcl = 0; + int ret; if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { DEBUG(0,("tar [IXbgan] \n")); @@ -1357,8 +1358,9 @@ int cmd_tar(void) if (!tar_parseargs(argcl, argl, buf, 0)) return 1; + ret = process_tar(); SAFE_FREE(argl); - return process_tar(); + return ret; } /**************************************************************************** -- cgit From b4cf9e95059071df49b34ff8574e48cb96f42da1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 7 Oct 2004 04:01:18 +0000 Subject: r2835: Since we always have -I. and -I$(srcdir) in CFLAGS, we can get rid of '..' from all #include preprocessor commands. This fixes bugzilla #1880 where OpenVMS gets confused about the '.' characters. (This used to be commit 7f161702fa4916979602cc0295919b541912acd6) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 4cadef558d..b4d6273f7b 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -37,7 +37,7 @@ #include "includes.h" #include "clitar.h" -#include "../client/client_proto.h" +#include "client/client_proto.h" static int clipfind(char **aret, int ret, char *tok); -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/client/clitar.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index b4d6273f7b..a92be1abe3 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -146,7 +146,7 @@ static char *string_create_s(int size) { char *tmp; - tmp = (char *)malloc(size+1); + tmp = (char *)SMB_MALLOC(size+1); if (tmp == NULL) { DEBUG(0, ("Out of memory in string_create_s\n")); @@ -177,7 +177,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m if (l+2 >= NAMSIZ) { /* write a GNU tar style long header */ char *b; - b = (char *)malloc(l+TBLOCK+100); + b = (char *)SMB_MALLOC(l+TBLOCK+100); if (!b) { DEBUG(0,("out of memory\n")); exit(1); @@ -385,7 +385,7 @@ static void initarbuf(void) { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; - tarbuf=malloc(tbufsiz); /* FIXME: We might not get the buffer */ + tarbuf=SMB_MALLOC(tbufsiz); /* FIXME: We might not get the buffer */ /* reset tar buffer pointer and tar file counter and total dumped */ tp=0; ntarf=0; ttarf=0; @@ -1059,7 +1059,7 @@ static char *get_longfilename(file_info2 finfo) /* finfo.size here is the length of the filename as written by the "/./@LongLink" name * header call. */ int namesize = finfo.size + strlen(cur_dir) + 2; - char *longname = malloc(namesize); + char *longname = SMB_MALLOC(namesize); int offset = 0, left = finfo.size; BOOL first = True; @@ -1506,7 +1506,7 @@ static int read_inclusion_file(char *filename) while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) { if (inclusion_buffer == NULL) { inclusion_buffer_size = 1024; - if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) { + if ((inclusion_buffer = SMB_MALLOC(inclusion_buffer_size)) == NULL) { DEBUG(0,("failure allocating buffer to read inclusion file\n")); error = 1; break; @@ -1520,7 +1520,7 @@ static int read_inclusion_file(char *filename) if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) { char *ib; inclusion_buffer_size *= 2; - ib = Realloc(inclusion_buffer,inclusion_buffer_size); + ib = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size); if (! ib) { DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", inclusion_buffer_size)); @@ -1539,7 +1539,7 @@ static int read_inclusion_file(char *filename) if (! error) { /* Allocate an array of clipn + 1 char*'s for cliplist */ - cliplist = malloc((clipn + 1) * sizeof(char *)); + cliplist = SMB_MALLOC_ARRAY(char *, clipn + 1); if (cliplist == NULL) { DEBUG(0,("failure allocating memory for cliplist\n")); error = 1; @@ -1550,7 +1550,7 @@ static int read_inclusion_file(char *filename) /* set current item to NULL so array will be null-terminated even if * malloc fails below. */ cliplist[i] = NULL; - if ((tmpstr = (char *)malloc(strlen(p)+1)) == NULL) { + if ((tmpstr = (char *)SMB_MALLOC(strlen(p)+1)) == NULL) { DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i)); error = 1; } else { @@ -1720,7 +1720,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) clipn=argc-Optind-1; clipcount = clipn; - if ((tmplist=malloc(clipn*sizeof(char *))) == NULL) { + if ((tmplist=SMB_MALLOC_ARRAY(char *,clipn)) == NULL) { DEBUG(0, ("Could not allocate space to process cliplist, count = %i\n", clipn)); return 0; } @@ -1729,7 +1729,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) DEBUG(5, ("Processing an item, %s\n", cliplist[clipcount])); - if ((tmpstr = (char *)malloc(strlen(cliplist[clipcount])+1)) == NULL) { + if ((tmpstr = (char *)SMB_MALLOC(strlen(cliplist[clipcount])+1)) == NULL) { DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", clipcount)); return 0; } @@ -1751,7 +1751,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) #ifdef HAVE_REGEX_H int errcode; - if ((preg = (regex_t *)malloc(65536)) == NULL) { + if ((preg = (regex_t *)SMB_MALLOC(65536)) == NULL) { DEBUG(0, ("Could not allocate buffer for regular expression search\n")); return; -- cgit From 66ffe146080e7570f6499ec3e1317f59ae727de9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 10 Feb 2005 03:34:25 +0000 Subject: r5295: fix compile issue with MIT 1.4 due to broken gssapi.h (This used to be commit f88f5e12187ed87934ae2cafbf9e9599d4fd7f6c) --- source3/client/clitar.c | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index a92be1abe3..14ebffb60f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -87,9 +87,6 @@ static BOOL tar_reset=False; static BOOL tar_excl=True; /* use regular expressions for search on file names */ static 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; /* Dump files with System attribute */ @@ -797,11 +794,7 @@ static void do_tar(file_info *finfo) DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || -#ifdef HAVE_REGEX_H - (tar_re_search && !regexec(preg, exclaim, 0, NULL, 0))) { -#else (tar_re_search && mask_match_list(exclaim, cliplist, clipn, True))) { -#endif DEBUG(3,("Skipping file %s\n", exclaim)); return; } @@ -1150,11 +1143,7 @@ static void do_tarput(void) /* Well, now we have a header, process the file ... */ /* Should we skip the file? We have the long name as well here */ skip = clipn && ((!tar_re_search && clipfind(cliplist, clipn, finfo.name) ^ tar_excl) || -#ifdef HAVE_REGEX_H - (tar_re_search && !regexec(preg, finfo.name, 0, NULL, 0))); -#else (tar_re_search && mask_match_list(finfo.name, cliplist, clipn, True))); -#endif DEBUG(5, ("Skip = %i, cliplist=%s, file=%s\n", skip, (cliplist?cliplist[0]:NULL), finfo.name)); if (skip) { @@ -1748,25 +1737,6 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) } if (Optind+1 Date: Mon, 7 Mar 2005 23:54:24 +0000 Subject: r5687: Fix for bug #2398 from Kevin Dalley . smbtar shouldn't assume /dev/null means dryrun. Jeremy. (This used to be commit 84e7b7db8992db7812b8e09b8633c257657fb91c) --- source3/client/clitar.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 14ebffb60f..524feca1d2 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1761,11 +1761,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) } } else { - if (tar_type=='c' && (dry_run || strcmp(argv[Optind], "/dev/null")==0)) { - if (!dry_run) { - DEBUG(0,("Output is /dev/null, assuming dry_run\n")); - dry_run = True; - } + if (tar_type=='c' && dry_run) { 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)) { -- cgit From b3e57cb3ffb6eeb3edb1a7b02be35f70e1e7dfcf Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Mar 2005 21:17:01 +0000 Subject: r5968: derrell's large file fix for libsmbclient (BUG 2505) (This used to be commit 85be4c5df398faa6c5bfacd1f9d2f12c39d411e1) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 524feca1d2..919545291f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -44,7 +44,7 @@ static int clipfind(char **aret, int ret, char *tok); typedef struct file_info_struct file_info2; struct file_info_struct { - SMB_BIG_UINT size; + SMB_OFF_T size; uint16 mode; uid_t uid; gid_t gid; -- cgit From 978ca8486031e43754a3c23757f361bf3a85f335 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 6 Apr 2005 16:28:04 +0000 Subject: r6225: get rid of warnings from my compiler about nested externs (This used to be commit efea76ac71412f8622cd233912309e91b9ea52da) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 919545291f..b241bd0ec2 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -63,6 +63,7 @@ typedef struct { } stack; #define SEPARATORS " \t\n\r" +extern time_t newer_than; extern struct cli_state *cli; /* These defines are for the do_setrattr routine, to indicate @@ -1621,7 +1622,6 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) return 0; } else { SMB_STRUCT_STAT stbuf; - extern time_t newer_than; if (sys_stat(argv[Optind], &stbuf) == 0) { newer_than = stbuf.st_mtime; -- cgit From 6d5757395a0e54245543794d0d6d6d6a32cd857a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 5 Nov 2005 04:21:55 +0000 Subject: r11511: A classic "friday night check-in" :-). This moves much of the Samba4 timezone handling code back into Samba3. Gets rid of "kludge-gmt" and removes the effectiveness of the parameter "time offset" (I can add this back in very easily if needed) - it's no longer being looked at. I'm hoping this will fix the problems people have been having with DST transitions. I'll start comprehensive testing tomorrow, but for now all modifications are done. Splits time get/set functions into srv_XXX and cli_XXX as they need to look at different timezone offsets. Get rid of much of the "efficiency" cruft that was added to Samba back in the day when the C library timezone handling functions were slow. Jeremy. (This used to be commit 414303bc0272f207046b471a0364fa296b67c1f8) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index b241bd0ec2..ad3387ffdd 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1626,7 +1626,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)))); newOptind++; Optind++; } else { -- cgit From a168730dda8f6917bf89d82824060cdd815c7297 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 06:58:54 +0000 Subject: r12045: More warning fixes... Just a few more to go. Jeremy. (This used to be commit cd192ed79a531c6775cdbfb35f0eb2e0fa230ce9) --- source3/client/clitar.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index ad3387ffdd..5afe154cbb 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1097,6 +1097,8 @@ static void do_tarput(void) char *longfilename = NULL, linkflag; int skip = False; + ZERO_STRUCT(finfo); + GetTimeOfDay(&tp_start); DEBUG(5, ("RJS do_tarput called ...\n")); -- cgit From 5a4881bf396e691524329bcd6aa1ae4a7f4084ec Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Dec 2005 20:52:36 +0000 Subject: r12522: Try and fix bug #2926 by removing setlocale(LC_ALL, "C") and replace calls to isupper/islower/toupper/tolower with ASCII equivalents (mapping into _w variants). Jeremy. (This used to be commit c2752347eb2deeb2798c580ec7fc751a847717e9) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 5afe154cbb..c15d24d619 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -482,7 +482,7 @@ static int strslashcmp(char *s1, char *s2) { char *s1_0=s1; - while(*s1 && *s2 && (*s1 == *s2 || tolower(*s1) == tolower(*s2) || + while(*s1 && *s2 && (*s1 == *s2 || tolower_ascii(*s1) == tolower_ascii(*s2) || (*s1 == '\\' && *s2=='/') || (*s1 == '/' && *s2=='\\'))) { s1++; s2++; } -- cgit From eca035db9a3e0c9eba13b3ceb1078442942e5cf9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Feb 2006 23:08:12 +0000 Subject: r13535: Fix #2353 based on a patch by William Jojo. Jeremy. (This used to be commit fe63a6ee06149195032320dd0fb9b6c7dfb460d3) --- source3/client/clitar.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c15d24d619..cd0ce27eb5 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1698,8 +1698,8 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) return 0; } newOptind++; - Optind++; - if (! read_inclusion_file(argv[Optind])) { + /* Optind points at the tar output file, Optind+1 at the inclusion file. */ + if (! read_inclusion_file(argv[Optind+1])) { return 0; } } else if (Optind+1 Date: Tue, 7 Mar 2006 06:31:04 +0000 Subject: r13915: Fixed a very interesting class of realloc() bugs found by Coverity. realloc can return NULL in one of two cases - (1) the realloc failed, (2) realloc succeeded but the new size requested was zero, in which case this is identical to a free() call. The error paths dealing with these two cases should be different, but mostly weren't. Secondly the standard idiom for dealing with realloc when you know the new size is non-zero is the following : tmp = realloc(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } However, there were *many* *many* places in Samba where we were using the old (broken) idiom of : p = realloc(p, size) if (!p) { return error; } which will leak the memory pointed to by p on realloc fail. This commit (hopefully) fixes all these cases by moving to a standard idiom of : p = SMB_REALLOC(p, size) if (!p) { return error; } Where if the realloc returns null due to the realloc failing or size == 0 we *guarentee* that the storage pointed to by p has been freed. This allows me to remove a lot of code that was dealing with the standard (more verbose) method that required a tmp pointer. This is almost always what you want. When a realloc fails you never usually want the old memory, you want to free it and get into your error processing asap. For the 11 remaining cases where we really do need to keep the old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR, which can be used as follows : tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the pointer p, even on size == 0 or realloc fail. All this is done by a hidden extra argument to Realloc(), BOOL free_old_on_error which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR macros (and their array counterparts). It remains to be seen what this will do to our Coverity bug count :-). Jeremy. (This used to be commit 1d710d06a214f3f1740e80e0bffd6aab44aac2b0) --- source3/client/clitar.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index cd0ce27eb5..ff9bc1f0fb 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1510,16 +1510,13 @@ static int read_inclusion_file(char *filename) } if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) { - char *ib; inclusion_buffer_size *= 2; - ib = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size); - if (! ib) { + inclusion_buffer = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size); + if (!inclusion_buffer) { DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", inclusion_buffer_size)); error = 1; break; - } else { - inclusion_buffer = ib; } } -- cgit From 58752bccdd301a9742f9bc3c5bd0c2978077e4ff Mon Sep 17 00:00:00 2001 From: Steve French Date: Fri, 10 Mar 2006 04:18:29 +0000 Subject: r14128: Remove warning generated by coverity scan tool (missing SAFE_FREE in error path) (This used to be commit 33a1e26114d7dfdfb72e393efa399454a588e11e) --- source3/client/clitar.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index ff9bc1f0fb..9ddb92d3df 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1077,6 +1077,7 @@ static char *get_longfilename(file_info2 finfo) while (left > 0) { if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + SAFE_FREE(longname); return(NULL); } -- cgit From 1c66bcef8de15efaaf329c3fa3e73549b067036b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 12 Mar 2006 17:24:10 +0000 Subject: r14242: Fix Coverity bug # 82 (This used to be commit 9f645e996279be74aaeebcbecbfa07adce49ec7c) --- source3/client/clitar.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 9ddb92d3df..020c11bf62 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -523,6 +523,8 @@ static BOOL ensurepath(char *fname) if ((partpath == NULL) || (ffname == NULL)){ DEBUG(0, ("Out of memory in ensurepath: %s\n", fname)); + SAFE_FREE(partpath); + SAFE_FREE(ffname); return(False); } -- cgit From 0837f6b584aeafe25c2c746b1cd085bf70ca5533 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 12 Mar 2006 17:48:51 +0000 Subject: r14246: Fix Coverity bug # 85 (This used to be commit ebc21336d80c5d417b309d4f9c22c074c324e123) --- source3/client/clitar.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 020c11bf62..90d06cc94e 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1112,6 +1112,7 @@ static void do_tarput(void) /* Get us to the next block, or the first block first time around */ if (next_block(tarbuf, &buffer_p, tbufsiz) <= 0) { DEBUG(0, ("Empty file, short tar file, or read error: %s\n", strerror(errno))); + SAFE_FREE(longfilename); return; } @@ -1183,6 +1184,7 @@ static void do_tarput(void) } break; case 'L': + SAFE_FREE(longfilename); longfilename = get_longfilename(finfo); if (!longfilename) { DEBUG(0, ("abandoning restore\n")); -- cgit From b84029452b37555944cfc77c9651a50278c67b11 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 12 Mar 2006 17:57:05 +0000 Subject: r14248: Fix Coverity bug # 84 (This used to be commit 811ae2b21f98bd8926f8edd70de19fe18265e28e) --- source3/client/clitar.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 90d06cc94e..306848bc0c 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1724,6 +1724,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) if ((tmpstr = (char *)SMB_MALLOC(strlen(cliplist[clipcount])+1)) == NULL) { DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", clipcount)); + SAFE_FREE(tmplist); return 0; } -- cgit From 2ebcc2933a12f5df69bf1ea9225ae4989c6208eb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 Apr 2006 00:47:46 +0000 Subject: r15141: Fix for #3592 inspired by Justin Best . Ignore a file in a tar output if the first read fails. Also cope with <2GB read fail. Jeremy. (This used to be commit 1b73e699e11c6e26e9a9123e74190eebd170fc05) --- source3/client/clitar.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 306848bc0c..a7bc4bfde3 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -561,15 +561,15 @@ static BOOL ensurepath(char *fname) return True; } -static int padit(char *buf, int bufsize, int padsize) +static int padit(char *buf, SMB_BIG_UINT bufsize, SMB_BIG_UINT padsize) { int berr= 0; int bytestowrite; - DEBUG(5, ("Padding with %d zeros\n", padsize)); - memset(buf, 0, bufsize); + DEBUG(5, ("Padding with %0.f zeros\n", (double)padsize)); + memset(buf, 0, (size_t)bufsize); while( !berr && padsize > 0 ) { - bytestowrite= MIN(bufsize, padsize); + bytestowrite= (int)MIN(bufsize, padsize); berr = dotarbuf(tarhandle, buf, bytestowrite) != bytestowrite; padsize -= bytestowrite; } @@ -682,12 +682,11 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name)); shallitime=0; } else { + BOOL wrote_tar_header = False; + DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", finfo.name, (double)finfo.size, lname)); - /* write a tar header, don't bother with mode - just set to 100644 */ - writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); - while (nread < finfo.size && !close_done) { DEBUG(3,("nread=%.0f\n",(double)nread)); @@ -701,6 +700,13 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) nread += datalen; + /* Only if the first read succeeds, write out the tar header. */ + if (!wrote_tar_header) { + /* write a tar header, don't bother with mode - just set to 100644 */ + writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); + wrote_tar_header = True; + } + /* if file size has increased since we made file size query, truncate read so tar header for this file will be correct. */ @@ -727,20 +733,25 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) datalen=0; } - /* pad tar file with zero's if we couldn't get entire file */ - if (nread < finfo.size) { - DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", - (double)finfo.size, (int)nread)); - if (padit(data, sizeof(data), finfo.size - nread)) - DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); - } + if (wrote_tar_header) { + /* pad tar file with zero's if we couldn't get entire file */ + if (nread < finfo.size) { + DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", + (double)finfo.size, (int)nread)); + if (padit(data, (SMB_BIG_UINT)sizeof(data), finfo.size - nread)) + DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); + } - /* round tar file to nearest block */ - if (finfo.size % TBLOCK) - dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); + /* round tar file to nearest block */ + if (finfo.size % TBLOCK) + dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); - ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); - ntarf++; + ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); + ntarf++; + } else { + DEBUG(4, ("skipping %s - initial read failed (file was locked ?)\n", finfo.name)); + shallitime=0; + } } cli_close(cli, fnum); -- cgit From a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Jun 2006 21:36:49 +0000 Subject: r16230: Fix Klocwork #861 and others. localtime and asctime can return NULL. Ensure we check all returns correctly. Jeremy. (This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index a7bc4bfde3..14c28acfc5 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1641,7 +1641,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)))); + time_to_asc(&newer_than))); newOptind++; Optind++; } else { -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/client/clitar.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 14c28acfc5..f0d0ac595c 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -201,7 +201,11 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m 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); +#ifdef HAVE_LONGLONG if (size > (SMB_BIG_UINT)077777777777LL) { +#else + if (size > (SMB_BIG_UINT)077777777777) { +#endif /* This is a non-POSIX compatible extention to store files greater than 8GB. */ -- cgit From a64925ddff467a47f7adfac4b1b977ddc0c7f4ef Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Aug 2006 16:44:00 +0000 Subject: r17800: Start using struct timespec internally for file times on the wire. This allows us to go to nsec resolution for systems that support it. It should also now be easy to add a correct "create time" (birth time) for systems that support it (*BSD). I'll be watching the build farm closely after this one for breakage :-). Jeremy. (This used to be commit 425280a1d23f97ef0b0be77462386d619f47b21d) --- source3/client/clitar.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f0d0ac595c..87ca3245c1 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -49,9 +49,9 @@ struct file_info_struct { uid_t uid; gid_t gid; /* These times are normally kept in GMT */ - time_t mtime; - time_t atime; - time_t ctime; + struct timespec mtime_ts; + struct timespec atime_ts; + struct timespec ctime_ts; char *name; /* This is dynamically allocate */ file_info2 *next, *prev; /* Used in the stack ... */ @@ -312,8 +312,9 @@ of link other than a GNUtar Longlink - ignoring\n")); * We only get the modification time of the file; set the creation time * from the mod. time, and the access time to current time */ - finfo->mtime = finfo->ctime = strtol(hb->dbuf.mtime, NULL, 8); - finfo->atime = time(NULL); + finfo->mtime_ts = finfo->ctime_ts = + convert_time_t_to_timespec((time_t)strtol(hb->dbuf.mtime, NULL, 8)); + finfo->atime_ts = convert_time_t_to_timespec(time(NULL)); finfo->size = unoct(hb->dbuf.size, sizeof(hb->dbuf.size)); return True; @@ -625,18 +626,18 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) finfo.mode = finfo1 -> mode; finfo.uid = finfo1 -> uid; finfo.gid = finfo1 -> gid; - finfo.mtime = finfo1 -> mtime; - finfo.atime = finfo1 -> atime; - finfo.ctime = finfo1 -> ctime; + finfo.mtime_ts = finfo1 -> mtime_ts; + finfo.atime_ts = finfo1 -> atime_ts; + finfo.ctime_ts = finfo1 -> ctime_ts; finfo.name = 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.mtime_ts = def_finfo.mtime_ts; + finfo.atime_ts = def_finfo.atime_ts; + finfo.ctime_ts = def_finfo.ctime_ts; finfo.name = def_finfo.name; } @@ -667,11 +668,14 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) safe_strcpy(finfo.name,rname, strlen(rname)); if (!finfo1) { - if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &finfo.atime, &finfo.mtime)) { + time_t atime, mtime; + if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &atime, &mtime)) { DEBUG(0, ("getattrE: %s\n", cli_errstr(cli))); return; } - finfo.ctime = finfo.mtime; + finfo.atime_ts = convert_time_t_to_timespec(atime); + finfo.mtime_ts = convert_time_t_to_timespec(mtime); + finfo.ctime_ts = finfo.mtime_ts; } DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); @@ -707,7 +711,8 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) /* Only if the first read succeeds, write out the tar header. */ if (!wrote_tar_header) { /* write a tar header, don't bother with mode - just set to 100644 */ - writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); + writetarheader(tarhandle, rname, finfo.size, + finfo.mtime_ts.tv_sec, "100644 \0", ftype); wrote_tar_header = True; } @@ -836,7 +841,7 @@ strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", /* write a tar directory, don't bother with mode - just set it to * 40755 */ - writetarheader(tarhandle, cur_dir, 0, finfo->mtime, "040755 \0", '5'); + writetarheader(tarhandle, cur_dir, 0, finfo->mtime_ts.tv_sec, "040755 \0", '5'); if (tar_noisy) { DEBUG(0,(" directory %s\n", cur_dir)); } @@ -1034,7 +1039,7 @@ static int get_file(file_info2 finfo) /* Now we update the creation date ... */ DEBUG(5, ("Updating creation date on %s\n", finfo.name)); - if (!cli_setatr(cli, finfo.name, finfo.mode, finfo.mtime)) { + if (!cli_setatr(cli, finfo.name, finfo.mode, finfo.mtime_ts.tv_sec)) { 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 */ -- cgit From 5196825b4c620d0c5e2f5893f3e4e57c14a91e8e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Aug 2006 14:55:46 +0000 Subject: r17850: Another dummy checkin for the build farm to retry (This used to be commit ac7087a6516fa7e0d10523a892acae852a80e29e) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 87ca3245c1..d8cf43e652 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -388,7 +388,7 @@ static void initarbuf(void) { /* initialize tar buffer */ tbufsiz=blocksize*TBLOCK; - tarbuf=SMB_MALLOC(tbufsiz); /* FIXME: We might not get the buffer */ + tarbuf=(char *)SMB_MALLOC(tbufsiz); /* FIXME: We might not get the buffer */ /* reset tar buffer pointer and tar file counter and total dumped */ tp=0; ntarf=0; ttarf=0; -- cgit From f8a17bd8bdbb52b200671e7ed52ffd982419f3f6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Sep 2006 19:47:48 +0000 Subject: r18047: More C++ stuff (This used to be commit 86f4ca84f2df2aa8977eb24828e3aa840dda7201) --- source3/client/clitar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index d8cf43e652..f228db1199 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1075,7 +1075,7 @@ static char *get_longfilename(file_info2 finfo) /* finfo.size here is the length of the filename as written by the "/./@LongLink" name * header call. */ int namesize = finfo.size + strlen(cur_dir) + 2; - char *longname = SMB_MALLOC(namesize); + char *longname = (char *)SMB_MALLOC(namesize); int offset = 0, left = finfo.size; BOOL first = True; @@ -1523,7 +1523,7 @@ static int read_inclusion_file(char *filename) while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) { if (inclusion_buffer == NULL) { inclusion_buffer_size = 1024; - if ((inclusion_buffer = SMB_MALLOC(inclusion_buffer_size)) == NULL) { + if ((inclusion_buffer = (char *)SMB_MALLOC(inclusion_buffer_size)) == NULL) { DEBUG(0,("failure allocating buffer to read inclusion file\n")); error = 1; break; @@ -1536,7 +1536,7 @@ static int read_inclusion_file(char *filename) if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) { inclusion_buffer_size *= 2; - inclusion_buffer = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size); + inclusion_buffer = (char *)SMB_REALLOC(inclusion_buffer,inclusion_buffer_size); if (!inclusion_buffer) { DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n", inclusion_buffer_size)); -- cgit From 4952fe368a40b239140b3035db6075427d237bb9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Mar 2007 23:40:03 +0000 Subject: r21714: Change the VFS interface to use struct timespec for utimes - change the call to ntimes. This preserves nsec timestamps we get from stat (if the system supports it) and only maps back down to usec or sec resolution on time set. Looks bigger than it is as I had to move lots of internal code from using time_t and struct utimebuf to struct timespec. Jeremy. (This used to be commit 8f3d530c5a748ea90f42ed8fbe68ae92178d4875) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f228db1199..c0748799b2 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1650,7 +1650,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", - time_to_asc(&newer_than))); + time_to_asc(newer_than))); newOptind++; Optind++; } else { -- cgit From 540911001d1bf25d9534b72b90a32fc7e5efc4b0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Mar 2007 23:54:57 +0000 Subject: r21768: Fix the client dfs code such that smbclient can process deep dfs links (ie. links that go to non root parts of a share). Make the directory handling conanonical in POSIX and Windows pathname processing. dfs should not be fully working in client tools. Please bug me if not. Jeremy. (This used to be commit 1c9e10569cd97ee41de39f9f012bea4e4c932b5d) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index c0748799b2..7bbb9fc58b 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -652,7 +652,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); - dos_clean_name(rname); + clean_name(rname); if (fnum == -1) { DEBUG(0,("%s opening remote file %s (%s)\n", -- cgit From 56ba44766854ed7cda265bdaf85913f2a1008282 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 28 Mar 2007 13:34:59 +0000 Subject: r22001: change prototype of dump_data(), so that it takes unsigned char * now, which matches what samba4 has. also fix all the callers to prevent compiler warnings metze (This used to be commit fa322f0cc9c26a9537ba3f0a7d4e4a25941317e7) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 7bbb9fc58b..3d925858a0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -264,7 +264,7 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) if (fchk != chk) { DEBUG(0, ("checksums don't match %ld %ld\n", fchk, chk)); - dump_data(5, (char *)hb - TBLOCK, TBLOCK *3); + dump_data(5, (uint8 *)hb - TBLOCK, TBLOCK *3); return -1; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 3d925858a0..93d8760c6f 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/client/clitar.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 93d8760c6f..b82a59953d 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* The following changes developed by Richard Sharpe for Canon Information Systems Research Australia (CISRA) -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/client/clitar.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index b82a59953d..0c820177b0 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -80,32 +80,32 @@ static char *tarbuf, *buffer_p; static int tp, ntarf, tbufsiz; static double ttarf; /* Incremental mode */ -static BOOL tar_inc=False; +static bool tar_inc=False; /* Reset archive bit */ -static BOOL tar_reset=False; +static bool tar_reset=False; /* Include / exclude mode (true=include, false=exclude) */ -static BOOL tar_excl=True; +static bool tar_excl=True; /* use regular expressions for search on file names */ -static BOOL tar_re_search=False; +static bool tar_re_search=False; /* Do not dump anything, just calculate sizes */ -static BOOL dry_run=False; +static bool dry_run=False; /* Dump files with System attribute */ -static BOOL tar_system=True; +static bool tar_system=True; /* Dump files with Hidden attribute */ -static BOOL tar_hidden=True; +static 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 */ +static bool tar_noisy=True; +static bool tar_real_noisy=False; /* Don't want to be really noisy by default */ char tar_type='\0'; static char **cliplist=NULL; static int clipn=0; -static BOOL must_free_cliplist = False; +static bool must_free_cliplist = False; extern file_info def_finfo; -extern BOOL lowercase; +extern bool lowercase; extern uint16 cnum; -extern BOOL readbraw_supported; +extern bool readbraw_supported; extern int max_xmit; extern pstring cur_dir; extern int get_total_time_ms; @@ -129,7 +129,7 @@ static void initarbuf(void); static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix); static long unoct(char *p, int ndgs); static void do_tarput(void); -static void unfixtarname(char *tptr, char *fp, int l, BOOL first); +static void unfixtarname(char *tptr, char *fp, int l, bool first); /* * tar specific utitlities @@ -512,7 +512,7 @@ static int strslashcmp(char *s1, char *s2) Ensure a remote path exists (make if necessary) ***************************************************************************/ -static BOOL ensurepath(char *fname) +static bool ensurepath(char *fname) { /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ @@ -608,8 +608,8 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) SMB_BIG_UINT nread=0; char ftype; file_info2 finfo; - BOOL close_done = False; - BOOL shallitime=True; + bool close_done = False; + bool shallitime=True; char data[65520]; int read_size = 65520; int datalen=0; @@ -689,7 +689,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name)); shallitime=0; } else { - BOOL wrote_tar_header = False; + bool wrote_tar_header = False; DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", finfo.name, (double)finfo.size, lname)); @@ -861,7 +861,7 @@ strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", Convert from UNIX to DOS file names ***************************************************************************/ -static void unfixtarname(char *tptr, char *fp, int l, BOOL first) +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! @@ -1076,7 +1076,7 @@ static char *get_longfilename(file_info2 finfo) int namesize = finfo.size + strlen(cur_dir) + 2; char *longname = (char *)SMB_MALLOC(namesize); int offset = 0, left = finfo.size; - BOOL first = True; + bool first = True; DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); DEBUG(5, ("Len = %.0f\n", (double)finfo.size)); -- cgit From 68be9a820059ee96dd26c527efd7c14e679d3f2c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Nov 2007 14:19:52 -0800 Subject: More pstring removal. This one was tricky. I had to add one horror (pstring_clean_name()) which will have to remain until I've removed all pstrings from the client code. Jeremy. (This used to be commit 1ea3ac80146b83c2522b69e7747c823366a2b47d) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0c820177b0..4ce92c674d 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -651,7 +651,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); - clean_name(rname); + pstring_clean_name(rname); if (fnum == -1) { DEBUG(0,("%s opening remote file %s (%s)\n", -- cgit From 0cfad17e4ac727314487bed9a5f6166a6a1543eb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Nov 2007 17:06:36 -0800 Subject: Fix bug #4393 smbclient does not store files with zero filesize in tar-archives from tometzky@batory.org.pl. Jeremy. (This used to be commit f3bd5e828af04f33178a66f9f332199f7d395b7b) --- source3/client/clitar.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 4ce92c674d..cb7a5deddd 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -608,7 +608,6 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) SMB_BIG_UINT nread=0; char ftype; file_info2 finfo; - bool close_done = False; bool shallitime=True; char data[65520]; int read_size = 65520; @@ -694,7 +693,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", finfo.name, (double)finfo.size, lname)); - while (nread < finfo.size && !close_done) { + do { DEBUG(3,("nread=%.0f\n",(double)nread)); @@ -733,13 +732,13 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) break; } - if (datalen == 0) { + if ( (datalen == 0) && (finfo.size != 0) ) { DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); break; } datalen=0; - } + } while ( nread < finfo.size ); if (wrote_tar_header) { /* pad tar file with zero's if we couldn't get entire file */ -- cgit From e67a6620a7e5e3edb4a6c285841224bc4173fc44 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 18:08:01 -0800 Subject: Add popt to binaries in makefile. Hack clitar to compile until I fix it. Jeremy. (This used to be commit 252ef28bb8f1406fdd92edba8538cb9e88f0b77f) --- source3/client/clitar.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index cb7a5deddd..1b0ea59a9a 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -38,6 +38,8 @@ #include "clitar.h" #include "client/client_proto.h" +static pstring cur_dir; /* FIXME !!! JRA*/ + static int clipfind(char **aret, int ret, char *tok); typedef struct file_info_struct file_info2; @@ -102,7 +104,6 @@ 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 bool readbraw_supported; @@ -117,7 +118,7 @@ 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 do_tar(file_info *finfo); +static void do_tar(file_info *finfo, const char *dir); static void oct_it(SMB_BIG_UINT value, int ndgs, char *p); static void fixtarname(char *tptr, const char *fp, size_t l); static int dotarbuf(int f, char *b, int n); @@ -629,14 +630,8 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) finfo.ctime_ts = finfo1 -> ctime_ts; finfo.name = 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_ts = def_finfo.mtime_ts; - finfo.atime_ts = def_finfo.atime_ts; - finfo.ctime_ts = def_finfo.ctime_ts; - finfo.name = def_finfo.name; + /* DEAL WITH NULL finfo1. */ + /* FIXME !!! JRA */ } if (dry_run) { @@ -650,7 +645,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); - pstring_clean_name(rname); +/* pstring_clean_name(rname); FIXME !!! JRA */ if (fnum == -1) { DEBUG(0,("%s opening remote file %s (%s)\n", @@ -793,7 +788,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) Append single file to tar file (or not) ***************************************************************************/ -static void do_tar(file_info *finfo) +static void do_tar(file_info *finfo, const char *dir) { pstring rname; -- cgit From 67344a467f77513c31fc8c941a22701ce26eea83 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 11:28:16 -0800 Subject: Remove pstring from clitar.c Jeremy (This used to be commit 1d5fee5038413c90b367434f9066d947849bdaed) --- source3/client/clitar.c | 366 +++++++++++++++++++++++++++++------------------- 1 file changed, 225 insertions(+), 141 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 1b0ea59a9a..ce2902e5e9 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1,19 +1,19 @@ -/* +/* Unix SMB/CIFS implementation. Tar Extensions Copyright (C) Ricky Poulten 1995-1998 Copyright (C) Richard Sharpe 1998 - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -21,7 +21,7 @@ Systems Research Australia (CISRA) 1. Restore can now restore files with long file names - 2. Save now saves directory information so that we can restore + 2. Save now saves directory information so that we can restore directory creation times 3. tar now accepts both UNIX path names and DOS path names. I prefer those lovely /'s to those UGLY \'s :-) @@ -38,8 +38,6 @@ #include "clitar.h" #include "client/client_proto.h" -static pstring cur_dir; /* FIXME !!! JRA*/ - static int clipfind(char **aret, int ret, char *tok); typedef struct file_info_struct file_info2; @@ -53,8 +51,7 @@ struct file_info_struct { struct timespec mtime_ts; struct timespec atime_ts; struct timespec ctime_ts; - char *name; /* This is dynamically allocate */ - + char *name; /* This is dynamically allocated */ file_info2 *next, *prev; /* Used in the stack ... */ }; @@ -108,7 +105,6 @@ extern bool lowercase; extern uint16 cnum; extern bool readbraw_supported; extern int max_xmit; -extern pstring cur_dir; extern int get_total_time_ms; extern int get_total_size; @@ -117,7 +113,7 @@ 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 do_atar(const char *rname_in,char *lname,file_info *finfo1); static void do_tar(file_info *finfo, const char *dir); static void oct_it(SMB_BIG_UINT value, int ndgs, char *p); static void fixtarname(char *tptr, const char *fp, size_t l); @@ -127,7 +123,7 @@ static void dotareof(int f); static void initarbuf(void); /* restore functions */ -static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix); +static long readtarheader(union hblock *hb, file_info2 *finfo, const char *prefix); static long unoct(char *p, int ndgs); static void do_tarput(void); static void unfixtarname(char *tptr, char *fp, int l, bool first); @@ -167,7 +163,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m DEBUG(5, ("WriteTarHdr, Type = %c, Size= %.0f, Name = %s\n", ftype, (double)size, aname)); memset(hb.dummy, 0, sizeof(hb.dummy)); - + l=strlen(aname); /* We will be prepending a '.' in fixtarheader so use +2 to * take care of the . and terminating zero. JRA. @@ -201,12 +197,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m 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); -#ifdef HAVE_LONGLONG - if (size > (SMB_BIG_UINT)077777777777LL) { -#else - if (size > (SMB_BIG_UINT)077777777777) { -#endif - + if (size > (SMB_BIG_UINT)077777777777LL) { /* This is a non-POSIX compatible extention to store files greater than 8GB. */ @@ -219,7 +210,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m 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++); @@ -233,7 +224,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m Read a tar header into a hblock structure, and validate ***************************************************************************/ -static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) +static long readtarheader(union hblock *hb, file_info2 *finfo, const char *prefix) { long chk, fchk; int i; @@ -284,7 +275,7 @@ static long readtarheader(union hblock *hb, file_info2 *finfo, char *prefix) if (hb->dbuf.linkflag == 0) { DEBUG(6, ("Warning: NULL link flag (gnu tar archive ?) %s\n", finfo->name)); - } else { + } else { if (hb -> dbuf.linkflag == 'L') { /* We have a longlink */ /* Do nothing here at the moment. do_tarput will handle this as long as the longlink gets back to it, as it has to advance @@ -296,7 +287,7 @@ of link other than a GNUtar Longlink - ignoring\n")); } } } - + if ((unoct(hb->dbuf.mode, sizeof(hb->dbuf.mode)) & S_IFDIR) || (*(finfo->name+strlen(finfo->name)-1) == '\\')) { finfo->mode=aDIR; @@ -369,7 +360,7 @@ static void dozerobuf(int f, int n) if (dry_run) return; - + if (n+tp >= tbufsiz) { memset(tarbuf+tp, 0, tbufsiz-tp); write(f, tarbuf, tbufsiz); @@ -446,13 +437,13 @@ static void oct_it (SMB_BIG_UINT value, int ndgs, char *p) /* skip final null, but do final space */ --ndgs; p[--ndgs] = ' '; - + /* Loop does at least one digit */ do { p[--ndgs] = '0' + (char) (value & 7); value >>= 3; } while (ndgs > 0 && value != 0); - + /* Do leading zeros */ while (ndgs > 0) p[--ndgs] = '0'; @@ -478,8 +469,8 @@ static long unoct(char *p, int ndgs) } /**************************************************************************** -Compare two strings in a slash insensitive way, allowing s1 to match s2 -if s1 is an "initial" string (up to directory marker). Thus, if s2 is +Compare two strings in a slash insensitive way, allowing s1 to match s2 +if s1 is an "initial" string (up to directory marker). Thus, if s2 is a file in any subdirectory of s1, declare a match. ***************************************************************************/ @@ -513,13 +504,14 @@ static int strslashcmp(char *s1, char *s2) Ensure a remote path exists (make if necessary) ***************************************************************************/ -static bool ensurepath(char *fname) +static bool ensurepath(const char *fname) { /* *must* be called with buffer ready malloc'ed */ /* ensures path exists */ char *partpath, *ffname; - char *p=fname, *basehack; + const char *p=fname; + char *basehack; DEBUG(5, ( "Ensurepath called with: %s\n", fname)); @@ -540,10 +532,13 @@ 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_m(ffname, '\\')) == NULL) { + SAFE_FREE(partpath); + SAFE_FREE(ffname); return True; - else + } else { *basehack='\0'; + } p=strtok(ffname, "\\"); @@ -552,7 +547,9 @@ static bool ensurepath(char *fname) if (!cli_chkpath(cli, partpath)) { if (!cli_mkdir(cli, partpath)) { - DEBUG(0, ("Error mkdirhiering\n")); + SAFE_FREE(partpath); + SAFE_FREE(ffname); + DEBUG(0, ("Error mkdir %s\n", cli_errstr(cli))); return False; } else { DEBUG(3, ("mkdirhiering %s\n", partpath)); @@ -563,6 +560,8 @@ static bool ensurepath(char *fname) p = strtok(NULL,"/\\"); } + SAFE_FREE(partpath); + SAFE_FREE(ffname); return True; } @@ -570,7 +569,7 @@ static int padit(char *buf, SMB_BIG_UINT bufsize, SMB_BIG_UINT padsize) { int berr= 0; int bytestowrite; - + DEBUG(5, ("Padding with %0.f zeros\n", (double)padsize)); memset(buf, 0, (size_t)bufsize); while( !berr && padsize > 0 ) { @@ -578,7 +577,7 @@ static int padit(char *buf, SMB_BIG_UINT bufsize, SMB_BIG_UINT padsize) berr = dotarbuf(tarhandle, buf, bytestowrite) != bytestowrite; padsize -= bytestowrite; } - + return berr; } @@ -603,60 +602,67 @@ 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(const char *rname_in,char *lname,file_info *finfo1) { - int fnum; + int fnum = -1; SMB_BIG_UINT nread=0; char ftype; file_info2 finfo; bool shallitime=True; - char data[65520]; + char *data = NULL; int read_size = 65520; int datalen=0; + char *rname = NULL; + TALLOC_CTX *ctx = talloc_stackframe(); struct timeval tp_start; GetTimeOfDay(&tp_start); + data = SMB_MALLOC(read_size); + if (!data) { + DEBUG(0,("do_atar: out of memory.\n")); + goto cleanup; + } + ftype = '0'; /* An ordinary file ... */ - if (finfo1) { - finfo.size = finfo1 -> size; - finfo.mode = finfo1 -> mode; - finfo.uid = finfo1 -> uid; - finfo.gid = finfo1 -> gid; - finfo.mtime_ts = finfo1 -> mtime_ts; - finfo.atime_ts = finfo1 -> atime_ts; - finfo.ctime_ts = finfo1 -> ctime_ts; - finfo.name = finfo1 -> name; - } else { - /* DEAL WITH NULL finfo1. */ - /* FIXME !!! JRA */ - } + ZERO_STRUCT(finfo); + + finfo.size = finfo1 -> size; + finfo.mode = finfo1 -> mode; + finfo.uid = finfo1 -> uid; + finfo.gid = finfo1 -> gid; + finfo.mtime_ts = finfo1 -> mtime_ts; + finfo.atime_ts = finfo1 -> atime_ts; + finfo.ctime_ts = finfo1 -> ctime_ts; if (dry_run) { - DEBUG(3,("skipping file %s of size %12.0f bytes\n", finfo.name, + DEBUG(3,("skipping file %s of size %12.0f bytes\n", finfo1->name, (double)finfo.size)); shallitime=0; ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); ntarf++; - return; + goto cleanup; } - fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); + rname = clean_name(ctx, rname_in); + if (!rname) { + goto cleanup; + } -/* pstring_clean_name(rname); FIXME !!! JRA */ + fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); if (fnum == -1) { DEBUG(0,("%s opening remote file %s (%s)\n", - cli_errstr(cli),rname, cur_dir)); - return; + cli_errstr(cli),rname, client_get_cur_dir())); + goto cleanup; } finfo.name = string_create_s(strlen(rname)); if (finfo.name == NULL) { DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); - return; + goto cleanup; } safe_strcpy(finfo.name,rname, strlen(rname)); @@ -664,7 +670,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) time_t atime, mtime; if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &atime, &mtime)) { DEBUG(0, ("getattrE: %s\n", cli_errstr(cli))); - return; + goto cleanup; } finfo.atime_ts = convert_time_t_to_timespec(atime); finfo.mtime_ts = convert_time_t_to_timespec(mtime); @@ -687,18 +693,18 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", finfo.name, (double)finfo.size, lname)); - + do { - + DEBUG(3,("nread=%.0f\n",(double)nread)); - + datalen = cli_read(cli, fnum, data, nread, read_size); - + if (datalen == -1) { DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli))); break; } - + nread += datalen; /* Only if the first read succeeds, write out the tar header. */ @@ -726,7 +732,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); break; } - + if ( (datalen == 0) && (finfo.size != 0) ) { DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); break; @@ -747,7 +753,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) /* round tar file to nearest block */ if (finfo.size % TBLOCK) dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); - + ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); ntarf++; } else { @@ -755,8 +761,9 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) shallitime=0; } } - + cli_close(cli, fnum); + fnum = -1; if (shallitime) { struct timeval tp_end; @@ -765,7 +772,7 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) /* if shallitime is true then we didn't skip */ if (tar_reset && !dry_run) (void) do_setrattr(finfo.name, aARCH, ATTRRESET); - + GetTimeOfDay(&tp_end); this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_usec - tp_start.tv_usec)/1000; get_total_time_ms += this_time; @@ -782,6 +789,15 @@ static void do_atar(char *rname,char *lname,file_info *finfo1) finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); } + + cleanup: + + if (fnum != -1) { + cli_close(cli, fnum); + fnum = -1; + } + TALLOC_FREE(ctx); + SAFE_FREE(data); } /**************************************************************************** @@ -790,64 +806,93 @@ Append single file to tar file (or not) static void do_tar(file_info *finfo, const char *dir) { - pstring rname; + TALLOC_CTX *ctx = talloc_stackframe(); if (strequal(finfo->name,"..") || strequal(finfo->name,".")) return; /* Is it on the exclude list ? */ if (!tar_excl && clipn) { - pstring exclaim; - - DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir))); + char *exclaim; - pstrcpy(exclaim, cur_dir); - *(exclaim+strlen(exclaim)-1)='\0'; + DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(client_get_cur_dir()))); - pstrcat(exclaim, "\\"); - pstrcat(exclaim, finfo->name); + exclaim = talloc_asprintf(ctx, + "%s\\%s", + client_get_cur_dir(), + finfo->name); + if (!exclaim) { + return; + } DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); if ((!tar_re_search && clipfind(cliplist, clipn, exclaim)) || (tar_re_search && mask_match_list(exclaim, cliplist, clipn, True))) { DEBUG(3,("Skipping file %s\n", exclaim)); + TALLOC_FREE(exclaim); return; } + TALLOC_FREE(exclaim); } if (finfo->mode & aDIR) { - pstring saved_curdir; - pstring mtar_mask; + char *saved_curdir = NULL; + char *new_cd = NULL; + char *mtar_mask = NULL; - pstrcpy(saved_curdir, cur_dir); + saved_curdir = talloc_strdup(ctx, client_get_cur_dir()); + if (!saved_curdir) { + return; + } - DEBUG(5, ("Sizeof(cur_dir)=%d, strlen(cur_dir)=%d, \ + DEBUG(5, ("strlen(cur_dir)=%d, \ strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", - (int)sizeof(cur_dir), (int)strlen(cur_dir), - (int)strlen(finfo->name), finfo->name, cur_dir)); - - pstrcat(cur_dir,finfo->name); - pstrcat(cur_dir,"\\"); + (int)strlen(saved_curdir), + (int)strlen(finfo->name), finfo->name, saved_curdir)); + + new_cd = talloc_asprintf(ctx, + "%s%s\\", + client_get_cur_dir(), + finfo->name); + if (!new_cd) { + return; + } + client_set_cur_dir(new_cd); - DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); + DEBUG(5, ("Writing a dir, Name = %s\n", client_get_cur_dir())); - /* write a tar directory, don't bother with mode - just set it to - * 40755 */ - writetarheader(tarhandle, cur_dir, 0, finfo->mtime_ts.tv_sec, "040755 \0", '5'); + /* write a tar directory, don't bother with mode - just + * set it to 40755 */ + writetarheader(tarhandle, client_get_cur_dir(), 0, + finfo->mtime_ts.tv_sec, "040755 \0", '5'); if (tar_noisy) { - DEBUG(0,(" directory %s\n", cur_dir)); + DEBUG(0,(" directory %s\n", + client_get_cur_dir())); } ntarf++; /* Make sure we have a file on there */ - pstrcpy(mtar_mask,cur_dir); - pstrcat(mtar_mask,"*"); + mtar_mask = talloc_asprintf(ctx, + "%s*", + client_get_cur_dir()); + if (!mtar_mask) { + return; + } DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask)); do_list(mtar_mask, attribute, do_tar, False, True); - pstrcpy(cur_dir,saved_curdir); + client_set_cur_dir(saved_curdir); + TALLOC_FREE(saved_curdir); + TALLOC_FREE(new_cd); + TALLOC_FREE(mtar_mask); } else { - pstrcpy(rname,cur_dir); - pstrcat(rname,finfo->name); + char *rname = talloc_asprintf(ctx, + "%s%s", + client_get_cur_dir(), + finfo->name); + if (!rname) { + return; + } do_atar(rname,finfo->name,finfo); + TALLOC_FREE(rname); } } @@ -959,7 +1004,7 @@ static int get_file(file_info2 finfo) DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size)); - if (ensurepath(finfo.name) && + if (ensurepath(finfo.name) && (fnum=cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { DEBUG(0, ("abandoning restore\n")); return(False); @@ -1045,7 +1090,7 @@ static int get_file(file_info2 finfo) } /* Create a directory. We just ensure that the path exists and return as there - is no file associated with a directory + is no file associated with a directory */ static int get_dir(file_info2 finfo) { @@ -1067,7 +1112,7 @@ static char *get_longfilename(file_info2 finfo) { /* finfo.size here is the length of the filename as written by the "/./@LongLink" name * header call. */ - int namesize = finfo.size + strlen(cur_dir) + 2; + int namesize = finfo.size + strlen(client_get_cur_dir()) + 2; char *longname = (char *)SMB_MALLOC(namesize); int offset = 0, left = finfo.size; bool first = True; @@ -1082,9 +1127,9 @@ static char *get_longfilename(file_info2 finfo) /* First, add cur_dir to the long file name */ - if (strlen(cur_dir) > 0) { - strncpy(longname, cur_dir, namesize); - offset = strlen(cur_dir); + if (strlen(client_get_cur_dir()) > 0) { + strncpy(longname, client_get_cur_dir(), namesize); + offset = strlen(client_get_cur_dir()); } /* Loop through the blocks picking up the name */ @@ -1131,7 +1176,8 @@ static void do_tarput(void) DEBUG(5, ("Reading the next header ...\n")); - switch (readtarheader((union hblock *) buffer_p, &finfo, cur_dir)) { + switch (readtarheader((union hblock *) buffer_p, + &finfo, client_get_cur_dir())) { case -2: /* Hmm, not good, but not fatal */ DEBUG(0, ("Skipping %s...\n", finfo.name)); if ((next_block(tarbuf, &buffer_p, tbufsiz) <= 0) && !skip_file(finfo.size)) { @@ -1175,7 +1221,7 @@ static void do_tarput(void) linkflag = ((union hblock *)buffer_p) -> dbuf.linkflag; switch (linkflag) { case '0': /* Should use symbolic names--FIXME */ - /* + /* * Skip to the next block first, so we can get the file, FIXME, should * be in get_file ... * The 'finfo.size != 0' fix is from Bob Boehmer @@ -1223,10 +1269,11 @@ Blocksize command int cmd_block(void) { - fstring buf; + TALLOC_CTX *ctx = talloc_tos(); + char *buf; int block; - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + if (!next_token_nr_talloc(ctx,NULL,&buf,NULL)) { DEBUG(0, ("blocksize \n")); return 1; } @@ -1239,7 +1286,6 @@ int cmd_block(void) blocksize=block; DEBUG(2,("blocksize is now %d\n", blocksize)); - return 0; } @@ -1249,9 +1295,10 @@ command to set incremental / reset mode int cmd_tarmode(void) { - fstring buf; + TALLOC_CTX *ctx = talloc_tos(); + char *buf; - while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { + while (next_token_nr_talloc(ctx,NULL,&buf,NULL)) { if (strequal(buf, "full")) tar_inc=False; else if (strequal(buf, "inc")) @@ -1274,6 +1321,7 @@ int cmd_tarmode(void) tar_noisy=False; else DEBUG(0, ("tarmode: unrecognised option %s\n", buf)); + TALLOC_FREE(buf); } DEBUG(0, ("tarmode is now %s, %s, %s, %s, %s\n", @@ -1291,23 +1339,29 @@ Feeble attrib command int cmd_setmode(void) { + TALLOC_CTX *ctx = talloc_tos(); char *q; - fstring buf; - pstring fname; + char *buf; + char *fname = NULL; uint16 attra[2]; int direct=1; attra[0] = attra[1] = 0; - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + if (!next_token_nr_talloc(ctx,NULL,&buf,NULL)) { DEBUG(0, ("setmode <[+|-]rsha>\n")); return 1; } - pstrcpy(fname, cur_dir); - pstrcat(fname, buf); + fname = talloc_asprintf(ctx, + "%s%s", + client_get_cur_dir(), + buf); + if (!fname) { + return 1; + } - while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { + while (next_token_nr_talloc(ctx,NULL,&buf,NULL)) { q=buf; while(*q) { @@ -1354,12 +1408,13 @@ Principal command for creating / extracting int cmd_tar(void) { - fstring buf; + TALLOC_CTX *ctx = talloc_tos(); + char *buf; char **argl = NULL; int argcl = 0; int ret; - if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + if (!next_token_nr_talloc(ctx,NULL,&buf,NULL)) { DEBUG(0,("tar [IXbgan] \n")); return 1; } @@ -1379,6 +1434,7 @@ Command line (option) version int process_tar(void) { + TALLOC_CTX *ctx = talloc_tos(); int rc = 0; initarbuf(); switch(tar_type) { @@ -1396,7 +1452,7 @@ int process_tar(void) case 'c': if (clipn && tar_excl) { int i; - pstring tarmac; + char *tarmac = NULL; for (i=0; i= inclusion_buffer_size) { inclusion_buffer_size *= 2; inclusion_buffer = (char *)SMB_REALLOC(inclusion_buffer,inclusion_buffer_size); @@ -1537,7 +1621,7 @@ static int read_inclusion_file(char *filename) break; } } - + safe_strcpy(inclusion_buffer + inclusion_buffer_sofar, buf, inclusion_buffer_size - inclusion_buffer_sofar); inclusion_buffer_sofar += strlen(buf) + 1; clipn++; @@ -1588,7 +1672,7 @@ static int read_inclusion_file(char *filename) } return 0; } - + /* cliplist and its elements are freed at the end of process_tar. */ return 1; } @@ -1639,7 +1723,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind) return 0; } else { SMB_STRUCT_STAT stbuf; - + if (sys_stat(argv[Optind], &stbuf) == 0) { newer_than = stbuf.st_mtime; DEBUG(1,("Getting files newer than %s", -- cgit From d58868f2a474c29d954eb7e6ff8627b3d77d0544 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 8 Dec 2007 11:25:05 +0100 Subject: C++ warning (This used to be commit 85a7f800b6ff8a21d234cee1a24123fb48bafa13) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index ce2902e5e9..0b4a8b2943 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -619,7 +619,7 @@ static void do_atar(const char *rname_in,char *lname,file_info *finfo1) GetTimeOfDay(&tp_start); - data = SMB_MALLOC(read_size); + data = SMB_MALLOC_ARRAY(char, read_size); if (!data) { DEBUG(0,("do_atar: out of memory.\n")); goto cleanup; -- cgit From bea16599112eade0a23b810abcb8cdc4b2480fd9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 19 Dec 2007 21:59:28 +0100 Subject: Remove next_token_nr_talloc and its associated global Only client.c and clitar.c used this, I think they should carry the static themselves. Also move the a bit funny routine toktocliplist to clitar.c, the only place where it is used. (This used to be commit 86d9412611fd99c21e15c71d30a3f95e35d8535b) --- source3/client/clitar.c | 60 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 5 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 0b4a8b2943..135815c3cd 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -100,6 +100,7 @@ char tar_type='\0'; static char **cliplist=NULL; static int clipn=0; static bool must_free_cliplist = False; +static const char *cmd_ptr = NULL; extern bool lowercase; extern uint16 cnum; @@ -1273,7 +1274,7 @@ int cmd_block(void) char *buf; int block; - if (!next_token_nr_talloc(ctx,NULL,&buf,NULL)) { + if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { DEBUG(0, ("blocksize \n")); return 1; } @@ -1298,7 +1299,7 @@ int cmd_tarmode(void) TALLOC_CTX *ctx = talloc_tos(); char *buf; - while (next_token_nr_talloc(ctx,NULL,&buf,NULL)) { + while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { if (strequal(buf, "full")) tar_inc=False; else if (strequal(buf, "inc")) @@ -1348,7 +1349,7 @@ int cmd_setmode(void) attra[0] = attra[1] = 0; - if (!next_token_nr_talloc(ctx,NULL,&buf,NULL)) { + if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { DEBUG(0, ("setmode <[+|-]rsha>\n")); return 1; } @@ -1361,7 +1362,7 @@ int cmd_setmode(void) return 1; } - while (next_token_nr_talloc(ctx,NULL,&buf,NULL)) { + while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { q=buf; while(*q) { @@ -1402,6 +1403,55 @@ int cmd_setmode(void) return 0; } +/** + Convert list of tokens to array; dependent on above routine. + Uses the global cmd_ptr from above - bit of a hack. +**/ + +static char **toktocliplist(int *ctok, const char *sep) +{ + char *s=(char *)cmd_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=(char *)cmd_ptr; + + if (!(ret=iret=SMB_MALLOC_ARRAY(char *,ictok+1))) + return NULL; + + while(ictok--) { + *iret++=s; + if (ictok > 0) { + while(*s++) + ; + while(!*s) + s++; + } + } + + ret[*ctok] = NULL; + return ret; +} + /**************************************************************************** Principal command for creating / extracting ***************************************************************************/ @@ -1414,7 +1464,7 @@ int cmd_tar(void) int argcl = 0; int ret; - if (!next_token_nr_talloc(ctx,NULL,&buf,NULL)) { + if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { DEBUG(0,("tar [IXbgan] \n")); return 1; } -- cgit From 587cf54c61c9f1f7bcae431a82035fd942716c32 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Jan 2008 11:04:10 +0100 Subject: strtok -> strtok_r (This used to be commit fd34ce437057bb34cdc37f4b066e424000d36789) --- source3/client/clitar.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 135815c3cd..816e7b1710 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -513,6 +513,7 @@ static bool ensurepath(const char *fname) char *partpath, *ffname; const char *p=fname; char *basehack; + char *saveptr; DEBUG(5, ( "Ensurepath called with: %s\n", fname)); @@ -528,7 +529,7 @@ static bool ensurepath(const char *fname) *partpath = 0; - /* fname copied to ffname so can strtok */ + /* fname copied to ffname so can strtok_r */ safe_strcpy(ffname, fname, strlen(fname)); @@ -541,7 +542,7 @@ static bool ensurepath(const char *fname) *basehack='\0'; } - p=strtok(ffname, "\\"); + p=strtok_r(ffname, "\\", &saveptr); while (p) { safe_strcat(partpath, p, strlen(fname) + 1); @@ -558,7 +559,7 @@ static bool ensurepath(const char *fname) } safe_strcat(partpath, "\\", strlen(fname) + 1); - p = strtok(NULL,"/\\"); + p = strtok_r(NULL, "/\\", &saveptr); } SAFE_FREE(partpath); -- cgit From ba6c78c355a596f190b16a53052994f31d1d58ca Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 24 Jan 2008 15:57:00 +0100 Subject: Fix Coverity ID 463 (This used to be commit 21d126c56a633d2d72ffad08db7331ecc0ee3c0c) --- source3/client/clitar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 816e7b1710..04cc987889 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1471,8 +1471,10 @@ int cmd_tar(void) } argl=toktocliplist(&argcl, NULL); - if (!tar_parseargs(argcl, argl, buf, 0)) + if (!tar_parseargs(argcl, argl, buf, 0)) { + SAFE_FREE(argl); return 1; + } ret = process_tar(); SAFE_FREE(argl); -- cgit From fa495ce1c1ee0ac668d083c97bb75d90e9b34e81 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 15 Mar 2008 22:07:44 +0100 Subject: Fix Coverity ID 564 finfo1==NULL just does not happen in current code (This used to be commit 9ea0078c3151984a901c9bba559ae2bd7959e077) --- source3/client/clitar.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 04cc987889..f53c9b4035 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -668,16 +668,6 @@ static void do_atar(const char *rname_in,char *lname,file_info *finfo1) } safe_strcpy(finfo.name,rname, strlen(rname)); - if (!finfo1) { - time_t atime, mtime; - if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &atime, &mtime)) { - DEBUG(0, ("getattrE: %s\n", cli_errstr(cli))); - goto cleanup; - } - finfo.atime_ts = convert_time_t_to_timespec(atime); - finfo.mtime_ts = convert_time_t_to_timespec(mtime); - finfo.ctime_ts = finfo.mtime_ts; - } DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); -- cgit From c8dfed63a62c9caed14af9b67197dc5243b0c3ee Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Jun 2008 21:08:56 +0200 Subject: Fix a brown paper bag segfault in clitar Thanks to "No Body is Perfect" from gmail, whoever that is :-) Volker (cherry picked from commit 679d8dfa390601f777bfb43c02cd921eae5edcf4) (This used to be commit b8e1d62b8e8f724b855c8ab9801abee0b2791e36) --- source3/client/clitar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client/clitar.c') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index f53c9b4035..084f87e399 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -100,7 +100,7 @@ char tar_type='\0'; static char **cliplist=NULL; static int clipn=0; static bool must_free_cliplist = False; -static const char *cmd_ptr = NULL; +extern const char *cmd_ptr; extern bool lowercase; extern uint16 cnum; -- cgit