diff --git a/.gitmodules b/.gitmodules index 4c3ff73..53c4720 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "kafel"] path = kafel url = https://github.com/google/kafel.git +[submodule "protobuf-c-text"] + path = protobuf-c-text + url = https://github.com/protobuf-c/protobuf-c-text.git diff --git a/Makefile b/Makefile index d4990dd..dc79dcc 100644 --- a/Makefile +++ b/Makefile @@ -24,14 +24,15 @@ CFLAGS += -O2 -c -std=gnu11 \ -fstack-protector-all -Wformat -Wformat=2 -Wformat-security -fPIE \ -Wno-format-nonliteral \ -Wall -Wextra -Werror \ - -Ikafel/include + -Ikafel/include \ + -Iprotobuf-c-text/protobuf-c-text LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie -Wl,-z,noexecstack +BIN = nsjail +LIBS = kafel/libkafel.a protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a SRCS = nsjail.c cmdline.c config.c contain.c log.c cgroup.c mount.c net.c pid.c sandbox.c subproc.c user.c util.c uts.c OBJS = $(SRCS:.c=.o) -BIN = nsjail -LIBS = kafel/libkafel.a ifdef DEBUG CFLAGS += -g -ggdb -gdwarf-4 @@ -46,23 +47,23 @@ ifeq ($(NL3_EXISTS), yes) endif endif -USE_PROTOBUFC ?= yes -ifeq ($(USE_PROTOBUFC), yes) -PROTOBUFC_EXISTS := $(shell pkg-config --exists libprotobuf-c && echo yes) -ifeq ($(PROTOBUFC_EXISTS), yes) +USE_PROTOBUF ?= yes +ifeq ($(USE_PROTOBUF), yes) +PROTOBUF_EXISTS := $(shell pkg-config --exists protobuf && echo yes) +ifeq ($(PROTOBUF_EXISTS), yes) PROTO_DEPS = config.pb-c.h config.pb-c.c SRCS += config.pb-c.c - CFLAGS += -DNSJAIL_WITH_PROTOBUFC $(shell pkg-config --cflags libprotobuf-c) + CFLAGS += -DNSJAIL_WITH_PROTOBUF $(shell pkg-config --cflags libprotobuf-c) LDFLAGS += $(shell pkg-config --libs libprotobuf-c) endif endif -.PHONY: all clear depend indent kafel +.PHONY: all clear depend indent kafel protobuf-c-text .c.o: %.c $(CC) $(CFLAGS) $< -o $@ -all: $(PROTO_DEPS) kafel $(BIN) +all: $(PROTO_DEPS) protobuf-c-text kafel $(BIN) $(BIN): $(OBJS) $(LIBS) $(CC) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS) @@ -72,9 +73,18 @@ ifeq ("$(wildcard kafel/Makefile)","") git submodule update --init endif +protobuf-c-text: +ifeq ("$(wildcard protobuf-c-text/configure)","") + git submodule update --init +endif + kafel/libkafel.a: $(MAKE) -C kafel +protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a: + sh -c "cd protobuf-c-text; ./autogen.sh;" + $(MAKE) -C protobuf-c-text + $(PROTO_DEPS): config.proto protoc-c --c_out=. config.proto @@ -106,4 +116,3 @@ subproc.o: util.h user.o: user.h common.h log.h subproc.h util.h util.o: util.h common.h log.h uts.o: uts.h common.h log.h -config.pb-c.o: config.pb-c.h diff --git a/config.c b/config.c index f67de8d..f9f0417 100644 --- a/config.c +++ b/config.c @@ -24,13 +24,13 @@ #include "log.h" #include "util.h" -#if !defined(NSJAIL_WITH_PROTOBUFC) +#if !defined(NSJAIL_WITH_PROTOBUF) bool configParse(struct nsjconf_t * nsjconf UNUSED, const char *file UNUSED) { LOG_W("nsjail was not compiled with the protobuf-c library"); return false; } -#else /* !defined(NSJAIL_WITH_PROTOBUFC) */ +#else /* !defined(NSJAIL_WITH_PROTOBUF) */ #include "config.pb-c.h" @@ -69,4 +69,4 @@ bool configParse(struct nsjconf_t * nsjconf, const char *file) nsjail__ns_jail_config__free_unpacked(njc, NULL); return ret; } -#endif /* !defined(NSJAIL_WITH_PROTOBUFC) */ +#endif /* !defined(NSJAIL_WITH_PROTOBUF) */ diff --git a/protobuf-c-text b/protobuf-c-text new file mode 160000 index 0000000..198cfc0 --- /dev/null +++ b/protobuf-c-text @@ -0,0 +1 @@ +Subproject commit 198cfc0dbe159c75026600055f28e8b797bdac3b