2 fuse_xattrs - Add xattrs support using sidecar files
4 Copyright (C) 2016 Felipe Barriga Richards <felipe {at} felipebarriga.cl>
6 This program can be distributed under the terms of the GNU GPL.
15 #include "fuse_xattrs_config.h"
17 char *prepend_source_directory(const char *a, const char *b) {
18 size_t len = strlen(a) + strlen(b) + 1;
19 char *dst = (char*) malloc(sizeof(char) * len);
20 sprintf(dst, "%s%s", a, b);
25 char *get_sidecar_path(const char *path)
27 const size_t path_len = strlen(path);
28 const size_t sidecar_ext_len = strlen(BINARY_SIDECAR_EXT); // this can be optimized
29 const size_t sidecar_path_len = path_len + sidecar_ext_len + 1;
30 char *sidecar_path = (char *) malloc(sidecar_path_len);
31 memset(sidecar_path, '\0', sidecar_path_len);
32 memcpy(sidecar_path, path, path_len);
33 memcpy(sidecar_path + path_len, BINARY_SIDECAR_EXT, sidecar_ext_len);
38 // TODO: make it work for binary data
39 char *sanitize_value(const char *value, size_t value_size)
41 char *sanitized = malloc(value_size + 1);
42 memcpy(sanitized, value, value_size);
43 sanitized[value_size] = '\0';
48 const size_t BINARY_SIDECAR_EXT_SIZE = strlen(BINARY_SIDECAR_EXT);
50 const int filename_is_sidecar(const char *string) {
54 size_t size = strlen(string);
55 if (size <= BINARY_SIDECAR_EXT_SIZE)
58 if (memcmp(string+size-BINARY_SIDECAR_EXT_SIZE, BINARY_SIDECAR_EXT, BINARY_SIDECAR_EXT_SIZE) == 0) {
65 enum namespace get_namespace(const char *name) {
66 if (strncmp(name, "user.", strlen("user.")) == 0) {
70 if (strncmp(name, "system.", strlen("system.")) == 0) {
74 if (strncmp(name, "security.", strlen("security.")) == 0) {
78 if (strncmp(name, "trusted.", strlen("trusted.")) == 0) {
82 error_print("invalid namespace for key: %s\n", name);