]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/xattr.c
Merge branch 'master' into basejobv3
[bacula/bacula] / bacula / src / filed / xattr.c
index 30ea749e1bda648fba4f0d21dba7f5ee33131f25..27254ba7f24c4bb3b9a3b6f5b34f830ba6c7e5e4 100644 (file)
@@ -131,12 +131,20 @@ static bxattr_exit_code send_xattr_stream(JCR *jcr, int stream)
  */
 #if defined(HAVE_DARWIN_OS)
 static int os_default_xattr_streams[1] = { STREAM_XATTR_DARWIN };
+static const char *xattr_acl_skiplist[2] = { "com.apple.system.Security", NULL };
+static const char *xattr_skiplist[3] = { "com.apple.system.extendedsecurity", "com.apple.ResourceFork", NULL };
 #elif defined(HAVE_FREEBSD_OS)
 static int os_default_xattr_streams[1] = { STREAM_XATTR_FREEBSD };
+static const char *xattr_acl_skiplist[1] = { NULL };
+static const char *xattr_skiplist[1] = { NULL };
 #elif defined(HAVE_LINUX_OS)
 static int os_default_xattr_streams[1] = { STREAM_XATTR_LINUX };
+static const char *xattr_acl_skiplist[2] = { "system.posix_acl_access", NULL };
+static const char *xattr_skiplist[1] = { NULL };
 #elif defined(HAVE_NETBSD_OS)
 static int os_default_xattr_streams[1] = { STREAM_XATTR_NETBSD };
+static const char *xattr_acl_skiplist[1] = { NULL };
+static const char *xattr_skiplist[1] = { NULL };
 #endif
 
 /*
@@ -243,7 +251,8 @@ static uint32_t serialize_xattr_stream(JCR *jcr, uint32_t expected_serialize_len
 
 static bxattr_exit_code generic_xattr_build_streams(JCR *jcr, FF_PKT *ff_pkt)
 {
-   int count = 0;
+   bool skip_xattr;
+   int cnt, xattr_count = 0;
    int32_t xattr_list_len,
            xattr_value_len;
    uint32_t expected_serialize_len = 0;
@@ -301,22 +310,41 @@ static bxattr_exit_code generic_xattr_build_streams(JCR *jcr, FF_PKT *ff_pkt)
     */
    bp = xattr_list;
    while ((bp - xattr_list) + 1 < xattr_list_len) {
-#if defined(HAVE_LINUX_OS)
+      skip_xattr = false;
+
       /*
-       * On Linux you also get the acls in the extented attribute list.
+       * On some OSes you also get the acls in the extented attribute list.
        * So we check if we are already backing up acls and if we do we
        * don't store the extended attribute with the same info.
        */
-      if ((ff_pkt->flags & FO_ACL) == 0 || strcmp(bp, "system.posix_acl_access"))
-         count++;
-#else
-      count++;
-#endif
+      if (ff_pkt->flags & FO_ACL) {
+         for (cnt = 0; xattr_acl_skiplist[cnt] != NULL; cnt++) {
+            if (!strcmp(bp, xattr_acl_skiplist[cnt])) {
+               skip_xattr = true;
+               break;
+            }
+         }
+      }
+
+      /*
+       * On some OSes we want to skip certain xattrs which are in the xattr_skiplist array.
+       */
+      if (!skip_xattr) {
+         for (cnt = 0; xattr_skiplist[cnt] != NULL; cnt++) {
+            if (!strcmp(bp, xattr_skiplist[cnt])) {
+               skip_xattr = true;
+               break;
+            }
+         }
+      }
 
+      if (!skip_xattr) {
+         xattr_count++;
+      }
       bp = strchr(bp, '\0') + 1;
    }
 
