blob: 96b3d38f5e86307cbd4789d71564e685d5a0c285 [file] [log] [blame]
Dmitry V. Levin80f7db12014-12-13 21:49:01 +00001#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
Dmitry V. Levin530bed02014-12-14 13:30:54 +000010# define printuid SIZEIFY(printuid)
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000011# define sys_chown SIZEIFY(sys_chown)
12# define sys_fchown SIZEIFY(sys_fchown)
Dmitry V. Levin530bed02014-12-14 13:30:54 +000013# 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)
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000021#endif /* STRACE_UID_SIZE */
22
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000023#include "defs.h"
24
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000025#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
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000039
40int
41sys_getuid(struct tcb *tcp)
42{
43 if (exiting(tcp))
44 tcp->u_rval = (uid_t) tcp->u_rval;
45 return RVAL_UDECIMAL;
46}
47
48int
49sys_setfsuid(struct tcb *tcp)
50{
51 if (entering(tcp))
52 tprintf("%u", (uid_t) tcp->u_arg[0]);
53 else
54 tcp->u_rval = (uid_t) tcp->u_rval;
55 return RVAL_UDECIMAL;
56}
57
58int
59sys_setuid(struct tcb *tcp)
60{
61 if (entering(tcp)) {
62 tprintf("%u", (uid_t) tcp->u_arg[0]);
63 }
64 return 0;
65}
66
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000067static void
68get_print_uid(struct tcb *tcp, const char *prefix, const long addr)
69{
70 uid_t uid;
71
72 if (umove(tcp, addr, &uid) < 0)
73 tprintf("%s%#lx", prefix, addr);
74 else
75 tprintf("%s[%u]", prefix, uid);
76}
77
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000078int
79sys_getresuid(struct tcb *tcp)
80{
81 if (exiting(tcp)) {
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000082 if (syserror(tcp)) {
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000083 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
84 tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000085 } else {
86 get_print_uid(tcp, "", tcp->u_arg[0]);
87 get_print_uid(tcp, ", ", tcp->u_arg[1]);
88 get_print_uid(tcp, ", ", tcp->u_arg[2]);
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000089 }
90 }
91 return 0;
92}
93
94int
95sys_setreuid(struct tcb *tcp)
96{
97 if (entering(tcp)) {
98 printuid("", tcp->u_arg[0]);
99 printuid(", ", tcp->u_arg[1]);
100 }
101 return 0;
102}
103
104int
105sys_setresuid(struct tcb *tcp)
106{
107 if (entering(tcp)) {
108 printuid("", tcp->u_arg[0]);
109 printuid(", ", tcp->u_arg[1]);
110 printuid(", ", tcp->u_arg[2]);
111 }
112 return 0;
113}
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000114
Dmitry V. Levin2f7d0202014-12-13 16:20:44 +0000115int
116sys_chown(struct tcb *tcp)
117{
118 if (entering(tcp)) {
119 printpath(tcp, tcp->u_arg[0]);
120 printuid(", ", tcp->u_arg[1]);
121 printuid(", ", tcp->u_arg[2]);
122 }
123 return 0;
124}
125
126int
127sys_fchown(struct tcb *tcp)
128{
129 if (entering(tcp)) {
130 printfd(tcp, tcp->u_arg[0]);
131 printuid(", ", tcp->u_arg[1]);
132 printuid(", ", tcp->u_arg[2]);
133 }
134 return 0;
135}
136
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000137void
138printuid(const char *text, const unsigned int uid)
139{
Dmitry V. Levin80f7db12014-12-13 21:49:01 +0000140 if ((unsigned int) -1 == uid || (uid_t) -1 == uid)
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000141 tprintf("%s-1", text);
142 else
143 tprintf("%s%u", text, uid);
144}
Dmitry V. Levin80f7db12014-12-13 21:49:01 +0000145
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000146int
147sys_setgroups(struct tcb *tcp)
148{
149 if (entering(tcp)) {
150 unsigned long len, size, start, cur, end, abbrev_end;
151 uid_t gid;
152 int failed = 0;
153
154 len = tcp->u_arg[0];
155 tprintf("%lu, ", len);
156 if (len == 0) {
157 tprints("[]");
158 return 0;
159 }
160 start = tcp->u_arg[1];
161 if (start == 0) {
162 tprints("NULL");
163 return 0;
164 }
165 size = len * sizeof(gid);
166 end = start + size;
167 if (!verbose(tcp) || size / sizeof(gid) != len || end < start) {
168 tprintf("%#lx", start);
169 return 0;
170 }
171 if (abbrev(tcp)) {
172 abbrev_end = start + max_strlen * sizeof(gid);
173 if (abbrev_end < start)
174 abbrev_end = end;
175 } else {
176 abbrev_end = end;
177 }
178 tprints("[");
179 for (cur = start; cur < end; cur += sizeof(gid)) {
180 if (cur > start)
181 tprints(", ");
182 if (cur >= abbrev_end) {
183 tprints("...");
184 break;
185 }
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100186 if (umoven(tcp, cur, sizeof(gid), &gid) < 0) {
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000187 tprints("?");
188 failed = 1;
189 break;
190 }
191 tprintf("%u", (unsigned int) gid);
192 }
193 tprints("]");
194 if (failed)
195 tprintf(" %#lx", tcp->u_arg[1]);
196 }
197 return 0;
198}
199
200int
201sys_getgroups(struct tcb *tcp)
202{
203 unsigned long len;
204
205 if (entering(tcp)) {
206 len = tcp->u_arg[0];
207 tprintf("%lu, ", len);
208 } else {
209 unsigned long size, start, cur, end, abbrev_end;
210 uid_t gid;
211 int failed = 0;
212
213 start = tcp->u_arg[1];
214 if (start == 0) {
215 tprints("NULL");
216 return 0;
217 }
218 len = tcp->u_rval;
219 if (len == 0) {
220 tprints("[]");
221 return 0;
222 }
223 size = len * sizeof(gid);
224 end = start + size;
225 if (!verbose(tcp) || tcp->u_arg[0] == 0 ||
226 size / sizeof(gid) != len || end < start) {
227 tprintf("%#lx", start);
228 return 0;
229 }
230 if (abbrev(tcp)) {
231 abbrev_end = start + max_strlen * sizeof(gid);
232 if (abbrev_end < start)
233 abbrev_end = end;
234 } else {
235 abbrev_end = end;
236 }
237 tprints("[");
238 for (cur = start; cur < end; cur += sizeof(gid)) {
239 if (cur > start)
240 tprints(", ");
241 if (cur >= abbrev_end) {
242 tprints("...");
243 break;
244 }
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100245 if (umoven(tcp, cur, sizeof(gid), &gid) < 0) {
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000246 tprints("?");
247 failed = 1;
248 break;
249 }
250 tprintf("%u", (unsigned int) gid);
251 }
252 tprints("]");
253 if (failed)
254 tprintf(" %#lx", tcp->u_arg[1]);
255 }
256 return 0;
257}
258
Dmitry V. Levin80f7db12014-12-13 21:49:01 +0000259#endif /* STRACE_UID_SIZE */