From 7211480fee9000a6631698354387475065c539ea Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Thu, 11 Dec 2014 19:25:02 +0000 Subject: [PATCH] process.c: move getgroups* and setgroups* parsers to a separate file * groups.c: New file. * Makefile.am (strace_SOURCES): Add it. * process.c: Move sys_setgroups, sys_getgroups, sys_setgroups32, sys_getgroups32, and related code to groups.c. --- Makefile.am | 1 + groups.c | 237 ++++++++++++++++++++++++++++++++++++++++++++++++++++ process.c | 234 --------------------------------------------------- 3 files changed, 238 insertions(+), 234 deletions(-) create mode 100644 groups.c diff --git a/Makefile.am b/Makefile.am index c344338d..52f7f46d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,7 @@ strace_SOURCES = \ get_robust_list.c \ getcpu.c \ getcwd.c \ + groups.c \ inotify.c \ io.c \ ioctl.c \ diff --git a/groups.c b/groups.c new file mode 100644 index 00000000..2b4350c7 --- /dev/null +++ b/groups.c @@ -0,0 +1,237 @@ +#include "defs.h" + +#include +#undef GETGROUPS_T +#define GETGROUPS_T __kernel_gid_t +#undef GETGROUPS32_T +#define GETGROUPS32_T __kernel_gid32_t + +int +sys_setgroups(struct tcb *tcp) +{ + if (entering(tcp)) { + unsigned long len, size, start, cur, end, abbrev_end; + GETGROUPS_T gid; + int failed = 0; + + len = tcp->u_arg[0]; + tprintf("%lu, ", len); + if (len == 0) { + tprints("[]"); + return 0; + } + start = tcp->u_arg[1]; + if (start == 0) { + tprints("NULL"); + return 0; + } + size = len * sizeof(gid); + end = start + size; + if (!verbose(tcp) || size / sizeof(gid) != len || end < start) { + tprintf("%#lx", start); + return 0; + } + if (abbrev(tcp)) { + abbrev_end = start + max_strlen * sizeof(gid); + if (abbrev_end < start) + abbrev_end = end; + } else { + abbrev_end = end; + } + tprints("["); + for (cur = start; cur < end; cur += sizeof(gid)) { + if (cur > start) + tprints(", "); + if (cur >= abbrev_end) { + tprints("..."); + break; + } + if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { + tprints("?"); + failed = 1; + break; + } + tprintf("%lu", (unsigned long) gid); + } + tprints("]"); + if (failed) + tprintf(" %#lx", tcp->u_arg[1]); + } + return 0; +} + +int +sys_getgroups(struct tcb *tcp) +{ + unsigned long len; + + if (entering(tcp)) { + len = tcp->u_arg[0]; + tprintf("%lu, ", len); + } else { + unsigned long size, start, cur, end, abbrev_end; + GETGROUPS_T gid; + int failed = 0; + + len = tcp->u_rval; + if (len == 0) { + tprints("[]"); + return 0; + } + start = tcp->u_arg[1]; + if (start == 0) { + tprints("NULL"); + return 0; + } + if (tcp->u_arg[0] == 0) { + tprintf("%#lx", start); + return 0; + } + size = len * sizeof(gid); + end = start + size; + if (!verbose(tcp) || tcp->u_arg[0] == 0 || + size / sizeof(gid) != len || end < start) { + tprintf("%#lx", start); + return 0; + } + if (abbrev(tcp)) { + abbrev_end = start + max_strlen * sizeof(gid); + if (abbrev_end < start) + abbrev_end = end; + } else { + abbrev_end = end; + } + tprints("["); + for (cur = start; cur < end; cur += sizeof(gid)) { + if (cur > start) + tprints(", "); + if (cur >= abbrev_end) { + tprints("..."); + break; + } + if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { + tprints("?"); + failed = 1; + break; + } + tprintf("%lu", (unsigned long) gid); + } + tprints("]"); + if (failed) + tprintf(" %#lx", tcp->u_arg[1]); + } + return 0; +} + +int +sys_setgroups32(struct tcb *tcp) +{ + if (entering(tcp)) { + unsigned long len, size, start, cur, end, abbrev_end; + GETGROUPS32_T gid; + int failed = 0; + + len = tcp->u_arg[0]; + tprintf("%lu, ", len); + if (len == 0) { + tprints("[]"); + return 0; + } + start = tcp->u_arg[1]; + if (start == 0) { + tprints("NULL"); + return 0; + } + size = len * sizeof(gid); + end = start + size; + if (!verbose(tcp) || size / sizeof(gid) != len || end < start) { + tprintf("%#lx", start); + return 0; + } + if (abbrev(tcp)) { + abbrev_end = start + max_strlen * sizeof(gid); + if (abbrev_end < start) + abbrev_end = end; + } else { + abbrev_end = end; + } + tprints("["); + for (cur = start; cur < end; cur += sizeof(gid)) { + if (cur > start) + tprints(", "); + if (cur >= abbrev_end) { + tprints("..."); + break; + } + if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { + tprints("?"); + failed = 1; + break; + } + tprintf("%lu", (unsigned long) gid); + } + tprints("]"); + if (failed) + tprintf(" %#lx", tcp->u_arg[1]); + } + return 0; +} + +int +sys_getgroups32(struct tcb *tcp) +{ + unsigned long len; + + if (entering(tcp)) { + len = tcp->u_arg[0]; + tprintf("%lu, ", len); + } else { + unsigned long size, start, cur, end, abbrev_end; + GETGROUPS32_T gid; + int failed = 0; + + len = tcp->u_rval; + if (len == 0) { + tprints("[]"); + return 0; + } + start = tcp->u_arg[1]; + if (start == 0) { + tprints("NULL"); + return 0; + } + size = len * sizeof(gid); + end = start + size; + if (!verbose(tcp) || tcp->u_arg[0] == 0 || + size / sizeof(gid) != len || end < start) { + tprintf("%#lx", start); + return 0; + } + if (abbrev(tcp)) { + abbrev_end = start + max_strlen * sizeof(gid); + if (abbrev_end < start) + abbrev_end = end; + } else { + abbrev_end = end; + } + tprints("["); + for (cur = start; cur < end; cur += sizeof(gid)) { + if (cur > start) + tprints(", "); + if (cur >= abbrev_end) { + tprints("..."); + break; + } + if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { + tprints("?"); + failed = 1; + break; + } + tprintf("%lu", (unsigned long) gid); + } + tprints("]"); + if (failed) + tprintf(" %#lx", tcp->u_arg[1]); + } + return 0; +} diff --git a/process.c b/process.c index cd0c516d..720559d2 100644 --- a/process.c +++ b/process.c @@ -72,10 +72,6 @@ #endif #include -#undef GETGROUPS_T -#define GETGROUPS_T __kernel_gid_t -#undef GETGROUPS32_T -#define GETGROUPS32_T __kernel_gid32_t #if defined(IA64) # include @@ -344,236 +340,6 @@ sys_setresuid(struct tcb *tcp) return 0; } -int -sys_setgroups(struct tcb *tcp) -{ - if (entering(tcp)) { - unsigned long len, size, start, cur, end, abbrev_end; - GETGROUPS_T gid; - int failed = 0; - - len = tcp->u_arg[0]; - tprintf("%lu, ", len); - if (len == 0) { - tprints("[]"); - return 0; - } - start = tcp->u_arg[1]; - if (start == 0) { - tprints("NULL"); - return 0; - } - size = len * sizeof(gid); - end = start + size; - if (!verbose(tcp) || size / sizeof(gid) != len || end < start) { - tprintf("%#lx", start); - return 0; - } - if (abbrev(tcp)) { - abbrev_end = start + max_strlen * sizeof(gid); - if (abbrev_end < start) - abbrev_end = end; - } else { - abbrev_end = end; - } - tprints("["); - for (cur = start; cur < end; cur += sizeof(gid)) { - if (cur > start) - tprints(", "); - if (cur >= abbrev_end) { - tprints("..."); - break; - } - if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { - tprints("?"); - failed = 1; - break; - } - tprintf("%lu", (unsigned long) gid); - } - tprints("]"); - if (failed) - tprintf(" %#lx", tcp->u_arg[1]); - } - return 0; -} - -int -sys_getgroups(struct tcb *tcp) -{ - unsigned long len; - - if (entering(tcp)) { - len = tcp->u_arg[0]; - tprintf("%lu, ", len); - } else { - unsigned long size, start, cur, end, abbrev_end; - GETGROUPS_T gid; - int failed = 0; - - len = tcp->u_rval; - if (len == 0) { - tprints("[]"); - return 0; - } - start = tcp->u_arg[1]; - if (start == 0) { - tprints("NULL"); - return 0; - } - if (tcp->u_arg[0] == 0) { - tprintf("%#lx", start); - return 0; - } - size = len * sizeof(gid); - end = start + size; - if (!verbose(tcp) || tcp->u_arg[0] == 0 || - size / sizeof(gid) != len || end < start) { - tprintf("%#lx", start); - return 0; - } - if (abbrev(tcp)) { - abbrev_end = start + max_strlen * sizeof(gid); - if (abbrev_end < start) - abbrev_end = end; - } else { - abbrev_end = end; - } - tprints("["); - for (cur = start; cur < end; cur += sizeof(gid)) { - if (cur > start) - tprints(", "); - if (cur >= abbrev_end) { - tprints("..."); - break; - } - if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { - tprints("?"); - failed = 1; - break; - } - tprintf("%lu", (unsigned long) gid); - } - tprints("]"); - if (failed) - tprintf(" %#lx", tcp->u_arg[1]); - } - return 0; -} - -int -sys_setgroups32(struct tcb *tcp) -{ - if (entering(tcp)) { - unsigned long len, size, start, cur, end, abbrev_end; - GETGROUPS32_T gid; - int failed = 0; - - len = tcp->u_arg[0]; - tprintf("%lu, ", len); - if (len == 0) { - tprints("[]"); - return 0; - } - start = tcp->u_arg[1]; - if (start == 0) { - tprints("NULL"); - return 0; - } - size = len * sizeof(gid); - end = start + size; - if (!verbose(tcp) || size / sizeof(gid) != len || end < start) { - tprintf("%#lx", start); - return 0; - } - if (abbrev(tcp)) { - abbrev_end = start + max_strlen * sizeof(gid); - if (abbrev_end < start) - abbrev_end = end; - } else { - abbrev_end = end; - } - tprints("["); - for (cur = start; cur < end; cur += sizeof(gid)) { - if (cur > start) - tprints(", "); - if (cur >= abbrev_end) { - tprints("..."); - break; - } - if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { - tprints("?"); - failed = 1; - break; - } - tprintf("%lu", (unsigned long) gid); - } - tprints("]"); - if (failed) - tprintf(" %#lx", tcp->u_arg[1]); - } - return 0; -} - -int -sys_getgroups32(struct tcb *tcp) -{ - unsigned long len; - - if (entering(tcp)) { - len = tcp->u_arg[0]; - tprintf("%lu, ", len); - } else { - unsigned long size, start, cur, end, abbrev_end; - GETGROUPS32_T gid; - int failed = 0; - - len = tcp->u_rval; - if (len == 0) { - tprints("[]"); - return 0; - } - start = tcp->u_arg[1]; - if (start == 0) { - tprints("NULL"); - return 0; - } - size = len * sizeof(gid); - end = start + size; - if (!verbose(tcp) || tcp->u_arg[0] == 0 || - size / sizeof(gid) != len || end < start) { - tprintf("%#lx", start); - return 0; - } - if (abbrev(tcp)) { - abbrev_end = start + max_strlen * sizeof(gid); - if (abbrev_end < start) - abbrev_end = end; - } else { - abbrev_end = end; - } - tprints("["); - for (cur = start; cur < end; cur += sizeof(gid)) { - if (cur > start) - tprints(", "); - if (cur >= abbrev_end) { - tprints("..."); - break; - } - if (umoven(tcp, cur, sizeof(gid), (char *) &gid) < 0) { - tprints("?"); - failed = 1; - break; - } - tprintf("%lu", (unsigned long) gid); - } - tprints("]"); - if (failed) - tprintf(" %#lx", tcp->u_arg[1]); - } - return 0; -} - #include "xlat/ptrace_cmds.h" #include "xlat/ptrace_setoptions_flags.h" #include "xlat/nt_descriptor_types.h" -- 2.34.1