-   if (count == 0) {
+   if (xattr_count == 0) {
       retval = bxattr_exit_ok;
       goto bail_out;
    }
@@ -325,8 +353,8 @@ static bxattr_exit_code generic_xattr_build_streams(JCR *jcr, FF_PKT *ff_pkt)
     * Allocate enough room to hold all extended attributes.
     * After allocating the storage make sure its empty by zeroing it.
     */
-   xattr_value_list = (xattr_t *)malloc(count * sizeof(xattr_t));
-   memset((caddr_t)xattr_value_list, 0, count * sizeof(xattr_t));
+   xattr_value_list = (xattr_t *)malloc(xattr_count * sizeof(xattr_t));
+   memset((caddr_t)xattr_value_list, 0, xattr_count * sizeof(xattr_t));
 
    /*
     * Walk the list of extended attributes names and retrieve the data.
@@ -335,17 +363,38 @@ static bxattr_exit_code generic_xattr_build_streams(JCR *jcr, FF_PKT *ff_pkt)
    current_xattr = xattr_value_list;
    bp = xattr_list;
    while ((bp - xattr_list) + 1 < xattr_list_len) {
-#if defined(HAVE_LINUX_OS)
+      skip_xattr = false;
+
       /*
-       * On Linux you also get the acls in the extented attribute list.
+       * On some OSes you also get the acls in the extented attribute list.
        * So we check if we are already backing up acls and if we do we
        * don't store the extended attribute with the same info.
        */
-      if (ff_pkt->flags & FO_ACL && !strcmp(bp, "system.posix_acl_access")) {
+      if (ff_pkt->flags & FO_ACL) {
+         for (cnt = 0; xattr_acl_skiplist[cnt] != NULL; cnt++) {
+            if (!strcmp(bp, xattr_acl_skiplist[cnt])) {
+               skip_xattr = true;
+               break;
+            }
+         }
+      }
+
+      /*
+       * On some OSes we want to skip certain xattrs which are in the xattr_skiplist array.
+       */
+      if (!skip_xattr) {
+         for (cnt = 0; xattr_skiplist[cnt] != NULL; cnt++) {
+            if (!strcmp(bp, xattr_skiplist[cnt])) {
+               skip_xattr = true;
+               break;
+            }
+         }
+      }
+
+      if (skip_xattr) {
          bp = strchr(bp, '\0') + 1;
          continue;
       }
-#endif
 
       /*
        * Each xattr valuepair starts with a magic so we can parse it easier.
@@ -674,18 +723,6 @@ static void add_xattr_link_cache_entry(JCR *jcr, ino_t inum, char *target)
    jcr->xattr_data->link_cache->append(ptr);
 }
 
-static void flush_xattr_link_cache(JCR *jcr)
-{
-   xattr_link_cache_entry_t *ptr;
-
-   foreach_alist(ptr, jcr->xattr_data->link_cache) {
-      if (ptr && ptr->target) {
-         free(ptr->target);
-      }
-   }
->>>>>>> Add all acl and xattr related variables which are either global or already part of the JCR:bacula/src/filed/xattr.c
-}
-
 #if defined(HAVE_SYS_NVPAIR_H) && defined(_PC_SATTR_ENABLED)
 /*
  * This function returns true if a non default extended system attribute
@@ -967,7 +1004,6 @@ static bxattr_exit_code solaris_save_xattr(JCR *jcr, int fd, const char *xattr_n
       cnt = bsnprintf(buffer, sizeof(buffer), "%s%c%s%c%s%c",
                      target_attrname, 0, attribs, 0, (acl_text) ? acl_text : "", 0);
       break;
-
    case S_IFDIR:
       /*
        * Get any acl on the xattr.
@@ -1068,7 +1104,6 @@ static bxattr_exit_code solaris_save_xattr(JCR *jcr, int fd, const char *xattr_n
          }
       }
       break;
-
    case S_IFLNK:
       /*
        * The current implementation of xattr on Solaris doesn't support this, but if it ever does we are prepared.
@@ -1099,11 +1134,14 @@ static bxattr_exit_code solaris_save_xattr(JCR *jcr, int fd, const char *xattr_n
       jcr->xattr_data->content_length = cnt;
       retval = send_xattr_stream(jcr, stream);
 
+      if (retval == bxattr_exit_ok) {
+         jcr->xattr_data->nr_saved++;
+      }
+
       /*
        * For a soft linked file we are ready now, no need to recursively save the attributes.
        */
       goto bail_out;
-
    default:
       goto bail_out;
    }
@@ -1118,6 +1156,7 @@ static bxattr_exit_code solaris_save_xattr(JCR *jcr, int fd, const char *xattr_n
       if (retval != bxattr_exit_ok) {
          goto bail_out;
       }
+      jcr->xattr_data->nr_saved++;
    }
 
    pm_memcpy(jcr->xattr_data->content, buffer, cnt);
@@ -1160,7 +1199,9 @@ static bxattr_exit_code solaris_save_xattr(JCR *jcr, int fd, const char *xattr_n
 
    if (retval) {
       retval = send_xattr_stream(jcr, stream);
-      jcr->xattr_data->nr_saved++;
+      if (retval == bxattr_exit_ok) {
+         jcr->xattr_data->nr_saved++;
+      }
    }
 
    /*
@@ -1788,16 +1829,15 @@ static bxattr_exit_code solaris_build_xattr_streams(JCR *jcr, FF_PKT *ff_pkt)
     */
    if (pathconf(jcr->last_fname, _PC_XATTR_EXISTS) > 0) {
       jcr->xattr_data->nr_saved = 0;
+      jcr->xattr_data->link_cache = New(alist(10, not_owned_by_alist));
 
       /*
        * As we change the cwd in the save function save the current cwd
        * for restore after return from the solaris_save_xattrs function.
        */
-      jcr->xattr_data->link_cache = New(alist(10, not_owned_by_alist));
       getcwd(cwd, sizeof(cwd));
       retval = solaris_save_xattrs(jcr, NULL, NULL);
       chdir(cwd);
-      flush_xattr_link_cache(jcr);
       delete jcr->xattr_data->link_cache;
       jcr->xattr_data->link_cache = NULL;
    }