summaryrefslogtreecommitdiff
path: root/source3/groupdb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/groupdb')
-rw-r--r--source3/groupdb/aliasdb.c147
-rw-r--r--source3/groupdb/aliasfile.c111
-rw-r--r--source3/groupdb/groupdb.c143
-rw-r--r--source3/groupdb/groupfile.c110
4 files changed, 160 insertions, 351 deletions
diff --git a/source3/groupdb/aliasdb.c b/source3/groupdb/aliasdb.c
index b787012b4d..e5e6ebfa53 100644
--- a/source3/groupdb/aliasdb.c
+++ b/source3/groupdb/aliasdb.c
@@ -26,14 +26,13 @@
extern int DEBUGLEVEL;
extern fstring global_sam_name;
-extern DOM_SID global_sam_sid;
/*
* NOTE. All these functions are abstracted into a structure
* that points to the correct function for the selected database. JRA.
*/
-static struct aliasdb_ops *aldb_ops = NULL;
+static struct aliasdb_ops *aldb_ops;
/***************************************************************
Initialise the alias db operations.
@@ -50,8 +49,8 @@ BOOL initialise_alias_db(void)
aldb_ops = nisplus_initialise_alias_db();
#elif defined(WITH_LDAP)
aldb_ops = ldap_initialise_alias_db();
-#elif defined(USE_SMBUNIX_DB)
- aldb_ops = unix_initialise_alias_db();
+#else
+ aldb_ops = file_initialise_alias_db();
#endif
return (aldb_ops != NULL);
@@ -68,28 +67,7 @@ BOOL initialise_alias_db(void)
*************************************************************************/
LOCAL_GRP *iterate_getaliasgid(gid_t gid, LOCAL_GRP_MEMBER **mem, int *num_mem)
{
- DOM_NAME_MAP gmep;
- uint32 rid;
- if (!lookupsmbgrpgid(gid, &gmep))
- {
- DEBUG(0,("iterate_getaliasgid: gid %d does not map to one of our Domain's Aliases\n", gid));
- return NULL;
- }
-
- if (gmep.type != SID_NAME_ALIAS )
- {
- DEBUG(0,("iterate_getaliasgid: gid %d does not map to one of our Domain's Aliases\n", gid));
- return NULL;
- }
-
- sid_split_rid(&gmep.sid, &rid);
- if (!sid_equal(&gmep.sid, &global_sam_sid))
- {
- DEBUG(0,("iterate_getaliasgid: gid %d does not map into our Domain SID\n", gid));
- return NULL;
- }
-
- return iterate_getaliasrid(rid, mem, num_mem);
+ return iterate_getaliasrid(pwdb_gid_to_alias_rid(gid), mem, num_mem);
}
/************************************************************************
@@ -114,7 +92,6 @@ LOCAL_GRP *iterate_getaliasrid(uint32 rid, LOCAL_GRP_MEMBER **mem, int *num_mem)
while ((als = getaliasent(fp, mem, num_mem)) != NULL && als->rid != rid)
{
- DEBUG(10,("iterate: %s 0x%x", als->name, als->rid));
}
if (als != NULL)
@@ -130,7 +107,7 @@ LOCAL_GRP *iterate_getaliasrid(uint32 rid, LOCAL_GRP_MEMBER **mem, int *num_mem)
Utility function to search alias database by name. use this if your database
does not have search facilities.
*************************************************************************/
-LOCAL_GRP *iterate_getaliasntnam(const char *name, LOCAL_GRP_MEMBER **mem, int *num_mem)
+LOCAL_GRP *iterate_getaliasnam(char *name, LOCAL_GRP_MEMBER **mem, int *num_mem)
{
LOCAL_GRP *als = NULL;
void *fp = NULL;
@@ -189,11 +166,11 @@ BOOL add_domain_alias(LOCAL_GRP **alss, int *num_alss, LOCAL_GRP *als)
/*************************************************************************
checks to see if a user is a member of a domain alias
*************************************************************************/
-static BOOL user_is_member(const char *user_name, LOCAL_GRP_MEMBER *mem, int num_mem)
+static BOOL user_is_member(char *user_name, LOCAL_GRP_MEMBER *mem, int num_mem)
{
int i;
pstring name;
- slprintf(name, sizeof(name)-1, "%s\\%s", global_sam_name, user_name);
+ slprintf(name, sizeof(name)-1, "\\%s\\%s", global_sam_name, user_name);
for (i = 0; i < num_mem; i++)
{
@@ -212,16 +189,16 @@ static BOOL user_is_member(const char *user_name, LOCAL_GRP_MEMBER *mem, int num
gets an array of aliases that a user is in. use this if your database
does not have search facilities
*************************************************************************/
-BOOL iterate_getuseraliasntnam(const char *user_name, LOCAL_GRP **alss, int *num_alss)
+BOOL iterate_getuseraliasnam(char *user_name, LOCAL_GRP **alss, int *num_alss)
{
- LOCAL_GRP *als = NULL;
+ LOCAL_GRP *als;
LOCAL_GRP_MEMBER *mem = NULL;
int num_mem = 0;
void *fp = NULL;
DEBUG(10, ("search for useralias by name: %s\n", user_name));
- if (user_name == NULL || alss == NULL || num_alss == NULL)
+ if (user_name == NULL || als == NULL || num_alss == NULL)
{
return False;
}
@@ -277,12 +254,12 @@ BOOL iterate_getuseraliasntnam(const char *user_name, LOCAL_GRP **alss, int *num
*************************************************************************/
BOOL enumdomaliases(LOCAL_GRP **alss, int *num_alss)
{
- LOCAL_GRP *als = NULL;
+ LOCAL_GRP *als;
void *fp = NULL;
DEBUG(10, ("enum user aliases\n"));
- if (alss == NULL || num_alss == NULL)
+ if (als == NULL || num_alss == NULL)
{
return False;
}
@@ -348,25 +325,11 @@ LOCAL_GRP *getaliasent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem)
/************************************************************************
Routine to add an entry to the alias database file.
- on entry, the entry is added by name.
- on exit, the RID is expected to have been set.
*************************************************************************/
-BOOL add_alias_entry(LOCAL_GRP *newgrp)
-{
- BOOL ret;
- if (newgrp->rid != 0xffffffff)
+
+BOOL add_alias_entry(LOCAL_GRP *newals)
{
- DEBUG(0,("add_alias_entry - RID must be 0xffffffff, \
-database instance is responsible for allocating the RID, not you.\n"));
- return False;
- }
- ret = aldb_ops->add_alias_entry(newgrp);
- if (newgrp->rid == 0xffffffff)
- {
- DEBUG(0,("add_alias_entry - RID has not been set by database\n"));
- return False;
- }
- return ret;
+ return aldb_ops->add_alias_entry(newals);
}
/************************************************************************
@@ -380,35 +343,12 @@ BOOL mod_alias_entry(LOCAL_GRP* als)
}
/************************************************************************
- Routine to delete alias database entry matching by rid.
-************************************************************************/
-BOOL del_alias_entry(uint32 rid)
-{
- return aldb_ops->del_alias_entry(rid);
-}
-
-/************************************************************************
- Routine to add a member to an entry in the alias database file.
-*************************************************************************/
-BOOL add_alias_member(uint32 rid, DOM_SID *member_sid)
-{
- return aldb_ops->add_alias_member(rid, member_sid);
-}
-
-/************************************************************************
- Routine to delete a member from an entry in the alias database file.
-*************************************************************************/
-BOOL del_alias_member(uint32 rid, DOM_SID *member_sid)
-{
- return aldb_ops->del_alias_member(rid, member_sid);
-}
-/************************************************************************
Routine to search alias database by name.
*************************************************************************/
-LOCAL_GRP *getaliasntnam(const char *name, LOCAL_GRP_MEMBER **mem, int *num_mem)
+LOCAL_GRP *getaliasnam(char *name, LOCAL_GRP_MEMBER **mem, int *num_mem)
{
- return aldb_ops->getaliasntnam(name, mem, num_mem);
+ return aldb_ops->getaliasnam(name, mem, num_mem);
}
/************************************************************************
@@ -432,65 +372,18 @@ LOCAL_GRP *getaliasgid(gid_t gid, LOCAL_GRP_MEMBER **mem, int *num_mem)
/*************************************************************************
gets an array of aliases that a user is in.
*************************************************************************/
-BOOL getuseraliasntnam(const char *user_name, LOCAL_GRP **als, int *num_alss)
+BOOL getuseraliasnam(char *user_name, LOCAL_GRP **als, int *num_alss)
{
- return aldb_ops->getuseraliasntnam(user_name, als, num_alss);
+ return aldb_ops->getuseraliasnam(user_name, als, num_alss);
}
/*************************************************************
initialises a LOCAL_GRP.
**************************************************************/
+
void aldb_init_als(LOCAL_GRP *als)
{
if (als == NULL) return;
ZERO_STRUCTP(als);
}
-/*************************************************************
- turns an alias entry into a string.
- **************************************************************/
-BOOL make_alias_line(char *p, int max_len,
- LOCAL_GRP *als,
- LOCAL_GRP_MEMBER **mem, int *num_mem)
-{
- int i;
- int len;
- len = slprintf(p, max_len-1, "%s:%s:%d:", als->name, als->comment, als->rid);
-
- if (len == -1)
- {
- DEBUG(0,("make_alias_line: cannot create entry\n"));
- return False;
- }
-
- p += len;
- max_len -= len;
-
- if (mem == NULL || num_mem == NULL)
- {
- return True;
- }
-
- for (i = 0; i < (*num_mem); i++)
- {
- len = strlen((*mem)[i].name);
- p = safe_strcpy(p, (*mem)[i].name, max_len);
-
- if (p == NULL)
- {
- DEBUG(0, ("make_alias_line: out of space for aliases!\n"));
- return False;
- }
-
- max_len -= len;
-
- if (i != (*num_mem)-1)
- {
- *p = ',';
- p++;
- max_len--;
- }
- }
-
- return True;
-}
diff --git a/source3/groupdb/aliasfile.c b/source3/groupdb/aliasfile.c
index c09d6cc23e..4b8bbe3079 100644
--- a/source3/groupdb/aliasfile.c
+++ b/source3/groupdb/aliasfile.c
@@ -19,7 +19,7 @@
#include "includes.h"
-#ifdef USE_SMBGROUP_DB
+#ifdef USE_SMBPASS_DB
static int al_file_lock_depth = 0;
extern int DEBUGLEVEL;
@@ -33,7 +33,7 @@ static char s_readbuf[1024];
static void *startalsfilepwent(BOOL update)
{
- return startfileent(lp_smb_alias_file(),
+ return startfilepwent(lp_smb_alias_file(),
s_readbuf, sizeof(s_readbuf),
&al_file_lock_depth, update);
}
@@ -44,7 +44,7 @@ static void *startalsfilepwent(BOOL update)
static void endalsfilepwent(void *vp)
{
- endfileent(vp, &al_file_lock_depth);
+ endfilepwent(vp, &al_file_lock_depth);
}
/*************************************************************************
@@ -65,6 +65,51 @@ static BOOL setalsfilepwpos(void *vp, SMB_BIG_UINT tok)
return setfilepwpos(vp, tok);
}
+static BOOL make_alias_line(char *p, int max_len,
+ LOCAL_GRP *als,
+ LOCAL_GRP_MEMBER **mem, int *num_mem)
+{
+ int i;
+ int len;
+ len = slprintf(p, max_len-1, "%s:%s:%d:", als->name, als->comment, als->rid);
+
+ if (len == -1)
+ {
+ DEBUG(0,("make_alias_line: cannot create entry\n"));
+ return False;
+ }
+
+ p += len;
+ max_len -= len;
+
+ if (mem == NULL || num_mem == NULL)
+ {
+ return True;
+ }
+
+ for (i = 0; i < (*num_mem); i++)
+ {
+ len = strlen((*mem)[i].name);
+ p = safe_strcpy(p, (*mem)[i].name, max_len);
+
+ if (p == NULL)
+ {
+ DEBUG(0, ("make_alias_line: out of space for aliases!\n"));
+ return False;
+ }
+
+ max_len -= len;
+
+ if (i != (*num_mem)-1)
+ {
+ *p = ',';
+ p++;
+ max_len--;
+ }
+ }
+
+ return True;
+}
/*************************************************************************
Routine to return the next entry in the smbdomainalias list.
@@ -85,36 +130,24 @@ static char *get_alias_members(char *p, int *num_mem, LOCAL_GRP_MEMBER **members
{
DOM_SID sid;
uint8 type;
- BOOL found = False;
- if (strnequal(name, "S-", 2))
+ if (lookup_sid(name, &sid, &type))
{
- /* sid entered directly */
- string_to_sid(&sid, name);
- found = lookup_sid(&sid, name, &type) == 0x0;
+ (*members) = Realloc((*members), ((*num_mem)+1) * sizeof(LOCAL_GRP_MEMBER));
+ (*num_mem)++;
}
else
{
- found = lookup_name(name, &sid, &type) == 0x0;
- }
-
- if (!found)
- {
DEBUG(0,("alias database: could not resolve alias named %s\n", name));
continue;
}
-
- (*members) = Realloc((*members), ((*num_mem)+1) * sizeof(LOCAL_GRP_MEMBER));
-
if ((*members) == NULL)
{
return NULL;
}
-
- fstrcpy((*members)[*num_mem].name, name);
- (*members)[*num_mem].sid_use = type;
- sid_copy(&(*members)[*num_mem].sid, &sid);
- (*num_mem)++;
+ fstrcpy((*members)[(*num_mem)-1].name, name);
+ (*members)[(*num_mem)-1].sid_use = type;
+ sid_copy(&(*members)[(*num_mem)-1].sid, &sid);
}
return p;
}
@@ -131,17 +164,15 @@ static LOCAL_GRP *getalsfilepwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
pstring linebuf;
char *p;
- uint8 type;
+ size_t linebuf_len;
aldb_init_als(&al_buf);
/*
* Scan the file, a line at a time and check if the name matches.
*/
- while (getfileline(vp, linebuf, sizeof(linebuf)) > 0)
+ while ((linebuf_len = getfileline(vp, linebuf, sizeof(linebuf))) > 0)
{
- DOM_NAME_MAP gmep;
-
/* get alias name */
p = strncpyn(al_buf.name, linebuf, sizeof(al_buf.name), ':');
@@ -193,25 +224,9 @@ static LOCAL_GRP *getalsfilepwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
}
}
- /*
- * look up the gid, turn it into a rid. the _correct_ type of rid */
- */
+ /* ok, set up the static data structure and return it */
- if (!lookupsmbgrpgid((gid_t)gidval, &gmep))
- {
- continue;
- }
- if (gmep.type != SID_NAME_DOM_GRP &&
- gmep.type != SID_NAME_WKN_GRP))
- {
- continue;
- }
-
- sid_split_rid(&gmep.sid, &gp_buf.rid);
- if (!sid_equal(&gmep.sid, &global_sam_sid))
- {
- continue;
- }
+ al_buf.rid = pwdb_gid_to_alias_rid((gid_t)gidval);
make_alias_line(linebuf, sizeof(linebuf), &al_buf, mem, num_mem);
DEBUG(10,("line: '%s'\n", linebuf));
@@ -235,7 +250,11 @@ static BOOL add_alsfileals_entry(LOCAL_GRP *newals)
/************************************************************************
Routine to search the aliasdb file for an entry matching the aliasname.
- and then modify its alias entry.
+ and then modify its alias entry. We can't use the startalspwent()/
+ getalspwent()/endalspwent() interfaces here as we depend on looking
+ in the actual file to decide how much room we have to write data.
+ override = False, normal
+ override = True, override XXXXXXXX'd out alias or NO PASS
************************************************************************/
static BOOL mod_alsfileals_entry(LOCAL_GRP* als)
@@ -252,7 +271,7 @@ static struct aliasdb_ops file_ops =
getalsfilepwpos,
setalsfilepwpos,
- iterate_getaliasntnam, /* In aliasdb.c */
+ iterate_getaliasnam, /* In aliasdb.c */
iterate_getaliasgid, /* In aliasdb.c */
iterate_getaliasrid, /* In aliasdb.c */
getalsfilepwent,
@@ -260,7 +279,7 @@ static struct aliasdb_ops file_ops =
add_alsfileals_entry,
mod_alsfileals_entry,
- iterate_getuseraliasntnam /* in aliasdb.c */
+ iterate_getuseraliasnam /* in aliasdb.c */
};
struct aliasdb_ops *file_initialise_alias_db(void)
diff --git a/source3/groupdb/groupdb.c b/source3/groupdb/groupdb.c
index ed09560b3a..b8952358fb 100644
--- a/source3/groupdb/groupdb.c
+++ b/source3/groupdb/groupdb.c
@@ -24,14 +24,13 @@
#include "nterr.h"
extern int DEBUGLEVEL;
-extern DOM_SID global_sam_sid;
/*
* NOTE. All these functions are abstracted into a structure
* that points to the correct function for the selected database. JRA.
*/
-static struct groupdb_ops *gpdb_ops = NULL;
+static struct groupdb_ops *gpdb_ops;
/***************************************************************
Initialise the group db operations.
@@ -48,8 +47,8 @@ BOOL initialise_group_db(void)
gpdb_ops = nisplus_initialise_group_db();
#elif defined(WITH_LDAP)
gpdb_ops = ldap_initialise_group_db();
-#elif defined(USE_SMBUNIX_DB)
- gpdb_ops = unix_initialise_group_db();
+#else
+ gpdb_ops = file_initialise_group_db();
#endif
return (gpdb_ops != NULL);
@@ -66,28 +65,7 @@ BOOL initialise_group_db(void)
*************************************************************************/
DOMAIN_GRP *iterate_getgroupgid(gid_t gid, DOMAIN_GRP_MEMBER **mem, int *num_mem)
{
- DOM_NAME_MAP gmep;
- uint32 rid;
- if (!lookupsmbgrpgid(gid, &gmep))
- {
- DEBUG(0,("iterate_getgroupgid: gid %d does not map to one of our Domain's Groups\n", gid));
- return NULL;
- }
-
- if (gmep.type != SID_NAME_DOM_GRP && gmep.type != SID_NAME_WKN_GRP)
- {
- DEBUG(0,("iterate_getgroupgid: gid %d does not map to one of our Domain's Groups\n", gid));
- return NULL;
- }
-
- sid_split_rid(&gmep.sid, &rid);
- if (!sid_equal(&gmep.sid, &global_sam_sid))
- {
- DEBUG(0,("iterate_getgroupgid: gid %d does not map into our Domain SID\n", gid));
- return NULL;
- }
-
- return iterate_getgrouprid(rid, mem, num_mem);
+ return iterate_getgrouprid(pwdb_gid_to_group_rid(gid), mem, num_mem);
}
/************************************************************************
@@ -127,7 +105,7 @@ DOMAIN_GRP *iterate_getgrouprid(uint32 rid, DOMAIN_GRP_MEMBER **mem, int *num_me
Utility function to search group database by name. use this if your database
does not have search facilities.
*************************************************************************/
-DOMAIN_GRP *iterate_getgroupntnam(const char *name, DOMAIN_GRP_MEMBER **mem, int *num_mem)
+DOMAIN_GRP *iterate_getgroupnam(char *name, DOMAIN_GRP_MEMBER **mem, int *num_mem)
{
DOMAIN_GRP *grp = NULL;
void *fp = NULL;
@@ -187,7 +165,7 @@ BOOL add_domain_group(DOMAIN_GRP **grps, int *num_grps, DOMAIN_GRP *grp)
/*************************************************************************
checks to see if a user is a member of a domain group
*************************************************************************/
-static BOOL user_is_member(const char *user_name, DOMAIN_GRP_MEMBER *mem, int num_mem)
+static BOOL user_is_member(char *user_name, DOMAIN_GRP_MEMBER *mem, int num_mem)
{
int i;
for (i = 0; i < num_mem; i++)
@@ -207,16 +185,16 @@ static BOOL user_is_member(const char *user_name, DOMAIN_GRP_MEMBER *mem, int nu
gets an array of groups that a user is in. use this if your database
does not have search facilities
*************************************************************************/
-BOOL iterate_getusergroupsnam(const char *user_name, DOMAIN_GRP **grps, int *num_grps)
+BOOL iterate_getusergroupsnam(char *user_name, DOMAIN_GRP **grps, int *num_grps)
{
- DOMAIN_GRP *grp = NULL;
+ DOMAIN_GRP *grp;
DOMAIN_GRP_MEMBER *mem = NULL;
int num_mem = 0;
void *fp = NULL;
DEBUG(10, ("search for usergroups by name: %s\n", user_name));
- if (user_name == NULL || grps == NULL || num_grps == NULL)
+ if (user_name == NULL || grp == NULL || num_grps == NULL)
{
return False;
}
@@ -272,12 +250,12 @@ BOOL iterate_getusergroupsnam(const char *user_name, DOMAIN_GRP **grps, int *num
*************************************************************************/
BOOL enumdomgroups(DOMAIN_GRP **grps, int *num_grps)
{
- DOMAIN_GRP *grp = NULL;
+ DOMAIN_GRP *grp;
void *fp = NULL;
DEBUG(10, ("enum user groups\n"));
- if (grps == NULL || num_grps == NULL)
+ if (grp == NULL || num_grps == NULL)
{
return False;
}
@@ -343,38 +321,15 @@ DOMAIN_GRP *getgroupent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_mem)
/************************************************************************
Routine to add an entry to the group database file.
- on entry, the entry is added by name.
- on exit, the RID is expected to have been set.
*************************************************************************/
BOOL add_group_entry(DOMAIN_GRP *newgrp)
{
- BOOL ret;
- if (newgrp->rid != 0xffffffff)
- {
- DEBUG(0,("add_group_entry - RID must be 0xffffffff, \
-database instance is responsible for allocating the RID, not you.\n"));
- return False;
- }
- ret = gpdb_ops->add_group_entry(newgrp);
- if (newgrp->rid == 0xffffffff)
- {
- DEBUG(0,("add_group_entry - RID has not been set by database\n"));
- return False;
- }
- return ret;
+ return gpdb_ops->add_group_entry(newgrp);
}
/************************************************************************
- Routine to delete group database entry matching by rid.
-************************************************************************/
-BOOL del_group_entry(uint32 rid)
-{
- return gpdb_ops->del_group_entry(rid);
-}
-
-/************************************************************************
- Routine to search group database file for entry matching by rid or groupname.
+ Routine to search the group database file for an entry matching the groupname.
and then replace the entry.
************************************************************************/
@@ -384,28 +339,12 @@ BOOL mod_group_entry(DOMAIN_GRP* grp)
}
/************************************************************************
- Routine to add a member to an entry in the group database file.
-*************************************************************************/
-BOOL add_group_member(uint32 rid, uint32 member_rid)
-{
- return gpdb_ops->add_group_member(rid, member_rid);
-}
-
-/************************************************************************
- Routine to delete a member from an entry in the group database file.
-*************************************************************************/
-BOOL del_group_member(uint32 rid, uint32 member_rid)
-{
- return gpdb_ops->del_group_member(rid, member_rid);
-}
-
-/************************************************************************
Routine to search group database by name.
*************************************************************************/
-DOMAIN_GRP *getgroupntnam(const char *name, DOMAIN_GRP_MEMBER **mem, int *num_mem)
+DOMAIN_GRP *getgroupnam(char *name, DOMAIN_GRP_MEMBER **mem, int *num_mem)
{
- return gpdb_ops->getgroupntnam(name, mem, num_mem);
+ return gpdb_ops->getgroupnam(name, mem, num_mem);
}
/************************************************************************
@@ -429,9 +368,9 @@ DOMAIN_GRP *getgroupgid(gid_t gid, DOMAIN_GRP_MEMBER **mem, int *num_mem)
/*************************************************************************
gets an array of groups that a user is in.
*************************************************************************/
-BOOL getusergroupsntnam(const char *user_name, DOMAIN_GRP **grp, int *num_grps)
+BOOL getusergroupsnam(char *user_name, DOMAIN_GRP **grp, int *num_grps)
{
- return gpdb_ops->getusergroupsntnam(user_name, grp, num_grps);
+ return gpdb_ops->getusergroupsnam(user_name, grp, num_grps);
}
/*************************************************************
@@ -444,51 +383,3 @@ void gpdb_init_grp(DOMAIN_GRP *grp)
ZERO_STRUCTP(grp);
}
-/*************************************************************************
- turns a list of groups into a string.
-*************************************************************************/
-BOOL make_group_line(char *p, int max_len,
- DOMAIN_GRP *grp,
- DOMAIN_GRP_MEMBER **mem, int *num_mem)
-{
- int i;
- int len;
- len = slprintf(p, max_len-1, "%s:%s:%d:", grp->name, grp->comment, grp->rid);
-
- if (len == -1)
- {
- DEBUG(0,("make_group_line: cannot create entry\n"));
- return False;
- }
-
- p += len;
- max_len -= len;
-
- if (mem == NULL || num_mem == NULL)
- {
- return True;
- }
-
- for (i = 0; i < (*num_mem); i++)
- {
- len = strlen((*mem)[i].name);
- p = safe_strcpy(p, (*mem)[i].name, max_len);
-
- if (p == NULL)
- {
- DEBUG(0, ("make_group_line: out of space for groups!\n"));
- return False;
- }
-
- max_len -= len;
-
- if (i != (*num_mem)-1)
- {
- *p = ',';
- p++;
- max_len--;
- }
- }
-
- return True;
-}
diff --git a/source3/groupdb/groupfile.c b/source3/groupdb/groupfile.c
index dba190ce56..88d362e7d4 100644
--- a/source3/groupdb/groupfile.c
+++ b/source3/groupdb/groupfile.c
@@ -19,16 +19,13 @@
#include "includes.h"
-#ifdef USE_SMBGROUP_DB
+#ifdef USE_SMBPASS_DB
static int gp_file_lock_depth = 0;
extern int DEBUGLEVEL;
static char s_readbuf[1024];
-extern DOM_SID global_sam_sid;
-extern fstring global_sam_name;
-
/***************************************************************
Start to enumerate the grppasswd list. Returns a void pointer
to ensure no modification outside this module.
@@ -36,7 +33,7 @@ extern fstring global_sam_name;
static void *startgrpfilepwent(BOOL update)
{
- return startfileent(lp_smb_group_file(),
+ return startfilepwent(lp_smb_group_file(),
s_readbuf, sizeof(s_readbuf),
&gp_file_lock_depth, update);
}
@@ -47,7 +44,7 @@ static void *startgrpfilepwent(BOOL update)
static void endgrpfilepwent(void *vp)
{
- endfileent(vp, &gp_file_lock_depth);
+ endfilepwent(vp, &gp_file_lock_depth);
}
/*************************************************************************
@@ -68,6 +65,51 @@ static BOOL setgrpfilepwpos(void *vp, SMB_BIG_UINT tok)
return setfilepwpos(vp, tok);
}
+static BOOL make_group_line(char *p, int max_len,
+ DOMAIN_GRP *grp,
+ DOMAIN_GRP_MEMBER **mem, int *num_mem)
+{
+ int i;
+ int len;
+ len = slprintf(p, max_len-1, "%s:%s:%d:", grp->name, grp->comment, grp->rid);
+
+ if (len == -1)
+ {
+ DEBUG(0,("make_group_line: cannot create entry\n"));
+ return False;
+ }
+
+ p += len;
+ max_len -= len;
+
+ if (mem == NULL || num_mem == NULL)
+ {
+ return True;
+ }
+
+ for (i = 0; i < (*num_mem); i++)
+ {
+ len = strlen((*mem)[i].name);
+ p = safe_strcpy(p, (*mem)[i].name, max_len);
+
+ if (p == NULL)
+ {
+ DEBUG(0, ("make_group_line: out of space for groups!\n"));
+ return False;
+ }
+
+ max_len -= len;
+
+ if (i != (*num_mem)-1)
+ {
+ *p = ',';
+ p++;
+ max_len--;
+ }
+ }
+
+ return True;
+}
/*************************************************************************
Routine to return the next entry in the smbdomaingroup list.
@@ -86,36 +128,11 @@ static char *get_group_members(char *p, int *num_mem, DOMAIN_GRP_MEMBER **member
while (next_token(&p, name, ",", sizeof(fstring)))
{
- DOM_SID sid;
- uint8 type;
- BOOL found = False;
-
- if (isdigit(name))
- {
- uint32 rid = get_number(name);
- sid_copy(&sid, &global_sam_sid);
- sid_append_rid(&sid, rid);
-
- found = lookup_sid(&sid, name, &type) == 0x0;
- }
- else
- {
- found = lookup_name(name, &sid, &type) == 0x0;
- }
-
- if (!found)
- {
- DEBUG(0,("group database: could not resolve name %s in domain %s\n",
- name, global_sam_name));
- continue;
- }
-
(*members) = Realloc((*members), ((*num_mem)+1) * sizeof(DOMAIN_GRP_MEMBER));
if ((*members) == NULL)
{
return NULL;
}
-
fstrcpy((*members)[(*num_mem)].name, name);
(*members)[(*num_mem)].attr = 0x07;
(*num_mem)++;
@@ -130,19 +147,19 @@ static DOMAIN_GRP *getgrpfilepwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_m
{
/* Static buffers we will return. */
static DOMAIN_GRP gp_buf;
- DOM_NAME_MAP gmep;
int gidval;
pstring linebuf;
char *p;
+ size_t linebuf_len;
gpdb_init_grp(&gp_buf);
/*
* Scan the file, a line at a time and check if the name matches.
*/
- while (getfileline(vp, linebuf, sizeof(linebuf)) > 0)
+ while ((linebuf_len = getfileline(vp, linebuf, sizeof(linebuf))) > 0)
{
/* get group name */
@@ -197,22 +214,7 @@ static DOMAIN_GRP *getgrpfilepwent(void *vp, DOMAIN_GRP_MEMBER **mem, int *num_m
/* ok, set up the static data structure and return it */
- if (!lookupsmbgrpgid((gid_t)gidval, &gmep))
- {
- continue;
- }
- if (gmep.type != SID_NAME_DOM_GRP &&
- gmep.type != SID_NAME_WKN_GRP))
- {
- continue;
- }
-
- sid_split_rid(&gmep.sid, &gp_buf.rid);
- if (!sid_equal(&gmep.sid, &global_sam_sid))
- {
- continue;
- }
-
+ gp_buf.rid = pwdb_gid_to_group_rid((gid_t)gidval);
gp_buf.attr = 0x07;
make_group_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
@@ -237,7 +239,11 @@ static BOOL add_grpfilegrp_entry(DOMAIN_GRP *newgrp)
/************************************************************************
Routine to search the grppasswd file for an entry matching the groupname.
- and then modify its group entry.
+ and then modify its group entry. We can't use the startgrppwent()/
+ getgrppwent()/endgrppwent() interfaces here as we depend on looking
+ in the actual file to decide how much room we have to write data.
+ override = False, normal
+ override = True, override XXXXXXXX'd out group or NO PASS
************************************************************************/
static BOOL mod_grpfilegrp_entry(DOMAIN_GRP* grp)
@@ -254,7 +260,7 @@ static struct groupdb_ops file_ops =
getgrpfilepwpos,
setgrpfilepwpos,
- iterate_getgroupntnam, /* In groupdb.c */
+ iterate_getgroupnam, /* In groupdb.c */
iterate_getgroupgid, /* In groupdb.c */
iterate_getgrouprid, /* In groupdb.c */
getgrpfilepwent,
@@ -262,7 +268,7 @@ static struct groupdb_ops file_ops =
add_grpfilegrp_entry,
mod_grpfilegrp_entry,
- iterate_getusergroupntnam /* in groupdb.c */
+ iterate_getusergroupsnam /* in groupdb.c */
};
struct groupdb_ops *file_initialise_group_db(void)