From 06e1569677ab9f494a857f05f3a80be3c9e2a0fe Mon Sep 17 00:00:00 2001 From: wbaumann Date: Thu, 15 Aug 2013 17:22:24 +0000 Subject: [PATCH] Fix has_permission (bug #33644) --- ChangeLog | 4 ++++ src/cache.c | 35 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2403ef0..068f506 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ ChangeLog for davfs2 -------------------- +2013-08-15 Werner Baumann (werner.baumann@onlinehome.de) + * cache.c: + Fix has_permission (bug #33644). + 2013-08-13 Werner Baumann (werner.baumann@onlinehome.de) * defaults.h, mount_davfs.c: Fix evaluation of default modes. diff --git a/src/cache.c b/src/cache.c index 2d24368..e61cbb6 100644 --- a/src/cache.c +++ b/src/cache.c @@ -2278,28 +2278,35 @@ has_permission(const dav_node *node, uid_t uid, int how) a_mode |= (how & W_OK) ? (S_IWUSR | S_IWGRP | S_IWOTH) : 0; a_mode |= (how & X_OK) ? (S_IXUSR | S_IXGRP | S_IXOTH) : 0; - if (!(~node->mode & S_IRWXO & a_mode)) - return 1; - - if (node->uid == uid && !(~node->mode & S_IRWXU & a_mode)) + if (node->uid == uid) { + if (~node->mode & S_IRWXU & a_mode) + return 0; return 1; + } struct passwd *pw = getpwuid(uid); if (!pw) return 0; - if (pw->pw_gid != node->gid) { - struct group *grp = getgrgid(node->gid); - if (!grp) + if (pw->pw_gid == node->gid) { + if (~node->mode & S_IRWXG & a_mode) return 0; - char **members = grp->gr_mem; - while (*members && strcmp(*members, pw->pw_name) != 0) - members++; - if (!*members) - return 0; - } - if (!(~node->mode & S_IRWXG & a_mode)) return 1; + } + struct group *grp = getgrgid(node->gid); + if (!grp) + return 0; + char **members = grp->gr_mem; + while (*members && strcmp(*members, pw->pw_name) != 0) + members++; + if (*members) { + if (~node->mode & S_IRWXG & a_mode) + return 0; + return 1; + } + + if (!(~node->mode & S_IRWXO & a_mode)) + return 1; return 0; }