summaryrefslogtreecommitdiff
path: root/bin/systrace
diff options
context:
space:
mode:
authorNikolay Sturm <sturm@cvs.openbsd.org>2006-03-12 20:56:11 +0000
committerNikolay Sturm <sturm@cvs.openbsd.org>2006-03-12 20:56:11 +0000
commitb40aed7e6ff3d8d11fc57c8b158c01885a20b2f5 (patch)
tree7f1cb436a1f0eb4c0b0212ae295a361e0de1f62a /bin/systrace
parentcf5bda676c3c3a2ae84fe880bc5ae65aad0204ff (diff)
add a few new translations, partly from NetBSD
ok provos@, deraadt@
Diffstat (limited to 'bin/systrace')
-rw-r--r--bin/systrace/register.c27
-rw-r--r--bin/systrace/systrace-translate.c178
-rw-r--r--bin/systrace/systrace.h5
3 files changed, 207 insertions, 3 deletions
diff --git a/bin/systrace/register.c b/bin/systrace/register.c
index c85ccb05719..c8bb5d84ef2 100644
--- a/bin/systrace/register.c
+++ b/bin/systrace/register.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: register.c,v 1.16 2003/07/19 11:48:58 sturm Exp $ */
+/* $OpenBSD: register.c,v 1.17 2006/03/12 20:56:10 sturm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -86,6 +86,16 @@ systrace_initcb(void)
&ic_translate_unlinkname);
alias = systrace_new_alias("native", "unlink", "native", "fswrite");
systrace_alias_add_trans(alias, tl);
+ X(intercept_register_sccb("native", "truncate", trans_cb, NULL));
+ tl = intercept_register_transfn("native", "truncate", 0);
+ alias = systrace_new_alias("native", "truncate", "native", "fswrite");
+ systrace_alias_add_trans(alias, tl);
+
+ X(intercept_register_sccb("native", "mkfifo", trans_cb, NULL));
+ tl = intercept_register_transfn("native", "mkfifo", 0);
+ intercept_register_translation("native", "mkfifo", 1, &ic_modeflags);
+ alias = systrace_new_alias("native", "mkfifo", "native", "fswrite");
+ systrace_alias_add_trans(alias, tl);
X(intercept_register_sccb("native", "chown", trans_cb, NULL));
intercept_register_transfn("native", "chown", 0);
@@ -95,12 +105,20 @@ systrace_initcb(void)
intercept_register_translation("native", "fchown", 0, &ic_fdt);
intercept_register_translation("native", "fchown", 1, &ic_uidt);
intercept_register_translation("native", "fchown", 2, &ic_gidt);
+ X(intercept_register_sccb("native", "lchown", trans_cb, NULL));
+ intercept_register_translation("native", "lchown", 0,
+ &ic_translate_unlinkname);
+ intercept_register_translation("native", "lchown", 1, &ic_uidt);
+ intercept_register_translation("native", "lchown", 2, &ic_gidt);
X(intercept_register_sccb("native", "chmod", trans_cb, NULL));
intercept_register_transfn("native", "chmod", 0);
intercept_register_translation("native", "chmod", 1, &ic_modeflags);
X(intercept_register_sccb("native", "fchmod", trans_cb, NULL));
intercept_register_translation("native", "fchmod", 0, &ic_fdt);
intercept_register_translation("native", "fchmod", 1, &ic_modeflags);
+ X(intercept_register_sccb("native", "chflags", trans_cb, NULL));
+ intercept_register_transfn("native", "chflags", 0);
+ intercept_register_translation("native", "chflags", 1, &ic_fileflags);
X(intercept_register_sccb("native", "readlink", trans_cb, NULL));
tl = intercept_register_translation("native", "readlink", 0,
&ic_translate_unlinkname);
@@ -154,6 +172,13 @@ systrace_initcb(void)
X(intercept_register_sccb("native", "kill", trans_cb, NULL));
intercept_register_translation("native", "kill", 0, &ic_pidname);
intercept_register_translation("native", "kill", 1, &ic_signame);
+ X(intercept_register_sccb("native", "fcntl", trans_cb, NULL));
+ intercept_register_translation("native", "fcntl", 1, &ic_fcntlcmd);
+
+ X(intercept_register_sccb("native", "mmap", trans_cb, NULL));
+ intercept_register_translation("native", "mmap", 2, &ic_memprot);
+ X(intercept_register_sccb("native", "mprotect", trans_cb, NULL));
+ intercept_register_translation("native", "mprotect", 2, &ic_memprot);
X(intercept_register_sccb("linux", "open", trans_cb, NULL));
tl = intercept_register_translink("linux", "open", 0);
diff --git a/bin/systrace/systrace-translate.c b/bin/systrace/systrace-translate.c
index 870bc33b98f..540858dc66a 100644
--- a/bin/systrace/systrace-translate.c
+++ b/bin/systrace/systrace-translate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: systrace-translate.c,v 1.18 2005/05/03 18:03:26 sturm Exp $ */
+/* $OpenBSD: systrace-translate.c,v 1.19 2006/03/12 20:56:10 sturm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -33,6 +33,8 @@
#include <sys/wait.h>
#include <sys/tree.h>
#include <sys/socket.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
@@ -61,6 +63,9 @@ static int print_number(char *, size_t, struct intercept_translate *);
static int print_uname(char *, size_t, struct intercept_translate *);
static int print_pidname(char *, size_t, struct intercept_translate *);
static int print_signame(char *, size_t, struct intercept_translate *);
+static int print_fcntlcmd(char *, size_t, struct intercept_translate *);
+static int print_memprot(char *, size_t, struct intercept_translate *);
+static int print_fileflags(char *, size_t, struct intercept_translate *);
static int get_argv(struct intercept_translate *, int, pid_t, void *);
static int print_argv(char *, size_t, struct intercept_translate *);
@@ -371,6 +376,162 @@ print_signame(char *buf, size_t buflen, struct intercept_translate *tl)
}
static int
+print_fcntlcmd(char *buf, size_t buflen, struct intercept_translate *tl)
+{
+ int cmd = (intptr_t)tl->trans_addr;
+ char *name;
+
+ switch (cmd) {
+ case F_DUPFD:
+ name = "F_DUPFD";
+ break;
+ case F_GETFD:
+ name = "F_GETFD";
+ break;
+ case F_SETFD:
+ name = "F_SETFD";
+ break;
+ case F_GETFL:
+ name = "F_GETFL";
+ break;
+ case F_SETFL:
+ name = "F_SETFL";
+ break;
+ case F_GETOWN:
+ name = "F_GETOWN";
+ break;
+ case F_SETOWN:
+ name = "F_SETOWN";
+ break;
+ case F_GETLK:
+ name = "F_GETLK";
+ break;
+ case F_SETLK:
+ name = "F_SETLK";
+ break;
+ case F_SETLKW:
+ name = "F_SETLKW";
+ break;
+ default:
+ snprintf(buf, buflen, "<unknown>: %d", cmd);
+ return (0);
+ }
+
+ snprintf(buf, buflen, "%s", name);
+ return (0);
+}
+
+static int
+print_memprot(char *buf, size_t buflen, struct intercept_translate *tl)
+{
+ int prot = (intptr_t)tl->trans_addr;
+ char lbuf[64];
+
+ if (prot == PROT_NONE) {
+ strlcpy(buf, "PROT_NONE", buflen);
+ return (0);
+ } else
+ *buf = '\0';
+
+ while (prot) {
+ if (*buf)
+ strlcat(buf, "|", buflen);
+
+ if (prot & PROT_READ) {
+ strlcat(buf, "PROT_READ", buflen);
+ prot &= ~PROT_READ;
+ continue;
+ }
+
+ if (prot & PROT_WRITE) {
+ strlcat(buf, "PROT_WRITE", buflen);
+ prot &= ~PROT_WRITE;
+ continue;
+ }
+
+ if (prot & PROT_EXEC) {
+ strlcat(buf, "PROT_EXEC", buflen);
+ prot &= ~PROT_EXEC;
+ continue;
+ }
+
+ if (prot) {
+ snprintf(lbuf, sizeof(lbuf), "<unknown:0x%x>", prot);
+ strlcat(buf, lbuf, buflen);
+ prot = 0;
+ continue;
+ }
+ }
+
+ return (0);
+}
+
+static int
+print_fileflags(char *buf, size_t buflen, struct intercept_translate *tl)
+{
+ unsigned int flags = (intptr_t)tl->trans_addr;
+ char lbuf[64];
+
+ *buf = '\0';
+
+ while (flags) {
+ if (*buf)
+ strlcat(buf, "|", buflen);
+
+ if (flags & UF_NODUMP) {
+ strlcat(buf, "UF_NODUMP", buflen);
+ flags &= ~UF_NODUMP;
+ continue;
+ }
+
+ if (flags & UF_IMMUTABLE) {
+ strlcat(buf, "UF_IMMUTABLE", buflen);
+ flags &= ~UF_IMMUTABLE;
+ continue;
+ }
+
+ if (flags & UF_APPEND) {
+ strlcat(buf, "UF_APPEND", buflen);
+ flags &= ~UF_APPEND;
+ continue;
+ }
+
+ if (flags & UF_OPAQUE) {
+ strlcat(buf, "UF_OPAQUE", buflen);
+ flags &= ~UF_OPAQUE;
+ continue;
+ }
+
+ if (flags & SF_ARCHIVED) {
+ strlcat(buf, "SF_ARCHIVED", buflen);
+ flags &= ~SF_ARCHIVED;
+ continue;
+ }
+
+ if (flags & SF_IMMUTABLE) {
+ strlcat(buf, "SF_IMMUTABLE", buflen);
+ flags &= ~SF_IMMUTABLE;
+ continue;
+ }
+
+ if (flags & SF_APPEND) {
+ strlcat(buf, "SF_APPEND", buflen);
+ flags &= ~SF_APPEND;
+ continue;
+ }
+
+ if (flags) {
+ snprintf(lbuf, sizeof(lbuf), "<unknown:0x%x>", flags);
+ strlcat(buf, lbuf, buflen);
+ flags = 0;
+ continue;
+ }
+ }
+
+ return (0);
+}
+
+static int
get_argv(struct intercept_translate *trans, int fd, pid_t pid, void *addr)
{
char *arg;
@@ -480,3 +641,18 @@ struct intercept_translate ic_signame = {
"signame",
NULL, print_signame,
};
+
+struct intercept_translate ic_fcntlcmd = {
+ "cmd",
+ NULL, print_fcntlcmd,
+};
+
+struct intercept_translate ic_memprot = {
+ "prot",
+ NULL, print_memprot,
+};
+
+struct intercept_translate ic_fileflags = {
+ "flags",
+ NULL, print_fileflags,
+};
diff --git a/bin/systrace/systrace.h b/bin/systrace/systrace.h
index ceb69613c35..ef148e91e85 100644
--- a/bin/systrace/systrace.h
+++ b/bin/systrace/systrace.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: systrace.h,v 1.25 2004/01/23 20:51:18 sturm Exp $ */
+/* $OpenBSD: systrace.h,v 1.26 2006/03/12 20:56:10 sturm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -231,6 +231,9 @@ extern struct intercept_translate ic_sockdom;
extern struct intercept_translate ic_socktype;
extern struct intercept_translate ic_pidname;
extern struct intercept_translate ic_signame;
+extern struct intercept_translate ic_fcntlcmd;
+extern struct intercept_translate ic_memprot;
+extern struct intercept_translate ic_fileflags;
extern struct intercept_translate ic_linux_oflags;