diff --git a/server/Makefile b/server/Makefile index 2057109e4..a99b24aa7 100644 --- a/server/Makefile +++ b/server/Makefile @@ -15,15 +15,13 @@ LDLIBS = -pthread -lrt -lm -lconfig CFLAGS = -std=gnu99 -Iinclude/ -MMD -Wall -O3 CFLAGS += -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -DV=$(V) -# Add git commit hash -ifneq (,$(shell which git)) - CFLAGS += -D_GIT_REV='"$(shell git rev-parse --short HEAD)"' -endif - -# Conditional debug flags +# Add more compiler flags ifdef DEBUG CFLAGS += -O0 -g endif +ifneq (,$(shell which git)) + CFLAGS += -D_GIT_REV='"$(shell git rev-parse --short HEAD)"' +endif # Enabled GTFPGA support when libpci is available ifneq (,$(wildcard /usr/include/pci/pci.h)) @@ -42,7 +40,7 @@ ifneq (,$(wildcard $(OPALDIR)/include_target/AsyncApi.h)) override OBJS += opal.o endif -.PHONY: all clean +.PHONY: all clean strip protected # Default target: build everything all: $(TARGETS) @@ -54,10 +52,14 @@ receive: receive.o $(OBJS) random: random.o $(OBJS) test: test.o $(OBJS) +protected: CFLAGS += -DPROTECT -DVALID_UNTIL=$(shell date -d "now +5months" +%s) -s -O3 -fvisibility=hidden +protected: clean strip + strip: $(TARGETS) strip --remove-section=.comment \ --remove-section=.note \ - --strip-unneeded \ + --strip-debug \ + --strip-all \ $(TARGETS) diff --git a/server/include/license.h b/server/include/license.h new file mode 100644 index 000000000..3e12f9cd7 --- /dev/null +++ b/server/include/license.h @@ -0,0 +1,43 @@ +#ifdef PROTECT + +#include +#include +#include + +/** Check for correct license */ +static inline __attribute__((always_inline)) int check_license() +{ + const struct { + char *file, *content; + off_t offset; + } checks[] = { + { "/sys/class/dmi/id/product_uuid", "5002E503-4904-EB05-7406-0C0700080009" }, + { "/sys/class/net/eth0/address" , "50:e5:49:eb:74:0c" }, + { "/etc/machine-id", "0d8399d0216314f083b9ed2053a354a8" }, + { "/dev/sda2", "\x53\xf6\xb5\xeb\x8b\x16\x46\xdc\x8d\x8f\x5b\x70\xb8\xc9\x1a\x2a", 0x468 }, /* EXT4 UUID */ + }; + + if (time(NULL) > VALID_UNTIL) + return -1; + + FILE *f; + char buf[128]; + + for (int i = 0; i < ARRAY_LEN(checks); i++) { + f = fopen(checks[i].file, "r"); + if (!f) + return -1; + + fseek(f, checks[i].offset, SEEK_SET); + fgets(buf, sizeof(buf), f); + fclose(f); + + if (strncmp(buf, checks[i].content, strlen(checks[i].content))) + return -1; + } + + return 0; +} +#else + #define check_license() +#endif diff --git a/server/include/utils.h b/server/include/utils.h index e91bfeab9..34372d0fa 100644 --- a/server/include/utils.h +++ b/server/include/utils.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "log.h" diff --git a/server/src/server.c b/server/src/server.c index 602f3b184..2060a3260 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -18,6 +18,7 @@ #include "cfg.h" #include "path.h" #include "node.h" +#include "license.h" #ifdef ENABLE_OPAL_ASYNC #include "opal.h" @@ -128,6 +129,9 @@ int main(int argc, char *argv[]) if (getuid() != 0) error("The server requires superuser privileges!"); + if (check_license()) + error("You're not allowed to use this software!"); + /* Initialize lists */ list_init(&nodes, (dtor_cb_t) node_destroy); list_init(&paths, (dtor_cb_t) path_destroy); diff --git a/server/src/utils.c b/server/src/utils.c index 3d49990b9..6c81a3b3a 100644 --- a/server/src/utils.c +++ b/server/src/utils.c @@ -8,13 +8,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #ifdef ENABLE_OPAL_ASYNC #define RTLAB