diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
commit | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch) | |
tree | 2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /grp | |
parent | 7d58530341304d403a6626d7f7a1913165fe2f32 (diff) | |
download | glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.bz2 |
2.5-18.1
Diffstat (limited to 'grp')
-rw-r--r-- | grp/initgroups.c | 27 | ||||
-rw-r--r-- | grp/putgrent.c | 11 | ||||
-rw-r--r-- | grp/setgroups.c | 35 |
3 files changed, 55 insertions, 18 deletions
diff --git a/grp/initgroups.c b/grp/initgroups.c index d052cf4..2e48946 100644 --- a/grp/initgroups.c +++ b/grp/initgroups.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1989,91,93,1996-2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1989,91,93,1996-2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -17,6 +17,7 @@ 02111-1307 USA. */ #include <alloca.h> +#include <assert.h> #include <errno.h> #include <grp.h> #include <limits.h> @@ -73,6 +74,8 @@ internal_getgrouplist (const char *user, gid_t group, long int *size, /* Start is one, because we have the first group as parameter. */ long int start = 1; + /* Never store more than the starting *SIZE number of elements. */ + assert (*size > 0); (*groupsp)[0] = group; if (__nss_group_database != NULL) @@ -140,11 +143,9 @@ internal_getgrouplist (const char *user, gid_t group, long int *size, int getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups) { - gid_t *newgroups; long int size = MAX (1, *ngroups); - int result; - newgroups = (gid_t *) malloc ((size + 1) * sizeof (gid_t)); + gid_t *newgroups = (gid_t *) malloc (size * sizeof (gid_t)); if (__builtin_expect (newgroups == NULL, 0)) /* No more memory. */ // XXX This is wrong. The user provided memory, we have to use @@ -153,20 +154,16 @@ getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups) // XXX too small. For initgroups a flag could say: increase size. return -1; - result = internal_getgrouplist (user, group, &size, &newgroups, -1); - - memcpy (groups, newgroups, MIN (*ngroups, result) * sizeof (gid_t)); + int total = internal_getgrouplist (user, group, &size, &newgroups, -1); - if (result > *ngroups) - { - *ngroups = result; - result = -1; - } - else - *ngroups = result; + memcpy (groups, newgroups, MIN (*ngroups, total) * sizeof (gid_t)); free (newgroups); - return result; + + int retval = total > *ngroups ? -1 : total; + *ngroups = total; + + return retval; } static_link_warning (getgrouplist) diff --git a/grp/putgrent.c b/grp/putgrent.c index cb9b6b1..382d6a4 100644 --- a/grp/putgrent.c +++ b/grp/putgrent.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 92, 96, 98, 99, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,96,98,99,2000,2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -44,8 +44,13 @@ putgrent (gr, stream) flockfile (stream); - retval = fprintf (stream, "%s:%s:%u:", - gr->gr_name, _S (gr->gr_passwd), gr->gr_gid); + if (gr->gr_name[0] == '+' || gr->gr_name[0] == '-') + retval = fprintf (stream, "%s:%s::", + gr->gr_name, _S (gr->gr_passwd)); + else + retval = fprintf (stream, "%s:%s:%lu:", + gr->gr_name, _S (gr->gr_passwd), + (unsigned long int) gr->gr_gid); if (__builtin_expect (retval, 0) < 0) { funlockfile (stream); diff --git a/grp/setgroups.c b/grp/setgroups.c new file mode 100644 index 0000000..74bae72 --- /dev/null +++ b/grp/setgroups.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1991,95,96,97,2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sys/types.h> +#include <grp.h> + +/* Set the group set for the current user to GROUPS (N of them). */ +int +setgroups (n, groups) + size_t n; + const gid_t *groups; +{ + __set_errno (ENOSYS); + return -1; +} +libc_hidden_def (setgroups) + +stub_warning (setgroups) +#include <stub-tag.h> |