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