2005-01-29 Miguel de Icaza <miguel@novell.com>

* utilunix.c (init_groups): Added support for getgrouplist patch
	from Stefan Gohmann <gohmann@univention.de>.

2005-01-29  Miguel de Icaza  <miguel@novell.com>

	* configure.ac: Check for getgrouplist API call.
This commit is contained in:
Miguel de Icaza 2005-01-30 05:06:13 +00:00
parent 020455853d
commit 324f4c5644
2 changed files with 33 additions and 1 deletions

View File

@ -170,7 +170,7 @@ dnl
AC_CHECK_FUNCS([atoll cfgetospeed getsid initgroups memcpy memmove memset \
putenv setreuid setuid statfs strerror strftime \
sysconf tcgetattr tcsetattr truncate])
sysconf tcgetattr tcsetattr truncate getgrouplist])
dnl S-Lang needs all four functions to be defined to use POSIX signal API
AC_CHECK_FUNCS([sigaction sigemptyset sigprocmask sigaddset], , [slang_signals=no])

View File

@ -92,6 +92,37 @@ void init_groups (void)
g_strdup (grp->gr_name));
}
#ifdef HAVE_GETGROUPLIST
{
gid_t *groups = NULL;
int ng = 1;
//struct group *grp;
gid_t *newgroups = NULL;
groups = (gid_t *) malloc(ng * sizeof(gid_t));
if (getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ng) == -1) {
newgroups = (gid_t *) malloc(ng * sizeof(gid_t));
if (newgroups != NULL) {
free (groups);
groups = newgroups;
getgrouplist (pwd->pw_name, pwd->pw_gid, groups, &ng);
} else
ng = 1;
}
for (i = 0; i < ng; i++) {
grp = getgrgid(groups[i]);
if (grp != NULL && !g_tree_lookup (current_user_gid, GUINT_TO_POINTER ((int) grp->gr_gid))) {
g_tree_insert (current_user_gid,
GUINT_TO_POINTER ((int) grp->gr_gid),
g_strdup (grp->gr_name));
}
}
free(groups);
}
#else
setgrent ();
while ((grp = getgrent ()) != NULL) {
for (i = 0; grp->gr_mem[i]; i++) {
@ -106,6 +137,7 @@ void init_groups (void)
}
}
endgrent ();
#endif
}
/* Return the index of the permissions triplet */