From c4ba93a6529ab549d42b601432ec88d8243909bf Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Tue, 29 Sep 2015 15:24:41 +0800 Subject: [PATCH] client: use fuse_req_getgroups() to get group list Signed-off-by: Yan, Zheng (cherry picked from commit 0eb6d0ba1b65ac0aaffc72a82f07857cc65a6b88) --- src/client/Client.cc | 7 +++---- src/client/Client.h | 2 +- src/client/fuse_ll.cc | 28 ++++++++++------------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index a966b1702116..21b80cddd2e9 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4391,14 +4391,13 @@ int Client::check_permissions(Inode *in, int flags, int uid, int gid) gid_t *sgids = NULL; int sgid_count = 0; if (getgroups_cb) { - sgid_count = getgroups_cb(callback_handle, uid, &sgids); - if (sgid_count < 0) { + sgid_count = getgroups_cb(callback_handle, &sgids); + if (sgid_count > 0) { ldout(cct, 3) << "getgroups failed!" << dendl; - return sgid_count; } } #if HAVE_GETGROUPLIST - else { + if (sgid_count <= 0) { // use PAM to get the group list // initial number of group entries, defaults to posix standard of 16 // PAM implementations may provide more than 16 groups.... diff --git a/src/client/Client.h b/src/client/Client.h index b476f5eff859..91383f30e633 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -138,7 +138,7 @@ typedef void (*client_dentry_callback_t)(void *handle, vinodeno_t dirino, vinodeno_t ino, string& name); typedef int (*client_remount_callback_t)(void *handle); -typedef int (*client_getgroups_callback_t)(void *handle, uid_t uid, gid_t **sgids); +typedef int (*client_getgroups_callback_t)(void *handle, gid_t **sgids); typedef void(*client_switch_interrupt_callback_t)(void *req, void *data); struct client_callback_args { diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index a83e5a698c3c..d65149563fa3 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -715,12 +715,14 @@ static void fuse_ll_flock(fuse_req_t req, fuse_ino_t ino, } #endif -#if 0 -static int getgroups_cb(void *handle, uid_t uid, gid_t **sgids) +static int getgroups_cb(void *handle, gid_t **sgids) { -#ifdef HAVE_FUSE_GETGROUPS +#if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8) + CephFuse::Handle *cfuse = (CephFuse::Handle *)handle; + fuse_req_t req = cfuse->get_fuse_req(); + assert(sgids); - int c = fuse_getgroups(0, NULL); + int c = fuse_req_getgroups(req, 0, NULL); if (c < 0) { return c; } @@ -732,16 +734,16 @@ static int getgroups_cb(void *handle, uid_t uid, gid_t **sgids) if (!*sgids) { return -ENOMEM; } - c = fuse_getgroups(c, *sgids); + c = fuse_req_getgroups(req, c, *sgids); if (c < 0) { free(*sgids); return c; } return c; +#else + return -ENOSYS; #endif - return 0; } -#endif static void ino_invalidate_cb(void *handle, vinodeno_t vino, int64_t off, int64_t len) @@ -979,17 +981,7 @@ int CephFuse::Handle::start() dentry_cb: dentry_invalidate_cb, switch_intr_cb: switch_interrupt_cb, remount_cb: remount_cb, - /* - * this is broken: - * - * - the cb needs the request handle to be useful; we should get the - * gids in the method here in fuse_ll.c and pass the gid list in, - * not use a callback. - * - the callback mallocs the list but it is not free()'d - * - * so disable it for now... - getgroups_cb: getgroups_cb, - */ + getgroups_cb: getgroups_cb, }; client->ll_register_callbacks(&args); -- 2.47.3