From 89c2398a963a952938752a7663f3d6acabb1cf0b Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 3 May 2017 11:37:09 -0400 Subject: [PATCH] more --- contrib/backends/nntpchan-daemon/.gitignore | 3 +- contrib/backends/nntpchan-daemon/Makefile | 35 ++++++++++++------- .../{nntpd.cpp => daemon/main.cpp} | 3 ++ .../backends/nntpchan-daemon/src/crypto.cpp | 11 ++++++ .../backends/nntpchan-daemon/src/crypto.hpp | 9 ++++- .../{tool.cpp => tools/authtool.cpp} | 13 +++---- .../nntpchan-daemon/tools/testtool.cpp | 13 +++++++ 7 files changed, 67 insertions(+), 20 deletions(-) rename contrib/backends/nntpchan-daemon/{nntpd.cpp => daemon/main.cpp} (98%) rename contrib/backends/nntpchan-daemon/{tool.cpp => tools/authtool.cpp} (89%) create mode 100644 contrib/backends/nntpchan-daemon/tools/testtool.cpp diff --git a/contrib/backends/nntpchan-daemon/.gitignore b/contrib/backends/nntpchan-daemon/.gitignore index 37ae6dc..2084365 100644 --- a/contrib/backends/nntpchan-daemon/.gitignore +++ b/contrib/backends/nntpchan-daemon/.gitignore @@ -1,6 +1,7 @@ *.o *.a nntpd -nntpchan-tool +tools/authtool +tools/testtool test .gdb_history \ No newline at end of file diff --git a/contrib/backends/nntpchan-daemon/Makefile b/contrib/backends/nntpchan-daemon/Makefile index 6de7a3e..5a3a469 100644 --- a/contrib/backends/nntpchan-daemon/Makefile +++ b/contrib/backends/nntpchan-daemon/Makefile @@ -1,9 +1,4 @@ -EXE = nntpd - -TOOL = nntpchan-tool - -CXX = g++ REPO=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) SRC_PATH = $(REPO)/src @@ -11,24 +6,40 @@ SOURCES := $(wildcard $(SRC_PATH)/*.cpp) HEADERS := $(wildcard $(SRC_PATH)/*.hpp) OBJECTS := $(SOURCES:.cpp=.o) +TOOL_SRC_PATH := $(REPO)/tools + +TOOL_SRC := $(wildcard $(TOOL_SRC_PATH)/*.cpp) +TOOLS := $(TOOL_SRC:.cpp=) + +DAEMON_SRC = $(REPO)/daemon + PKGS := libuv libsodium LD_FLAGS := $(shell pkg-config --libs $(PKGS)) INC_FLAGS := $(shell pkg-config --cflags $(PKGS)) -I $(REPO)/src -CXXFLAGS := -std=c++11 -Wall -Wextra $(INC_FLAGS) -g +CXXFLAGS := -std=c++11 -Wall -Wextra $(INC_FLAGS) -LIB = libnntpchan.a +ifeq ($(DEBUG),1) + CXXFLAGS += -g +endif -all: $(EXE) $(TOOL) +LIB = $(REPO)/libnntpchan.a + +EXE = $(REPO)/nntpd + + +all: $(EXE) $(TOOLS) $(LIB): $(OBJECTS) $(AR) -r $(LIB) $(OBJECTS) $(EXE): $(LIB) - $(CXX) -o $(EXE) $(CXXFLAGS) nntpd.cpp $(LIB) $(LD_FLAGS) + $(CXX) $(CXXFLAGS) $(DAEMON_SRC)/main.cpp $(LIB) $(LD_FLAGS) -o $(EXE) -$(TOOL): $(LIB) - $(CXX) -o $(TOOL) $(CXXFLAGS) tool.cpp $(LIB) $(LD_FLAGS) +$(TOOL_SRC): $(LIB) + +$(TOOLS): $(TOOL_SRC) + $(CXX) $(CXXFLAGS) $< $(LIB) $(LD_FLAGS) -o $@ build-test: $(LIB) $(CXX) -o test $(CXXFLAGS) test.cpp $(LIB) $(LD_FLAGS) @@ -40,4 +51,4 @@ test: build-test $(CXX) $(CXXFLAGS) -c -o $@ clean: - rm -f $(OBJECTS) $(LIB) $(EXE) $(TOOL) test + rm -f $(OBJECTS) $(LIB) $(EXE) $(TOOLS) diff --git a/contrib/backends/nntpchan-daemon/nntpd.cpp b/contrib/backends/nntpchan-daemon/daemon/main.cpp similarity index 98% rename from contrib/backends/nntpchan-daemon/nntpd.cpp rename to contrib/backends/nntpchan-daemon/daemon/main.cpp index 3d8660e..d77b165 100644 --- a/contrib/backends/nntpchan-daemon/nntpd.cpp +++ b/contrib/backends/nntpchan-daemon/daemon/main.cpp @@ -1,5 +1,6 @@ #include "ini.hpp" +#include "crypto.hpp" #include "storage.hpp" #include "nntp_server.hpp" #include "event.hpp" @@ -15,6 +16,8 @@ int main(int argc, char * argv[]) { return 1; } + nntpchan::Crypto crypto(); + nntpchan::Mainloop loop; nntpchan::NNTPServer nntp(loop); diff --git a/contrib/backends/nntpchan-daemon/src/crypto.cpp b/contrib/backends/nntpchan-daemon/src/crypto.cpp index 5ca5c0b..be6fd06 100644 --- a/contrib/backends/nntpchan-daemon/src/crypto.cpp +++ b/contrib/backends/nntpchan-daemon/src/crypto.cpp @@ -1,4 +1,6 @@ #include "crypto.hpp" +#include +#include namespace nntpchan { @@ -6,4 +8,13 @@ namespace nntpchan { crypto_hash(h.data(), d, l); } + + Crypto::Crypto() + { + assert(sodium_init() == 0); + } + + Crypto::~Crypto() + { + } } diff --git a/contrib/backends/nntpchan-daemon/src/crypto.hpp b/contrib/backends/nntpchan-daemon/src/crypto.hpp index fd529f7..c563566 100644 --- a/contrib/backends/nntpchan-daemon/src/crypto.hpp +++ b/contrib/backends/nntpchan-daemon/src/crypto.hpp @@ -7,8 +7,15 @@ namespace nntpchan { typedef std::array SHA512Digest; - + void SHA512(const uint8_t * d, std::size_t l, SHA512Digest & h); + + /** global crypto initializer */ + struct Crypto + { + Crypto(); + ~Crypto(); + }; } diff --git a/contrib/backends/nntpchan-daemon/tool.cpp b/contrib/backends/nntpchan-daemon/tools/authtool.cpp similarity index 89% rename from contrib/backends/nntpchan-daemon/tool.cpp rename to contrib/backends/nntpchan-daemon/tools/authtool.cpp index e2f7095..e7a577b 100644 --- a/contrib/backends/nntpchan-daemon/tool.cpp +++ b/contrib/backends/nntpchan-daemon/tools/authtool.cpp @@ -9,11 +9,12 @@ static void print_help(const std::string & exename) { - std::cout << "usage: " << exename << " [help|gencred|checkcred]" << std::endl; + std::cout << "usage: " << exename << " [help|gen|check]" << std::endl; } -static void print_long_help() { - +static void print_long_help() +{ + } static void gen_passwd(const std::string & username, const std::string & passwd) @@ -58,16 +59,16 @@ int main(int argc, char * argv[]) print_long_help(); return 0; } - if (cmd == "gencred") { + if (cmd == "gen") { if(argc == 4) { gen_passwd(argv[2], argv[3]); return 0; } else { - std::cout << "usage: " << argv[0] << " passwd username password" << std::endl; + std::cout << "usage: " << argv[0] << " gen username password" << std::endl; return 1; } } - if(cmd == "checkcred" ) { + if(cmd == "check" ) { std::string cred; std::cout << "credential: " ; if(!std::getline(std::cin, cred)) { diff --git a/contrib/backends/nntpchan-daemon/tools/testtool.cpp b/contrib/backends/nntpchan-daemon/tools/testtool.cpp new file mode 100644 index 0000000..a84c670 --- /dev/null +++ b/contrib/backends/nntpchan-daemon/tools/testtool.cpp @@ -0,0 +1,13 @@ +#include "exec_frontend.hpp" +#include +#include + + + +int main(int , char * []) +{ + nntpchan::Frontend * f = new nntpchan::ExecFrontend("./contrib/nntpchan.sh"); + assert(f->AcceptsMessage("")); + assert(f->AcceptsNewsgroup("overchan.test")); + std::cout << "all good" << std::endl; +}