From 4d6b478b19dd583cb4df3db2d59a4815236c593c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Jan 2004 10:04:10 +0000 Subject: On my SuSE 8.2 (glibc 2.3.2) the getpwnam inside pdb_getsampwnam reset the surrounding getpwent loop to the first entry. So smbd went into an endless loop. Volker (This used to be commit 1797b16fadd61ef1f30a1be950e3afe7a2e1d791) --- source3/groupdb/mapping.c | 73 ++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 30 deletions(-) (limited to 'source3') diff --git a/source3/groupdb/mapping.c b/source3/groupdb/mapping.c index 97abbd46e3..7513f3b141 100644 --- a/source3/groupdb/mapping.c +++ b/source3/groupdb/mapping.c @@ -701,10 +701,12 @@ BOOL get_group_from_gid(gid_t gid, GROUP_MAP *map) BOOL get_sid_list_of_group(gid_t gid, DOM_SID **sids, int *num_sids) { struct group *grp; - struct passwd *pwd; int i=0; char *gr; DOM_SID *s; + + struct sys_pwent *userlist; + struct sys_pwent *user; if(!init_group_mapping()) { DEBUG(0,("failed to initialize group mapping")); @@ -751,41 +753,52 @@ BOOL get_sid_list_of_group(gid_t gid, DOM_SID **sids, int *num_sids) winbind_off(); - setpwent(); - while ((pwd=getpwent()) != NULL) { - if (pwd->pw_gid==gid) { - SAM_ACCOUNT *group_member_acct = NULL; - BOOL found_user; - s = Realloc((*sids), sizeof(**sids)*(*num_sids+1)); - if (!s) { - DEBUG(0,("get_sid_list_of_group: unable to enlarge SID list!\n")); - winbind_on(); - return False; - } - else (*sids) = s; + user = userlist = getpwent_list(); + + while (user != NULL) { + + SAM_ACCOUNT *group_member_acct = NULL; + BOOL found_user; + + if (user->pw_gid != gid) { + user = user->next; + continue; + } + + s = Realloc((*sids), sizeof(**sids)*(*num_sids+1)); + if (!s) { + DEBUG(0,("get_sid_list_of_group: unable to enlarge " + "SID list!\n")); + winbind_on(); + return False; + } + else (*sids) = s; - if (!NT_STATUS_IS_OK(pdb_init_sam(&group_member_acct))) { - continue; - } + if (!NT_STATUS_IS_OK(pdb_init_sam(&group_member_acct))) { + continue; + } - become_root(); - found_user = pdb_getsampwnam(group_member_acct, pwd->pw_name); - unbecome_root(); + become_root(); + found_user = pdb_getsampwnam(group_member_acct, user->pw_name); + unbecome_root(); - if (found_user) { - sid_copy(&(*sids)[*num_sids], pdb_get_user_sid(group_member_acct)); + if (found_user) { + sid_copy(&(*sids)[*num_sids], + pdb_get_user_sid(group_member_acct)); + (*num_sids)++; + } else { + DEBUG(4,("get_sid_list_of_group: User %s [uid == %lu] " + "has no samba account\n", + user->pw_name, (unsigned long)user->pw_uid)); + if (algorithmic_uid_to_sid(&(*sids)[*num_sids], + user->pw_uid)) (*num_sids)++; - } else { - DEBUG(4,("get_sid_list_of_group: User %s [uid == %lu] has no samba account\n", - pwd->pw_name, (unsigned long)pwd->pw_uid)); - if (algorithmic_uid_to_sid(&(*sids)[*num_sids], pwd->pw_uid)) - (*num_sids)++; - } - - pdb_free_sam(&group_member_acct); } + pdb_free_sam(&group_member_acct); + + user = user->next; } - endpwent(); + pwent_free(userlist); DEBUG(10, ("got primary groups, members: [%d]\n", *num_sids)); winbind_on(); -- cgit