Greg Dickie spotted some wierd memory corruption problem with group
[samba.git] / source3 / groupdb / aliasunix.c
index 39d7255ac5bec4c0fe3141eab8666a9de54b76e0..c53692f32825df470c2854434312ac253cc8f594 100644 (file)
@@ -170,7 +170,7 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
 {
        /* Static buffers we will return. */
        static LOCAL_GRP gp_buf;
 {
        /* Static buffers we will return. */
        static LOCAL_GRP gp_buf;
-       struct group *unix_grp = NULL;
+       struct group unix_grp;
        struct unix_entries *grps = (struct unix_entries *)vp;
 
        if (lp_server_role() == ROLE_DOMAIN_NONE)
        struct unix_entries *grps = (struct unix_entries *)vp;
 
        if (lp_server_role() == ROLE_DOMAIN_NONE)
@@ -195,12 +195,12 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
                DOM_NAME_MAP gmep;
                fstring sid_str;
 
                DOM_NAME_MAP gmep;
                fstring sid_str;
 
-               unix_grp = &grps->grps[grps->grp_idx];
+               memcpy(&unix_grp, &grps->grps[grps->grp_idx], sizeof(unix_grp));
 
                DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
 
                DEBUG(10,("getgrpunixpwent: enum unix group entry %s\n",
-                          unix_grp->gr_name));
+                          unix_grp.gr_name));
                        
                        
-               if (!lookupsmbgrpgid(unix_grp->gr_gid, &gmep))
+               if (!lookupsmbgrpgid(unix_grp.gr_gid, &gmep))
                {
                        continue;
                }
                {
                        continue;
                }
@@ -221,11 +221,10 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
                }
 
                fstrcpy(gp_buf.name, gmep.nt_name);
                }
 
                fstrcpy(gp_buf.name, gmep.nt_name);
-               grps->grp_idx++;
                break;
        }
 
                break;
        }
 
-       if (unix_grp == NULL || grps->grp_idx >= grps->num_grps)
+       if (grps->grp_idx >= grps->num_grps)
        {
                return NULL;
        }
        {
                return NULL;
        }
@@ -237,8 +236,8 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
                (*mem) = NULL;
                (*num_mem) = 0;
 
                (*mem) = NULL;
                (*num_mem) = 0;
 
-               unix_grp = getgrgid(unix_grp->gr_gid);
-               get_unixalias_members(unix_grp, num_mem, mem);
+               memcpy(&unix_grp, getgrgid(unix_grp.gr_gid), sizeof(unix_grp));
+               get_unixalias_members(&unix_grp, num_mem, mem);
        }
 
        {
        }
 
        {
@@ -247,6 +246,7 @@ static LOCAL_GRP *getalsunixpwent(void *vp, LOCAL_GRP_MEMBER **mem, int *num_mem
                DEBUG(10,("line: '%s'\n", linebuf));
        }
 
                DEBUG(10,("line: '%s'\n", linebuf));
        }
 
+       grps->grp_idx++; /* advance so next enum gets next entry */
        return &gp_buf;
 }
 
        return &gp_buf;
 }