]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/create_file.c
Add openssl-compat.h which went in wrong directory
[bacula/bacula] / bacula / src / findlib / create_file.c
index 05416ced8254aeff53a5fab7d92885fdc8fb4e1c..9488dbc5a127b8111aca50e269a3c80ac979da33 100644 (file)
@@ -1,37 +1,26 @@
 /*
-   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 and included
-   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.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2015 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 /*
  *  Create a file, and reset the modes
  *
  *    Kern Sibbald, November MM
  *
- *   Version $Id$
- *
  */
 
 #include "bacula.h"
 #define O_CTG 0
 #endif
 
+#ifndef O_EXCL
+#define O_EXCL 0
+#endif
+#ifndef O_NOFOLLOW
+#define O_NOFOLLOW 0
+#endif
+
 static int separate_path_and_file(JCR *jcr, char *fname, char *ofile);
 static int path_already_seen(JCR *jcr, char *path, int pnl);
 
@@ -71,13 +67,15 @@ static int path_already_seen(JCR *jcr, char *path, int pnl);
  */
 int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
 {
-   int new_mode, parent_mode, mode;
+   mode_t new_mode, parent_mode;
+   int flags;
    uid_t uid;
    gid_t gid;
    int pnl;
    bool exists = false;
    struct stat mstatp;
 
+   bfd->reparse_point = false;
    if (is_win32_stream(attr->data_stream)) {
       set_win32_backup(bfd);
    } else {
@@ -132,6 +130,10 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
          break;
 
       case REPLACE_NEVER:
+         /* Set attributes if we created this directory */
+         if (attr->type == FT_DIREND && path_list_lookup(jcr, attr->ofname)) {
+            break;
+         }
          Qmsg(jcr, M_SKIPPED, 0, _("File skipped. Already exists: %s\n"), attr->ofname);
          return CF_SKIP;
 
@@ -147,7 +149,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    case FT_SPEC:                      /* fifo, ... to be backed up */
    case FT_REGE:                      /* empty file */
    case FT_REG:                       /* regular file */
-      /* 
+      /*
        * Note, we do not delete FT_RAW because these are device files
        *  or FIFOs that should already exist. If we blow it away,
        *  we may blow away a FIFO that is being used to read the
@@ -160,7 +162,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
             berrno be;
             Qmsg(jcr, M_ERROR, 0, _("File %s already exists and could not be replaced. ERR=%s.\n"),
                attr->ofname, be.bstrerror());
-            /* Continue despite error */
+            return CF_ERROR;
          }
       }
       /*
@@ -190,7 +192,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
              * execute bit set (i.e. parent_mode), and preserve what already
              * exists. Normally, this should do nothing.
              */
