This source file includes following definitions.
- show_uids
- show_gids
- show
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
27 #include "macros.h"
28
29 static void
30 show_uids ()
31 {
32 #if HAVE_GETRESUID
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",
38 (int) real, (int) effective, (int) saved);
39 #elif HAVE_GETEUID
40 printf ("uids: real=%d effective=%d",
41 (int) getuid (), (int) geteuid ());
42 #elif HAVE_GETUID
43 printf ("uids: real=%d",
44 (int) getuid ());
45 #endif
46 }
47
48 static void
49 show_gids ()
50 {
51 #if HAVE_GETRESGID
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",
57 (int) real, (int) effective, (int) saved);
58 #elif HAVE_GETEGID
59 printf ("gids: real=%d effective=%d",
60 (int) getgid (), (int) getegid ());
61 #elif HAVE_GETGID
62 printf ("gids: real=%d",
63 (int) getgid ());
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
91
92
93 for (i = 1; i < argc; i++)
94 {
95 const char *arg = argv[i];
96 if (strcmp (arg, "-v") == 0)
97 verbose = true;
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
109 #if HAVE_GETRESUID
110 {
111 uid_t real;
112 uid_t effective;
113 uid_t saved;
114 if (getresuid (&real, &effective, &saved) < 0
115 || real != uid
116 || effective != uid
117 || saved != uid)
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
131 {
132 gid_t real;
133 gid_t effective;
134 gid_t saved;
135 if (getresgid (&real, &effective, &saved) < 0
136 || real != gid
137 || effective != gid
138 || saved != gid)
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 }