From: Eric Bollengier Date: Thu, 23 Apr 2020 14:34:07 +0000 (+0200) Subject: BEE Backport bacula/src/lib/util.c X-Git-Tag: Release-11.3.2~1779 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=101b4eac1942687eacf8fdc00172b36330eb3cf8;p=thirdparty%2Fbacula.git BEE Backport bacula/src/lib/util.c This commit is the result of the squash of the following main commits: Author: Eric Bollengier Date: Mon Feb 17 12:59:43 2020 +0100 Move dedup functions in separted files Author: Eric Bollengier Date: Wed May 1 15:24:21 2019 +0200 Accept |script in the Client Address directive Author: Eric Bollengier Date: Mon Jan 14 20:32:10 2019 +0100 Fix xattr on CIFS share Author: Eric Bollengier Date: Thu Sep 20 17:10:58 2018 +0200 Add xattr_list_append() function to manipulate the listxattr() list --- diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 2cbb7c4e8d..73b4e6fbbc 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -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; +}