-            if (make_path(jcr, attr->ofname, parent_mode, parent_mode, uid, gid, 1, NULL) != 0) {
+            if (!makepath(attr, attr->ofname, parent_mode, parent_mode, uid, gid, 1)) {
                Dmsg1(10, "Could not make path. %s\n", attr->ofname);
                attr->ofname[pnl] = savechr;     /* restore full name */
                return CF_ERROR;
@@ -203,28 +205,28 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
       switch(attr->type) {
       case FT_REGE:
       case FT_REG:
-         Dmsg1(100, "Create file %s\n", attr->ofname);
-         mode =  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; /*  O_NOFOLLOW; */
+         Dmsg1(100, "Create=%s\n", attr->ofname);
+         flags =  O_WRONLY | O_CREAT | O_BINARY | O_EXCL;
          if (IS_CTG(attr->statp.st_mode)) {
-            mode |= O_CTG;               /* set contiguous bit if needed */
+            flags |= O_CTG;              /* set contiguous bit if needed */
          }
-         Dmsg1(50, "Create file: %s\n", attr->ofname);
          if (is_bopen(bfd)) {
             Qmsg1(jcr, M_ERROR, 0, _("bpkt already open fid=%d\n"), bfd->fid);
             bclose(bfd);
          }
-      
 
-         if ((bopen(bfd, attr->ofname, mode, S_IRUSR | S_IWUSR)) < 0) {
+         set_fattrs(bfd, &attr->statp);
+         if ((bopen(bfd, attr->ofname, flags, S_IRUSR | S_IWUSR)) < 0) {
             berrno be;
             be.set_errno(bfd->berrno);
             Qmsg2(jcr, M_ERROR, 0, _("Could not create %s: ERR=%s\n"),
                   attr->ofname, be.bstrerror());
+            Dmsg2(100,"Could not create %s: ERR=%s\n", attr->ofname, be.bstrerror());
             return CF_ERROR;
          }
          return CF_EXTRACT;
 
-#ifndef HAVE_WIN32  // none of these exists on MS Windows
+#ifndef HAVE_WIN32  // none of these exist in MS Windows
       case FT_RAW:                    /* Bacula raw device e.g. /dev/sda1 */
       case FT_FIFO:                   /* Bacula fifo to save data */
       case FT_SPEC:
@@ -259,24 +261,25 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
           * Here we are going to attempt to restore to a FIFO, which
           *   means that the FIFO must already exist, AND there must
           *   be some process already attempting to read from the
-          *   FIFO, so we open it write-only. 
+          *   FIFO, so we open it write-only.
           */
          if (attr->type == FT_RAW || attr->type == FT_FIFO) {
             btimer_t *tid;
             Dmsg1(400, "FT_RAW|FT_FIFO %s\n", attr->ofname);
-            mode =  O_WRONLY | O_BINARY;
+            flags =  O_WRONLY | O_BINARY;
             /* Timeout open() in 60 seconds */
             if (attr->type == FT_FIFO) {
                Dmsg0(400, "Set FIFO timer\n");
-               tid = start_thread_timer(pthread_self(), 60);
+               tid = start_thread_timer(jcr, pthread_self(), 60);
             } else {
                tid = NULL;
             }
             if (is_bopen(bfd)) {
                Qmsg1(jcr, M_ERROR, 0, _("bpkt already open fid=%d\n"), bfd->fid);
             }
-            Dmsg2(400, "open %s mode=0x%x\n", attr->ofname, mode);
-            if ((bopen(bfd, attr->ofname, mode, 0)) < 0) {
+            Dmsg2(400, "open %s flags=0x%x\n", attr->ofname, flags);
+            set_fattrs(bfd, &attr->statp);
+            if ((bopen(bfd, attr->ofname, flags, 0)) < 0) {
                berrno be;
                be.set_errno(bfd->berrno);
                Qmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"),
@@ -307,14 +310,12 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
             berrno be;
 #ifdef HAVE_CHFLAGS
             struct stat s;
-
-        /*
+           /*
             * If using BSD user flags, maybe has a file flag
             * preventing this. So attempt to disable, retry link,
             * and reset flags.
             * Note that BSD securelevel may prevent disabling flag.
-        */
-
+            */
             if (stat(attr->olname, &s) == 0 && s.st_flags != 0) {
                if (chflags(attr->olname, 0) == 0) {
                   if (link(attr->olname, attr->ofname) != 0) {
@@ -326,6 +327,8 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
 #endif /* HAVE_CHFLAGS */
             Qmsg3(jcr, M_ERROR, 0, _("Could not hard link %s -> %s: ERR=%s\n"),
                   attr->ofname, attr->olname, be.bstrerror());
+            Dmsg3(200, "Could not hard link %s -> %s: ERR=%s\n",
+                  attr->ofname, attr->olname, be.bstrerror());
             return CF_ERROR;
 #ifdef HAVE_CHFLAGS
                   }
@@ -350,10 +353,14 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
 #endif
       } /* End inner switch */
 
+   case FT_REPARSE:
+   case FT_JUNCTION:
+      bfd->reparse_point = true;
+      /* Fall through wanted */
    case FT_DIRBEGIN:
    case FT_DIREND:
       Dmsg2(200, "Make dir mode=%o dir=%s\n", new_mode, attr->ofname);
-      if (make_path(jcr, attr->ofname, new_mode, parent_mode, uid, gid, 0, NULL) != 0) {
+      if (!makepath(attr, attr->ofname, new_mode, parent_mode, uid, gid, 0)) {
          return CF_ERROR;
       }
       /*
@@ -365,13 +372,14 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
          if (is_bopen(bfd)) {
             Qmsg1(jcr, M_ERROR, 0, _("bpkt already open fid=%d\n"), bfd->fid);
          }
+         set_fattrs(bfd, &attr->statp);
          if ((bopen(bfd, attr->ofname, O_WRONLY|O_BINARY, 0)) < 0) {
             berrno be;
             be.set_errno(bfd->berrno);
 #ifdef HAVE_WIN32
             /* Check for trying to create a drive, if so, skip */
-            if (attr->ofname[1] == ':' && 
-                IsPathSeparator(attr->ofname[2]) && 
+            if (attr->ofname[1] == ':' &&
+                IsPathSeparator(attr->ofname[2]) &&
                 attr->ofname[3] == '\0') {
                return CF_SKIP;
             }
@@ -385,6 +393,9 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
          return CF_CREATED;
       }
 
+   case FT_DELETED:
+      Qmsg2(jcr, M_INFO, 0, _("Original file %s have been deleted: type=%d\n"), attr->fname, attr->type);
+      break;
    /* The following should not occur */
    case FT_NOACCESS:
    case FT_NOFOLLOW:
@@ -399,6 +410,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
       break;
    default:
       Qmsg2(jcr, M_ERROR, 0, _("Unknown file type %d; not restored: %s\n"), attr->type, attr->fname);
+      Pmsg2(000, "Unknown file type %d; not restored: %s\n", attr->type, attr->fname);
       break;
    }
    return CF_ERROR;