2007-05-17 00:49:35 +04:00
|
|
|
/* $NetBSD: systrace-translate.c,v 1.21 2007/05/16 20:49:35 christos Exp $ */
|
2002-08-28 07:52:44 +04:00
|
|
|
/* $OpenBSD: systrace-translate.c,v 1.10 2002/08/01 20:50:17 provos Exp $ */
|
2002-06-17 20:29:07 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Niels Provos.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/tree.h>
|
2002-10-11 08:40:11 +04:00
|
|
|
#include <sys/socket.h>
|
2002-11-02 22:49:21 +03:00
|
|
|
#include <sys/signal.h>
|
2005-06-25 16:22:43 +04:00
|
|
|
#include <sys/mman.h>
|
2002-07-30 20:29:28 +04:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <limits.h>
|
2002-06-17 20:29:07 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
2002-07-30 20:29:28 +04:00
|
|
|
#include <pwd.h>
|
2002-06-17 20:29:07 +04:00
|
|
|
#include <err.h>
|
|
|
|
|
2002-08-01 12:47:03 +04:00
|
|
|
#ifdef __OpenBSD__
|
2002-06-17 20:29:07 +04:00
|
|
|
#include "../../sys/compat/linux/linux_types.h"
|
|
|
|
#include "../../sys/compat/linux/linux_fcntl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "intercept.h"
|
|
|
|
#include "systrace.h"
|
|
|
|
|
2002-08-01 12:47:03 +04:00
|
|
|
#if defined(__NetBSD__) && defined(HAVE_LINUX_FCNTL_H)
|
|
|
|
#include "../../sys/compat/linux/common/linux_types.h"
|
|
|
|
#include "../../sys/compat/linux/common/linux_fcntl.h"
|
|
|
|
#endif
|
|
|
|
|
2002-06-17 20:29:07 +04:00
|
|
|
#define FL(w,c) do { \
|
|
|
|
if (flags & (w)) \
|
|
|
|
*p++ = (c); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static int print_oflags(char *, size_t, struct intercept_translate *);
|
2002-08-02 18:29:34 +04:00
|
|
|
#ifdef HAVE_LINUX_FCNTL_H
|
2002-06-17 20:29:07 +04:00
|
|
|
static int linux_print_oflags(char *, size_t, struct intercept_translate *);
|
2002-08-02 18:29:34 +04:00
|
|
|
#endif
|
2002-06-17 20:29:07 +04:00
|
|
|
static int print_modeflags(char *, size_t, struct intercept_translate *);
|
|
|
|
static int print_number(char *, size_t, struct intercept_translate *);
|
2002-07-30 20:29:28 +04:00
|
|
|
static int print_uname(char *, size_t, struct intercept_translate *);
|
2002-11-02 22:49:21 +03:00
|
|
|
static int print_pidname(char *, size_t, struct intercept_translate *);
|
|
|
|
static int print_signame(char *, size_t, struct intercept_translate *);
|
2005-05-07 19:11:02 +04:00
|
|
|
static int print_fcntlcmd(char *, size_t, struct intercept_translate *);
|
2005-06-25 16:22:43 +04:00
|
|
|
static int print_memprot(char *, size_t, struct intercept_translate *);
|
2002-07-30 20:29:28 +04:00
|
|
|
static int get_argv(struct intercept_translate *, int, pid_t, void *);
|
|
|
|
static int print_argv(char *, size_t, struct intercept_translate *);
|
2002-06-17 20:29:07 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
print_oflags(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
char str[32], *p;
|
2002-07-30 20:29:28 +04:00
|
|
|
int flags = (intptr_t)tl->trans_addr;
|
|
|
|
int isread = 0;
|
2002-06-17 20:29:07 +04:00
|
|
|
|
|
|
|
p = str;
|
|
|
|
switch (flags & O_ACCMODE) {
|
|
|
|
case O_RDONLY:
|
|
|
|
strcpy(p, "ro");
|
2002-07-30 20:29:28 +04:00
|
|
|
isread = 1;
|
2002-06-17 20:29:07 +04:00
|
|
|
break;
|
|
|
|
case O_WRONLY:
|
|
|
|
strcpy(p, "wo");
|
|
|
|
break;
|
|
|
|
case O_RDWR:
|
|
|
|
strcpy(p, "rw");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(p, "--");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-30 20:29:28 +04:00
|
|
|
/* XXX - Open handling of alias */
|
|
|
|
#ifdef __NetBSD__
|
|
|
|
if (isread)
|
|
|
|
systrace_switch_alias("netbsd", "open", "netbsd", "fsread");
|
|
|
|
else
|
|
|
|
systrace_switch_alias("netbsd", "open", "netbsd", "fswrite");
|
|
|
|
#else
|
|
|
|
if (isread)
|
|
|
|
systrace_switch_alias("native", "open", "native", "fsread");
|
|
|
|
else
|
|
|
|
systrace_switch_alias("native", "open", "native", "fswrite");
|
|
|
|
#endif
|
|
|
|
|
2002-06-17 20:29:07 +04:00
|
|
|
p += 2;
|
|
|
|
|
|
|
|
FL(O_NONBLOCK, 'n');
|
|
|
|
FL(O_APPEND, 'a');
|
|
|
|
FL(O_CREAT, 'c');
|
|
|
|
FL(O_TRUNC, 't');
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
strlcpy(buf, str, buflen);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-08-02 18:29:34 +04:00
|
|
|
#ifdef HAVE_LINUX_FCNTL_H
|
2002-06-17 20:29:07 +04:00
|
|
|
static int
|
|
|
|
linux_print_oflags(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
char str[32], *p;
|
2002-07-30 20:29:28 +04:00
|
|
|
int flags = (intptr_t)tl->trans_addr;
|
|
|
|
int isread = 0;
|
2002-06-17 20:29:07 +04:00
|
|
|
|
|
|
|
p = str;
|
|
|
|
switch (flags & LINUX_O_ACCMODE) {
|
|
|
|
case LINUX_O_RDONLY:
|
|
|
|
strcpy(p, "ro");
|
2002-07-30 20:29:28 +04:00
|
|
|
isread = 1;
|
2002-06-17 20:29:07 +04:00
|
|
|
break;
|
|
|
|
case LINUX_O_WRONLY:
|
|
|
|
strcpy(p, "wo");
|
|
|
|
break;
|
|
|
|
case LINUX_O_RDWR:
|
|
|
|
strcpy(p, "rw");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(p, "--");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-30 20:29:28 +04:00
|
|
|
/* XXX - Open handling of alias */
|
|
|
|
if (isread)
|
|
|
|
systrace_switch_alias("linux", "open", "linux", "fsread");
|
|
|
|
else
|
|
|
|
systrace_switch_alias("linux", "open", "linux", "fswrite");
|
|
|
|
|
2002-06-17 20:29:07 +04:00
|
|
|
p += 2;
|
|
|
|
|
|
|
|
FL(LINUX_O_APPEND, 'a');
|
|
|
|
FL(LINUX_O_CREAT, 'c');
|
|
|
|
FL(LINUX_O_TRUNC, 't');
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
strlcpy(buf, str, buflen);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2002-08-02 18:29:34 +04:00
|
|
|
#endif
|
2002-06-17 20:29:07 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
print_modeflags(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
2002-07-30 20:29:28 +04:00
|
|
|
int mode = (intptr_t)tl->trans_addr;
|
2002-06-17 20:29:07 +04:00
|
|
|
|
|
|
|
mode &= 00007777;
|
|
|
|
snprintf(buf, buflen, "%o", mode);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_number(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
2002-07-30 20:29:28 +04:00
|
|
|
int number = (intptr_t)tl->trans_addr;
|
2002-06-17 20:29:07 +04:00
|
|
|
|
|
|
|
snprintf(buf, buflen, "%d", number);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-10-11 08:40:11 +04:00
|
|
|
static int
|
|
|
|
print_sockdom(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
int domain = (intptr_t)tl->trans_addr;
|
2005-06-25 03:21:09 +04:00
|
|
|
const char *what = NULL;
|
2002-10-11 08:40:11 +04:00
|
|
|
|
|
|
|
switch (domain) {
|
|
|
|
case AF_UNIX:
|
|
|
|
what = "AF_UNIX";
|
|
|
|
break;
|
|
|
|
case AF_INET:
|
|
|
|
what = "AF_INET";
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
what = "AF_INET6";
|
|
|
|
break;
|
2006-12-10 04:22:02 +03:00
|
|
|
case AF_IPX:
|
|
|
|
what = "AF_IPX";
|
|
|
|
break;
|
2002-10-11 08:40:11 +04:00
|
|
|
case AF_ISO:
|
|
|
|
what = "AF_ISO";
|
|
|
|
break;
|
|
|
|
case AF_NS:
|
|
|
|
what = "AF_NS";
|
|
|
|
break;
|
|
|
|
case AF_IMPLINK:
|
|
|
|
what = "AF_IMPLINK";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(buf, buflen, "AF_UNKNOWN(%d)", domain);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (what != NULL)
|
|
|
|
strlcpy(buf, what, buflen);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_socktype(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
int type = (intptr_t)tl->trans_addr;
|
2005-06-25 03:21:09 +04:00
|
|
|
const char *what = NULL;
|
2002-10-11 08:40:11 +04:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SOCK_STREAM:
|
|
|
|
what = "SOCK_STREAM";
|
|
|
|
break;
|
|
|
|
case SOCK_DGRAM:
|
|
|
|
what = "SOCK_DGRAM";
|
|
|
|
break;
|
|
|
|
case SOCK_RAW:
|
|
|
|
what = "SOCK_RAW";
|
|
|
|
break;
|
|
|
|
case SOCK_SEQPACKET:
|
|
|
|
what = "SOCK_SEQPACKET";
|
|
|
|
break;
|
|
|
|
case SOCK_RDM:
|
|
|
|
what = "SOCK_RDM";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(buf, buflen, "SOCK_UNKNOWN(%d)", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (what != NULL)
|
|
|
|
strlcpy(buf, what, buflen);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-07-30 20:29:28 +04:00
|
|
|
static int
|
|
|
|
print_uname(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
uid_t uid = (intptr_t)tl->trans_addr;
|
|
|
|
|
|
|
|
pw = getpwuid(uid);
|
2005-06-25 22:47:42 +04:00
|
|
|
strlcpy(buf, pw != NULL ? pw->pw_name : "<unknown>", buflen);
|
2002-07-30 20:29:28 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-11-02 22:49:21 +03:00
|
|
|
static int
|
|
|
|
print_pidname(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
struct intercept_pid *icpid;
|
|
|
|
pid_t pid = (intptr_t)tl->trans_addr;
|
|
|
|
|
2007-05-17 00:49:35 +04:00
|
|
|
if (pid > 0) {
|
2003-03-26 02:15:22 +03:00
|
|
|
icpid = intercept_getpid(pid);
|
2006-12-10 04:22:02 +03:00
|
|
|
strlcpy(buf, icpid != NULL ? icpid->name : "<unknown>", buflen);
|
|
|
|
} else if (pid == 0) {
|
2003-03-26 02:15:22 +03:00
|
|
|
strlcpy(buf, "<own process group>", buflen);
|
2006-12-10 04:22:02 +03:00
|
|
|
} else if (pid == -1) {
|
|
|
|
strlcpy(buf, "<every process: -1>", buflen);
|
|
|
|
} else {
|
|
|
|
/* pid is negative but not -1 - trying to signal pgroup */
|
|
|
|
pid = -pid;
|
|
|
|
icpid = intercept_findpid(pid);
|
|
|
|
strlcpy(buf, "pg:", buflen);
|
|
|
|
strlcat(buf, icpid != NULL ? icpid->name : "unknown", buflen);
|
|
|
|
}
|
2002-11-02 22:49:21 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_signame(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
int sig = (intptr_t)tl->trans_addr;
|
2005-06-25 03:21:09 +04:00
|
|
|
const char *name;
|
2002-11-02 22:49:21 +03:00
|
|
|
|
|
|
|
switch (sig) {
|
|
|
|
case SIGHUP:
|
|
|
|
name = "SIGHUP";
|
|
|
|
break;
|
|
|
|
case SIGINT:
|
|
|
|
name = "SIGINT";
|
|
|
|
break;
|
|
|
|
case SIGQUIT:
|
|
|
|
name = "SIGQUIT";
|
|
|
|
break;
|
|
|
|
case SIGILL:
|
|
|
|
name = "SIGILL";
|
|
|
|
break;
|
|
|
|
case SIGABRT:
|
|
|
|
name = "SIGABRT";
|
|
|
|
break;
|
|
|
|
case SIGFPE:
|
|
|
|
name = "SIGFPE";
|
|
|
|
break;
|
|
|
|
case SIGKILL:
|
|
|
|
name = "SIGKILL";
|
|
|
|
break;
|
|
|
|
case SIGBUS:
|
|
|
|
name = "SIGBUS";
|
|
|
|
break;
|
|
|
|
case SIGSEGV:
|
|
|
|
name = "SIGSEGV";
|
|
|
|
break;
|
|
|
|
case SIGSYS:
|
|
|
|
name = "SIGSYS";
|
|
|
|
break;
|
|
|
|
case SIGPIPE:
|
|
|
|
name = "SIGPIPE";
|
|
|
|
break;
|
|
|
|
case SIGALRM:
|
|
|
|
name = "SIGALRM";
|
|
|
|
break;
|
|
|
|
case SIGTERM:
|
|
|
|
name = "SIGTERM";
|
|
|
|
break;
|
|
|
|
case SIGURG:
|
|
|
|
name = "SIGURG";
|
|
|
|
break;
|
|
|
|
case SIGSTOP:
|
|
|
|
name = "SIGSTOP";
|
|
|
|
break;
|
|
|
|
case SIGTSTP:
|
|
|
|
name = "SIGTSTP";
|
|
|
|
break;
|
|
|
|
case SIGCONT:
|
|
|
|
name = "SIGCONT";
|
|
|
|
break;
|
|
|
|
case SIGCHLD:
|
|
|
|
name = "SIGCHLD";
|
|
|
|
break;
|
|
|
|
case SIGTTIN:
|
|
|
|
name = "SIGTTIN";
|
|
|
|
break;
|
|
|
|
case SIGTTOU:
|
|
|
|
name = "SIGTTOU";
|
|
|
|
break;
|
|
|
|
case SIGIO:
|
|
|
|
name = "SIGIO";
|
|
|
|
break;
|
|
|
|
case SIGPROF:
|
|
|
|
name = "SIGPROF";
|
|
|
|
break;
|
|
|
|
case SIGWINCH:
|
|
|
|
name = "SIGWINCH";
|
|
|
|
break;
|
|
|
|
case SIGINFO:
|
|
|
|
name = "SIGINFO";
|
|
|
|
break;
|
|
|
|
case SIGUSR1:
|
|
|
|
name = "SIGUSR1";
|
|
|
|
break;
|
|
|
|
case SIGUSR2:
|
|
|
|
name = "SIGUSR2";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(buf, buflen, "<unknown>: %d", sig);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-06-25 22:47:42 +04:00
|
|
|
strlcpy(buf, name, buflen);
|
2002-11-02 22:49:21 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-05-07 19:11:02 +04:00
|
|
|
static int
|
|
|
|
print_fcntlcmd(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
|
|
|
int cmd = (intptr_t)tl->trans_addr;
|
2005-06-25 03:21:09 +04:00
|
|
|
const char *name;
|
2005-05-07 19:11:02 +04:00
|
|
|
|
|
|
|
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_CLOSEM:
|
|
|
|
name = "F_CLOSEM";
|
|
|
|
break;
|
|
|
|
case F_MAXFD:
|
|
|
|
name = "F_MAXFD";
|
|
|
|
break;
|
2006-11-13 02:29:37 +03:00
|
|
|
case F_GETLK:
|
|
|
|
name = "F_GETLK";
|
|
|
|
break;
|
|
|
|
case F_SETLK:
|
|
|
|
name = "F_SETLK";
|
|
|
|
break;
|
|
|
|
case F_SETLKW:
|
|
|
|
name = "F_SETLKW";
|
|
|
|
break;
|
2005-05-07 19:11:02 +04:00
|
|
|
default:
|
|
|
|
snprintf(buf, buflen, "<unknown>: %d", cmd);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-06-25 22:47:42 +04:00
|
|
|
strlcpy(buf, name, buflen);
|
2005-05-07 19:11:02 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-12-10 04:22:02 +03:00
|
|
|
struct linux_i386_mmap_arg_struct {
|
|
|
|
unsigned long addr;
|
|
|
|
unsigned long len;
|
|
|
|
unsigned long prot;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long fd;
|
|
|
|
unsigned long offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_linux_memprot(struct intercept_translate *trans, int fd, pid_t pid,
|
|
|
|
void *addr)
|
|
|
|
{
|
|
|
|
struct linux_i386_mmap_arg_struct arg;
|
|
|
|
size_t len = sizeof(arg);
|
|
|
|
extern struct intercept_system intercept;
|
|
|
|
|
|
|
|
if (intercept.io(fd, pid, INTERCEPT_READ, addr,
|
|
|
|
(void *)&arg, len) == -1)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
trans->trans_addr = (void *)arg.prot;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-06-25 16:22:43 +04:00
|
|
|
static int
|
2005-06-25 18:37:33 +04:00
|
|
|
print_memprot(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
2005-06-25 16:22:43 +04:00
|
|
|
int prot = (intptr_t)tl->trans_addr;
|
2005-06-25 18:37:33 +04:00
|
|
|
char lbuf[64];
|
2005-06-25 16:22:43 +04:00
|
|
|
|
|
|
|
if (prot == PROT_NONE) {
|
2005-06-25 18:37:33 +04:00
|
|
|
(void)strlcpy(buf, "PROT_NONE", buflen);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*buf = '\0';
|
2005-06-25 16:22:43 +04:00
|
|
|
|
|
|
|
while (prot) {
|
2005-06-25 18:37:33 +04:00
|
|
|
if (*buf)
|
|
|
|
strlcat(buf, "|", buflen);
|
|
|
|
|
2005-06-25 16:22:43 +04:00
|
|
|
if (prot & PROT_READ) {
|
2005-06-25 18:37:33 +04:00
|
|
|
strlcat(buf, "PROT_READ", buflen);
|
2005-06-25 16:22:43 +04:00
|
|
|
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) {
|
2005-06-25 18:37:33 +04:00
|
|
|
snprintf(lbuf, sizeof(lbuf), "<unknown:0x%x>", prot);
|
|
|
|
strlcat(buf, lbuf, buflen);
|
2005-06-25 16:22:43 +04:00
|
|
|
prot = 0;
|
2005-06-25 18:37:33 +04:00
|
|
|
continue;
|
2005-06-25 16:22:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-25 18:37:33 +04:00
|
|
|
return 0;
|
2005-06-25 16:22:43 +04:00
|
|
|
}
|
2005-05-07 19:11:02 +04:00
|
|
|
|
2002-07-30 20:29:28 +04:00
|
|
|
static int
|
|
|
|
get_argv(struct intercept_translate *trans, int fd, pid_t pid, void *addr)
|
|
|
|
{
|
|
|
|
char *arg;
|
|
|
|
char buf[_POSIX2_LINE_MAX], *p;
|
|
|
|
int i, off = 0, len;
|
|
|
|
extern struct intercept_system intercept;
|
|
|
|
|
2002-08-28 07:52:44 +04:00
|
|
|
i = 0;
|
2002-07-30 20:29:28 +04:00
|
|
|
buf[0] = '\0';
|
|
|
|
while (1) {
|
|
|
|
if (intercept.io(fd, pid, INTERCEPT_READ, (char *)addr + off,
|
|
|
|
(void *)&arg, sizeof(char *)) == -1) {
|
|
|
|
warn("%s: ioctl", __func__);
|
2002-09-28 21:56:54 +04:00
|
|
|
return (-1);
|
2002-07-30 20:29:28 +04:00
|
|
|
}
|
|
|
|
if (arg == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
p = intercept_get_string(fd, pid, arg);
|
|
|
|
if (p == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
strlcat(buf, " ", sizeof(buf));
|
|
|
|
strlcat(buf, p, sizeof(buf));
|
|
|
|
|
|
|
|
off += sizeof(char *);
|
2002-08-28 07:52:44 +04:00
|
|
|
i++;
|
2002-07-30 20:29:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(buf) + 1;
|
|
|
|
trans->trans_data = malloc(len);
|
|
|
|
if (trans->trans_data == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
/* XXX - No argument replacement */
|
|
|
|
trans->trans_size = 0;
|
|
|
|
memcpy(trans->trans_data, buf, len);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_argv(char *buf, size_t buflen, struct intercept_translate *tl)
|
|
|
|
{
|
2005-06-25 22:47:42 +04:00
|
|
|
strlcpy(buf, (char *)tl->trans_data, buflen);
|
2002-07-30 20:29:28 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_trargv = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "argv",
|
|
|
|
.translate = get_argv,
|
|
|
|
.print = print_argv,
|
2002-07-30 20:29:28 +04:00
|
|
|
};
|
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_oflags = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "oflags",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_oflags,
|
2002-06-17 20:29:07 +04:00
|
|
|
};
|
|
|
|
|
2002-08-02 18:29:34 +04:00
|
|
|
#ifdef HAVE_LINUX_FCNTL_H
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_linux_oflags = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "oflags",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = linux_print_oflags,
|
2002-06-17 20:29:07 +04:00
|
|
|
};
|
2002-08-02 18:29:34 +04:00
|
|
|
#endif
|
2002-06-17 20:29:07 +04:00
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_modeflags = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "mode",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_modeflags,
|
2002-06-17 20:29:07 +04:00
|
|
|
};
|
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_uidt = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "uid",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_number,
|
2002-06-17 20:29:07 +04:00
|
|
|
};
|
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_uname = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "uname",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_uname,
|
2002-07-30 20:29:28 +04:00
|
|
|
};
|
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_gidt = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "gid",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_number,
|
2002-06-17 20:29:07 +04:00
|
|
|
};
|
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_fdt = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "fd",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_number,
|
2002-06-17 20:29:07 +04:00
|
|
|
};
|
2002-10-11 08:40:11 +04:00
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_sockdom = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "sockdom",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_sockdom,
|
2002-10-11 08:40:11 +04:00
|
|
|
};
|
|
|
|
|
2002-11-02 22:43:27 +03:00
|
|
|
struct intercept_translate ic_socktype = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "socktype",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_socktype,
|
2002-10-11 08:40:11 +04:00
|
|
|
};
|
2002-11-02 22:49:21 +03:00
|
|
|
|
|
|
|
struct intercept_translate ic_pidname = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "pidname",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_pidname,
|
2002-11-02 22:49:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct intercept_translate ic_signame = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "signame",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_signame,
|
2002-11-02 22:49:21 +03:00
|
|
|
};
|
2005-05-07 19:11:02 +04:00
|
|
|
|
|
|
|
struct intercept_translate ic_fcntlcmd = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "cmd",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_fcntlcmd,
|
2005-05-07 19:11:02 +04:00
|
|
|
};
|
2005-06-25 16:22:43 +04:00
|
|
|
|
|
|
|
struct intercept_translate ic_memprot = {
|
2006-10-16 04:43:00 +04:00
|
|
|
.name = "prot",
|
|
|
|
.translate = NULL,
|
|
|
|
.print = print_memprot,
|
2005-06-25 16:22:43 +04:00
|
|
|
};
|
2006-12-10 04:22:02 +03:00
|
|
|
|
|
|
|
struct intercept_translate ic_linux_memprot = {
|
2006-12-10 20:33:01 +03:00
|
|
|
.name = "prot",
|
|
|
|
.translate = get_linux_memprot,
|
|
|
|
.print = print_memprot,
|
2006-12-10 04:22:02 +03:00
|
|
|
};
|