]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/find_one.c
kes Prevent door and port files from being restored (mostly
[bacula/bacula] / bacula / src / findlib / find_one.c
old mode 100755 (executable)
new mode 100644 (file)
index b4e5831..84792fa
@@ -1,21 +1,33 @@
 /*
-   Copyright (C) 2000-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   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 
-   the file LICENSE for additional details.
-
- */
-
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
 
-   This file is based on GNU TAR source code. Except for a few key
+   This file was derived from GNU TAR source code. Except for a few key
    ideas, it has been entirely rewritten for Bacula.
 
       Kern Sibbald, MM
@@ -108,6 +120,34 @@ static int accept_fstype(FF_PKT *ff, void *dummy) {
    return accept;
 }
 
+/*
+ * Check to see if we allow the drive type of a file or directory.
+ * If we do not have a list of drive types, we accept anything.
+ */
+static int accept_drivetype(FF_PKT *ff, void *dummy) {
+   int i;
+   char dt[100];
+   bool accept = true;
+
+   if (ff->drivetypes.size()) {
+      accept = false;
+      if (!drivetype(ff->fname, dt, sizeof(dt))) {
+         Dmsg1(50, "Cannot determine drive type for \"%s\"\n", ff->fname);
+      } else {
+         for (i = 0; i < ff->drivetypes.size(); ++i) {
+            if (strcmp(dt, (char *)ff->drivetypes.get(i)) == 0) {
+               Dmsg2(100, "Accepting drive type %s for \"%s\"\n", dt, ff->fname);
+               accept = true;
+               break;
+            }
+            Dmsg3(200, "drive type %s for \"%s\" does not match %s\n", dt,
+                  ff->fname, ff->drivetypes.get(i));
+         }
+      }
+   }
+   return accept;
+}
+
 /*
  * This function determines whether we can use getattrlist()
  * It's odd, but we have to use the function to determine that...
@@ -141,6 +181,51 @@ static bool volume_has_attrlist(const char *fname)
    return false;
 }
 
+/* check if a file have changed during backup and display an error */
+bool has_file_changed(JCR *jcr, FF_PKT *ff_pkt)
+{
+   struct stat statp;
+   Dmsg1(500, "has_file_changed fname=%s\n",ff_pkt->fname);
+
+   if (ff_pkt->type != FT_REG) { /* not a regular file */
+      return false;
+   }
+
+   if (lstat(ff_pkt->fname, &statp) != 0) {
+      berrno be;
+      Jmsg(jcr, M_WARNING, 0, 
+           _("Cannot stat file %s: ERR=%s\n"),ff_pkt->fname,be.strerror());
+      return true;
+   }
+
+   if (statp.st_mtime != ff_pkt->statp.st_mtime) {
+      /* TODO: add time of changes */
+      Jmsg(jcr, M_ERROR, 0, _("%s mtime changed during backup.\n"), ff_pkt->fname);
+      return true;
+   }
+
+   if (statp.st_ctime != ff_pkt->statp.st_ctime) {
+      /* TODO: add time of changes */
+      Jmsg(jcr, M_ERROR, 0, _("%s ctime changed during backup.\n"), ff_pkt->fname);
+      return true;
+   }
+  
+   if (statp.st_size != ff_pkt->statp.st_size) {
+      /* TODO: add size change */
+      Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname);
+      return true;
+   }
+
+   if ((statp.st_blksize != ff_pkt->statp.st_blksize) ||
+       (statp.st_blocks  != ff_pkt->statp.st_blocks)) {
+      /* TODO: add size change */
+      Jmsg(jcr, M_ERROR, 0, _("%s size changed during backup.\n"),ff_pkt->fname);
+      return true;
+   }
+
+   return false;
+}
+
 /*
  * Find a single file.
  * handle_file is the callback for handling the file.
@@ -176,7 +261,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
    restore_times.modtime = ff_pkt->statp.st_mtime;
 
    /*
-    * We check for allowed fstypes at top_level and fstype change (below).
+    * We check for allowed fstypes and drivetypes at top_level and fstype change (below).
     */
    if (top_level) {
       if (!accept_fstype(ff_pkt, NULL)) {
@@ -184,7 +269,29 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
          if (ff_pkt->flags & FO_KEEPATIME) {
             utime(fname, &restore_times);
          }
-         Jmsg1(jcr, M_ERROR, 0, _("Top level directory \"%s\" has an unlisted fstype\n"), fname);
+
+         char fs[100];
+
+         if (!fstype(ff_pkt->fname, fs, sizeof(fs))) {
+             bstrncpy(fs, "unknown", sizeof(fs));
+         }
+
+         Jmsg(jcr, M_INFO, 0, _("Top level directory \"%s\" has unlisted fstype \"%s\"\n"), fname, fs);
+         return 1;      /* Just ignore this error - or the whole backup is cancelled */
+      }
+      if (!accept_drivetype(ff_pkt, NULL)) {
+         ff_pkt->type = FT_INVALIDDT;
+         if (ff_pkt->flags & FO_KEEPATIME) {
+            utime(fname, &restore_times);
+         }
+
+         char dt[100];
+
+         if (!drivetype(ff_pkt->fname, dt, sizeof(dt))) {
+             bstrncpy(dt, "unknown", sizeof(dt));
+         }
+
+         Jmsg(jcr, M_INFO, 0, _("Top level directory \"%s\" has an unlisted drive type \"%s\"\n"), fname, dt);
          return 1;      /* Just ignore this error - or the whole backup is cancelled */
       }
       ff_pkt->volhas_attrlist = volume_has_attrlist(fname);
@@ -285,7 +392,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
 
    /* This is not a link to a previously dumped file, so dump it.  */
    if (S_ISREG(ff_pkt->statp.st_mode)) {
-      off_t sizeleft;
+      boffset_t sizeleft;
 
       sizeleft = ff_pkt->statp.st_size;
 
@@ -366,7 +473,7 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt,
       link = (char *)bmalloc(link_len + 2);
       bstrncpy(link, fname, link_len);
       /* Strip all trailing slashes */
-      while (len >= 1 && link[len - 1] == '/')
+      while (len >= 1 && IsPathSeparator(link[len - 1]))
         len--;
       link[len++] = '/';             /* add back one */
       link[len] = 0;