Still have some infinite loops in iterate_getgrouprid

Sean Mathews mathewss at nutech.com
Mon Jan 11 22:22:05 GMT 1999


 these two patches should fix any os issues related to
the group database.

 Luke this is a change to what i had posted to you
before it fixes the problem more completly..


 Regards 
  Sean Mathews Nu Tech CTO

struct SoftwareProfessional { 
  double salary;
  long   lunches;
  float  jobs;
  char   unstable;
  void   work;
  short  tempers; 
};

-------------- next part --------------
--- groupunix.c	Mon Jan 11 09:59:25 1999
+++ /usr/local/src/samba/source/groupdb/groupunix.c	Mon Jan 11 13:56:51 1999
@@ -33,8 +33,9 @@
 
 static void *startgrpunixpwent(BOOL update)
 {
+	static int vfp=0;
 	setgrent();
-	return (void*)(-1);
+	return (void*)(&vfp);
 }
 
 /***************************************************************
@@ -43,6 +44,9 @@
 
 static void endgrpunixpwent(void *vp)
 {
+	int *pInt;
+	pInt=(int *)vp;
+	*pInt=0;
 	endgrent();
 }
 
@@ -143,6 +147,18 @@
 	/* Static buffers we will return. */
 	static DOMAIN_GRP gp_buf;
 	struct group *unix_grp;
+	gid_t gidlist[100];    
+	int gidcount=-1;
+	int currentgid=0;
+	int *pInt=NULL;
+	if(vp)
+	{
+	  pInt=(int *)vp;
+	  currentgid=*pInt;
+  	}
+
+	memset(gidlist,0,sizeof(gidlist));
+        DEBUG(10,("getgrpunixpwent: startat %d\n",currentgid));
 
 	if (lp_server_role() == ROLE_DOMAIN_NONE || 
 	    lp_server_role() == ROLE_DOMAIN_MEMBER)
@@ -157,31 +173,41 @@
 	}
 
 	gpdb_init_grp(&gp_buf);
+    while ((unix_grp = getgrent()) !=NULL)
+	{
+		gidcount++;
+		gidlist[gidcount]=unix_grp->gr_gid;
+		DEBUG(10,("getgrpunixpwent: enum unix group entry %s %d\n",
+		           unix_grp->gr_name,gidcount));
+	}
 
 	fstrcpy(gp_buf.comment, "");
 	gp_buf.attr    = 0x07;
 
 	/* cycle through unix groups */
-	while ((unix_grp = getgrent()) != NULL)
+	
+	while (currentgid<=gidcount)
 	{
 		DOM_NAME_MAP gmep;
-		DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
-		           unix_grp->gr_name));
+		
 			
-		if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
+		if (!lookupsmbgrpgid(gidlist[currentgid], &gmep))
 		{
+			currentgid++;
 			continue;
 		}
 
 		if (gmep.type != SID_NAME_DOM_GRP &&
 		    gmep.type != SID_NAME_WKN_GRP)
 		{
+			currentgid++;
 			continue;
 		}
 
 		sid_split_rid(&gmep.sid, &gp_buf.rid);
 		if (!sid_equal(&gmep.sid, &global_sam_sid))
 		{
+			currentgid++;
 			continue;
 		}
 
@@ -189,10 +215,12 @@
 		break;
 	}
 
-	if (unix_grp == NULL)
+	if (currentgid>gidcount)
 	{
 		return NULL;
 	}
+	
+	unix_grp = getgrgid(gidlist[currentgid]);
 
 	/* get the user's domain groups.  there are a maximum of 32 */
 
@@ -209,7 +237,12 @@
 		make_group_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
 		DEBUG(10,("line: '%s'\n", linebuf));
 	}
-
+	if(pInt)
+	{
+	 currentgid++;
+	 *pInt=currentgid;
+	 DEBUG(10,("new file pointer at: %d\n", *pInt));
+	}
 	return &gp_buf;
 }
 
-------------- next part --------------
--- builtinunix.c	Mon Jan 11 09:59:24 1999
+++ /usr/local/src/samba/source/groupdb/builtinunix.c	Mon Jan 11 13:57:58 1999
@@ -35,8 +35,9 @@
 
 static void *startbltunixpwent(BOOL update)
 {
+	static int vfp=0;
 	setgrent();
-	return (void*)(-1);
+	return (void*)(&vfp);
 }
 
 /***************************************************************
@@ -45,6 +46,9 @@
 
 static void endbltunixpwent(void *vp)
 {
+	int * pInt;
+	pInt=(int *)vp;
+	*pInt=0;
 	endgrent();
 }
 
@@ -144,6 +148,17 @@
 	/* Static buffers we will return. */
 	static LOCAL_GRP gp_buf;
 	struct group *unix_grp;
+	gid_t gidlist[100];    
+	int gidcount=-1;
+	int currentgid=0;
+	int *pInt=NULL;
+	if(vp)
+	{
+	 pInt=(int *)vp;
+         currentgid=*pInt;
+	}
+	memset(gidlist,0,sizeof(gidlist));
+	DEBUG(10,("getbltunixpwent: startat %d\n",currentgid));
 
 	if (lp_server_role() == ROLE_DOMAIN_NONE)
 	{
@@ -157,16 +172,24 @@
 
 	bidb_init_blt(&gp_buf);
 
+    while ((unix_grp = getgrent()) !=NULL)
+	{
+		gidcount++;
+		gidlist[gidcount]=unix_grp->gr_gid;
+		DEBUG(10,("getgrpunixpwent: enum unix group entry %s %d\n",
+		           unix_grp->gr_name,gidcount));
+	}
+
+
 	/* cycle through unix groups */
-	while ((unix_grp = getgrent()) != NULL)
+	while (currentgid<=gidcount)
 	{
 		DOM_NAME_MAP gmep;
 		fstring sid_str;
-		DEBUG(10,("getbltunixpwent: enum unix group entry %s\n",
-		           unix_grp->gr_name));
 			
-		if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
+		if (!lookupsmbgrpgid(gidlist[currentgid], &gmep))
 		{
+			currentgid++;
 			continue;
 		}
 
@@ -176,12 +199,14 @@
 
 		if (gmep.type != SID_NAME_ALIAS)
 		{
+			currentgid++;
 			continue;
 		}
 
 		sid_split_rid(&gmep.sid, &gp_buf.rid);
 		if (!sid_equal(&global_sid_S_1_5_20, &gmep.sid))
 		{
+			currentgid++;
 			continue;
 		}
 
@@ -189,11 +214,12 @@
 		break;
 	}
 
-	if (unix_grp == NULL)
+	if (currentgid>gidcount)
 	{
 		return NULL;
 	}
-
+	
+	unix_grp = getgrgid(gidlist[currentgid]);
 	/* get the user's domain builtin aliases.  there are a maximum of 32 */
 
 	if (mem != NULL && num_mem != NULL)
@@ -209,7 +235,11 @@
 		make_builtin_line(linebuf, sizeof(linebuf), &gp_buf, mem, num_mem);
 		DEBUG(10,("line: '%s'\n", linebuf));
 	}
-
+	if(pInt)
+	{
+	  currentgid++;
+	  *pInt=currentgid;
+	}
 	return &gp_buf;
 }
 


More information about the samba-ntdom mailing list