--- a/src/server/webdav/xattrbackend.c Sat Mar 18 14:16:05 2023 +0100 +++ b/src/server/webdav/xattrbackend.c Sat Mar 18 15:52:35 2023 +0100 @@ -29,6 +29,9 @@ #include "xattrbackend.h" +#include "../util/util.h" +#include "../util/libxattr.h" + static WebdavBackend webdav_xattr_backend = { webdav_xattr_propfind_init, @@ -61,6 +64,7 @@ } // TODO: config + repo->xattr_name = "webdav_properties"; return repo; } @@ -93,6 +97,22 @@ const char *href, WebdavPList **outplist) { + // make sure the sys vfs is used, because currently only + // native sysfs xattr is supported + if(rq->rq->vfs) { + log_ereport(LOG_FAILURE, "webdav-propfind: xattr backend unsupported with non-native VFS"); + return 1; + } + + XAttrPropfind *xprop = pool_malloc(rq->sn->pool, sizeof(XAttrPropfind)); + if(!xprop) { + return 1; + } + rq->userdata = xprop; + + xprop->base_href = href; + xprop->base_path = path; + return 0; } @@ -103,6 +123,47 @@ WebdavResource *resource, struct stat *s) { + Session *sn = request->sn; + Request *rq = request->rq; + + WebdavXAttrBackend *xdav = request->dav->instance; + WebdavXAttrRepository *repo = xdav->repo; + XAttrPropfind *xprop = request->userdata; + + const char *path; + char *path_dp = NULL; + if(!parent) { + // use base path + path = xprop->base_path; + } else { + size_t base_href_len = strlen(xprop->base_href); + size_t base_path_len = strlen(xprop->base_path); + char *res_path = resource->href + base_href_len; + size_t res_path_len = strlen(res_path); + + path_dp = pool_malloc(sn->pool, base_path_len + res_path_len + 2); + memcpy(path_dp, xprop->base_path, base_path_len); + int s = 0; + if(path_dp[base_path_len-1] != '/' && res_path[0] != '/') { + path_dp[base_path_len] = '/'; + s = 1; + } + memcpy(path_dp + base_path_len + s, res_path, res_path_len); + path_dp[base_path_len + s + res_path_len] = 0; + + path = path_dp; + } + + ssize_t xattr_data_len = 0; + char *xattr_data = xattr_get_alloc( + sn->pool, + (libxattr_malloc_func)pool_malloc, + (libxattr_free_func)pool_free, + path, + repo->xattr_name, + &xattr_data_len); + + return 0; }