summaryrefslogtreecommitdiff
path: root/source3/groupdb
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-02-03 00:49:24 +0000
committerLuke Leighton <lkcl@samba.org>1999-02-03 00:49:24 +0000
commit1153f00f889e5bb310e895d319eed75bc93deef4 (patch)
tree992b761fc48443b56324b1403708d4d0ff22c813 /source3/groupdb
parentfe609d810e145d5491968fee5d691d6eee41e152 (diff)
downloadsamba-1153f00f889e5bb310e895d319eed75bc93deef4.tar.gz
samba-1153f00f889e5bb310e895d319eed75bc93deef4.tar.bz2
samba-1153f00f889e5bb310e895d319eed75bc93deef4.zip
cache unix groups so that two-level getgrent calls don't occur.
(This used to be commit f7dfa55a2e191ae780d399026bce48f68cda4bf0)
Diffstat (limited to 'source3/groupdb')
-rw-r--r--source3/groupdb/aliasunix.c50
-rw-r--r--source3/groupdb/builtinunix.c64
-rw-r--r--source3/groupdb/groupunix.c55
3 files changed, 146 insertions, 23 deletions
diff --git a/source3/groupdb/aliasunix.c b/source3/groupdb/aliasunix.c
index f9537ddeb4..39d7255ac5 100644
--- a/source3/groupdb/aliasunix.c
+++ b/source3/groupdb/aliasunix.c
@@ -27,6 +27,13 @@ extern int DEBUGLEVEL;
extern DOM_SID global_sam_sid;
extern fstring global_sam_name;
+struct unix_entries
+{
+ struct group *grps;
+ int num_grps;
+ int grp_idx;
+};
+
/***************************************************************
Start to enumerate the alspasswd list. Returns a void pointer
to ensure no modification outside this module.
@@ -34,8 +41,23 @@ extern fstring global_sam_name;
static void *startalsunixpwent(BOOL update)
{
- setgrent();
- return (void*)(-1);
+ struct unix_entries *grps;
+ grps = (struct unix_entries*)malloc(sizeof(struct unix_entries));
+
+ if (grps == NULL)
+ {
+ return NULL;
+ }
+
+ if (!get_unix_grps(&grps->num_grps, &grps->grps))
+ {
+ free(grps);
+ return NULL;
+ }
+
+ grps->grp_idx = 0;
+
+ return (void*)grps;
}
/***************************************************************
@@ -44,7 +66,13 @@ static void *startalsunixpwent(BOOL update)
static void endalsunixpwent(void *vp)
{
- endgrent();
+ struct unix_entries *grps = (struct unix_entries *)vp;
+
+ if (grps != NULL)
+ {
+ free_unix_grps(grps->num_grps, grps->grps);
+ free(vp);
+ }
}
/*************************************************************************
@@ -142,7 +170,8 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
{
/* Static buffers we will return. */
static LOCAL_GRP gp_buf;
- struct group *unix_grp;
+ struct group *unix_grp = NULL;
+ struct unix_entries *grps = (struct unix_entries *)vp;
if (lp_server_role() == ROLE_DOMAIN_NONE)
{
@@ -156,11 +185,18 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
aldb_init_als(&gp_buf);
+ /* get array of unix names + gids. this function does NOT
+ get a copy of the unix group members
+ */
+
/* cycle through unix groups */
- while ((unix_grp = getgrent()) != NULL)
+ for (; grps->grp_idx < grps->num_grps; grps->grp_idx++)
{
DOM_NAME_MAP gmep;
fstring sid_str;
+
+ unix_grp = &grps->grps[grps->grp_idx];
+
DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
unix_grp->gr_name));
@@ -185,10 +221,11 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
}
fstrcpy(gp_buf.name, gmep.nt_name);
+ grps->grp_idx++;
break;
}
- if (unix_grp == NULL)
+ if (unix_grp == NULL || grps->grp_idx >= grps->num_grps)
{
return NULL;
}
@@ -200,6 +237,7 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
(*mem) = NULL;
(*num_mem) = 0;
+ unix_grp = getgrgid(unix_grp->gr_gid);
get_unixalias_members(unix_grp, num_mem, mem);
}
diff --git a/source3/groupdb/builtinunix.c b/source3/groupdb/builtinunix.c
index c8ea767a77..bb45f2983f 100644
--- a/source3/groupdb/builtinunix.c
+++ b/source3/groupdb/builtinunix.c
@@ -23,6 +23,12 @@
extern int DEBUGLEVEL;
+struct unix_entries
+{
+ struct group *grps;
+ int num_grps;
+ int grp_idx;
+};
extern DOM_SID global_sid_S_1_5_20;
extern DOM_SID global_sam_sid;
@@ -35,8 +41,23 @@ extern fstring global_sam_name;
static void *startbltunixpwent(BOOL update)
{
- setgrent();
- return (void*)(-1);
+ struct unix_entries *grps;
+ grps = (struct unix_entries*)malloc(sizeof(struct unix_entries));
+
+ if (grps == NULL)
+ {
+ return NULL;
+ }
+
+ if (!get_unix_grps(&grps->num_grps, &grps->grps))
+ {
+ free(grps);
+ return NULL;
+ }
+
+ grps->grp_idx = 0;
+
+ return (void*)grps;
}
/***************************************************************
@@ -45,7 +66,13 @@ static void *startbltunixpwent(BOOL update)
static void endbltunixpwent(void *vp)
{
- endgrent();
+ struct unix_entries *grps = (struct unix_entries *)vp;
+
+ if (grps != NULL)
+ {
+ free_unix_grps(grps->num_grps, grps->grps);
+ free(vp);
+ }
}
/*************************************************************************
@@ -143,12 +170,18 @@ static LOCAL_GRP *getbltunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
{
/* Static buffers we will return. */
static LOCAL_GRP gp_buf;
- struct group *unix_grp;
+ struct group *unix_grp = NULL;
+ struct unix_entries *grps = (struct unix_entries *)vp;
+
+ if (grps == NULL)
+ {
+ return NULL;
+ }
if (lp_server_role() == ROLE_DOMAIN_NONE)
{
/*
- * no domain role, no domain builtin aliases (or domain groups,
+ * no domain role, no domain aliases (or domain groups,
* but that's dealt with by groupdb...).
*/
@@ -157,12 +190,19 @@ static LOCAL_GRP *getbltunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
bidb_init_blt(&gp_buf);
+ /* get array of unix names + gids. this function does NOT
+ get a copy of the unix group members
+ */
+
/* cycle through unix groups */
- while ((unix_grp = getgrent()) != NULL)
+ for (; grps->grp_idx < grps->num_grps; grps->grp_idx++)
{
DOM_NAME_MAP gmep;
fstring sid_str;
- DEBUG(10,("getbltunixpwent: enum unix group entry %s\n",
+
+ unix_grp = &grps->grps[grps->grp_idx];
+
+ DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
unix_grp->gr_name));
if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
@@ -180,33 +220,35 @@ static LOCAL_GRP *getbltunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
}
sid_split_rid(&gmep.sid, &gp_buf.rid);
- if (!sid_equal(&global_sid_S_1_5_20, &gmep.sid))
+ if (!sid_equal(&global_sam_sid, &gmep.sid))
{
continue;
}
fstrcpy(gp_buf.name, gmep.nt_name);
+ grps->grp_idx++;
break;
}
- if (unix_grp == NULL)
+ if (unix_grp == NULL || grps->grp_idx >= grps->num_grps)
{
return NULL;
}
- /* get the user's domain builtin aliases. there are a maximum of 32 */
+ /* get the user's domain aliases. there are a maximum of 32 */
if (mem != NULL && num_mem != NULL)
{
(*mem) = NULL;
(*num_mem) = 0;
+ unix_grp = getgrgid(unix_grp->gr_gid);
get_unixbuiltin_members(unix_grp, num_mem, mem);
}
{
pstring linebuf;
- make_builtin_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
+ make_alias_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
DEBUG(10,("line: '%s'\n", linebuf));
}
diff --git a/source3/groupdb/groupunix.c b/source3/groupdb/groupunix.c
index 35f386cbf8..a8f40a313a 100644
--- a/source3/groupdb/groupunix.c
+++ b/source3/groupdb/groupunix.c
@@ -31,10 +31,32 @@ extern DOM_SID global_sam_sid;
to ensure no modification outside this module.
****************************************************************/
+struct unix_entries
+{
+ struct group *grps;
+ int num_grps;
+ int grp_idx;
+};
+
static void *startgrpunixpwent(BOOL update)
{
- setgrent();
- return (void*)(-1);
+ struct unix_entries *grps;
+ grps = (struct unix_entries*)malloc(sizeof(struct unix_entries));
+
+ if (grps == NULL)
+ {
+ return NULL;
+ }
+
+ if (!get_unix_grps(&grps->num_grps, &grps->grps))
+ {
+ free(grps);
+ return NULL;
+ }
+
+ grps->grp_idx = 0;
+
+ return (void*)grps;
}
/***************************************************************
@@ -43,7 +65,13 @@ static void *startgrpunixpwent(BOOL update)
static void endgrpunixpwent(void *vp)
{
- endgrent();
+ struct unix_entries *grps = (struct unix_entries *)vp;
+
+ if (grps != NULL)
+ {
+ free_unix_grps(grps->num_grps, grps->grps);
+ free(vp);
+ }
}
/*************************************************************************
@@ -142,7 +170,13 @@ static DOMAIN_GRP *getgrpunixpwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_m
{
/* Static buffers we will return. */
static DOMAIN_GRP gp_buf;
- struct group *unix_grp;
+ struct group *unix_grp = NULL;
+ struct unix_entries *grps = (struct unix_entries *)vp;
+
+ if (grps == NULL)
+ {
+ return NULL;
+ }
if (lp_server_role() == ROLE_DOMAIN_NONE ||
lp_server_role() == ROLE_DOMAIN_MEMBER)
@@ -161,10 +195,17 @@ static DOMAIN_GRP *getgrpunixpwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_m
fstrcpy(gp_buf.comment, "");
gp_buf.attr = 0x07;
+ /* get array of unix names + gids. this function does NOT
+ get a copy of the unix group members
+ */
+
/* cycle through unix groups */
- while ((unix_grp = getgrent()) != NULL)
+ for (; grps->grp_idx < grps->num_grps; grps->grp_idx++)
{
DOM_NAME_MAP gmep;
+
+ unix_grp = &grps->grps[grps->grp_idx];
+
DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
unix_grp->gr_name));
@@ -186,10 +227,11 @@ static DOMAIN_GRP *getgrpunixpwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_m
}
fstrcpy(gp_buf.name, gmep.nt_name);
+ grps->grp_idx++;
break;
}
- if (unix_grp == NULL)
+ if (unix_grp == NULL || grps->grp_idx >= grps->num_grps)
{
return NULL;
}
@@ -201,6 +243,7 @@ static DOMAIN_GRP *getgrpunixpwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_m
(*mem) = NULL;
(*num_mem) = 0;
+ unix_grp = getgrgid(unix_grp->gr_gid);
get_unixgroup_members(unix_grp, num_mem, mem);
}