blob: 376d0591ae69e4ee1ab9cc21a2ed31e69ec0d429 [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
10# define sys_getuid SIZEIFY(sys_getuid)
11# define sys_setfsuid SIZEIFY(sys_setfsuid)
12# define sys_setuid SIZEIFY(sys_setuid)
13# define sys_getresuid SIZEIFY(sys_getresuid)
14# define sys_setreuid SIZEIFY(sys_setreuid)
15# define sys_setresuid SIZEIFY(sys_setresuid)
16# define sys_chown SIZEIFY(sys_chown)
17# define sys_fchown SIZEIFY(sys_fchown)
18# define printuid SIZEIFY(printuid)
19#endif /* STRACE_UID_SIZE */
20
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000021#include "defs.h"
22
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000023#ifdef STRACE_UID_SIZE
24# if !NEED_UID16_PARSERS
25# undef STRACE_UID_SIZE
26# endif
27#else
28# define STRACE_UID_SIZE 32
29#endif
30
31#ifdef STRACE_UID_SIZE
32
33# undef uid_t
34# define uid_t uid_t_(STRACE_UID_SIZE)
35# define uid_t_(size) uid_t__(size)
36# define uid_t__(size) uint ## size ## _t
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000037
38int
39sys_getuid(struct tcb *tcp)
40{
41 if (exiting(tcp))
42 tcp->u_rval = (uid_t) tcp->u_rval;
43 return RVAL_UDECIMAL;
44}
45
46int
47sys_setfsuid(struct tcb *tcp)
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
56int
57sys_setuid(struct tcb *tcp)
58{
59 if (entering(tcp)) {
60 tprintf("%u", (uid_t) tcp->u_arg[0]);
61 }
62 return 0;
63}
64
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000065static void
66get_print_uid(struct tcb *tcp, const char *prefix, const long addr)
67{
68 uid_t uid;
69
70 if (umove(tcp, addr, &uid) < 0)
71 tprintf("%s%#lx", prefix, addr);
72 else
73 tprintf("%s[%u]", prefix, uid);
74}
75
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000076int
77sys_getresuid(struct tcb *tcp)
78{
79 if (exiting(tcp)) {
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000080 if (syserror(tcp)) {
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000081 tprintf("%#lx, %#lx, %#lx", tcp->u_arg[0],
82 tcp->u_arg[1], tcp->u_arg[2]);
Dmitry V. Levin80f7db12014-12-13 21:49:01 +000083 } else {
84 get_print_uid(tcp, "", tcp->u_arg[0]);
85 get_print_uid(tcp, ", ", tcp->u_arg[1]);
86 get_print_uid(tcp, ", ", tcp->u_arg[2]);
Dmitry V. Levine93ef1e2014-12-11 19:25:02 +000087 }
88 }
89 return 0;
90}
91
92int
93sys_setreuid(struct tcb *tcp)
94{
95 if (entering(tcp)) {
96 printuid("", tcp->u_arg[0]);
97 printuid(", ", tcp->u_arg[1]);
98 }
99 return 0;
100}
101
102int
103sys_setresuid(struct tcb *tcp)
104{
105 if (entering(tcp)) {
106 printuid("", tcp->u_arg[0]);
107 printuid(", ", tcp->u_arg[1]);
108 printuid(", ", tcp->u_arg[2]);
109 }
110 return 0;
111}
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000112
Dmitry V. Levin2f7d0202014-12-13 16:20:44 +0000113int
114sys_chown(struct tcb *tcp)
115{
116 if (entering(tcp)) {
117 printpath(tcp, tcp->u_arg[0]);
118 printuid(", ", tcp->u_arg[1]);
119 printuid(", ", tcp->u_arg[2]);
120 }
121 return 0;
122}
123
124int
125sys_fchown(struct tcb *tcp)
126{
127 if (entering(tcp)) {
128 printfd(tcp, tcp->u_arg[0]);
129 printuid(", ", tcp->u_arg[1]);
130 printuid(", ", tcp->u_arg[2]);
131 }
132 return 0;
133}
134
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000135void
136printuid(const char *text, const unsigned int uid)
137{
Dmitry V. Levin80f7db12014-12-13 21:49:01 +0000138 if ((unsigned int) -1 == uid || (uid_t) -1 == uid)
Dmitry V. Levin25ebe462014-12-13 16:02:22 +0000139 tprintf("%s-1", text);
140 else
141 tprintf("%s%u", text, uid);
142}
Dmitry V. Levin80f7db12014-12-13 21:49:01 +0000143
144#endif /* STRACE_UID_SIZE */