Move capget and capset parsers to a separate file
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 3 Dec 2014 20:30:15 +0000 (20:30 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 4 Dec 2014 02:21:41 +0000 (02:21 +0000)
* 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
capability.c [new file with mode: 0644]
system.c

index 9efebf136be76544b6e7e580015c03b08141a9c5..f0e4e13c9800ceafb44e4469be0a05119c985142 100644 (file)
@@ -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 (file)
index 0000000..18a5691
--- /dev/null
@@ -0,0 +1,108 @@
+#include "defs.h"
+
+#define _LINUX_SOCKET_H
+#define _LINUX_FS_H
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#ifdef HAVE_LINUX_CAPABILITY_H
+# include <linux/capability.h>
+#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
index 0d57e6188454c1c3203445ab9b6b0fe8f13a0580..a522e1a898515dae8eca353bd4172c1423d167e6 100644 (file)
--- 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 */
 #define MS_MGC_VAL     0xc0ed0000      /* Magic flag number */
 #define MS_MGC_MSK     0xffff0000      /* Magic flag mask */
 
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#ifdef HAVE_LINUX_CAPABILITY_H
-# include <linux/capability.h>
-#endif
 #ifdef HAVE_ASM_CACHECTL_H
 # include <asm/cachectl.h>
 #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