]>
Commit | Line | Data |
---|---|---|
313fed01 | 1 | /* Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc. |
5290baf0 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Library General Public License as | |
6 | published by the Free Software Foundation; either version 2 of the | |
7 | License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Library General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Library General Public | |
15 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
16 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 | Boston, MA 02111-1307, USA. */ | |
18 | ||
9ffbb612 | 19 | #include <errno.h> |
5290baf0 | 20 | #include <grp.h> |
0dee6738 UD |
21 | #include <unistd.h> |
22 | #include <sys/types.h> | |
23 | ||
24 | #include <sysdep.h> | |
25 | #include <sys/syscall.h> | |
5290baf0 | 26 | #include <linux/posix_types.h> |
313fed01 UD |
27 | #include "kernel-features.h" |
28 | ||
29 | ||
30 | extern int __syscall_setgroups (int, const __kernel_gid_t *); | |
5290baf0 | 31 | |
313fed01 | 32 | #ifdef __NR_setgroups32 |
bcaad6ee | 33 | extern int __syscall_setgroups32 (int, const __kernel_gid32_t *); |
313fed01 UD |
34 | # if __ASSUME_32BITUIDS == 0 |
35 | /* This variable is shared with all files that need to check for 32bit | |
36 | uids. */ | |
37 | extern int __libc_missing_32bit_uids; | |
38 | # endif | |
39 | #endif /* __NR_setgroups32 */ | |
5290baf0 UD |
40 | |
41 | /* Set the group set for the current user to GROUPS (N of them). For | |
42 | Linux we must convert the array of groups into the format that the | |
43 | kernel expects. */ | |
44 | int | |
313fed01 | 45 | setgroups (size_t n, const gid_t *groups) |
5290baf0 | 46 | { |
160698e2 | 47 | if (n > (size_t) __sysconf (_SC_NGROUPS_MAX)) |
9271a050 UD |
48 | { |
49 | __set_errno (EINVAL); | |
50 | return -1; | |
51 | } | |
78e5779b | 52 | else |
9ffbb612 | 53 | { |
313fed01 UD |
54 | #if __ASSUME_32BITUIDS > 0 |
55 | return INLINE_SYSCALL (setgroups32, 2, n, groups); | |
56 | #else | |
9271a050 UD |
57 | size_t i; |
58 | __kernel_gid_t kernel_groups[n]; | |
313fed01 | 59 | # ifdef __NR_setgroups32 |
cd090f71 | 60 | if (__libc_missing_32bit_uids <= 0) |
313fed01 UD |
61 | { |
62 | int result; | |
63 | int saved_errno = errno; | |
64 | ||
65 | result = INLINE_SYSCALL (setgroups32, 2, n, groups); | |
66 | if (result == 0 || errno != ENOSYS) | |
67 | return result; | |
9271a050 | 68 | |
313fed01 UD |
69 | __set_errno (saved_errno); |
70 | __libc_missing_32bit_uids = 1; | |
71 | } | |
72 | # endif /* __NR_setgroups32 */ | |
9271a050 | 73 | for (i = 0; i < n; i++) |
9ffbb612 | 74 | { |
9271a050 UD |
75 | kernel_groups[i] = groups[i]; |
76 | if (groups[i] != (gid_t) ((__kernel_gid_t) groups[i])) | |
77 | { | |
78 | __set_errno (EINVAL); | |
79 | return -1; | |
80 | } | |
9ffbb612 | 81 | } |
0dee6738 | 82 | |
9271a050 | 83 | return INLINE_SYSCALL (setgroups, 2, n, kernel_groups); |
313fed01 | 84 | #endif |
ebf282c9 | 85 | } |
5290baf0 | 86 | } |