]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/restore.c
Merge branch 'master' into basejobv3
[bacula/bacula] / bacula / src / filed / restore.c
index 0fc635e39fb5a2fd09d06fe80fdabcbf3cc638cc..808daec84b14a4f5b3867cf85888134df2d57b68 100644 (file)
@@ -57,11 +57,16 @@ const bool have_acl = false;
 #endif
 
 #ifdef HAVE_SHA2
-   const bool have_sha2 = true;
+const bool have_sha2 = true;
 #else
-   const bool have_sha2 = false;
+const bool have_sha2 = false;
 #endif
 
+#if defined(HAVE_XATTR)
+const bool have_xattr = true;
+#else
+const bool have_xattr = false;
+#endif
 
 /* Data received from Storage Daemon */
 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
@@ -171,6 +176,7 @@ void do_restore(JCR *jcr)
    int non_support_acl = 0;
    int non_support_progname = 0;
    int non_support_crypto = 0;
+   int non_support_xattr = 0;
 
 #ifdef HAVE_DARWIN_OS
    struct attrlist attrList;
@@ -223,8 +229,9 @@ void do_restore(JCR *jcr)
     *        d. Alternate data stream (e.g. Resource Fork)
     *        e. Finder info
     *        f. ACLs
-    *        g. Possibly a cryptographic signature
-    *        h. Possibly MD5 or SHA1 record
+    *        g. XATTRs
+    *        h. Possibly a cryptographic signature
+    *        i. Possibly MD5 or SHA1 record
     *   3. Repeat step 1
     *
     * NOTE: We keep track of two bacula file descriptors:
@@ -243,9 +250,16 @@ void do_restore(JCR *jcr)
    binit(&rctx.bfd);
    binit(&rctx.forkbfd);
    attr = rctx.attr = new_attr(jcr);
-   jcr->acl_text = get_pool_memory(PM_MESSAGE);
-
-   
+   if (have_acl) {
+      jcr->acl_data = (acl_data_t *)malloc(sizeof(acl_data_t));
+      memset((caddr_t)jcr->acl_data, 0, sizeof(acl_data_t));
+      jcr->acl_data->content = get_pool_memory(PM_MESSAGE);
+   }
+   if (have_xattr) {
+      jcr->xattr_data = (xattr_data_t *)malloc(sizeof(xattr_data_t));
+      memset((caddr_t)jcr->xattr_data, 0, sizeof(xattr_data_t));
+      jcr->xattr_data->content = get_pool_memory(PM_MESSAGE);
+   }
 
    while (bget_msg(sd) >= 0 && !job_canceled(jcr)) {
       /* Remember previous stream type */
@@ -573,6 +587,21 @@ void do_restore(JCR *jcr)
          break;
 
       case STREAM_UNIX_ACCESS_ACL:
+      case STREAM_UNIX_DEFAULT_ACL:
+      case STREAM_ACL_AIX_TEXT:
+      case STREAM_ACL_DARWIN_ACCESS_ACL:
+      case STREAM_ACL_FREEBSD_DEFAULT_ACL:
+      case STREAM_ACL_FREEBSD_ACCESS_ACL:
+      case STREAM_ACL_HPUX_ACL_ENTRY:
+      case STREAM_ACL_IRIX_DEFAULT_ACL:
+      case STREAM_ACL_IRIX_ACCESS_ACL:
+      case STREAM_ACL_LINUX_DEFAULT_ACL:
+      case STREAM_ACL_LINUX_ACCESS_ACL:
+      case STREAM_ACL_TRU64_DEFAULT_ACL:
+      case STREAM_ACL_TRU64_DEFAULT_DIR_ACL:
+      case STREAM_ACL_TRU64_ACCESS_ACL:
+      case STREAM_ACL_SOLARIS_ACLENT:
+      case STREAM_ACL_SOLARIS_ACE:
          /*
           * Do not restore ACLs when
           * a) The current file is not extracted
@@ -583,28 +612,65 @@ void do_restore(JCR *jcr)
             break;
          }
          if (have_acl) {
-            pm_strcpy(jcr->acl_text, sd->msg);
-            Dmsg2(400, "Restoring ACL type 0x%2x <%s>\n", BACL_TYPE_ACCESS, jcr->acl_text);
-            if (bacl_set(jcr, BACL_TYPE_ACCESS) != 0) {
-               Qmsg1(jcr, M_WARNING, 0, _("Can't restore ACL of %s\n"), jcr->last_fname);
+            pm_memcpy(jcr->acl_data->content, sd->msg, sd->msglen);
+            jcr->acl_data->content_length = sd->msglen;
+            switch (parse_acl_streams(jcr, rctx.stream)) {
+            case bacl_exit_fatal:
+               goto bail_out;
+            case bacl_exit_error:
+               /*
+                * Non-fatal errors, count them and when the number is under ACL_REPORT_ERR_MAX_PER_JOB
+                * print the error message set by the lower level routine in jcr->errmsg.
+                */
+               if (jcr->acl_data->nr_errors < ACL_REPORT_ERR_MAX_PER_JOB) {
+                  Qmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+               }
+               jcr->acl_data->nr_errors++;
+               break;
+            case bacl_exit_ok:
+               break;
             }
          } else {
             non_support_acl++;
          }
          break;
 
