From 5e7987b4a8314df9a6309a6f461ebbca6e0cb3ff Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 3 Dec 2014 20:30:15 +0000 Subject: [PATCH] Move capget and capset parsers to a separate file * capability.c: New file. * Makefile.am (strace_SOURCES): Add it. * system.c: Move inclusion of headers and macro definitions related to capget and capset decoding to capability.c. (print_cap_header, print_cap_data, sys_capget, sys_capset): Move to capability.c. --- Makefile.am | 1 + capability.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ system.c | 106 -------------------------------------------------- 3 files changed, 109 insertions(+), 106 deletions(-) create mode 100644 capability.c diff --git a/Makefile.am b/Makefile.am index 9efebf13..f0e4e13c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,6 +20,7 @@ strace_SOURCES = \ aio.c \ bjm.c \ block.c \ + capability.c \ count.c \ desc.c \ dirent.c \ diff --git a/capability.c b/capability.c new file mode 100644 index 00000000..18a5691c --- /dev/null +++ b/capability.c @@ -0,0 +1,108 @@ +#include "defs.h" + +#define _LINUX_SOCKET_H +#define _LINUX_FS_H + +#include +#include +#include +#ifdef HAVE_LINUX_CAPABILITY_H +# include +#endif + +#ifdef SYS_capget + +#include "xlat/capabilities.h" + +#ifndef _LINUX_CAPABILITY_VERSION_1 +# define _LINUX_CAPABILITY_VERSION_1 0x19980330 +#endif +#ifndef _LINUX_CAPABILITY_VERSION_2 +# define _LINUX_CAPABILITY_VERSION_2 0x20071026 +#endif +#ifndef _LINUX_CAPABILITY_VERSION_3 +# define _LINUX_CAPABILITY_VERSION_3 0x20080522 +#endif + +#include "xlat/cap_version.h" + +static void +print_cap_header(struct tcb *tcp, unsigned long addr) +{ + union { cap_user_header_t p; long *a; char *c; } arg; + long a[sizeof(*arg.p) / sizeof(long) + 1]; + arg.a = a; + + if (!addr) + tprints("NULL"); + else if (!verbose(tcp) || + umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0) + tprintf("%#lx", addr); + else { + tprints("{"); + printxval(cap_version, arg.p->version, + "_LINUX_CAPABILITY_VERSION_???"); + tprintf(", %d}", arg.p->pid); + } +} + +static void +print_cap_data(struct tcb *tcp, unsigned long addr) +{ + union { cap_user_data_t p; long *a; char *c; } arg; + long a[sizeof(*arg.p) / sizeof(long) + 1]; + arg.a = a; + + if (!addr) + tprints("NULL"); + else if (!verbose(tcp) || + (exiting(tcp) && syserror(tcp)) || + umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0) + tprintf("%#lx", addr); + else { + tprints("{"); + printflags(capabilities, arg.p->effective, "CAP_???"); + tprints(", "); + printflags(capabilities, arg.p->permitted, "CAP_???"); + tprints(", "); + printflags(capabilities, arg.p->inheritable, "CAP_???"); + tprints("}"); + } +} + +int +sys_capget(struct tcb *tcp) +{ + if (entering(tcp)) { + print_cap_header(tcp, tcp->u_arg[0]); + tprints(", "); + } else { + print_cap_data(tcp, tcp->u_arg[1]); + } + return 0; +} + +int +sys_capset(struct tcb *tcp) +{ + if (entering(tcp)) { + print_cap_header(tcp, tcp->u_arg[0]); + tprints(", "); + print_cap_data(tcp, tcp->u_arg[1]); + } + return 0; +} + +#else + +int sys_capget(struct tcb *tcp) +{ + return printargs(tcp); +} + +int sys_capset(struct tcb *tcp) +{ + return printargs(tcp); +} + +#endif diff --git a/system.c b/system.c index 0d57e618..a522e1a8 100644 --- a/system.c +++ b/system.c @@ -30,9 +30,6 @@ #include "defs.h" -#define _LINUX_SOCKET_H -#define _LINUX_FS_H - #define MS_RDONLY 1 /* Mount read-only */ #define MS_NOSUID 2 /* Ignore suid and sgid bits */ #define MS_NODEV 4 /* Disallow access to device special files */ @@ -63,12 +60,6 @@ #define MS_MGC_VAL 0xc0ed0000 /* Magic flag number */ #define MS_MGC_MSK 0xffff0000 /* Magic flag mask */ -#include -#include -#include -#ifdef HAVE_LINUX_CAPABILITY_H -# include -#endif #ifdef HAVE_ASM_CACHECTL_H # include #endif @@ -305,100 +296,3 @@ sys_cacheflush(struct tcb *tcp) return 0; } #endif /* SH */ - -#ifdef SYS_capget - -#include "xlat/capabilities.h" - -#ifndef _LINUX_CAPABILITY_VERSION_1 -# define _LINUX_CAPABILITY_VERSION_1 0x19980330 -#endif -#ifndef _LINUX_CAPABILITY_VERSION_2 -# define _LINUX_CAPABILITY_VERSION_2 0x20071026 -#endif -#ifndef _LINUX_CAPABILITY_VERSION_3 -# define _LINUX_CAPABILITY_VERSION_3 0x20080522 -#endif - -#include "xlat/cap_version.h" - -static void -print_cap_header(struct tcb *tcp, unsigned long addr) -{ - union { cap_user_header_t p; long *a; char *c; } arg; - long a[sizeof(*arg.p) / sizeof(long) + 1]; - arg.a = a; - - if (!addr) - tprints("NULL"); - else if (!verbose(tcp) || - umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0) - tprintf("%#lx", addr); - else { - tprints("{"); - printxval(cap_version, arg.p->version, - "_LINUX_CAPABILITY_VERSION_???"); - tprintf(", %d}", arg.p->pid); - } -} - -static void -print_cap_data(struct tcb *tcp, unsigned long addr) -{ - union { cap_user_data_t p; long *a; char *c; } arg; - long a[sizeof(*arg.p) / sizeof(long) + 1]; - arg.a = a; - - if (!addr) - tprints("NULL"); - else if (!verbose(tcp) || - (exiting(tcp) && syserror(tcp)) || - umoven(tcp, addr, sizeof(*arg.p), arg.c) < 0) - tprintf("%#lx", addr); - else { - tprints("{"); - printflags(capabilities, arg.p->effective, "CAP_???"); - tprints(", "); - printflags(capabilities, arg.p->permitted, "CAP_???"); - tprints(", "); - printflags(capabilities, arg.p->inheritable, "CAP_???"); - tprints("}"); - } -} - -int -sys_capget(struct tcb *tcp) -{ - if (entering(tcp)) { - print_cap_header(tcp, tcp->u_arg[0]); - tprints(", "); - } else { - print_cap_data(tcp, tcp->u_arg[1]); - } - return 0; -} - -int -sys_capset(struct tcb *tcp) -{ - if (entering(tcp)) { - print_cap_header(tcp, tcp->u_arg[0]); - tprints(", "); - print_cap_data(tcp, tcp->u_arg[1]); - } - return 0; -} - -#else - -int sys_capget(struct tcb *tcp) -{ - return printargs(tcp); -} - -int sys_capset(struct tcb *tcp) -{ - return printargs(tcp); -} - -#endif -- 2.40.0