]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/lib/util.c
authorEric Bollengier <eric@baculasystems.com>
Thu, 23 Apr 2020 14:34:07 +0000 (16:34 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:17 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Feb 17 12:59:43 2020 +0100

    Move dedup functions in separted files

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed May 1 15:24:21 2019 +0200

    Accept |script in the Client Address directive

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Jan 14 20:32:10 2019 +0100

    Fix xattr on CIFS share

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Sep 20 17:10:58 2018 +0200

    Add xattr_list_append() function to manipulate the listxattr() list

bacula/src/lib/util.c

index 2cbb7c4e8d5631d172ffb86f74e82a7dc81cf04b..73b4e6fbbcd3671b406144ff7f3d4a35e7232562 100644 (file)
@@ -862,7 +862,7 @@ void decode_session_key(char *decode, char *session, char *key, int maxlen)
  *  to = recepients list
  *
  */
-POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to, job_code_callback_t callback)
+POOLMEM *edit_job_codes(JCR *jcr, POOLMEM *&omsg, char *imsg, const char *to, job_code_callback_t callback)
 {
    char *p, *q;
    const char *str;
@@ -999,7 +999,7 @@ POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, const char *to, job_co
          str = add;
       }
       Dmsg1(1200, "add_str %s\n", str);
-      pm_strcat(&omsg, str);
+      pm_strcat(omsg, str);
       Dmsg1(1200, "omsg=%s\n", omsg);
    }
    return omsg;
@@ -1034,3 +1034,66 @@ const char *last_path_separator(const char *str)
    }
    return NULL;
 }
+
+/* Append a string to a xattr list returned by listxattr()
+ * The list is composed attr1\0attr2\0attr3\0
+ * We must lookup the list and append the attribute if
+ * it is not already here.
+ * Tested with tools/xattr_append_test
+ */
+int xattr_list_append(POOLMEM *&list, int len, const char *str, int str_len)
+{
+   /* 0  1  2  3  4  5  6
+    * f  o  o \0
+    *
+    *  len = 3, need to append at 4
+    *  len = 0, need to append at 0
+    */
+   int pos = (len > 0) ? len + 1 : 0;
+   bool found=false;
+
+   if (len > 0) {               /* Do the search only if it's needed */
+      char *end;
+      char *begin=list;
+
+      /* Look up to the last \0 */
+      for (int i = 0;  i < len + 1; i++) {
+         /* The string can contain \0 and we just skip them */
+         if (list[i] == '\0') {
+            end = list + i;
+            Dmsg1(100, "found <%s>\n", begin);
+            if ((end - begin) == str_len) {
+               if (strncmp(begin, str, str_len) == 0) {
+                  found=true;
+                  break;
+               }
+            }
+            /* Point after current position */
+            begin = list + i + 1;
+         }
+      }
+   }
+
+   if (!found) {
+      /* The size can be different since the query... */
+      list = check_pool_memory_size(list, len + str_len + 2);
+      bstrncpy(list+pos, str, str_len+1);
+      len += str_len + 1;
+   }
+
+   return len;
+}
+
+bool is_offset_stream(int stream)
+{ // Does the rec of this stream have an OFFSET of OFFSET_FADDR_SIZE at the beginning
+   switch (stream & STREAMMASK_TYPE) {
+   case STREAM_SPARSE_DATA:
+   case STREAM_SPARSE_GZIP_DATA:
+   case STREAM_SPARSE_COMPRESSED_DATA:
+      return true;
+   }
+   if (stream & STREAM_BIT_OFFSETS) {
+      return true;
+   }
+   return false;
+}