Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 1 | #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. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 10 | # define printuid SIZEIFY(printuid) |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 11 | # define sys_chown SIZEIFY(sys_chown) |
| 12 | # define sys_fchown SIZEIFY(sys_fchown) |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 13 | # 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. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 21 | #endif /* STRACE_UID_SIZE */ |
| 22 | |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 23 | #include "defs.h" |
| 24 | |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 25 | #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. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 39 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 40 | SYS_FUNC(getuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 41 | { |
| 42 | if (exiting(tcp)) |
| 43 | tcp->u_rval = (uid_t) tcp->u_rval; |
| 44 | return RVAL_UDECIMAL; |
| 45 | } |
| 46 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 47 | SYS_FUNC(setfsuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 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 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 56 | SYS_FUNC(setuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 57 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 58 | printuid("", tcp->u_arg[0]); |
| 59 | |
| 60 | return RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 63 | static void |
| 64 | get_print_uid(struct tcb *tcp, const char *prefix, const long addr) |
| 65 | { |
| 66 | uid_t uid; |
| 67 | |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 68 | tprints(prefix); |
| 69 | if (!umove_or_printaddr(tcp, addr, &uid)) |
| 70 | tprintf("[%u]", uid); |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 73 | SYS_FUNC(getresuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 74 | { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 75 | if (entering(tcp)) |
| 76 | return 0; |
| 77 | |
| 78 | get_print_uid(tcp, "", tcp->u_arg[0]); |
| 79 | get_print_uid(tcp, ", ", tcp->u_arg[1]); |
| 80 | get_print_uid(tcp, ", ", tcp->u_arg[2]); |
| 81 | |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 85 | SYS_FUNC(setreuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 86 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 87 | printuid("", tcp->u_arg[0]); |
| 88 | printuid(", ", tcp->u_arg[1]); |
| 89 | |
| 90 | return RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 93 | SYS_FUNC(setresuid) |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 94 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 95 | printuid("", tcp->u_arg[0]); |
| 96 | printuid(", ", tcp->u_arg[1]); |
| 97 | printuid(", ", tcp->u_arg[2]); |
| 98 | |
| 99 | return RVAL_DECODED; |
Dmitry V. Levin | e93ef1e | 2014-12-11 19:25:02 +0000 | [diff] [blame] | 100 | } |
Dmitry V. Levin | 25ebe46 | 2014-12-13 16:02:22 +0000 | [diff] [blame] | 101 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 102 | SYS_FUNC(chown) |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 103 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 104 | printpath(tcp, tcp->u_arg[0]); |
| 105 | printuid(", ", tcp->u_arg[1]); |
| 106 | printuid(", ", tcp->u_arg[2]); |
| 107 | |
| 108 | return RVAL_DECODED; |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 111 | SYS_FUNC(fchown) |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 112 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 113 | printfd(tcp, tcp->u_arg[0]); |
| 114 | printuid(", ", tcp->u_arg[1]); |
| 115 | printuid(", ", tcp->u_arg[2]); |
| 116 | |
| 117 | return RVAL_DECODED; |
Dmitry V. Levin | 2f7d020 | 2014-12-13 16:20:44 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Dmitry V. Levin | 25ebe46 | 2014-12-13 16:02:22 +0000 | [diff] [blame] | 120 | void |
| 121 | printuid(const char *text, const unsigned int uid) |
| 122 | { |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 123 | if ((unsigned int) -1 == uid || (uid_t) -1 == uid) |
Dmitry V. Levin | 25ebe46 | 2014-12-13 16:02:22 +0000 | [diff] [blame] | 124 | tprintf("%s-1", text); |
| 125 | else |
| 126 | tprintf("%s%u", text, uid); |
| 127 | } |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 128 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 129 | SYS_FUNC(setgroups) |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 130 | { |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 131 | unsigned long cur, abbrev_end; |
| 132 | uid_t gid; |
| 133 | int failed = 0; |
| 134 | const unsigned long len = tcp->u_arg[0]; |
| 135 | const unsigned long start = tcp->u_arg[1]; |
| 136 | const unsigned long size = len * sizeof(gid); |
| 137 | const unsigned long end = start + size; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 138 | |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 139 | tprintf("%lu, ", len); |
| 140 | if (len == 0) { |
| 141 | tprints("[]"); |
| 142 | return RVAL_DECODED; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 143 | } |
Dmitry V. Levin | 1427862 | 2015-07-16 00:01:25 +0000 | [diff] [blame] | 144 | if (!start || !verbose(tcp) || |
| 145 | size / sizeof(gid) != len || end < start) { |
| 146 | printaddr(start); |
| 147 | return RVAL_DECODED; |
| 148 | } |
| 149 | if (abbrev(tcp)) { |
| 150 | abbrev_end = start + max_strlen * sizeof(gid); |
| 151 | if (abbrev_end < start) |
| 152 | abbrev_end = end; |
| 153 | } else { |
| 154 | abbrev_end = end; |
| 155 | } |
| 156 | tprints("["); |
| 157 | for (cur = start; cur < end; cur += sizeof(gid)) { |
| 158 | if (cur > start) |
| 159 | tprints(", "); |
| 160 | if (cur >= abbrev_end) { |
| 161 | tprints("..."); |
| 162 | break; |
| 163 | } |
| 164 | if (umoven(tcp, cur, sizeof(gid), &gid) < 0) { |
| 165 | tprints("?"); |
| 166 | failed = 1; |
| 167 | break; |
| 168 | } |
| 169 | tprintf("%u", (unsigned int) gid); |
| 170 | } |
| 171 | tprints("]"); |
| 172 | if (failed) { |
| 173 | tprints(" "); |
| 174 | printaddr(start); |
| 175 | } |
| 176 | |
| 177 | return RVAL_DECODED; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 180 | SYS_FUNC(getgroups) |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 181 | { |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 182 | if (entering(tcp)) { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 183 | tprintf("%lu, ", tcp->u_arg[0]); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 184 | } else { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 185 | unsigned long cur, abbrev_end; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 186 | uid_t gid; |
| 187 | int failed = 0; |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 188 | const unsigned long len = tcp->u_rval; |
| 189 | const unsigned long size = len * sizeof(gid); |
| 190 | const unsigned long start = tcp->u_arg[1]; |
| 191 | const unsigned long end = start + size; |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 192 | |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 193 | if (!start) { |
| 194 | printaddr(start); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 195 | return 0; |
| 196 | } |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 197 | if (len == 0) { |
| 198 | tprints("[]"); |
| 199 | return 0; |
| 200 | } |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 201 | if (!verbose(tcp) || syserror(tcp) || |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 202 | size / sizeof(gid) != len || end < start) { |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 203 | printaddr(start); |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | if (abbrev(tcp)) { |
| 207 | abbrev_end = start + max_strlen * sizeof(gid); |
| 208 | if (abbrev_end < start) |
| 209 | abbrev_end = end; |
| 210 | } else { |
| 211 | abbrev_end = end; |
| 212 | } |
| 213 | tprints("["); |
| 214 | for (cur = start; cur < end; cur += sizeof(gid)) { |
| 215 | if (cur > start) |
| 216 | tprints(", "); |
| 217 | if (cur >= abbrev_end) { |
| 218 | tprints("..."); |
| 219 | break; |
| 220 | } |
Denys Vlasenko | 7e69ed9 | 2015-03-21 19:50:53 +0100 | [diff] [blame] | 221 | if (umoven(tcp, cur, sizeof(gid), &gid) < 0) { |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 222 | tprints("?"); |
| 223 | failed = 1; |
| 224 | break; |
| 225 | } |
| 226 | tprintf("%u", (unsigned int) gid); |
| 227 | } |
| 228 | tprints("]"); |
Dmitry V. Levin | 288a870 | 2015-07-15 23:37:31 +0000 | [diff] [blame] | 229 | if (failed) { |
| 230 | tprints(" "); |
| 231 | printaddr(start); |
| 232 | } |
Dmitry V. Levin | 530bed0 | 2014-12-14 13:30:54 +0000 | [diff] [blame] | 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
Dmitry V. Levin | 80f7db1 | 2014-12-13 21:49:01 +0000 | [diff] [blame] | 237 | #endif /* STRACE_UID_SIZE */ |