|
|
21ab4e |
From ba4af70fb7d3ae21187ac0e9e3fe5539a4f8f829 Mon Sep 17 00:00:00 2001
|
|
|
21ab4e |
From: Csaba Henk <csaba@redhat.com>
|
|
|
21ab4e |
Date: Wed, 5 Jul 2017 17:48:37 +0200
|
|
|
21ab4e |
Subject: [PATCH 545/557] groups: don't allocate auxiliary gid list on stack
|
|
|
21ab4e |
|
|
|
21ab4e |
When glusterfs wants to retrieve the list of auxiliary gids
|
|
|
21ab4e |
of a user, it typically allocates a sufficiently big gid_t
|
|
|
21ab4e |
array on stack and calls getgrouplist(3) with it. However,
|
|
|
21ab4e |
"sufficiently big" means to be of maximum supported gid list
|
|
|
21ab4e |
size, which in GlusterFS is GF_MAX_AUX_GROUPS = 64k.
|
|
|
21ab4e |
That means a 64k * sizeof(gid_t) = 256k allocation, which is
|
|
|
21ab4e |
big enough to overflow the stack in certain cases.
|
|
|
21ab4e |
|
|
|
21ab4e |
A further observation is that stack allocation of the gid list
|
|
|
21ab4e |
brings no gain, as in all cases the content of the gid list
|
|
|
21ab4e |
eventually gets copied over to a heap allocated buffer.
|
|
|
21ab4e |
|
|
|
21ab4e |
So we add a convenience wrapper of getgrouplist to libglusterfs
|
|
|
21ab4e |
called gf_getgrouplist which calls getgrouplist with a sufficiently
|
|
|
21ab4e |
big heap allocated buffer (it takes care of the allocation too).
|
|
|
21ab4e |
We are porting all the getgrouplist invocations to gf_getgrouplist
|
|
|
21ab4e |
and thus eliminate the huge stack allocation.
|
|
|
21ab4e |
|
|
|
21ab4e |
> BUG: 1464327
|
|
|
21ab4e |
> Reviewed-on: https://review.gluster.org/17706
|
|
|
21ab4e |
> Smoke: Gluster Build System <jenkins@build.gluster.org>
|
|
|
21ab4e |
> Reviewed-by: Niels de Vos <ndevos@redhat.com>
|
|
|
21ab4e |
> Reviewed-by: Amar Tumballi <amarts@redhat.com>
|
|
|
21ab4e |
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
|
|
|
21ab4e |
|
|
|
21ab4e |
BUG: 1452513
|
|
|
21ab4e |
Change-Id: Icea76d0d74dcf2f87d26cb299acc771ca3b32d2b
|
|
|
21ab4e |
Signed-off-by: Csaba Henk <csaba@redhat.com>
|
|
|
21ab4e |
Reviewed-on: https://code.engineering.redhat.com/gerrit/111305
|
|
|
21ab4e |
Tested-by: Csaba Henk <chenk@redhat.com>
|
|
|
21ab4e |
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
21ab4e |
---
|
|
|
21ab4e |
libglusterfs/src/common-utils.c | 73 ++++++++++++++++++++++++++++
|
|
|
21ab4e |
libglusterfs/src/common-utils.h | 3 ++
|
|
|
21ab4e |
libglusterfs/src/glusterfs.h | 3 --
|
|
|
21ab4e |
libglusterfs/src/stack.h | 15 ++++--
|
|
|
21ab4e |
xlators/mount/fuse/src/fuse-helpers.c | 20 +++-----
|
|
|
21ab4e |
xlators/nfs/server/src/nfs-fops.c | 36 +++++---------
|
|
|
21ab4e |
xlators/protocol/server/src/server-helpers.c | 23 +++------
|
|
|
21ab4e |
7 files changed, 113 insertions(+), 60 deletions(-)
|
|
|
21ab4e |
|
|
|
21ab4e |
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
|
|
|
21ab4e |
index 862ec3b..c123f70 100644
|
|
|
21ab4e |
--- a/libglusterfs/src/common-utils.c
|
|
|
21ab4e |
+++ b/libglusterfs/src/common-utils.c
|
|
|
21ab4e |
@@ -30,6 +30,7 @@
|
|
|
21ab4e |
#include <signal.h>
|
|
|
21ab4e |
#include <assert.h>
|
|
|
21ab4e |
#include <libgen.h> /* for dirname() */
|
|
|
21ab4e |
+#include <grp.h>
|
|
|
21ab4e |
|
|
|
21ab4e |
#if defined(GF_BSD_HOST_OS) || defined(GF_DARWIN_HOST_OS)
|
|
|
21ab4e |
#include <sys/sysctl.h>
|
|
|
21ab4e |
@@ -4853,3 +4854,75 @@ close_fds_except (int *fdv, size_t count)
|
|
|
21ab4e |
#endif /* !GF_LINUX_HOST_OS */
|
|
|
21ab4e |
return 0;
|
|
|
21ab4e |
}
|
|
|
21ab4e |
+
|
|
|
21ab4e |
+/**
|
|
|
21ab4e |
+ * gf_getgrouplist - get list of groups to which a user belongs
|
|
|
21ab4e |
+ *
|
|
|
21ab4e |
+ * A convenience wrapper for getgrouplist(3).
|
|
|
21ab4e |
+ *
|
|
|
21ab4e |
+ * @param user - same as in getgrouplist(3)
|
|
|
21ab4e |
+ * @param group - same as in getgrouplist(3)
|
|
|
21ab4e |
+ * @param groups - pointer to a gid_t pointer
|
|
|
21ab4e |
+ *
|
|
|
21ab4e |
+ * gf_getgrouplist allocates a gid_t buffer which is big enough to
|
|
|
21ab4e |
+ * hold the list of auxiliary group ids for user, up to the GF_MAX_AUX_GROUPS
|
|
|
21ab4e |
+ * threshold. Upon succesfull invocation groups will be pointed to that buffer.
|
|
|
21ab4e |
+ *
|
|
|
21ab4e |
+ * @return success: the number of auxiliary group ids retrieved
|
|
|
21ab4e |
+ * failure: -1
|
|
|
21ab4e |
+ */
|
|
|
21ab4e |
+int
|
|
|
21ab4e |
+gf_getgrouplist (const char *user, gid_t group, gid_t **groups)
|
|
|
21ab4e |
+{
|
|
|
21ab4e |
+ int ret = -1;
|
|
|
21ab4e |
+ int ngroups = SMALL_GROUP_COUNT;
|
|
|
21ab4e |
+
|
|
|
21ab4e |
+ *groups = GF_CALLOC (sizeof (gid_t), ngroups, gf_common_mt_groups_t);
|
|
|
21ab4e |
+ if (!*groups)
|
|
|
21ab4e |
+ return -1;
|
|
|
21ab4e |
+
|
|
|
21ab4e |
+ /*
|
|
|
21ab4e |
+ * We are running getgrouplist() in a loop until we succeed (or hit
|
|
|
21ab4e |
+ * certain exit conditions, see the comments below). This is because
|
|
|
21ab4e |
+ * the indicated number of auxiliary groups that we obtain in case of
|
|
|
21ab4e |
+ * the failure of the first invocation is not guaranteed to keep its
|
|
|
21ab4e |
+ * validity upon the next invocation with a gid buffer of that size.
|
|
|
21ab4e |
+ */
|
|
|
21ab4e |
+ for (;;) {
|
|
|
21ab4e |
+ int ngroups_old = ngroups;
|
|
|
21ab4e |
+ ret = getgrouplist (user, group, *groups, &ngroups);
|
|
|
21ab4e |
+ if (ret != -1)
|
|
|
21ab4e |
+ break;
|
|
|
21ab4e |
+
|
|
|
21ab4e |
+ if (ngroups >= GF_MAX_AUX_GROUPS) {
|
|
|
21ab4e |
+ /*
|
|
|
21ab4e |
+ * This should not happen as GF_MAX_AUX_GROUPS is set
|
|
|
21ab4e |
+ * to the max value of number of supported auxiliary
|
|
|
21ab4e |
+ * groups across all platforms supported by GlusterFS.
|
|
|
21ab4e |
+ * However, if it still happened some way, we wouldn't
|
|
|
21ab4e |
+ * care about the incompleteness of the result, we'd
|
|
|
21ab4e |
+ * just go on with what we got.
|
|
|
21ab4e |
+ */
|
|
|
21ab4e |
+ return GF_MAX_AUX_GROUPS;
|
|
|
21ab4e |
+ } else if (ngroups <= ngroups_old) {
|
|
|
21ab4e |
+ /*
|
|
|
21ab4e |
+ * There is an edge case that getgrouplist() fails but
|
|
|
21ab4e |
+ * ngroups remains the same. This is actually not
|
|
|
21ab4e |
+ * specified in getgrouplist(3), but implementations
|
|
|
21ab4e |
+ * can do this upon internal failure[1]. To avoid
|
|
|
21ab4e |
+ * falling into an infinite loop when this happens, we
|
|
|
21ab4e |
+ * break the loop if the getgrouplist call failed
|
|
|
21ab4e |
+ * without an increase in the indicated group number.
|
|
|
21ab4e |
+ *
|
|
|
21ab4e |
+ * [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=grp/initgroups.c;hb=refs/heads/release/2.25/master#l168
|
|
|
21ab4e |
+ */
|
|
|
21ab4e |
+ GF_FREE (*groups);
|
|
|
21ab4e |
+ return -1;
|
|
|
21ab4e |
+ }
|
|
|
21ab4e |
+
|
|
|
21ab4e |
+ *groups = GF_REALLOC (*groups, ngroups * sizeof (gid_t));
|
|
|
21ab4e |
+ if (!*groups)
|
|
|
21ab4e |
+ return -1;
|
|
|
21ab4e |
+ }
|
|
|
21ab4e |
+ return ret;
|
|
|
21ab4e |
+}
|
|
|
21ab4e |
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
|
|
|
21ab4e |
index 1af9529..4765b5e 100644
|
|
|
21ab4e |
--- a/libglusterfs/src/common-utils.h
|
|
|
21ab4e |
+++ b/libglusterfs/src/common-utils.h
|
|
|
21ab4e |
@@ -903,4 +903,7 @@ get_ip_from_addrinfo (struct addrinfo *addr, char **ip);
|
|
|
21ab4e |
|
|
|
21ab4e |
int
|
|
|
21ab4e |
close_fds_except (int *fdv, size_t count);
|
|
|
21ab4e |
+
|
|
|
21ab4e |
+int
|
|
|
21ab4e |
+gf_getgrouplist (const char *user, gid_t group, gid_t **groups);
|
|
|
21ab4e |
#endif /* _COMMON_UTILS_H */
|
|
|
21ab4e |
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
|
|
|
21ab4e |
index d812aa7..43acf4c 100644
|
|
|
21ab4e |
--- a/libglusterfs/src/glusterfs.h
|
|
|
21ab4e |
+++ b/libglusterfs/src/glusterfs.h
|
|
|
21ab4e |
@@ -233,9 +233,6 @@
|
|
|
21ab4e |
#define GF_REPLICATE_TRASH_DIR ".landfill"
|
|
|
21ab4e |
|
|
|
21ab4e |
/* GlusterFS's maximum supported Auxiliary GIDs */
|
|
|
21ab4e |
-/* TODO: Keeping it to 200, so that we can fit in 2KB buffer for auth data
|
|
|
21ab4e |
- * in RPC server code, if there is ever need for having more aux-gids, then
|
|
|
21ab4e |
- * we have to add aux-gid in payload of actors */
|
|
|
21ab4e |
#define GF_MAX_AUX_GROUPS 65535
|
|
|
21ab4e |
|
|
|
21ab4e |
#define GF_UUID_BUF_SIZE 50
|
|
|
21ab4e |
diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h
|
|
|
21ab4e |
index be7e900..c2848b7 100644
|
|
|
21ab4e |
--- a/libglusterfs/src/stack.h
|
|
|
21ab4e |
+++ b/libglusterfs/src/stack.h
|
|
|
21ab4e |
@@ -422,21 +422,26 @@ STACK_RESET (call_stack_t *stack)
|
|
|
21ab4e |
} while (0)
|
|
|
21ab4e |
|
|
|
21ab4e |
|
|
|
21ab4e |
+static void
|
|
|
21ab4e |
+call_stack_set_groups (call_stack_t *stack, int ngrps, gid_t *groupbuf)
|
|
|
21ab4e |
+{
|
|
|
21ab4e |
+ stack->groups = groupbuf;
|
|
|
21ab4e |
+ stack->ngrps = ngrps;
|
|
|
21ab4e |
+}
|
|
|
21ab4e |
+
|
|
|
21ab4e |
static inline int
|
|
|
21ab4e |
call_stack_alloc_groups (call_stack_t *stack, int ngrps)
|
|
|
21ab4e |
{
|
|
|
21ab4e |
if (ngrps <= SMALL_GROUP_COUNT) {
|
|
|
21ab4e |
- stack->groups = stack->groups_small;
|
|
|
21ab4e |
+ call_stack_set_groups (stack, ngrps, stack->groups_small);
|
|
|
21ab4e |
} else {
|
|
|
21ab4e |
- stack->groups_large = GF_CALLOC (sizeof (gid_t), ngrps,
|
|
|
21ab4e |
+ stack->groups_large = GF_CALLOC (ngrps, sizeof (gid_t),
|
|
|
21ab4e |
gf_common_mt_groups_t);
|
|
|
21ab4e |
if (!stack->groups_large)
|
|
|
21ab4e |
return -1;
|
|
|
21ab4e |
- stack->groups = stack->groups_large;
|
|
|
21ab4e |
+ call_stack_set_groups (stack, ngrps, stack->groups_large);
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
- stack->ngrps = ngrps;
|
|
|
21ab4e |
-
|
|
|
21ab4e |
return 0;
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
diff --git a/xlators/mount/fuse/src/fuse-helpers.c b/xlators/mount/fuse/src/fuse-helpers.c
|
|
|
21ab4e |
index 3e54197..5ccb0a5 100644
|
|
|
21ab4e |
--- a/xlators/mount/fuse/src/fuse-helpers.c
|
|
|
21ab4e |
+++ b/xlators/mount/fuse/src/fuse-helpers.c
|
|
|
21ab4e |
@@ -20,7 +20,6 @@
|
|
|
21ab4e |
#include <sys/sysctl.h>
|
|
|
21ab4e |
#endif
|
|
|
21ab4e |
#include <pwd.h>
|
|
|
21ab4e |
-#include <grp.h>
|
|
|
21ab4e |
|
|
|
21ab4e |
#include "fuse-bridge.h"
|
|
|
21ab4e |
|
|
|
21ab4e |
@@ -158,8 +157,8 @@ frame_fill_groups (call_frame_t *frame)
|
|
|
21ab4e |
char *saveptr = NULL;
|
|
|
21ab4e |
char *endptr = NULL;
|
|
|
21ab4e |
int ret = 0;
|
|
|
21ab4e |
- int ngroups = FUSE_MAX_AUX_GROUPS;
|
|
|
21ab4e |
- gid_t mygroups[GF_MAX_AUX_GROUPS];
|
|
|
21ab4e |
+ int ngroups = 0;
|
|
|
21ab4e |
+ gid_t *mygroups = NULL;
|
|
|
21ab4e |
|
|
|
21ab4e |
if (priv->resolve_gids) {
|
|
|
21ab4e |
struct passwd pwent;
|
|
|
21ab4e |
@@ -173,23 +172,16 @@ frame_fill_groups (call_frame_t *frame)
|
|
|
21ab4e |
return;
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
- ngroups = GF_MAX_AUX_GROUPS;
|
|
|
21ab4e |
- if (getgrouplist (result->pw_name, frame->root->gid, mygroups,
|
|
|
21ab4e |
- &ngroups) == -1) {
|
|
|
21ab4e |
+ ngroups = gf_getgrouplist (result->pw_name, frame->root->gid,
|
|
|
21ab4e |
+ &mygroups);
|
|
|
21ab4e |
+ if (ngroups == -1) {
|
|
|
21ab4e |
gf_log (this->name, GF_LOG_ERROR, "could not map %s to "
|
|
|
21ab4e |
"group list (ngroups %d, max %d)",
|
|
|
21ab4e |
result->pw_name, ngroups, GF_MAX_AUX_GROUPS);
|
|
|
21ab4e |
return;
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
- if (call_stack_alloc_groups (frame->root, ngroups) != 0)
|
|
|
21ab4e |
- goto out;
|
|
|
21ab4e |
-
|
|
|
21ab4e |
- /* Copy data to the frame. */
|
|
|
21ab4e |
- for (idx = 0; idx < ngroups; ++idx) {
|
|
|
21ab4e |
- frame->root->groups[idx] = mygroups[idx];
|
|
|
21ab4e |
- }
|
|
|
21ab4e |
- frame->root->ngrps = ngroups;
|
|
|
21ab4e |
+ call_stack_set_groups (frame->root, ngroups, mygroups);
|
|
|
21ab4e |
} else {
|
|
|
21ab4e |
ret = snprintf (filename, sizeof filename, "/proc/%d/status",
|
|
|
21ab4e |
frame->root->pid);
|
|
|
21ab4e |
diff --git a/xlators/nfs/server/src/nfs-fops.c b/xlators/nfs/server/src/nfs-fops.c
|
|
|
21ab4e |
index f6361f0..28b1781 100644
|
|
|
21ab4e |
--- a/xlators/nfs/server/src/nfs-fops.c
|
|
|
21ab4e |
+++ b/xlators/nfs/server/src/nfs-fops.c
|
|
|
21ab4e |
@@ -8,7 +8,6 @@
|
|
|
21ab4e |
cases as published by the Free Software Foundation.
|
|
|
21ab4e |
*/
|
|
|
21ab4e |
|
|
|
21ab4e |
-#include <grp.h>
|
|
|
21ab4e |
#include <pwd.h>
|
|
|
21ab4e |
|
|
|
21ab4e |
#include "dict.h"
|
|
|
21ab4e |
@@ -34,12 +33,7 @@ nfs_fix_groups (xlator_t *this, call_stack_t *root)
|
|
|
21ab4e |
struct passwd mypw;
|
|
|
21ab4e |
char mystrs[1024];
|
|
|
21ab4e |
struct passwd *result;
|
|
|
21ab4e |
-#ifdef GF_DARWIN_HOST_OS
|
|
|
21ab4e |
- /* BSD/DARWIN does not correctly uses gid_t in getgrouplist */
|
|
|
21ab4e |
- int mygroups[GF_MAX_AUX_GROUPS];
|
|
|
21ab4e |
-#else
|
|
|
21ab4e |
- gid_t mygroups[GF_MAX_AUX_GROUPS];
|
|
|
21ab4e |
-#endif
|
|
|
21ab4e |
+ gid_t *mygroups;
|
|
|
21ab4e |
int ngroups;
|
|
|
21ab4e |
int i;
|
|
|
21ab4e |
int max_groups;
|
|
|
21ab4e |
@@ -88,25 +82,13 @@ nfs_fix_groups (xlator_t *this, call_stack_t *root)
|
|
|
21ab4e |
gf_msg_trace (this->name, 0, "mapped %u => %s",
|
|
|
21ab4e |
root->uid, result->pw_name);
|
|
|
21ab4e |
|
|
|
21ab4e |
- ngroups = GF_MAX_AUX_GROUPS;
|
|
|
21ab4e |
- if (getgrouplist(result->pw_name,root->gid,mygroups,&ngroups) == -1) {
|
|
|
21ab4e |
+ ngroups = gf_getgrouplist (result->pw_name, root->gid, &mygroups);
|
|
|
21ab4e |
+ if (ngroups == -1) {
|
|
|
21ab4e |
gf_msg (this->name, GF_LOG_ERROR, 0, NFS_MSG_MAP_GRP_LIST_FAIL,
|
|
|
21ab4e |
"could not map %s to group list", result->pw_name);
|
|
|
21ab4e |
return;
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
- /* Add the group data to the cache. */
|
|
|
21ab4e |
- gl.gl_list = GF_CALLOC(ngroups, sizeof(gid_t), gf_nfs_mt_aux_gids);
|
|
|
21ab4e |
- if (gl.gl_list) {
|
|
|
21ab4e |
- /* It's not fatal if the alloc failed. */
|
|
|
21ab4e |
- gl.gl_id = root->uid;
|
|
|
21ab4e |
- gl.gl_uid = 0;
|
|
|
21ab4e |
- gl.gl_gid = 0;
|
|
|
21ab4e |
- gl.gl_count = ngroups;
|
|
|
21ab4e |
- memcpy(gl.gl_list, mygroups, sizeof(gid_t) * ngroups);
|
|
|
21ab4e |
- if (gid_cache_add(&priv->gid_cache, &gl) != 1)
|
|
|
21ab4e |
- GF_FREE(gl.gl_list);
|
|
|
21ab4e |
- }
|
|
|
21ab4e |
|
|
|
21ab4e |
/* RPC enforces the GF_AUTH_GLUSTERFS_MAX_GROUPS limit */
|
|
|
21ab4e |
if (ngroups > max_groups) {
|
|
|
21ab4e |
@@ -115,16 +97,24 @@ nfs_fix_groups (xlator_t *this, call_stack_t *root)
|
|
|
21ab4e |
"too many groups, reducing %d -> %d",
|
|
|
21ab4e |
ngroups, max_groups);
|
|
|
21ab4e |
|
|
|
21ab4e |
- ngroups = max_groups;
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
/* Copy data to the frame. */
|
|
|
21ab4e |
- for (i = 0; i < ngroups; ++i) {
|
|
|
21ab4e |
+ for (i = 0; i < ngroups && i < max_groups; ++i) {
|
|
|
21ab4e |
gf_msg_trace (this->name, 0, "%s is in group %u",
|
|
|
21ab4e |
result->pw_name, mygroups[i]);
|
|
|
21ab4e |
root->groups[i] = mygroups[i];
|
|
|
21ab4e |
}
|
|
|
21ab4e |
root->ngrps = ngroups;
|
|
|
21ab4e |
+
|
|
|
21ab4e |
+ /* Add the group data to the cache. */
|
|
|
21ab4e |
+ gl.gl_list = mygroups;
|
|
|
21ab4e |
+ gl.gl_id = root->uid;
|
|
|
21ab4e |
+ gl.gl_uid = 0;
|
|
|
21ab4e |
+ gl.gl_gid = 0;
|
|
|
21ab4e |
+ gl.gl_count = ngroups;
|
|
|
21ab4e |
+ if (gid_cache_add(&priv->gid_cache, &gl) != 1)
|
|
|
21ab4e |
+ GF_FREE(mygroups);
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
struct nfs_fop_local *
|
|
|
21ab4e |
diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c
|
|
|
21ab4e |
index 590662b..3ad3d84 100644
|
|
|
21ab4e |
--- a/xlators/protocol/server/src/server-helpers.c
|
|
|
21ab4e |
+++ b/xlators/protocol/server/src/server-helpers.c
|
|
|
21ab4e |
@@ -19,7 +19,6 @@
|
|
|
21ab4e |
|
|
|
21ab4e |
#include <fnmatch.h>
|
|
|
21ab4e |
#include <pwd.h>
|
|
|
21ab4e |
-#include <grp.h>
|
|
|
21ab4e |
#include "compound-fop-utils.h"
|
|
|
21ab4e |
|
|
|
21ab4e |
/* based on nfs_fix_aux_groups() */
|
|
|
21ab4e |
@@ -30,10 +29,10 @@ gid_resolve (server_conf_t *conf, call_stack_t *root)
|
|
|
21ab4e |
struct passwd mypw;
|
|
|
21ab4e |
char mystrs[1024];
|
|
|
21ab4e |
struct passwd *result;
|
|
|
21ab4e |
- gid_t mygroups[GF_MAX_AUX_GROUPS];
|
|
|
21ab4e |
+ gid_t *mygroups;
|
|
|
21ab4e |
gid_list_t gl;
|
|
|
21ab4e |
const gid_list_t *agl;
|
|
|
21ab4e |
- int ngroups, i;
|
|
|
21ab4e |
+ int ngroups;
|
|
|
21ab4e |
|
|
|
21ab4e |
agl = gid_cache_lookup (&conf->gid_cache, root->uid, 0, 0);
|
|
|
21ab4e |
if (agl) {
|
|
|
21ab4e |
@@ -58,9 +57,8 @@ gid_resolve (server_conf_t *conf, call_stack_t *root)
|
|
|
21ab4e |
gf_msg_trace ("gid-cache", 0, "mapped %u => %s", root->uid,
|
|
|
21ab4e |
result->pw_name);
|
|
|
21ab4e |
|
|
|
21ab4e |
- ngroups = GF_MAX_AUX_GROUPS;
|
|
|
21ab4e |
- ret = getgrouplist (result->pw_name, root->gid, mygroups, &ngroups);
|
|
|
21ab4e |
- if (ret == -1) {
|
|
|
21ab4e |
+ ngroups = gf_getgrouplist (result->pw_name, root->gid, &mygroups);
|
|
|
21ab4e |
+ if (ngroups == -1) {
|
|
|
21ab4e |
gf_msg ("gid-cache", GF_LOG_ERROR, 0, PS_MSG_MAPPING_ERROR,
|
|
|
21ab4e |
"could not map %s to group list (%d gids)",
|
|
|
21ab4e |
result->pw_name, root->ngrps);
|
|
|
21ab4e |
@@ -84,8 +82,10 @@ fill_groups:
|
|
|
21ab4e |
if (gl.gl_list)
|
|
|
21ab4e |
memcpy (gl.gl_list, mygroups,
|
|
|
21ab4e |
sizeof(gid_t) * root->ngrps);
|
|
|
21ab4e |
- else
|
|
|
21ab4e |
+ else {
|
|
|
21ab4e |
+ GF_FREE (mygroups);
|
|
|
21ab4e |
return -1;
|
|
|
21ab4e |
+ }
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
if (root->ngrps == 0) {
|
|
|
21ab4e |
@@ -93,14 +93,7 @@ fill_groups:
|
|
|
21ab4e |
goto out;
|
|
|
21ab4e |
}
|
|
|
21ab4e |
|
|
|
21ab4e |
- if (call_stack_alloc_groups (root, root->ngrps) != 0) {
|
|
|
21ab4e |
- ret = -1;
|
|
|
21ab4e |
- goto out;
|
|
|
21ab4e |
- }
|
|
|
21ab4e |
-
|
|
|
21ab4e |
- /* finally fill the groups from the */
|
|
|
21ab4e |
- for (i = 0; i < root->ngrps; ++i)
|
|
|
21ab4e |
- root->groups[i] = gl.gl_list[i];
|
|
|
21ab4e |
+ call_stack_set_groups (root, root->ngrps, mygroups);
|
|
|
21ab4e |
|
|
|
21ab4e |
out:
|
|
|
21ab4e |
if (agl) {
|
|
|
21ab4e |
--
|
|
|
21ab4e |
1.8.3.1
|
|
|
21ab4e |
|