Archived
1
0
This commit is contained in:
Jeff Becker 2017-05-03 11:37:09 -04:00
parent 279faa56b7
commit 89c2398a96
7 changed files with 67 additions and 20 deletions

View File

@ -1,6 +1,7 @@
*.o
*.a
nntpd
nntpchan-tool
tools/authtool
tools/testtool
test
.gdb_history

View File

@ -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)

View File

@ -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);

View File

@ -1,4 +1,6 @@
#include "crypto.hpp"
#include <sodium.h>
#include <cassert>
namespace nntpchan
{
@ -6,4 +8,13 @@ namespace nntpchan
{
crypto_hash(h.data(), d, l);
}
Crypto::Crypto()
{
assert(sodium_init() == 0);
}
Crypto::~Crypto()
{
}
}

View File

@ -7,8 +7,15 @@
namespace nntpchan
{
typedef std::array<uint8_t, crypto_hash_BYTES> SHA512Digest;
void SHA512(const uint8_t * d, std::size_t l, SHA512Digest & h);
/** global crypto initializer */
struct Crypto
{
Crypto();
~Crypto();
};
}

View File

@ -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)) {

View File

@ -0,0 +1,13 @@
#include "exec_frontend.hpp"
#include <cassert>
#include <iostream>
int main(int , char * [])
{
nntpchan::Frontend * f = new nntpchan::ExecFrontend("./contrib/nntpchan.sh");
assert(f->AcceptsMessage("<test@server>"));
assert(f->AcceptsNewsgroup("overchan.test"));
std::cout << "all good" << std::endl;
}