]> git.wh0rd.org - dump.git/commitdiff
Lots of fixes from Philipe Troin:
authorStelian Pop <stelian@popies.net>
Wed, 26 Mar 2003 10:58:19 +0000 (10:58 +0000)
committerStelian Pop <stelian@popies.net>
Wed, 26 Mar 2003 10:58:19 +0000 (10:58 +0000)
* 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).

CHANGES
common/dumprmt.c
dump/dump.h
dump/main.c
dump/tape.c
restore/main.c

diff --git a/CHANGES b/CHANGES
index e42879b32d6f9c81d4608c9673ff2adfd490f218..d1dc5ea00940b31a8cd277547295ec370891bec6 100644 (file)
--- 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 <jsahn@ee.snu.ac.kr> 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 <phil@fifi.org> 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 <phil@fifi.org> 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 <phil@fifi.org> for the patch.
+
+13.    Fixed the 'S' command handling in the rmt client part.
+       Thanks to Philippe Troin <phil@fifi.org> 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 <phil@fifi.org> for the patch.
+
 Changes between versions 0.4b32 and 0.4b33 (released February 10, 2003)
 =======================================================================
 
index 699122f4349d666fb21c3719a03958f0ed8fe58e..d39e13432b2c9a4ca391ba9eb16c5839b544ebae 100644 (file)
@@ -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 <config.h>
@@ -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);
index 31210746faa87efe2cdc4979fdf580bb6d168321..e8180427b02b9fb59e7783327feed08cecdce2c2 100644 (file)
@@ -5,7 +5,7 @@
  *     Stelian Pop <stelian@popies.net>, 1999-2000
  *     Stelian Pop <stelian@popies.net> - AlcĂ´ve <www.alcove.com>, 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 */
index 610410f353c0c291fac837da0a314efb1d539f27..d1e8c5f59e58547a11714d0d979771ad9f60561c 100644 (file)
@@ -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 <config.h>
@@ -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");
index a9e3c52bc2cab2e47d9b7b189137f16f5def2703..5af63925a301f2567996379602099410d5e7dba7 100644 (file)
@@ -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 <config.h>
@@ -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);
index c8c76a9536b8dd9818c336b65946e311e5401fea..0329554dcc3dc36fd68d9277539f0f5eee8f103d 100644 (file)
@@ -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 <config.h>
@@ -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))