summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-06-29 00:17:44 +0000
committerUlrich Drepper <drepper@redhat.com>2001-06-29 00:17:44 +0000
commit90e5b29e1470b218fe4288df7c58593e2f8fd753 (patch)
treef7e4469da4867fa59b5a3ec3732e872891e9f391
parent5746ef6f2a918bcd476d4e33017edcec22684928 (diff)
downloadglibc-90e5b29e1470b218fe4288df7c58593e2f8fd753.tar.gz
glibc-90e5b29e1470b218fe4288df7c58593e2f8fd753.tar.xz
glibc-90e5b29e1470b218fe4288df7c58593e2f8fd753.zip
Update.
	* manual/users.texi (Setting Groups): Correct initgroups
	documentation.  Add documentation for getgrouplist.

2001-06-28  H.J. Lu  <hjl@gnu.org>

	* locale/findlocale.c (locale_file_list): Renamed to ...
	(_nl_locale_file_list): This. Make it extern.
	(free_mem): Move to ...
	* locale/setlocale.c (free_mem): Here.

2001-06-28  Mark Kettenis  <kettenis@gnu.org>

2001-06-20  Isamu Hasegawa  <isamu@yamato.ibm.com>
2001-06-26  Isamu Hasegawa  <isamu@yamato.ibm.com>
	* posix/regex.c (count_mbs_length): Use binary search for optimization.
-rw-r--r--ChangeLog19
-rw-r--r--locale/setlocale.c28
-rw-r--r--manual/users.texi52
3 files changed, 85 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index c795869718..ef2c31e204 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2001-06-28  Mark Kettenis  <kettenis@gnu.org>
 
+	* manual/users.texi (Setting Groups): Correct initgroups
+	documentation.  Add documentation for getgrouplist.
+
+2001-06-28  H.J. Lu  <hjl@gnu.org>
+
+	* locale/findlocale.c (locale_file_list): Renamed to ...
+	(_nl_locale_file_list): This. Make it extern.
+	(free_mem): Move to ...
+	* locale/setlocale.c (free_mem): Here.
+
+2001-06-28  Mark Kettenis  <kettenis@gnu.org>
+
 	* sysdeps/mach/hurd/read.c: Include <hurd/fd.h>.
 	(__libc_read): Don't call __pread.  Use _hurd_fd_read directly
 	instead.
@@ -18,17 +30,16 @@
 
 	* posix/Makefile: Add rules to build and run tst-regex.
 
-2001-06-20 Isamu Hasegawa <isamu@yamato.ibm.com>
+2001-06-20  Isamu Hasegawa  <isamu@yamato.ibm.com>
 
 	* posix/regex.c (FREE_WCS_BUFFERS): New macro to free buffers.
 	(re_search_2): invoke convert_mbs_to_wcs and FREE_WCS_BUFFERS.
 	(wcs_re_match_2_internal): Check whether the wcs buffers need
 	seting up or not, and skip seting up routin if not needed.
 
-2001-06-26 Isamu Hasegawa <isamu@yamato.ibm.com>
+2001-06-26  Isamu Hasegawa  <isamu@yamato.ibm.com>
 
-	* posix/regex.c (count_mbs_length): Use binary search for
-	optimization.
+	* posix/regex.c (count_mbs_length): Use binary search for optimization.
 
 2001-06-27  Ulrich Drepper  <drepper@redhat.com>
 
diff --git a/locale/setlocale.c b/locale/setlocale.c
index c7848b9a5c..c5a8d49069 100644
--- a/locale/setlocale.c
+++ b/locale/setlocale.c
@@ -430,6 +430,7 @@ setlocale (int category, const char *locale)
     }
 }
 
+extern struct loaded_l10nfile *_nl_locale_file_list[];
 
 static void __attribute__ ((unused))
 free_mem (void)
