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-2018 The strace developers.
10 * SPDX-License-Identifier: LGPL-2.1-or-later
13 #ifdef STRACE_UID_SIZE
14 # if STRACE_UID_SIZE != 16
15 # error invalid STRACE_UID_SIZE
18 # define SIZEIFY(x) SIZEIFY_(x, STRACE_UID_SIZE)
19 # define SIZEIFY_(x, size) SIZEIFY__(x, size)
20 # define SIZEIFY__(x, size) x ## size
22 # define printuid SIZEIFY(printuid)
23 # define sys_chown SIZEIFY(sys_chown)
24 # define sys_fchown SIZEIFY(sys_fchown)
25 # define sys_getgroups SIZEIFY(sys_getgroups)
26 # define sys_getresuid SIZEIFY(sys_getresuid)
27 # define sys_getuid SIZEIFY(sys_getuid)
28 # define sys_setfsuid SIZEIFY(sys_setfsuid)
29 # define sys_setgroups SIZEIFY(sys_setgroups)
30 # define sys_setresuid SIZEIFY(sys_setresuid)
31 # define sys_setreuid SIZEIFY(sys_setreuid)
32 # define sys_setuid SIZEIFY(sys_setuid)
33 #endif /* STRACE_UID_SIZE */
37 #ifdef STRACE_UID_SIZE
38 # if !HAVE_ARCH_UID16_SYSCALLS
39 # undef STRACE_UID_SIZE
42 # define STRACE_UID_SIZE 32
45 #ifdef STRACE_UID_SIZE
48 # define uid_t uid_t_(STRACE_UID_SIZE)
49 # define uid_t_(size) uid_t__(size)
50 # define uid_t__(size) uint ## size ## _t
59 printuid("", tcp->u_arg[0]);
66 printuid("", tcp->u_arg[0]);
72 get_print_uid(struct tcb *const tcp, const char *const prefix,
73 const kernel_ulong_t addr)
78 if (!umove_or_printaddr(tcp, addr, &uid)) {
89 get_print_uid(tcp, "", tcp->u_arg[0]);
90 get_print_uid(tcp, ", ", tcp->u_arg[1]);
91 get_print_uid(tcp, ", ", tcp->u_arg[2]);
98 printuid("", tcp->u_arg[0]);
99 printuid(", ", tcp->u_arg[1]);
106 printuid("", tcp->u_arg[0]);
107 printuid(", ", tcp->u_arg[1]);
108 printuid(", ", tcp->u_arg[2]);
115 printpath(tcp, tcp->u_arg[0]);
116 printuid(", ", tcp->u_arg[1]);
117 printuid(", ", tcp->u_arg[2]);
124 printfd(tcp, tcp->u_arg[0]);
125 printuid(", ", tcp->u_arg[1]);
126 printuid(", ", tcp->u_arg[2]);
132 printuid(const char *text, const unsigned int uid)
134 if ((uid_t) -1U == (uid_t) uid)
135 tprintf("%s-1", text);
137 tprintf("%s%u", text, (uid_t) uid);
141 print_gid(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
143 printuid("", (*(uid_t *) elem_buf));
149 print_groups(struct tcb *const tcp, const unsigned int len,
150 const kernel_ulong_t addr)
152 static unsigned long ngroups_max;
154 ngroups_max = sysconf(_SC_NGROUPS_MAX);
156 if (len > ngroups_max) {
162 print_array(tcp, addr, len, &gid, sizeof(gid),
163 tfetch_mem, print_gid, 0);
168 const int len = tcp->u_arg[0];
170 tprintf("%d, ", len);
171 print_groups(tcp, len, tcp->u_arg[1]);
178 tprintf("%d, ", (int) tcp->u_arg[0]);
180 print_groups(tcp, tcp->u_rval, tcp->u_arg[1]);
184 #endif /* STRACE_UID_SIZE */