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-2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Copyright (c) 2014-2017 The strace developers.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifdef STRACE_UID_SIZE
34 # if STRACE_UID_SIZE != 16
35 # error invalid STRACE_UID_SIZE
38 # define SIZEIFY(x) SIZEIFY_(x, STRACE_UID_SIZE)
39 # define SIZEIFY_(x, size) SIZEIFY__(x, size)
40 # define SIZEIFY__(x, size) x ## size
42 # define printuid SIZEIFY(printuid)
43 # define sys_chown SIZEIFY(sys_chown)
44 # define sys_fchown SIZEIFY(sys_fchown)
45 # define sys_getgroups SIZEIFY(sys_getgroups)
46 # define sys_getresuid SIZEIFY(sys_getresuid)
47 # define sys_getuid SIZEIFY(sys_getuid)
48 # define sys_setfsuid SIZEIFY(sys_setfsuid)
49 # define sys_setgroups SIZEIFY(sys_setgroups)
50 # define sys_setresuid SIZEIFY(sys_setresuid)
51 # define sys_setreuid SIZEIFY(sys_setreuid)
52 # define sys_setuid SIZEIFY(sys_setuid)
53 #endif /* STRACE_UID_SIZE */
57 #ifdef STRACE_UID_SIZE
58 # if !NEED_UID16_PARSERS
59 # undef STRACE_UID_SIZE
62 # define STRACE_UID_SIZE 32
65 #ifdef STRACE_UID_SIZE
68 # define uid_t uid_t_(STRACE_UID_SIZE)
69 # define uid_t_(size) uid_t__(size)
70 # define uid_t__(size) uint ## size ## _t
74 return RVAL_UDECIMAL | RVAL_DECODED;
79 printuid("", tcp->u_arg[0]);
81 return RVAL_UDECIMAL | RVAL_DECODED;
86 printuid("", tcp->u_arg[0]);
92 get_print_uid(struct tcb *const tcp, const char *const prefix,
93 const kernel_ulong_t addr)
98 if (!umove_or_printaddr(tcp, addr, &uid)) {
109 get_print_uid(tcp, "", tcp->u_arg[0]);
110 get_print_uid(tcp, ", ", tcp->u_arg[1]);
111 get_print_uid(tcp, ", ", tcp->u_arg[2]);
118 printuid("", tcp->u_arg[0]);
119 printuid(", ", tcp->u_arg[1]);
126 printuid("", tcp->u_arg[0]);
127 printuid(", ", tcp->u_arg[1]);
128 printuid(", ", tcp->u_arg[2]);
135 printpath(tcp, tcp->u_arg[0]);
136 printuid(", ", tcp->u_arg[1]);
137 printuid(", ", tcp->u_arg[2]);
144 printfd(tcp, tcp->u_arg[0]);
145 printuid(", ", tcp->u_arg[1]);
146 printuid(", ", tcp->u_arg[2]);
152 printuid(const char *text, const unsigned int uid)
154 if ((uid_t) -1U == (uid_t) uid)
155 tprintf("%s-1", text);
157 tprintf("%s%u", text, (uid_t) uid);
161 print_gid(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
163 printuid("", (*(uid_t *) elem_buf));
169 print_groups(struct tcb *const tcp, const unsigned int len,
170 const kernel_ulong_t addr)
172 static unsigned long ngroups_max;
174 ngroups_max = sysconf(_SC_NGROUPS_MAX);
176 if (len > ngroups_max) {
182 print_array(tcp, addr, len, &gid, sizeof(gid),
183 umoven_or_printaddr, print_gid, 0);
188 const int len = tcp->u_arg[0];
190 tprintf("%d, ", len);
191 print_groups(tcp, len, tcp->u_arg[1]);
198 tprintf("%d, ", (int) tcp->u_arg[0]);
200 print_groups(tcp, tcp->u_rval, tcp->u_arg[1]);
204 #endif /* STRACE_UID_SIZE */