Remove support for extended attributes

This commit is contained in:
wbaumann 2013-08-09 18:42:48 +00:00
parent d61383d148
commit f5e14315d4
5 changed files with 30 additions and 246 deletions

View File

@ -100,7 +100,6 @@ enum {
CTIME,
SMTIME,
ETAG,
MIME,
LOCK_EXPIRE,
DIRTY,
REMOTE_EXISTS,
@ -124,7 +123,6 @@ static const char* const type[] = {
[CTIME] = "ctime",
[SMTIME] = "smtime",
[ETAG] = "etag",
[MIME] = "mime",
[LOCK_EXPIRE] = "lock_expire",
[DIRTY] = "dirty",
[REMOTE_EXISTS] = "remote_exists",
@ -764,7 +762,7 @@ dav_tidy_cache(void)
set_execute = 1;
int ret = dav_put(node->path, node->cache_path, &node->remote_exists,
&node->lock_expire, &node->etag, &node->smtime,
&node->mime_type, set_execute);
set_execute);
if (!ret) {
node->utime = time(NULL);
node->dirty = 0;
@ -857,7 +855,7 @@ dav_close(dav_node *node, int fd, int flags, pid_t pid, pid_t pgid)
set_execute = 1;
int ret = dav_put(node->path, node->cache_path, &node->remote_exists,
&node->lock_expire, &node->etag, &node->smtime,
&node->mime_type, set_execute);
set_execute);
if (!ret) {
node->utime = time(NULL);
node->dirty = 0;
@ -930,8 +928,7 @@ dav_create(dav_node **nodep, dav_node *parent, const char *name, uid_t uid,
if (!ret) {
(*nodep)->smtime = (*nodep)->mtime;
if (!is_created(*nodep))
dav_head((*nodep)->path, &(*nodep)->etag, &(*nodep)->smtime, NULL,
&(*nodep)->mime_type);
dav_head((*nodep)->path, &(*nodep)->etag, &(*nodep)->smtime, NULL);
(*nodep)->utime = (*nodep)->smtime;
delete_cache_file(parent);
parent->mtime = (*nodep)->mtime;
@ -973,58 +970,6 @@ dav_getattr(dav_node *node, uid_t uid)
}


int
dav_getxattr(dav_node *node, const char *name, char *buf, size_t *size,
uid_t uid)
{
if (!is_valid(node))
return ENOENT;
if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "getxattr %s", node->path);
if (node->parent != NULL && !has_permission(node->parent, uid, X_OK | R_OK))
return EACCES;
if (strcmp(name, "user.mime_type") != 0 || !node->mime_type)
return ENOTSUP;

if (*size == 0) {
*size = strlen(node->mime_type);
} else if (strlen(node->mime_type) > *size) {
return ERANGE;
} else {
*size = strlen(node->mime_type);
strncpy(buf, node->mime_type, *size);
}

return 0;
}


int
dav_listxattr(dav_node *node, char *buf, size_t *size, uid_t uid)
{
if (!is_valid(node))
return ENOENT;
if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "listxattr %s", node->path);
if (node->parent != NULL && !has_permission(node->parent, uid, X_OK | R_OK))
return EACCES;
if (!node->mime_type)
return ENOTSUP;

if (*size == 0) {
*size = strlen("user.mime_type") + 1;
} else if (strlen("user.mime_type") > *size) {
return ERANGE;
} else {
*size = strlen("user.mime_type") + 1;
strncpy(buf, "user.mime_type", *size - 1);
*(buf + *size - 1) = '\0';
}

return 0;
}


int
dav_lookup(dav_node **nodep, dav_node *parent, const char *name, uid_t uid)
{
@ -1487,7 +1432,7 @@ dav_setattr(dav_node *node, uid_t uid, int sm, mode_t mode, int so,
int err = 0;
time_t smtime = 0;
char *etag = NULL;
dav_head(node->path, &etag, &smtime, NULL, NULL);
dav_head(node->path, &etag, &smtime, NULL);
if (etag && node->etag && strcmp(etag, node->etag) != 0)
err = EIO;
if (smtime && smtime > node->smtime)
@ -1499,8 +1444,7 @@ dav_setattr(dav_node *node, uid_t uid, int sm, mode_t mode, int so,
}
dav_set_execute(node->path, set_execute);
if (is_dirty(node))
dav_head(node->path, &node->etag, &node->smtime, NULL,
&node->mime_type);
dav_head(node->path, &node->etag, &node->smtime, NULL);
}
}
node->mode = (node->mode & ~DAV_A_MASK) | mode;
@ -1678,8 +1622,6 @@ backup_node(dav_node *orig)
node->name = xstrdup(orig->cache_path + strlen(cache_dir) +1);
node->cache_path = orig->cache_path;
orig->cache_path = NULL;
node->mime_type = orig->mime_type;
orig->mime_type = NULL;
orig->dirty = 0;
node->size = orig->size;
node->uid = default_uid;
@ -1746,8 +1688,7 @@ clean_tree(dav_node *node, int upload)
set_execute = 1;
int ret = dav_put(node->path, node->cache_path,
&node->remote_exists, &node->lock_expire,
&node->etag, &node->smtime,
&node->mime_type, set_execute);
&node->etag, &node->smtime, set_execute);
if (is_locked(node))
dav_unlock(node->path, &node->lock_expire);
if (!ret) {
@ -1786,8 +1727,6 @@ delete_node(dav_node *node)
delete_cache_file(node);
if (node->etag)
free(node->etag);
if (node->mime_type)
free(node->mime_type);
while (node->handles) {
dav_handle *tofree = node->handles;
node->handles = node->handles->next;
@ -1923,7 +1862,7 @@ move_no_remote(dav_node *src, dav_node *dst, dav_node *dst_parent,
src->smtime = time(NULL);

if (!is_created(src))
dav_head(src->path, &src->etag, &src->smtime, NULL, &src->mime_type);
dav_head(src->path, &src->etag, &src->smtime, NULL);
src->utime = time(NULL);

return 0;
@ -1958,7 +1897,7 @@ move_reg(dav_node *src, dav_node *dst, dav_node *dst_parent,
dav_lock(dst_path, &src->lock_expire, &src->remote_exists);
}
if (is_cached(src))
dav_head(dst_path, &src->etag, &src->smtime, NULL, &src->mime_type);
dav_head(dst_path, &src->etag, &src->smtime, NULL);
if (dst) {
remove_from_tree(dst);
remove_from_changed(dst);
@ -2015,7 +1954,6 @@ new_node(dav_node *parent, mode_t mode)
node->name = NULL;
node->cache_path = NULL;
node->etag = NULL;
node->mime_type = NULL;
node->handles = NULL;
node->size = 0;

@ -2614,8 +2552,7 @@ update_cache_file(dav_node *node)
if (get_upload_time(node) >= time(NULL))
return 0;
ret = dav_put(node->path, node->cache_path, &node->remote_exists,
&node->lock_expire, &node->etag, &node->smtime,
&node->mime_type, -1);
&node->lock_expire, &node->etag, &node->smtime, -1);
if (!ret) {
node->utime = time(NULL);
node->dirty = 0;
@ -2643,7 +2580,7 @@ update_cache_file(dav_node *node)
int modified = 0;
off_t old_size = node->size;
ret = dav_get_file(node->path, node->cache_path, &node->size,
&node->etag, &node->smtime, &node->mime_type,
&node->etag, &node->smtime,
&modified);
if (!ret) {
if (modified) {
@ -2660,7 +2597,7 @@ update_cache_file(dav_node *node)
time_t smtime = 0;
char *etag = NULL;
ret = dav_get_file(node->path, node->cache_path, &node->size, &etag,
&smtime, &node->mime_type, NULL);
&smtime, NULL);
if (!ret) {
node->etag = etag;
if (smtime) {
@ -2994,12 +2931,6 @@ write_node(dav_node *node, FILE *file, const char *indent)
return -1;
}

if (is_reg(node) && node->mime_type != NULL) {
if (fprintf(file, "%s<d:%s><![CDATA[%s]]></d:%s>\n", ind, type[MIME],
node->mime_type, type[MIME]) < 0)
return -1;
}

if (is_reg(node)) {
if (fprintf(file, "%s<d:%s>%lli</d:%s>\n", ind, type[SIZE],
(long long int) node->size, type[SIZE]) < 0)
@ -3318,7 +3249,7 @@ xml_end_reg(void *userdata, int state, const char *nspace, const char *name)

/* Finishes the creation of the root directory. userdata must be equal to root,
or the complete tree will be deleted.
Members path, name, cache_path,etag and mime_type will be NULL.
Members path, name, cache_path and etag will be NULL.
return value : allways 0. */
static int
xml_end_root(void *userdata, int state, const char *nspace, const char *name)
@ -3341,10 +3272,6 @@ xml_end_root(void *userdata, int state, const char *nspace, const char *name)
free(dir->etag);
dir->etag = NULL;
}
if (dir->mime_type) {
free(dir->mime_type);
dir->mime_type = NULL;
}
dir->size = 0;
dir->smtime = 0;

@ -3405,9 +3332,6 @@ xml_end_string(void *userdata, int state, const char *nspace, const char *name)
case ETAG:
(*((dav_node **) userdata))->etag = xml_data;
break;
case MIME:
(*((dav_node **) userdata))->mime_type = xml_data;
break;
default:
free(xml_data);
xml_data = NULL;
@ -3442,9 +3366,6 @@ xml_end_string_old(void *userdata, int state, const char *nspace,
case ETAG:
(*((dav_node **) userdata))->etag = xml_data;
break;
case MIME:
(*((dav_node **) userdata))->mime_type = xml_data;
break;
default:
free(xml_data);
xml_data = NULL;
@ -3686,8 +3607,6 @@ xml_start_string(void *userdata, int parent, const char *nspace,
ret = CACHE_PATH;
} else if (strcmp(name, type[ETAG]) == 0) {
ret = ETAG;
} else if (strcmp(name, type[MIME]) == 0) {
ret = MIME;
} else {
return 0;
}

View File

@ -83,8 +83,6 @@ struct dav_node {
changed remotely. If present it overrides information from the
Last-Modified time (smtime). */
char *etag;
/* The media-type as in HTTP-header Content-Type. */
char *mime_type;
/* A linked list of handles for open files. */
dav_handle *handles;
/* Size of the contents of the node.
@ -287,23 +285,6 @@ int
dav_getattr(dav_node *node, uid_t uid);


/* Checks whether node exists and uid has permissions. The value of
extended attribute name is copied into buf. If its size is greater
than size, EOVERFLOW is returned.
Permissions:
uid must have execute permission for parent and all of its ancestors, as
well as read permission for parent. */
int
dav_getxattr(dav_node *node, const char *name, char *buf, size_t *size,
uid_t uid);


/* Returns the list of supported extended attributes. This is just
user.mime_type. */
int
dav_listxattr(dav_node *node, char *buf, size_t *size, uid_t uid);


/* Searches for a node with name name in the directory parent and returns the
node in nodep.
Permissions:

View File

@ -128,15 +128,9 @@ fuse_create(void);
static uint32_t
fuse_getattr(void);

static uint32_t
fuse_getxattr(void);

static uint32_t
fuse_init(void);

static uint32_t
fuse_listxattr(void);

static uint32_t
fuse_lookup(void);

@ -385,15 +379,21 @@ dav_run_msgloop(volatile int *keep_on_running)
break;
case FUSE_SETXATTR:
if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "FUSE_GETXATTR:");
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "FUSE_SETXATTR:");
oh->error = -ENOSYS;
oh->len = sizeof(struct fuse_out_header);
break;
case FUSE_GETXATTR:
oh->len = fuse_getxattr();
if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "FUSE_GETXATTR:");
oh->error = -ENOSYS;
oh->len = sizeof(struct fuse_out_header);
break;
case FUSE_LISTXATTR:
oh->len = fuse_listxattr();
if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "FUSE_LISTXATTR:");
oh->error = -ENOSYS;
oh->len = sizeof(struct fuse_out_header);
break;
case FUSE_REMOVEXATTR:
if (debug)
@ -603,50 +603,6 @@ fuse_getattr(void)
}


static uint32_t
fuse_getxattr(void)
{
struct fuse_in_header *ih = (struct fuse_in_header *) buf;
struct fuse_getxattr_in *in = (struct fuse_getxattr_in *)
(buf + sizeof(struct fuse_in_header));
char *name = (char *) (buf + sizeof(struct fuse_in_header)
+ sizeof(struct fuse_getxattr_in));
struct fuse_out_header *oh = (struct fuse_out_header *) buf;
struct fuse_getxattr_out *out = (struct fuse_getxattr_out *)
(buf + sizeof(struct fuse_out_header));
char *value = (char *) (buf + sizeof(struct fuse_out_header));
if (debug) {
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "FUSE_GETXATTR:");
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), " n 0x%llx, %s, %i",
(unsigned long long) ih->nodeid, name, in->size);
}

size_t size = in->size;
if (size == 0) {
oh->error = dav_getxattr((dav_node *) ((size_t) ih->nodeid), name,
value, &size, ih->uid);
if (oh->error) {
oh->error *= -1;
return sizeof(struct fuse_out_header);
}
out->size = size;
out->padding = 0;
return sizeof(struct fuse_out_header)
+ sizeof(struct fuse_getxattr_out);
} else {
if (size > (buf_size - sizeof(struct fuse_out_header)))
size = buf_size - sizeof(struct fuse_out_header);
oh->error = dav_getxattr((dav_node *) ((size_t) ih->nodeid), name,
value, &size, ih->uid);
if (oh->error) {
oh->error *= -1;
return sizeof(struct fuse_out_header);
}
return sizeof(struct fuse_out_header) + size;
}
}


static uint32_t
fuse_init(void)
{
@ -685,48 +641,6 @@ fuse_init(void)
}


static uint32_t
fuse_listxattr(void)
{
struct fuse_in_header *ih = (struct fuse_in_header *) buf;
struct fuse_getxattr_in *in = (struct fuse_getxattr_in *)
(buf + sizeof(struct fuse_in_header));
struct fuse_out_header *oh = (struct fuse_out_header *) buf;
struct fuse_getxattr_out *out = (struct fuse_getxattr_out *)
(buf + sizeof(struct fuse_out_header));
char *value = (char *) (buf + sizeof(struct fuse_out_header));
if (debug) {
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "FUSE_LISTXATTR:");
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), " n 0x%llx, %i",
(unsigned long long) ih->nodeid, in->size);
}

size_t size = in->size;
if (size == 0) {
oh->error = dav_listxattr((dav_node *) ((size_t) ih->nodeid), value,
&size, ih->uid);
if (oh->error) {
oh->error *= -1;
return sizeof(struct fuse_out_header);
}
out->size = size;
out->padding = 0;
return sizeof(struct fuse_out_header)
+ sizeof(struct fuse_getxattr_out);
} else {
if (size > (buf_size - sizeof(struct fuse_out_header)))
size = buf_size - sizeof(struct fuse_out_header);
oh->error = dav_listxattr((dav_node *) ((size_t) ih->nodeid), value,
&size, ih->uid);
if (oh->error) {
oh->error *= -1;
return sizeof(struct fuse_out_header);
}
return sizeof(struct fuse_out_header) + size;
}
}


static uint32_t
fuse_lookup(void)
{

View File

@ -680,7 +680,7 @@ dav_get_webdav_error()

int
dav_get_file(const char *path, const char *cache_path, off_t *size,
char **etag, time_t *mtime, char **mime, int *modified)
char **etag, time_t *mtime, int *modified)
{
int ret;
if (!initialized) {
@ -733,13 +733,6 @@ dav_get_file(const char *path, const char *cache_path, off_t *size,
if (*etag) free(*etag);
*etag = normalize_etag(ne_get_response_header(req, "ETag"));
}

value = ne_get_response_header(req, "Content-Type");
if (mime && value) {
if (*mime)
free(*mime);
*mime = xstrdup(value);
}
}

ne_request_destroy(req);
@ -753,8 +746,7 @@ dav_get_file(const char *path, const char *cache_path, off_t *size,


int
dav_head(const char *path, char **etag, time_t *mtime, off_t *length,
char **mime)
dav_head(const char *path, char **etag, time_t *mtime, off_t *length)
{
int ret;
if (!initialized) {
@ -784,13 +776,6 @@ dav_head(const char *path, char **etag, time_t *mtime, off_t *length,
if (!ret && length && value)
*length = strtol(value, NULL, 10);

value = ne_get_response_header(req, "Content-Type");
if (!ret && mime && value) {
if (*mime)
free(*mime);
*mime = xstrdup(value);
}

ne_request_destroy(req);
free(spath);
return ret;
@ -816,7 +801,7 @@ dav_lock(const char *path, time_t *expire, int *exists)
#else /* NE_VERSION_MINOR == 25 */
if (precheck && !*exists) {
#endif /* NE_VERSION_MINOR == 25 */
if (dav_head(path, NULL, NULL, NULL, NULL) == 0) {
if (dav_head(path, NULL, NULL, NULL) == 0) {
return EEXIST;
}
}
@ -942,7 +927,7 @@ dav_move(const char *src, const char *dst)

int
dav_put(const char *path, const char *cache_path, int *exists, time_t *expire,
char **etag, time_t *mtime, char **mime, int execute)
char **etag, time_t *mtime, int execute)
{
int ret = 0;
if (!initialized) {
@ -956,7 +941,7 @@ dav_put(const char *path, const char *cache_path, int *exists, time_t *expire,
char *r_etag = NULL;
time_t r_mtime = 0;
off_t r_length = 0;
ret = dav_head(path, &r_etag, &r_mtime, &r_length, NULL);
ret = dav_head(path, &r_etag, &r_mtime, &r_length);
if (!ret) {
if (!*exists && r_length) {
ret = EEXIST;
@ -1072,14 +1057,6 @@ dav_put(const char *path, const char *cache_path, int *exists, time_t *expire,
}
}

if (mime) {
value = ne_get_response_header(req, "Content-Type");
if (value) {
if (*mime)
free(*mime);
*mime = xstrdup(value);
}
}
}

ne_request_destroy(req);
@ -1090,7 +1067,7 @@ dav_put(const char *path, const char *cache_path, int *exists, time_t *expire,
if (execute == 1)
dav_set_execute(path, execute);
if (need_head)
dav_head(path, etag, mtime, NULL, mime);
dav_head(path, etag, mtime, NULL);
}

return ret;

View File

@ -141,16 +141,13 @@ dav_get_collection(const char *path, dav_props **props);
mtime : Points to the Last-Modified value of the cached version. Will
be updated if a new version of the file is retrieved.
May be NULL.
mime : Points to the mime_type string of the cached version. Will
be updated by the value of the Content-Type header, if any.
May be NULL;
modified : Points to a flag that will be set 1 if the file cache_path
has been replaced by a new version. May be NULL.
return value : 0 on success; an appropriate file error code otherwise.
Not-Modified counts as success. */
int
dav_get_file(const char *path, const char *cache_path, off_t *size,
char **etag, time_t *mtime, char **mime, int *modified);
char **etag, time_t *mtime, int *modified);


/* Returns the error string from the last WebDAV request.
@ -168,12 +165,10 @@ dav_get_webdav_error(void);
etag : Points to the Etag; will be updated on success. May be NULL.
mtime : Points to mtime; will be updated on success. May be NULL.
length: Points to length; will be updated on success. May be NULL.
mime : Points to mime_type; will be updated on success. May be NULL.
return value : 0 if the file exists; an appropriate file error code
otherwise. */
int
dav_head(const char *path, char **etag, time_t *mtime, off_t *length,
char **mime);
dav_head(const char *path, char **etag, time_t *mtime, off_t *length);


/* Locks the file path on the server with an excluse write lock and updates
@ -238,13 +233,11 @@ dav_move(const char *src, const char *dst);
Updated on success. May be NULL.
mtime : The Last_Modified value used to check for changes on the
server. Updated on success. May be NULL.
mime : The value of mime_type. Updated on successMay be NULL.
If a mime_type is set, the Content-Type header will be sent.
execute : if 1 set execute property, else no change of execute property.
return value : 0 on success; an appropriate file error code otherwise. */
int
dav_put(const char *path, const char *cache_path, int *exists, time_t *expire,
char **etag, time_t *mtime, char **mime, int execute);
char **etag, time_t *mtime, int execute);

/* Makes a PROPFIND request for path to get quota information (RFC 4331)
and places them in total and used.