From: Martin Mares Date: Sat, 19 Jan 2008 13:43:37 +0000 (+0100) Subject: Added a switch for defining new path rules. X-Git-Tag: python-dummy-working~251 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=d99e7d3fac37d35fa3e4b688e91f40f4af4ae70f;p=moe.git Added a switch for defining new path rules. --- diff --git a/src/box.c b/src/box.c index d6b820d..688bc59 100644 --- a/src/box.c +++ b/src/box.c @@ -91,6 +91,15 @@ msg(char *msg, ...) va_end(args); } +static void * +xmalloc(size_t size) +{ + void *p = malloc(size); + if (!p) + die("Out of memory"); + return p; +} + static const char * const syscall_names[] = { #include "syscall-table.h" }; @@ -239,7 +248,7 @@ syscall_by_name(char *name) } static int -set_action(char *a) +set_syscall_action(char *a) { char *sep = strchr(a, '='); enum action act = SC_YES; @@ -285,6 +294,35 @@ static struct path_rule default_path_rules[] = { { "/proc/self/exe", SC_YES }, // Needed by FPC 2.0.x runtime }; +static struct path_rule *user_path_rules; +static struct path_rule **last_path_rule = &user_path_rules; + +static int +set_path_action(char *a) +{ + char *sep = strchr(a, '='); + enum action act = SC_YES; + if (sep) + { + *sep++ = 0; + if (!strcmp(sep, "yes")) + act = SC_YES; + else if (!strcmp(sep, "no")) + act = SC_NO; + else + return 0; + } + + struct path_rule *r = xmalloc(sizeof(*r) + strlen(a)); + r->path = (char *)(r+1); + strcpy(r->path, a); + r->action = act; + r->next = NULL; + *last_path_rule = r; + last_path_rule = &r->next; + return 1; +} + static enum action match_path_rule(struct path_rule *r, char *path) { @@ -356,6 +394,10 @@ valid_filename(unsigned long addr) if (strstr(namebuf, "..")) act = SC_NO; + // Scan user rules + for (struct path_rule *r = user_path_rules; r && !act; r=r->next) + act = match_path_rule(r, namebuf); + // Scan built-in rules if (file_access >= 2) for (int i=0; i\tRedirect stdin from \n\ -m \tLimit address space to KB\n\ -o \tRedirect stdout to \n\ +-p \tPermit access to the specified path (or subtree if it ends with a `/')\n\ +-p =\tDefine action for the specified path (=yes/no)\n\ -s \tPermit the specified syscall (be careful)\n\ -s =\tDefine action for the specified syscall (=yes/no/file)\n\ -t