Mercurial > gnulib
annotate tests/test-idpriv-drop.c @ 17363:5a51fb7777a9
sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin
Problem reported by Marco Atzeri in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>.
* lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]:
Simply delegate to the system <sys/select.h> in this case too.
Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only
if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to
be needed on Solaris either.
* lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]:
Simply delgate to the system <sys/time.h> in this case.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 19 Mar 2013 09:08:47 -0700 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
11614 | 1 /* Test of dropping uid/gid privileges of the current process permanently. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2009-2013 Free Software Foundation, Inc. |
11614 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program 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 | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 #include <config.h> | |
18 | |
19 #include "idpriv.h" | |
20 | |
21 #include <stdbool.h> | |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 #include <unistd.h> | |
26 | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
27 #include "macros.h" |
11614 | 28 |
29 static void | |
30 show_uids () | |
31 { | |
32 #if HAVE_GETRESUID /* glibc, FreeBSD, OpenBSD, HP-UX */ | |
33 uid_t real; | |
34 uid_t effective; | |
35 uid_t saved; | |
36 ASSERT (getresuid (&real, &effective, &saved) >= 0); | |
37 printf ("uids: real=%d effective=%d saved=%d", | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
38 (int) real, (int) effective, (int) saved); |
11614 | 39 #elif HAVE_GETEUID |
40 printf ("uids: real=%d effective=%d", | |
13051 | 41 (int) getuid (), (int) geteuid ()); |
11614 | 42 #elif HAVE_GETUID |
43 printf ("uids: real=%d", | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
44 (int) getuid ()); |
11614 | 45 #endif |
46 } | |
47 | |
48 static void | |
49 show_gids () | |
50 { | |
51 #if HAVE_GETRESGID /* glibc, FreeBSD, OpenBSD, HP-UX */ | |
52 gid_t real; | |
53 gid_t effective; | |
54 gid_t saved; | |
55 ASSERT (getresgid (&real, &effective, &saved) >= 0); | |
56 printf ("gids: real=%d effective=%d saved=%d", | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
57 (int) real, (int) effective, (int) saved); |
11614 | 58 #elif HAVE_GETEGID |
59 printf ("gids: real=%d effective=%d", | |
13051 | 60 (int) getgid (), (int) getegid ()); |
11614 | 61 #elif HAVE_GETGID |
62 printf ("gids: real=%d", | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
63 (int) getgid ()); |
11614 | 64 #endif |
65 } | |
66 | |
67 static void | |
68 show (const char *prefix) | |
69 { | |
70 printf ("%s ", prefix); | |
71 show_uids (); | |
72 printf (" "); | |
73 show_gids (); | |
74 printf ("\n"); | |
75 } | |
76 | |
77 int | |
78 main (int argc, char *argv[]) | |
79 { | |
80 bool verbose = false; | |
81 int i; | |
82 | |
83 #if HAVE_GETUID | |
84 int uid = getuid (); | |
85 #endif | |
86 #if HAVE_GETGID | |
87 int gid = getgid (); | |
88 #endif | |
89 | |
90 /* Parse arguments. | |
91 -v enables verbose output. | |
92 */ | |
93 for (i = 1; i < argc; i++) | |
94 { | |
95 const char *arg = argv[i]; | |
96 if (strcmp (arg, "-v") == 0) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
97 verbose = true; |
11614 | 98 } |
99 | |
100 if (verbose) | |
101 show ("before drop:"); | |
102 | |
103 ASSERT (idpriv_drop () == 0); | |
104 | |
105 if (verbose) | |
106 show ("after drop: "); | |
107 | |
108 /* Verify that the privileges have really been dropped. */ | |
109 #if HAVE_GETRESUID /* glibc, FreeBSD, OpenBSD, HP-UX */ | |
110 { | |
111 uid_t real; | |
112 uid_t effective; | |
113 uid_t saved; | |
114 if (getresuid (&real, &effective, &saved) < 0 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
115 || real != uid |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
116 || effective != uid |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
117 || saved != uid) |
11614 | 118 abort (); |
119 } | |
120 #else | |
121 # if HAVE_GETEUID | |
122 if (geteuid () != uid) | |
123 abort (); | |
124 # endif | |
125 # if HAVE_GETUID | |
126 if (getuid () != uid) | |
127 abort (); | |
128 # endif | |
129 #endif | |
130 #if HAVE_GETRESGID /* glibc, FreeBSD, OpenBSD, HP-UX */ | |
131 { | |
132 gid_t real; | |
133 gid_t effective; | |
134 gid_t saved; | |
135 if (getresgid (&real, &effective, &saved) < 0 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
136 || real != gid |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
137 || effective != gid |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11614
diff
changeset
|
138 || saved != gid) |
11614 | 139 abort (); |
140 } | |
141 #else | |
142 # if HAVE_GETEGID | |
143 if (getegid () != gid) | |
144 abort (); | |
145 # endif | |
146 # if HAVE_GETGID | |
147 if (getgid () != gid) | |
148 abort (); | |
149 # endif | |
150 #endif | |
151 | |
152 return 0; | |
153 } |