@@ -440,17 +441,30 @@ free_mem (void)
     if (category != LC_ALL)
       {
 	struct locale_data *here = *_nl_current[category];
+	struct loaded_l10nfile *runp = _nl_locale_file_list[category];
 
 	/* If this category is already "C" don't do anything.  */
-	if (here == _nl_C[category])
-	  continue;
+	if (here != _nl_C[category])
+	  {
+	    /* We have to be prepared that sometime later me still
+	       might need the locale information.  */
+	    setdata (category, _nl_C[category]);
+	    setname (category, _nl_C_name);
 
-	/* We have to be prepared that sometime later me still might
-	   need the locale information.  */
-	setdata (category, _nl_C[category]);
-	setname (category, _nl_C_name);
+	    _nl_unload_locale (here);
+	  }
 
-	_nl_unload_locale (here);
+	while (runp != NULL)
+	  {
+	    struct loaded_l10nfile *curr = runp;
+	    struct locale_data *data = (struct locale_data *) runp->data;
+
+	    if (data != NULL && data != here && data != _nl_C[category])
+	      _nl_unload_locale (data);
+	    runp = runp->next;
+	    free ((char *) curr->filename);
+	    free (curr);
+	  }
       }
 
   setname (LC_ALL, _nl_C_name);
diff --git a/manual/users.texi b/manual/users.texi
index d13139c4c5..406e48bfb5 100644
--- a/manual/users.texi
+++ b/manual/users.texi
@@ -454,10 +454,10 @@ The calling process is not privileged.
 
 @comment grp.h
 @comment BSD
-@deftypefun int initgroups (const char *@var{user}, gid_t @var{gid})
+@deftypefun int initgroups (const char *@var{user}, gid_t @var{group})
 The @code{initgroups} function sets the process's supplementary group
-IDs to be the normal default for the user name @var{user}. If @var{gid}
-is not -1, it includes that group also.
+IDs to be the normal default for the user name @var{user}.  The group
+@var{group} is automatically included.
 
 This function works by scanning the group database for all the groups
 @var{user} belongs to.  It then calls @code{setgroups} with the list it
@@ -467,6 +467,52 @@ The return values and error conditions are the same as for
 @code{setgroups}.
 @end deftypefun
 
+If you are interested in the groups a particular user belongs to, but do
+not want to change the process's supplementary group IDs, you can use
+@code{getgrouplist}.  To use @code{getgrouplist}, your programs should
+include the header file @file{grp.h}.
+@pindex grp.h
+
+@comment grp.h
+@comment BSD
+@deftypefun int getgrouplist (const char *@var{user}, gid_t @var{group}, gid_t *@var{groups}, int *@var{ngroups})
+The @code{getgrouplist} function scans the group database for all the
+groups @var{user} belongs to.  Up to *@var{ngroups} group IDs
+corresponding to these groups are stored in the array @var{groups}; the
+return value from the function is the number of group IDs actually
+stored.  If *@var{ngroups} is smaller than the total number of groups
+found, then @code{getgrouplist} returns a value of @code{-1} and stores
+the actual number of groups in *@var{ngroups}.  The group @var{group} is
+automatically included in the list of groups returned by
+@code{getgrouplist}.
+
+Here's how to use @code{getgrouplist} to read all supplementary groups
+for @var{user}:
+
+@smallexample
+@group
+gid_t *
+supplementary_groups (char *user)
+@{
+  int ngroups = 16;
+  gid_t *groups
+    = (gid_t *) xmalloc (ngroups * sizeof (gid_t));
+  struct passwd *pw = getpwnam (user);
+
+  if (pw == NULL)
+    return NULL;
+
+  if (getgrouplist (pw->pw_name, pw->pw_gid, groups, &ngroups) < 0)
+    @{
+      groups = xrealloc (ngroups * sizeof (gid_t));
+      getgrouplist (pw->pw_name, pw->pw_gid, groups, &ngroups);
+    @}
+  return groups;
+@}
+@end group
+@end smallexample
+@end deftypefun
+
 @node Enable/Disable Setuid
 @section Enabling and Disabling Setuid Access