blob: 7cf545fa2338dfd76b962263884405bcd8c7e542 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993-1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2003-2015 Dmitry V. Levin <ldv@altlinux.org>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000032#ifdef STRACE_UID_SIZE
33# if STRACE_UID_SIZE != 16
34# error invalid STRACE_UID_SIZE
35# endif
36
37# define SIZEIFY(x) SIZEIFY_(x,STRACE_UID_SIZE)
38# define SIZEIFY_(x,size) SIZEIFY__(x,size)
39# define SIZEIFY__(x,size) x ## size
40
Dmitry V. Levin530bed02014-12-14 13:30:54 +000041# define printuid SIZEIFY(printuid)
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000042# define sys_chown SIZEIFY(sys_chown)
43# define sys_fchown SIZEIFY(sys_fchown)
Dmitry V. Levin530bed02014-12-14 13:30:54 +000044# define sys_getgroups SIZEIFY(sys_getgroups)
45# define sys_getresuid SIZEIFY(sys_getresuid)
46# define sys_getuid SIZEIFY(sys_getuid)
47# define sys_setfsuid SIZEIFY(sys_setfsuid)
48# define sys_setgroups SIZEIFY(sys_setgroups)
49# define sys_setresuid SIZEIFY(sys_setresuid)
50# define sys_setreuid SIZEIFY(sys_setreuid)
51# define sys_setuid SIZEIFY(sys_setuid)
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000052#endif /* STRACE_UID_SIZE */
53
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000054#include "defs.h"
55
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000056#ifdef STRACE_UID_SIZE
57# if !NEED_UID16_PARSERS
58# undef STRACE_UID_SIZE
59# endif
60#else
61# define STRACE_UID_SIZE 32
62#endif
63
64#ifdef STRACE_UID_SIZE
65
66# undef uid_t
67# define uid_t uid_t_(STRACE_UID_SIZE)
68# define uid_t_(size) uid_t__(size)
69# define uid_t__(size) uint ## size ## _t
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000070
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000071SYS_FUNC(getuid)
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000072{
Dmitry V. Levinabfa9392015-12-27 00:18:03 +000073 return RVAL_UDECIMAL | RVAL_DECODED;
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000074}
75
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000076SYS_FUNC(setfsuid)
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000077{
Dmitry V. Levinba210af2016-04-18 16:24:48 +000078 tprintf("%u", (uid_t) tcp->u_arg[0]);
Dmitry V. Levinabfa9392015-12-27 00:18:03 +000079
80 return RVAL_UDECIMAL | RVAL_DECODED;
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000081}
82
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000083SYS_FUNC(setuid)
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000084{
Dmitry V. Levin14278622015-07-16 00:01:25 +000085 printuid("", tcp->u_arg[0]);
86
87 return RVAL_DECODED;
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000088}
89
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000090static void
91get_print_uid(struct tcb *tcp, const char *prefix, const long addr)
92{
93 uid_t uid;
94
Dmitry V. Levin288a8702015-07-15 23:37:31 +000095 tprints(prefix);
96 if (!umove_or_printaddr(tcp, addr, &uid))
97 tprintf("[%u]", uid);
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000098}
99
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000100SYS_FUNC(getresuid)
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +0000101{
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000102 if (entering(tcp))
103 return 0;
104
105 get_print_uid(tcp, "", tcp->u_arg[0]);
106 get_print_uid(tcp, ", ", tcp->u_arg[1]);
107 get_print_uid(tcp, ", ", tcp->u_arg[2]);
108
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +0000109 return 0;
110}
111
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000112SYS_FUNC(setreuid)
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +0000113{
Dmitry V. Levin14278622015-07-16 00:01:25 +0000114 printuid("", tcp->u_arg[0]);
115 printuid(", ", tcp->u_arg[1]);
116
117 return RVAL_DECODED;
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +0000118}
119
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000120SYS_FUNC(setresuid)
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +0000121{
Dmitry V. Levin14278622015-07-16 00:01:25 +0000122 printuid("", tcp->u_arg[0]);
123 printuid(", ", tcp->u_arg[1]);
124 printuid(", ", tcp->u_arg[2]);
125
126 return RVAL_DECODED;
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +0000127}
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000128
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000129SYS_FUNC(chown)
Dmitry V. Levin2f7d0202014-12-13 16:20:44 +0000130{
Dmitry V. Levin14278622015-07-16 00:01:25 +0000131 printpath(tcp, tcp->u_arg[0]);
132 printuid(", ", tcp->u_arg[1]);
133 printuid(", ", tcp->u_arg[2]);
134
135 return RVAL_DECODED;
Dmitry V. Levin2f7d0202014-12-13 16:20:44 +0000136}
137
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000138SYS_FUNC(fchown)
Dmitry V. Levin2f7d0202014-12-13 16:20:44 +0000139{
Dmitry V. Levin14278622015-07-16 00:01:25 +0000140 printfd(tcp, tcp->u_arg[0]);
141 printuid(", ", tcp->u_arg[1]);
142 printuid(", ", tcp->u_arg[2]);
143
144 return RVAL_DECODED;
Dmitry V. Levin2f7d0202014-12-13 16:20:44 +0000145}
146
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000147void
148printuid(const char *text, const unsigned int uid)
149{
Dmitry V. Levina99bcbf2016-04-14 23:53:08 +0000150 if ((uid_t) -1U == (uid_t) uid)
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000151 tprintf("%s-1", text);
152 else
Dmitry V. Levina99bcbf2016-04-14 23:53:08 +0000153 tprintf("%s%u", text, (uid_t) uid);
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000154}
Dmitry V. Levin80f7db12014-12-13 21:49:01 +0000155
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000156SYS_FUNC(setgroups)
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000157{
Dmitry V. Levin14278622015-07-16 00:01:25 +0000158 unsigned long cur, abbrev_end;
159 uid_t gid;
160 int failed = 0;
161 const unsigned long len = tcp->u_arg[0];
162 const unsigned long start = tcp->u_arg[1];
163 const unsigned long size = len * sizeof(gid);
164 const unsigned long end = start + size;
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000165
Dmitry V. Levin14278622015-07-16 00:01:25 +0000166 tprintf("%lu, ", len);
167 if (len == 0) {
168 tprints("[]");
169 return RVAL_DECODED;
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000170 }
Dmitry V. Levin14278622015-07-16 00:01:25 +0000171 if (!start || !verbose(tcp) ||
172 size / sizeof(gid) != len || end < start) {
173 printaddr(start);
174 return RVAL_DECODED;
175 }
176 if (abbrev(tcp)) {
177 abbrev_end = start + max_strlen * sizeof(gid);
178 if (abbrev_end < start)
179 abbrev_end = end;
180 } else {
181 abbrev_end = end;
182 }
183 tprints("[");
184 for (cur = start; cur < end; cur += sizeof(gid)) {
185 if (cur > start)
186 tprints(", ");
187 if (cur >= abbrev_end) {
188 tprints("...");
189 break;
190 }
191 if (umoven(tcp, cur, sizeof(gid), &gid) < 0) {
192 tprints("?");
193 failed = 1;
194 break;
195 }
196 tprintf("%u", (unsigned int) gid);
197 }
198 tprints("]");
199 if (failed) {
200 tprints(" ");
201 printaddr(start);
202 }
203
204 return RVAL_DECODED;
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000205}
206
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000207SYS_FUNC(getgroups)
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000208{
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000209 if (entering(tcp)) {
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000210 tprintf("%lu, ", tcp->u_arg[0]);
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000211 } else {
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000212 unsigned long cur, abbrev_end;
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000213 uid_t gid;
214 int failed = 0;
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000215 const unsigned long len = tcp->u_rval;
216 const unsigned long size = len * sizeof(gid);
217 const unsigned long start = tcp->u_arg[1];
218 const unsigned long end = start + size;
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000219
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000220 if (!start) {
221 printaddr(start);
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000222 return 0;
223 }
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000224 if (len == 0) {
225 tprints("[]");
226 return 0;
227 }
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000228 if (!verbose(tcp) || syserror(tcp) ||
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000229 size / sizeof(gid) != len || end < start) {
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000230 printaddr(start);
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000231 return 0;
232 }
233 if (abbrev(tcp)) {
234 abbrev_end = start + max_strlen * sizeof(gid);
235 if (abbrev_end < start)
236 abbrev_end = end;
237 } else {
238 abbrev_end = end;
239 }
240 tprints("[");
241 for (cur = start; cur < end; cur += sizeof(gid)) {
242 if (cur > start)
243 tprints(", ");
244 if (cur >= abbrev_end) {
245 tprints("...");
246 break;
247 }
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100248 if (umoven(tcp, cur, sizeof(gid), &gid) < 0) {
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000249 tprints("?");
250 failed = 1;
251 break;
252 }
253 tprintf("%u", (unsigned int) gid);
254 }
255 tprints("]");
Dmitry V. Levin288a8702015-07-15 23:37:31 +0000256 if (failed) {
257 tprints(" ");
258 printaddr(start);
259 }
Dmitry V. Levin530bed02014-12-14 13:30:54 +0000260 }
261 return 0;
262}
263
Dmitry V. Levin80f7db12014-12-13 21:49:01 +0000264#endif /* STRACE_UID_SIZE */