-      case STREAM_UNIX_DEFAULT_ACL:
+      case STREAM_XATTR_SOLARIS_SYS:
+      case STREAM_XATTR_SOLARIS:
+      case STREAM_XATTR_DARWIN:
+      case STREAM_XATTR_FREEBSD:
+      case STREAM_XATTR_LINUX:
+      case STREAM_XATTR_NETBSD:
+         /*
+          * Do not restore Extended Attributes when
+          * a) The current file is not extracted
+          * b)     and it is not a directory (they are never "extracted")
+          * c) or the file name is empty
+          */
          if ((!rctx.extract && jcr->last_type != FT_DIREND) || (*jcr->last_fname == 0)) {
             break;
          }
-         if (have_acl) {
-            pm_strcpy(jcr->acl_text, sd->msg);
-            Dmsg2(400, "Restoring ACL type 0x%2x <%s>\n", BACL_TYPE_DEFAULT, jcr->acl_text);
-            if (bacl_set(jcr, BACL_TYPE_DEFAULT) != 0) {
-               Qmsg1(jcr, M_WARNING, 0, _("Can't restore default ACL of %s\n"), jcr->last_fname);
+         if (have_xattr) {
+            pm_memcpy(jcr->xattr_data->content, sd->msg, sd->msglen);
+            jcr->xattr_data->content_length = sd->msglen;
+            switch (parse_xattr_streams(jcr, rctx.stream)) {
+            case bxattr_exit_fatal:
+               goto bail_out;
+            case bxattr_exit_error:
+               /*
+                * Non-fatal errors, count them and when the number is under XATTR_REPORT_ERR_MAX_PER_JOB
+                * print the error message set by the lower level routine in jcr->errmsg.
+                */
+               if (jcr->xattr_data->nr_errors < XATTR_REPORT_ERR_MAX_PER_JOB) {
+                  Qmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+               }
+               jcr->xattr_data->nr_errors++;
+               break;
+            case bxattr_exit_ok:
+               break;
             }
          } else {
-            non_support_acl++;
+            non_support_xattr++;
          }
          break;
 
@@ -667,7 +733,42 @@ bail_out:
    set_jcr_job_status(jcr, JS_ErrorTerminated);
 
 ok_out:
-   /* Free Signature & Crypto Data */
+   /*
+    * First output the statistics.
+    */
+   Dmsg2(10, "End Do Restore. Files=%d Bytes=%s\n", jcr->JobFiles,
+      edit_uint64(jcr->JobBytes, ec1));
+   if (have_acl && jcr->acl_data->nr_errors > 0) {
+      Jmsg(jcr, M_ERROR, 0, _("Encountered %ld acl errors while doing restore\n"),
+           jcr->acl_data->nr_errors);
+   }
+   if (have_xattr && jcr->xattr_data->nr_errors > 0) {
+      Jmsg(jcr, M_ERROR, 0, _("Encountered %ld xattr errors while doing restore\n"),
+           jcr->xattr_data->nr_errors);
+   }
+   if (non_support_data > 1 || non_support_attr > 1) {
+      Jmsg(jcr, M_ERROR, 0, _("%d non-supported data streams and %d non-supported attrib streams ignored.\n"),
+         non_support_data, non_support_attr);
+   }
+   if (non_support_rsrc) {
+      Jmsg(jcr, M_INFO, 0, _("%d non-supported resource fork streams ignored.\n"), non_support_rsrc);
+   }
+   if (non_support_finfo) {
+      Jmsg(jcr, M_INFO, 0, _("%d non-supported Finder Info streams ignored.\n"), non_support_rsrc);
+   }
+   if (non_support_acl) {
+      Jmsg(jcr, M_INFO, 0, _("%d non-supported acl streams ignored.\n"), non_support_acl);
+   }
+   if (non_support_crypto) {
+      Jmsg(jcr, M_INFO, 0, _("%d non-supported crypto streams ignored.\n"), non_support_acl);
+   }
+   if (non_support_xattr) {
+      Jmsg(jcr, M_INFO, 0, _("%d non-supported xattr streams ignored.\n"), non_support_xattr);
+   }
+
+   /*
+    * Free Signature & Crypto Data
+    */
    free_signature(rctx);
    free_session(rctx);
    if (jcr->crypto.digest) {
@@ -675,17 +776,22 @@ ok_out:
       jcr->crypto.digest = NULL;
    }
 
-   /* Free file cipher restore context */
+   /*
+    * Free file cipher restore context
+    */
    if (rctx.cipher_ctx.cipher) {
       crypto_cipher_free(rctx.cipher_ctx.cipher);
       rctx.cipher_ctx.cipher = NULL;
    }
+
    if (rctx.cipher_ctx.buf) {
       free_pool_memory(rctx.cipher_ctx.buf);
       rctx.cipher_ctx.buf = NULL;
    }
 
-   /* Free alternate stream cipher restore context */
+   /*
+    * Free alternate stream cipher restore context
+    */
    if (rctx.fork_cipher_ctx.cipher) {
       crypto_cipher_free(rctx.fork_cipher_ctx.cipher);
       rctx.fork_cipher_ctx.cipher = NULL;
@@ -700,29 +806,22 @@ ok_out:
       jcr->compress_buf = NULL;
       jcr->compress_buf_size = 0;
    }
-   bclose(&rctx.forkbfd);
-   bclose(&rctx.bfd);
-   free_attr(rctx.attr);
-   free_pool_memory(jcr->acl_text);
-   Dmsg2(10, "End Do Restore. Files=%d Bytes=%s\n", jcr->JobFiles,
-      edit_uint64(jcr->JobBytes, ec1));
-   if (non_support_data > 1 || non_support_attr > 1) {
-      Jmsg(jcr, M_ERROR, 0, _("%d non-supported data streams and %d non-supported attrib streams ignored.\n"),
-         non_support_data, non_support_attr);
-   }
-   if (non_support_rsrc) {
-      Jmsg(jcr, M_INFO, 0, _("%d non-supported resource fork streams ignored.\n"), non_support_rsrc);
-   }
-   if (non_support_finfo) {
-      Jmsg(jcr, M_INFO, 0, _("%d non-supported Finder Info streams ignored.\n"), non_support_rsrc);
-   }
-   if (non_support_acl) {
-      Jmsg(jcr, M_INFO, 0, _("%d non-supported acl streams ignored.\n"), non_support_acl);
+
+   if (have_acl && jcr->acl_data) {
+      free_pool_memory(jcr->acl_data->content);
+      free(jcr->acl_data);
+      jcr->acl_data = NULL;
    }
-   if (non_support_crypto) {
-      Jmsg(jcr, M_INFO, 0, _("%d non-supported crypto streams ignored.\n"), non_support_acl);
+
+   if (have_xattr && jcr->xattr_data) {
+      free_pool_memory(jcr->xattr_data->content);
+      free(jcr->xattr_data);
+      jcr->xattr_data = NULL;
    }
 
+   bclose(&rctx.forkbfd);
+   bclose(&rctx.bfd);
+   free_attr(rctx.attr);
 }
 
 #ifdef HAVE_LIBZ