+struct path_rule {
+ char *path;
+ enum action action;
+ struct path_rule *next;
+};
+
+static struct path_rule default_path_rules[] = {
+ { "/etc/", SC_YES },
+ { "/lib/", SC_YES },
+ { "/usr/lib/", SC_YES },
+ { "/opt/lib/", SC_YES },
+ { "/usr/share/zoneinfo/", SC_YES },
+ { "/usr/share/locale/", SC_YES },
+ { "/dev/null", SC_YES },
+ { "/dev/zero", SC_YES },
+ { "/proc/meminfo", SC_YES },
+ { "/proc/self/stat", SC_YES },
+ { "/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)
+{
+ char *rr = r->path;
+ while (*rr)
+ if (*rr++ != *path++)
+ {
+ if (rr[-1] == '/' && !path[-1])
+ break;
+ return SC_DEFAULT;
+ }
+ if (rr > r->path && rr[-1] != '/' && *path)
+ return SC_DEFAULT;
+ return r->action;
+}
+