LD = gcc
LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie
-SRCS = nsjail.c cmdline.c contain.c log.c net.c subproc.c sandbox.c seccomp/bpf-helper.c
+SRCS = nsjail.c cmdline.c contain.c log.c net.c subproc.c sandbox.c util.c seccomp/bpf-helper.c
OBJS = $(SRCS:.c=.o)
BIN = nsjail
# DO NOT DELETE THIS LINE -- make depend depends on it.
nsjail.o: nsjail.h cmdline.h common.h log.h net.h subproc.h
-cmdline.o: cmdline.h common.h log.h
+cmdline.o: cmdline.h common.h log.h util.h
contain.o: contain.h common.h log.h
log.o: log.h common.h
net.o: net.h common.h log.h
-subproc.o: subproc.h common.h contain.h log.h net.h sandbox.h
+subproc.o: subproc.h common.h contain.h log.h net.h sandbox.h util.h
sandbox.o: sandbox.h common.h log.h seccomp/bpf-helper.h
+util.o: util.h log.h common.h
seccomp/bpf-helper.o: seccomp/bpf-helper.h
#include "common.h"
#include "log.h"
+#include "util.h"
struct custom_option {
struct option opt;
break;
case 'R':
{
- struct mounts_t *p = malloc(sizeof(struct mounts_t));
- if (p == NULL) {
- PLOG_F("malloc(%zu)", sizeof(struct mounts_t));
- }
+ struct mounts_t *p = util_malloc(sizeof(struct mounts_t));
p->src = optarg;
p->dst = cmdlineMountParam(optarg);
p->flags = MS_BIND | MS_REC | MS_PRIVATE | MS_RDONLY;
break;
case 'B':
{
- struct mounts_t *p = malloc(sizeof(struct mounts_t));
- if (p == NULL) {
- PLOG_F("malloc(%zu)", sizeof(struct mounts_t));
- }
+ struct mounts_t *p = util_malloc(sizeof(struct mounts_t));
p->src = optarg;
p->dst = cmdlineMountParam(optarg);
p->flags = MS_BIND | MS_REC | MS_PRIVATE;
break;
case 'T':
{
- struct mounts_t *p = malloc(sizeof(struct mounts_t));
- if (p == NULL) {
- PLOG_F("malloc(%zu)", sizeof(struct mounts_t));
- }
+ struct mounts_t *p = util_malloc(sizeof(struct mounts_t));
p->src = "none";
p->dst = optarg;
p->flags = 0;
LOG_E("Modes supported: -M l - MODE_LISTEN_TCP (default)");
LOG_E(" -M o - MODE_STANDALONE_ONCE");
LOG_E(" -M r - MODE_STANDALONE_RERUN");
+ LOG_E(" -M e - MODE_STANDALONE_EXECVE");
cmdlineUsage(argv[0], custom_opts);
return false;
break;
}
if (nsjconf->mount_proc == true) {
- struct mounts_t *p = malloc(sizeof(struct mounts_t));
- if (p == NULL) {
- PLOG_F("malloc(%zu)", sizeof(struct mounts_t));
- }
+ struct mounts_t *p = util_malloc(sizeof(struct mounts_t));
p->src = "none";
p->dst = "/proc";
p->flags = 0;
TAILQ_INSERT_HEAD(&nsjconf->mountpts, p, pointers);
}
if (strlen(nsjconf->chroot) > 0) {
- struct mounts_t *p = malloc(sizeof(struct mounts_t));
- if (p == NULL) {
- PLOG_F(" malloc(%zu) ", sizeof(struct mounts_t));
- }
+ struct mounts_t *p = util_malloc(sizeof(struct mounts_t));
p->src = nsjconf->chroot;
p->dst = "/";
p->flags = MS_BIND | MS_REC | MS_PRIVATE;
#include "log.h"
#include "net.h"
#include "sandbox.h"
+#include "util.h"
static int subprocNewProc(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_err, int pipefd)
{
static void subprocAdd(struct nsjconf_t *nsjconf, pid_t pid, int sock)
{
- struct pids_t *p = malloc(sizeof(struct pids_t));
- if (p == NULL) {
- PLOG_E("malloc");
- return;
- }
-
+ struct pids_t *p = util_malloc(sizeof(struct pids_t));
p->pid = pid;
p->start = time(NULL);
netConnToText(sock, true /* remote */ , p->remote_txt, sizeof(p->remote_txt),