summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolay Sturm <sturm@cvs.openbsd.org>2006-06-10 07:19:14 +0000
committerNikolay Sturm <sturm@cvs.openbsd.org>2006-06-10 07:19:14 +0000
commita3196c404a66cbaca454c0982e4c210d6a7e1653 (patch)
treeb3889462ad05d2d4671c98a738243ea2a084e528
parent7ef6f7d2cd654e05221c8685686f1597bd6b1918 (diff)
add a translation for sendmsg()
from provos, with feedback from ray and pat
-rw-r--r--bin/systrace/intercept-translate.c57
-rw-r--r--bin/systrace/intercept.h3
-rw-r--r--bin/systrace/register.c5
3 files changed, 62 insertions, 3 deletions
diff --git a/bin/systrace/intercept-translate.c b/bin/systrace/intercept-translate.c
index 51736d8535e..b2bf3acfa66 100644
--- a/bin/systrace/intercept-translate.c
+++ b/bin/systrace/intercept-translate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: intercept-translate.c,v 1.12 2006/05/02 19:49:05 sturm Exp $ */
+/* $OpenBSD: intercept-translate.c,v 1.13 2006/06/10 07:19:13 sturm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -289,6 +289,56 @@ ic_print_sockaddr(char *buf, size_t buflen, struct intercept_translate *tl)
return (0);
}
+static int
+ic_get_msghdr(struct intercept_translate *trans, int fd, pid_t pid,
+ void *addr)
+{
+ struct msghdr msg;
+ int len = sizeof(struct msghdr);
+
+ if (intercept.io(fd, pid, INTERCEPT_READ, addr,
+ (void *)&msg, len) == -1)
+ return (-1);
+
+ len = msg.msg_namelen;
+ if (msg.msg_name == NULL || len <= 0 || len > 2048) {
+ trans->trans_data = NULL;
+ trans->trans_size = 0;
+ return (0);
+ }
+
+ trans->trans_size = len;
+ trans->trans_data = malloc(len);
+ if (trans->trans_data == NULL)
+ return (-1);
+ if (intercept.io(fd, pid, INTERCEPT_READ, msg.msg_name,
+ (void *)trans->trans_data, trans->trans_size) == -1)
+ return (-1);
+
+ return (0);
+}
+
+static int
+ic_print_msghdr(char *buf, size_t buflen, struct intercept_translate *tl)
+{
+ int res = 0;
+
+ if (tl->trans_size == 0) {
+ snprintf(buf, buflen, "<unknown>");
+ } else {
+ res = ic_print_sockaddr(buf, buflen, tl);
+ /*
+ * disable replacement of this argument because it's two levels
+ * deep and we cant replace that fast.
+ */
+ tl->trans_size = 0;
+
+ /* TODO: make this less of a hack */
+ }
+
+ return (res);
+}
+
struct intercept_translate ic_translate_string = {
"string",
ic_get_string, ic_print_filename,
@@ -314,3 +364,8 @@ struct intercept_translate ic_translate_connect = {
ic_get_sockaddr, ic_print_sockaddr,
/* XXX - Special handling */ 1,
};
+
+struct intercept_translate ic_translate_sendmsg = {
+ "sockaddr",
+ ic_get_msghdr, ic_print_msghdr,
+};
diff --git a/bin/systrace/intercept.h b/bin/systrace/intercept.h
index 9c4530b6886..bf8f595eb48 100644
--- a/bin/systrace/intercept.h
+++ b/bin/systrace/intercept.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: intercept.h,v 1.22 2006/05/02 19:49:05 sturm Exp $ */
+/* $OpenBSD: intercept.h,v 1.23 2006/06/10 07:19:13 sturm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -182,6 +182,7 @@ extern struct intercept_translate ic_translate_filename;
extern struct intercept_translate ic_translate_linkname;
extern struct intercept_translate ic_translate_unlinkname;
extern struct intercept_translate ic_translate_connect;
+extern struct intercept_translate ic_translate_sendmsg;
void intercept_freepid(pid_t);
struct intercept_pid *intercept_findpid(pid_t);
diff --git a/bin/systrace/register.c b/bin/systrace/register.c
index 02c7868b7d0..9e4c14c11ab 100644
--- a/bin/systrace/register.c
+++ b/bin/systrace/register.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: register.c,v 1.19 2006/04/03 21:10:29 sturm Exp $ */
+/* $OpenBSD: register.c,v 1.20 2006/06/10 07:19:13 sturm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* All rights reserved.
@@ -58,6 +58,9 @@ systrace_initcb(void)
alias = systrace_new_alias("native", "open", "native", "fswrite");
systrace_alias_add_trans(alias, tl);
+ X(intercept_register_sccb("native", "sendmsg", trans_cb, NULL));
+ intercept_register_translation("native", "sendmsg", 1,
+ &ic_translate_sendmsg);
X(intercept_register_sccb("native", "connect", trans_cb, NULL));
intercept_register_translation("native", "connect", 1,
&ic_translate_connect);