1 #ifdef STRACE_UID_SIZE
2 # if STRACE_UID_SIZE != 16
3 # error invalid STRACE_UID_SIZE
4 # endif
5
6 # define SIZEIFY(x) SIZEIFY_(x,STRACE_UID_SIZE)
7 # define SIZEIFY_(x,size) SIZEIFY__(x,size)
8 # define SIZEIFY__(x,size) x ## size
9
10 # define printuid SIZEIFY(printuid)
11 # define sys_chown SIZEIFY(sys_chown)
12 # define sys_fchown SIZEIFY(sys_fchown)
13 # define sys_getgroups SIZEIFY(sys_getgroups)
14 # define sys_getresuid SIZEIFY(sys_getresuid)
15 # define sys_getuid SIZEIFY(sys_getuid)
16 # define sys_setfsuid SIZEIFY(sys_setfsuid)
17 # define sys_setgroups SIZEIFY(sys_setgroups)
18 # define sys_setresuid SIZEIFY(sys_setresuid)
19 # define sys_setreuid SIZEIFY(sys_setreuid)
20 # define sys_setuid SIZEIFY(sys_setuid)
21 #endif /* STRACE_UID_SIZE */
22
23 #include "defs.h"
24
25 #ifdef STRACE_UID_SIZE
26 # if !NEED_UID16_PARSERS
27 # undef STRACE_UID_SIZE
28 # endif
29 #else
30 # define STRACE_UID_SIZE 32
31 #endif
32
33 #ifdef STRACE_UID_SIZE
34
35 # undef uid_t
36 # define uid_t uid_t_(STRACE_UID_SIZE)
37 # define uid_t_(size) uid_t__(size)
38 # define uid_t__(size) uint ## size ## _t
39
SYS_FUNC(getuid)40 SYS_FUNC(getuid)
41 {
42 if (exiting(tcp))
43 tcp->u_rval = (uid_t) tcp->u_rval;
44 return RVAL_UDECIMAL;
45 }
46
SYS_FUNC(setfsuid)47 SYS_FUNC(setfsuid)
48 {
49 if (entering(tcp))
50 tprintf("%u", (uid_t) tcp->u_arg[0]);
51 else
52 tcp->u_rval = (uid_t) tcp->u_rval;
53 return RVAL_UDECIMAL;
54 }
55
SYS_FUNC(setuid)56 SYS_FUNC(setuid)
57 {
58 if (entering(tcp)) {
59 tprintf("%u", (uid_t) tcp->u_arg[0]);
60 }
61 return 0;
62 }
63
64 static void
get_print_uid(struct tcb * tcp,const char * prefix,const long addr)65 get_print_uid(struct tcb *tcp, const char *prefix, const long addr)
66 {
67 uid_t uid;
68
69 if (umove(tcp, addr, &uid) < 0)
70 tprintf("%s%#lx", prefix, addr);
71 else
72 tprintf("%s[%u]", prefix, uid);
73 }
74
SYS_FUNC(getresuid)75 SYS_FUNC(getresuid)
76 {
77 if (exiting(tcp)) {
78 if (syserror(tcp)) {
79 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
80 tcp->u_arg[1], tcp->u_arg[2]);
81 } else {
82 get_print_uid(tcp, "", tcp->u_arg[0]);
83 get_print_uid(tcp, ", ", tcp->u_arg[1]);
84 get_print_uid(tcp, ", ", tcp->u_arg[2]);
85 }
86 }
87 return 0;
88 }
89
SYS_FUNC(setreuid)90 SYS_FUNC(setreuid)
91 {
92 if (entering(tcp)) {
93 printuid("", tcp->u_arg[0]);
94 printuid(", ", tcp->u_arg[1]);
95 }
96 return 0;
97 }
98
SYS_FUNC(setresuid)99 SYS_FUNC(setresuid)
100 {
101 if (entering(tcp)) {
102 printuid("", tcp->u_arg[0]);
103 printuid(", ", tcp->u_arg[1]);
104 printuid(", ", tcp->u_arg[2]);
105 }
106 return 0;
107 }
108
SYS_FUNC(chown)109 SYS_FUNC(chown)
110 {
111 if (entering(tcp)) {
112 printpath(tcp, tcp->u_arg[0]);
113 printuid(", ", tcp->u_arg[1]);
114 printuid(", ", tcp->u_arg[2]);
115 }
116 return 0;
117 }
118
SYS_FUNC(fchown)119 SYS_FUNC(fchown)
120 {
121 if (entering(tcp)) {
122 printfd(tcp, tcp->u_arg[0]);
123 printuid(", ", tcp->u_arg[1]);
124 printuid(", ", tcp->u_arg[2]);
125 }
126 return 0;
127 }
128
129 void
printuid(const char * text,const unsigned int uid)130 printuid(const char *text, const unsigned int uid)
131 {
132 if ((unsigned int) -1 == uid || (uid_t) -1 == uid)
133 tprintf("%s-1", text);
134 else
135 tprintf("%s%u", text, uid);
136 }
137
SYS_FUNC(setgroups)138 SYS_FUNC(setgroups)
139 {
140 if (entering(tcp)) {
141 unsigned long len, size, start, cur, end, abbrev_end;
142 uid_t gid;
143 int failed = 0;
144
145 len = tcp->u_arg[0];
146 tprintf("%lu, ", len);
147 if (len == 0) {
148 tprints("[]");
149 return 0;
150 }
151 start = tcp->u_arg[1];
152 if (start == 0) {
153 tprints("NULL");
154 return 0;
155 }
156 size = len * sizeof(gid);
157 end = start + size;
158 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
159 tprintf("%#lx", start);
160 return 0;
161 }
162 if (abbrev(tcp)) {
163 abbrev_end = start + max_strlen * sizeof(gid);
164 if (abbrev_end < start)
165 abbrev_end = end;
166 } else {
167 abbrev_end = end;
168 }
169 tprints("[");
170 for (cur = start; cur < end; cur += sizeof(gid)) {
171 if (cur > start)
172 tprints(", ");
173 if (cur >= abbrev_end) {
174 tprints("...");
175 break;
176 }
177 if (umoven(tcp, cur, sizeof(gid), &gid) < 0) {
178 tprints("?");
179 failed = 1;
180 break;
181 }
182 tprintf("%u", (unsigned int) gid);
183 }
184 tprints("]");
185 if (failed)
186 tprintf(" %#lx", tcp->u_arg[1]);
187 }
188 return 0;
189 }
190
SYS_FUNC(getgroups)191 SYS_FUNC(getgroups)
192 {
193 unsigned long len;
194
195 if (entering(tcp)) {
196 len = tcp->u_arg[0];
197 tprintf("%lu, ", len);
198 } else {
199 unsigned long size, start, cur, end, abbrev_end;
200 uid_t gid;
201 int failed = 0;
202
203 start = tcp->u_arg[1];
204 if (start == 0) {
205 tprints("NULL");
206 return 0;
207 }
208 len = tcp->u_rval;
209 if (len == 0) {
210 tprints("[]");
211 return 0;
212 }
213 size = len * sizeof(gid);
214 end = start + size;
215 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
216 size / sizeof(gid) != len || end < start) {
217 tprintf("%#lx", start);
218 return 0;
219 }
220 if (abbrev(tcp)) {
221 abbrev_end = start + max_strlen * sizeof(gid);
222 if (abbrev_end < start)
223 abbrev_end = end;
224 } else {
225 abbrev_end = end;
226 }
227 tprints("[");
228 for (cur = start; cur < end; cur += sizeof(gid)) {
229 if (cur > start)
230 tprints(", ");
231 if (cur >= abbrev_end) {
232 tprints("...");
233 break;
234 }
235 if (umoven(tcp, cur, sizeof(gid), &gid) < 0) {
236 tprints("?");
237 failed = 1;
238 break;
239 }
240 tprintf("%u", (unsigned int) gid);
241 }
242 tprints("]");
243 if (failed)
244 tprintf(" %#lx", tcp->u_arg[1]);
245 }
246 return 0;
247 }
248
249 #endif /* STRACE_UID_SIZE */
250