From: Stelian Pop Date: Wed, 26 Mar 2003 10:58:19 +0000 (+0000) Subject: Lots of fixes from Philipe Troin: X-Git-Tag: release_0_4b34~9 X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=commitdiff_plain;h=c3f69f06e7c87a8e39d2bc02396fa3ba8db76e84 Lots of fixes from Philipe Troin: * Fixed open and creation modes and permissions for QFA and table-of-contents files in dump and restore. * Fixed the archive file descriptor handling enabling it to be 0. This can happen in some cases when shell redirections are used. * Delayed the opening of archive file until after suid had been dropped (fixing a possible security issue if dump is suid). * Fixed the 'S' command handling in the rmt client part. * Modified the end-of-tape script handling to print out statistics (and stop the timer) before launching the eot script. Also, the eot script does not get run anymore when using -M (which makes sense) or when multiple tapes are listed on the command line (-f tape0,tape1,tapen) (which also makes sense). --- diff --git a/CHANGES b/CHANGES index e42879b..d1dc5ea 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -$Id: CHANGES,v 1.220 2003/03/07 09:15:44 stelian Exp $ +$Id: CHANGES,v 1.221 2003/03/26 10:58:19 stelian Exp $ Changes between versions 0.4b33 and 0.4b34 (released ?????????????????) ======================================================================= @@ -44,6 +44,28 @@ Changes between versions 0.4b33 and 0.4b34 (released ?????????????????) Thanks to Jin-su Ahn for reporting the bug and providing the fix. +10. Fixed open and creation modes and permissions for QFA and + table-of-contents files in dump and restore. Thanks to + Philippe Troin for the patch. + +11. Fixed the archive file descriptor handling enabling it to be 0. + This can happen in some cases when shell redirections are used. + Thanks to Philippe Troin for the patch. + +12. Delayed the opening of archive file until after suid had been + dropped (fixing a possible security issue if dump is suid). + Thanks to Philippe Troin for the patch. + +13. Fixed the 'S' command handling in the rmt client part. + Thanks to Philippe Troin for the patch. + +14. Modified the end-of-tape script handling to print out statistics + (and stop the timer) before launching the eot script. Also, the eot + script does not get run anymore when using -M (which makes sense) or + when multiple tapes are listed on the command line + (-f tape0,tape1,tapen) (which also makes sense). + Thanks to Philippe Troin for the patch. + Changes between versions 0.4b32 and 0.4b33 (released February 10, 2003) ======================================================================= diff --git a/common/dumprmt.c b/common/dumprmt.c index 699122f..d39e134 100644 --- a/common/dumprmt.c +++ b/common/dumprmt.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: dumprmt.c,v 1.25 2003/02/12 11:02:29 stelian Exp $"; + "$Id: dumprmt.c,v 1.26 2003/03/26 10:58:22 stelian Exp $"; #endif /* not lint */ #include @@ -350,7 +350,15 @@ rmtstatus(void) if (rmtstate != TS_OPEN) return (NULL); - rmtcall("status", "S\n"); + i = rmtcall("status", "S"); + if (i < 0) return NULL; + if (i != (int)sizeof(mts)) { + msg("mtget sizes different between host (%d) " + "and remote tape (%d)", sizeof(mts), i); + for ( /* empty */; i > 0; --i) + rmtgetb(); + return NULL; + } for (i = 0, cp = (char *)&mts; i < (int)sizeof(mts); i++) *cp++ = rmtgetb(); return (&mts); diff --git a/dump/dump.h b/dump/dump.h index 3121074..e818042 100644 --- a/dump/dump.h +++ b/dump/dump.h @@ -5,7 +5,7 @@ * Stelian Pop , 1999-2000 * Stelian Pop - AlcĂ´ve , 2000-2002 * - * $Id: dump.h,v 1.42 2003/01/10 14:42:50 stelian Exp $ + * $Id: dump.h,v 1.43 2003/03/26 10:58:22 stelian Exp $ */ /*- @@ -78,6 +78,7 @@ extern char *dumpdates; /* name of the file containing dump date information*/ extern char lastlevel; /* dump level of previous dump */ extern char level; /* dump level of this dump */ extern int Afile; /* archive file descriptor */ +extern int AfileActive; /* Afile flag */ extern int bzipflag; /* compression is done using bzlib */ extern int uflag; /* update flag */ extern int mflag; /* dump metadata only if possible flag */ diff --git a/dump/main.c b/dump/main.c index 610410f..d1e8c5f 100644 --- a/dump/main.c +++ b/dump/main.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.82 2003/03/07 09:15:50 stelian Exp $"; + "$Id: main.c,v 1.83 2003/03/26 10:58:22 stelian Exp $"; #endif /* not lint */ #include @@ -106,7 +106,8 @@ char *dumpdates; /* name of the file containing dump date information*/ char lastlevel; /* dump level of previous dump */ char level; /* dump level of this dump */ int bzipflag; /* compression is done using bzlib */ -int Afile = 0; /* archive file descriptor */ +int Afile = -1; /* archive file descriptor */ +int AfileActive = 1;/* Afile flag */ int uflag; /* update flag */ int mflag; /* dump metadata only if possible */ int Mflag; /* multi-volume flag */ @@ -270,14 +271,6 @@ main(int argc, char *argv[]) case 'A': /* archive file */ Apath = optarg; - if ((Afile = open(Apath, O_RDWR|O_CREAT|O_TRUNC, - S_IRUSR | S_IWUSR)) < 0) { - msg("Cannot open %s for writing: %s\n", - optarg, strerror(errno)); - msg("The ENTIRE dump is aborted.\n"); - exit(X_STARTUP); - } - memset(volinfo, 0, TP_NINOS * sizeof(dump_ino_t)); break; case 'a': /* `auto-size', Write to EOM. */ @@ -515,6 +508,14 @@ main(int argc, char *argv[]) #endif } (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */ + if (Apath && (Afile = open(Apath, O_WRONLY|O_CREAT|O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | + S_IWGRP | S_IROTH | S_IWOTH)) < 0) { + msg("Cannot open %s for writing: %s\n", + optarg, strerror(errno)); + msg("The ENTIRE dump is aborted.\n"); + exit(X_STARTUP); + } if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, sig); @@ -880,7 +881,10 @@ main(int argc, char *argv[]) #ifdef USE_QFA if (tapepos) { msg("writing QFA positions to %s\n", gTapeposfile); - if ((gTapeposfd = open(gTapeposfile, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR | S_IWUSR)) < 0) + if ((gTapeposfd = open(gTapeposfile, + O_WRONLY|O_CREAT|O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP + | S_IROTH | S_IWOTH)) < 0) quit("can't open tapeposfile\n"); /* print QFA-file header */ snprintf(gTps, sizeof(gTps), "%s\n%s\n%ld\n\n", QFA_MAGIC, QFA_VERSION, (unsigned long)spcl.c_date); @@ -965,7 +969,7 @@ main(int argc, char *argv[]) tend_writing = time(NULL); spcl.c_type = TS_END; - if (Afile) { + if (Afile >= 0) { volinfo[1] = ROOTINO; memcpy(spcl.c_inos, volinfo, TP_NINOS * sizeof(dump_ino_t)); spcl.c_flags |= DR_INODEINFO; @@ -1011,7 +1015,7 @@ main(int argc, char *argv[]) spcl.c_tapea, tapekb, rate); } - if (Afile) + if (Afile >= 0) msg("Archiving dump to %s\n", Apath); broadcast("DUMP IS DONE!\7\7\n"); diff --git a/dump/tape.c b/dump/tape.c index a9e3c52..5af6392 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.72 2003/01/10 10:52:48 stelian Exp $"; + "$Id: tape.c,v 1.73 2003/03/26 10:58:22 stelian Exp $"; #endif /* not lint */ #include @@ -110,7 +110,6 @@ extern int ntrec; /* blocking factor on tape */ extern int cartridge; char *nexttape; extern pid_t rshpid; -int eot_code = 1; long long tapea_bytes = 0; /* bytes_written at start of current volume */ static int magtapeout; /* output is really a tape */ @@ -237,14 +236,14 @@ writerec(const void *dp, int isspcl) *(union u_spcl *)(*(nextblock)) = *(union u_spcl *)dp; /* Need to write it to the archive file */ - if (Afile < 0 && isspcl && (spcl.c_type == TS_END)) - Afile = -Afile; - if (Afile > 0) { + if (! AfileActive && isspcl && (spcl.c_type == TS_END)) + AfileActive = 1; + if (AfileActive && Afile >= 0) { /* When we dump an inode which is not a directory, * it means we ended the archive contents */ if (isspcl && (spcl.c_type == TS_INODE) && ((spcl.c_dinode.di_mode & S_IFMT) != IFDIR)) - Afile = -Afile; + AfileActive = 0; else { union u_spcl tmp; tmp = *(union u_spcl *)dp; @@ -560,15 +559,6 @@ trewind(void) (void) close(f); } } - eot_code = 1; - if (eot_script && spcl.c_type != TS_END) { - msg("Launching %s\n", eot_script); - eot_code = system_command(eot_script, tape, tapeno); - } - if (eot_code != 0 && eot_code != 1) { - msg("Dump aborted by the end of tape script\n"); - dumpabort(0); - } } return do_stats(); } @@ -577,8 +567,19 @@ trewind(void) void close_rewind(void) { + int eot_code = 1; (void)trewind(); - if (nexttape || Mflag || (eot_code == 0) ) + if (nexttape || Mflag) + return; + if (eot_script) { + msg("Launching %s\n", eot_script); + eot_code = system_command(eot_script, tape, tapeno); + } + if (eot_code != 0 && eot_code != 1) { + msg("Dump aborted by the end of tape script\n"); + dumpabort(0); + } + if (eot_code == 0) return; if (!nogripe) { msg("Change Volumes: Mount volume #%d\n", tapeno+1); diff --git a/restore/main.c b/restore/main.c index c8c76a9..0329554 100644 --- a/restore/main.c +++ b/restore/main.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.42 2002/11/15 09:25:41 stelian Exp $"; + "$Id: main.c,v 1.43 2003/03/26 10:58:22 stelian Exp $"; #endif /* not lint */ #include @@ -124,6 +124,8 @@ static void obsolete __P((int *, char **[])); static void usage __P((void)); static void use_stdin __P((const char *)); +#define FORCED_UMASK (077) + int main(int argc, char *argv[]) { @@ -134,6 +136,7 @@ main(int argc, char *argv[]) char *p, name[MAXPATHLEN]; FILE *filelist = NULL; char fname[MAXPATHLEN]; + mode_t orig_umask; #ifdef DEBUG_QFA time_t tistart, tiend, titaken; #endif @@ -143,7 +146,7 @@ main(int argc, char *argv[]) #endif /* USE_QFA */ /* Temp files should *not* be readable. We set permissions later. */ - (void) umask(077); + orig_umask = umask(FORCED_UMASK); filesys[0] = '\0'; #if defined(__linux__) || defined(sunos) __progname = argv[0]; @@ -550,8 +553,12 @@ main(int argc, char *argv[]) #endif setup(); msg("writing QFA positions to %s\n", gTapeposfile); - if ((gTapeposfd = open(gTapeposfile, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR)) < 0) + (void) umask(orig_umask); + if ((gTapeposfd = open(gTapeposfile, O_WRONLY|O_CREAT|O_TRUNC, + S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP + |S_IROTH|S_IWOTH)) < 0) errx(1, "can't create tapeposfile\n"); + (void) umask(FORCED_UMASK); /* print QFA-file header */ sprintf(gTps, "%s\n%s\n%ld\n\n", QFA_MAGIC, QFA_VERSION,(unsigned long)spcl.c_date); if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps))