]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/restore.c
Use dcr more in SD + int to bool conversions
[bacula/bacula] / bacula / src / filed / restore.c
index b7bb63320aa2f5c7229f3b6969f2d82146c0672f..e2da0c849a2edb9c978491e36765fe5c6ab4b584 100644 (file)
@@ -7,7 +7,7 @@
  *
  */
 /*
-   Copyright (C) 2000-2003 Kern Sibbald and John Walker
+   Copyright (C) 2000-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
 #include "bacula.h"
 #include "filed.h"
 
+#ifdef HAVE_ACL
+#include <sys/acl.h>
+#include <acl/libacl.h>
+#endif
+
 /* Data received from Storage Daemon */
 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
 
 /* Forward referenced functions */
-static char *zlib_strerror(int stat);
+#ifdef HAVE_LIBZ
+static const char *zlib_strerror(int stat);
+#endif
 
 #define RETRY 10                     /* retry wait time */
 
@@ -57,15 +64,27 @@ void do_restore(JCR *jcr)
    uint64_t fileAddr = 0;            /* file write address */
    int non_support_data = 0;
    int non_support_attr = 0;
+   int non_support_acl = 0;
    int prog_name_msg = 0;
    ATTR *attr;
-   
+#ifdef HAVE_ACL
+   acl_t acl;
+#endif
 
    binit(&bfd);
    sd = jcr->store_bsock;
    set_jcr_job_status(jcr, JS_Running);
 
-   if (!bnet_set_buffer_size(sd, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_READ)) {
+   LockRes();
+   CLIENT *client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
+   UnlockRes();
+   uint32_t buf_size;
+   if (client) {
+      buf_size = client->max_network_buffer_size;
+   } else {
+      buf_size = 0;                  /* use default */
+   }
+   if (!bnet_set_buffer_size(sd, buf_size, BNET_SETBUF_WRITE)) {
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       return;
    }
@@ -296,6 +315,34 @@ void do_restore(JCR *jcr)
 #endif
         break;
 
+      case STREAM_UNIX_ATTRIBUTES_ACL:  
+#ifdef HAVE_ACL
+        /* Recover ACL from stream and check it */
+        acl = acl_from_text(sd->msg);
+        if (acl_valid(acl) != 0) {
+            Emsg1(M_WARNING, 0, "Failure in the ACL of %s! FD is not able to restore it!\n", jcr->last_fname);
+           acl_free(acl);
+        }
+        
+        /* Try to restore ACL */
+        if (attr->type == FT_DIREND) {
+           /* Directory */
+           if (acl_set_file(jcr->last_fname, ACL_TYPE_DEFAULT, acl) != 0 &&
+               acl_set_file(jcr->last_fname, ACL_TYPE_ACCESS, acl) != 0) {
+               Emsg1(M_WARNING, 0, "Error! Can't restore ACL of directory: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
+           }
+        /* File or Link */
+        } else if (acl_set_file(jcr->last_fname, ACL_TYPE_ACCESS, acl) != 0) {
+            Emsg1(M_WARNING, 0, "Error! Can't restore ACL of file: %s! Maybe system does not support ACLs!\n", jcr->last_fname);
+        }
+        acl_free(acl);
+         Dmsg1(200, "ACL of file: %s successfully restored!", jcr->last_fname);
+        break;
+#else 
+        non_support_acl++;
+        break;                       /* unconfigured, ignore */
+#endif  
+        
       case STREAM_MD5_SIGNATURE:
       case STREAM_SHA1_SIGNATURE:
         break;
@@ -349,12 +396,17 @@ ok_out:
       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_acl) {
+      Jmsg(jcr, M_INFO, 0, _("%d non-supported acl streams ignored.\n"), non_support_acl);
+   }
+
 }         
 
+#ifdef HAVE_LIBZ
 /*
  * Convert ZLIB error code into an ASCII message
  */
-static char *zlib_strerror(int stat)
+static const char *zlib_strerror(int stat)
 {
    if (stat >= 0) {
       return "None";
@@ -376,3 +428,4 @@ static char *zlib_strerror(int stat)
       return "*none*";
    }
 }
+#endif