1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

Fixed getgrent() recurse problem.

Jeremy.
(This used to be commit b5420f6152)
This commit is contained in:
Jeremy Allison 2000-01-04 01:01:27 +00:00
parent fbd17c8daf
commit 7434c1aabd

View File

@ -618,24 +618,61 @@ static char *validate_group(char *group,char *password,int pwlen,int snum)
#ifdef HAVE_GETGRENT
{
struct group *gptr;
char **member;
setgrent();
while ((gptr = (struct group *)getgrent())) {
if (!strequal(gptr->gr_name,group))
continue;
member = gptr->gr_mem;
while (member && *member) {
if (strequal(gptr->gr_name,group))
break;
}
/*
* As user_ok can recurse doing a getgrent(), we must
* copy the member list into a pstring on the stack before
* use. Bug pointed out by leon@eatworms.swmed.edu.
*/
if (gptr) {
pstring member_list;
char *member;
size_t copied_len = 0;
int i;
*member_list = '\0';
member = member_list;
for(i = 0; gptr->gr_mem && gptr->gr_mem[i]; i++) {
size_t member_len = strlen(gptr->gr_mem[i]) + 1;
if( copied_len + member_len < sizeof(pstring)) {
DEBUG(10,("validate_group: = gr_mem = %s\n", gptr->gr_mem[i]));
safe_strcpy(member, gptr->gr_mem[i], sizeof(pstring) - copied_len - 1);
copied_len += member_len;
member += copied_len;
} else {
*member = '\0';
}
}
endgrent();
member = member_list;
while (*member) {
static fstring name;
fstrcpy(name,*member);
fstrcpy(name,member);
if (user_ok(name,snum) &&
password_ok(name,password,pwlen,NULL)) {
endgrent();
return(&name[0]);
}
member++;
DEBUG(10,("validate_group = member = %s\n", member));
member += strlen(member) + 1;
}
} else {
endgrent();
return NULL;
}
endgrent();
}
#endif
return(NULL);