From 26b6b53b8c50fa07b48925a27ecf25c6cc33cb00 Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 14 Dec 2020 20:30:28 +0100 Subject: [PATCH] prepare for packaging --- Makefile | 21 +++++++++++---------- debian/README.Debian | 6 ++++++ debian/README.source | 10 ++++++++++ debian/changelog | 5 +++++ debian/control | 16 ++++++++++++++++ debian/copyright | 43 +++++++++++++++++++++++++++++++++++++++++++ debian/dirs | 1 + debian/rules | 25 +++++++++++++++++++++++++ debian/source/format | 1 + src/crypto.cpp | 16 ++++++++++------ src/memdb.h | 8 ++++++-- src/shepherd.cpp | 41 ++++++++++++++++++----------------------- 12 files changed, 152 insertions(+), 41 deletions(-) create mode 100644 debian/README.Debian create mode 100644 debian/README.source create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/dirs create mode 100755 debian/rules create mode 100644 debian/source/format diff --git a/Makefile b/Makefile index 8ecf3d0..6d55672 100644 --- a/Makefile +++ b/Makefile @@ -3,27 +3,26 @@ CXX = g++ LD = g++ CXXFLAGS = -std=c++17 -Wall -Werror -Wpointer-arith -Wfatal-errors CFLAGS = -Wall -Werror -Wpointer-arith -Wfatal-errors -DEBUG = -g -prefix=/usr/local +#prefix=/usr/local OBJECTS = build/memdb.o build/spmemvfs.o build/crypto.o build/Manager.o build/Database.o -all: build/shepherd +all: shepherd build/shepherd: build/shepherd.o $(OBJECTS) @mkdir -p $(dir $@) @echo link $@ @$(LD) $(CXXFLAGS) $^ -o $@ -lsqlite3 -lsodium -lstdc++fs -build/test: build/testmemvfs.o $(OBJECTS) +build/test: build/shepherd.o $(OBJECTS) @mkdir -p $(dir $@) @echo link $@ @$(LD) $(CXXFLAGS) $^ -o $@ -lsqlite3 -lsodium -lstdc++fs build/%.o: src/%.cpp src/%.h @mkdir -p $(dir $@) - @echo complie $@ + @echo compile $@ @$(CXX) $(CXXFLAGS) -c -o $@ $< build/%.o: src/%.c src/%.h @@ -36,15 +35,17 @@ rsa: rsa.cpp $(CC) $(CFLAGS) rsa.cpp -o bin/rsa -lssl -lcrypto install: build/shepherd - install -m 0755 $@ $(prefix)/bin + install -m 0755 $^ $(DESTDIR)/usr/bin -.PHONY: test -test: - test/test.sh test/test.db +shepherd: build/shepherd + +#.PHONY: test +#test: build/test +# test/test.sh test/test.db # remove produced files, invoke as "make clean" clean: - @echo clean build* + @echo clean build/* @rm -f build/* #%.o : %.cpp diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..2f2b719 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,6 @@ +shepherd for Debian +------------------ + + + + -- jedi Mon, 14 Dec 2020 20:11:42 +0100 diff --git a/debian/README.source b/debian/README.source new file mode 100644 index 0000000..96c6916 --- /dev/null +++ b/debian/README.source @@ -0,0 +1,10 @@ +shepherd for Debian +------------------ + + + + + + -- jedi Mon, 14 Dec 2020 20:11:42 +0100 + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..bf589e8 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +shepherd (0.9-1) unstable; urgency=medium + + * Initial release + + -- jedi Mon, 14 Dec 2020 19:32:43 +0100 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..26b1f01 --- /dev/null +++ b/debian/control @@ -0,0 +1,16 @@ +Source: shepherd +Section: unknown +Priority: optional +Maintainer: jedi +Build-Depends: debhelper-compat (= 13), libsodium-dev, libsqlite3-dev +Standards-Version: 4.5.1 +Homepage: https://git.neulandlabor.de/j3d1/shepherd +#Vcs-Browser: https://salsa.debian.org/debian/shepherd +#Vcs-Git: https://salsa.debian.org/debian/shepherd.git +Rules-Requires-Root: no + +Package: shepherd +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libsodium23, libsqlite3-0 +Description: + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..c9f7de2 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,43 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: shepherd +Upstream-Contact: +Source: + +Files: * +Copyright: + +License: + + + . + + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: debian/* +Copyright: 2020 jedi +License: GPL-2+ + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid picking licenses with terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. +# +# If you need, there are some extra license texts available in two places: +# /usr/share/debhelper/dh_make/licenses/ +# /usr/share/common-licenses/ diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..e772481 --- /dev/null +++ b/debian/dirs @@ -0,0 +1 @@ +usr/bin diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..59ea751 --- /dev/null +++ b/debian/rules @@ -0,0 +1,25 @@ +#!/usr/bin/make -f +# See debhelper(7) (uncomment to enable) +# output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# see FEATURE AREAS in dpkg-buildflags(1) +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# see ENVIRONMENT in dpkg-buildflags(1) +# package maintainers to append CFLAGS +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# package maintainers to append LDFLAGS +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +%: + dh $@ + + +# dh_make generated override targets +# This is example for Cmake (See https://bugs.debian.org/641051 ) +#override_dh_auto_configure: +# dh_auto_configure -- \ +# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/src/crypto.cpp b/src/crypto.cpp index 4c12058..8ff9da5 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -2,6 +2,7 @@ // Created by jedi on 3/16/19. // +#include #include #include #include "crypto.h" @@ -11,10 +12,12 @@ #define CONTEXT "SHEPHERD" +namespace fs = std::filesystem; +using namespace std; + namespace shepherd::crypto { - using namespace std; static char getch() { char buf = 0; struct termios old = {0}; @@ -70,18 +73,15 @@ namespace shepherd::crypto { kdf_t ret; - //master key if (crypto_pwhash (ret.master_key, sizeof ret.master_key, secret.c_str(), secret.size(), file->salt, crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE, crypto_pwhash_ALG_DEFAULT) != 0) { /* out of memory */ - std::cerr << "errör" << std::endl; - exit(1); + abort(); } - //used key crypto_kdf_derive_from_key(ret.key, sizeof ret.key, 2, CONTEXT, ret.master_key); @@ -107,6 +107,10 @@ namespace shepherd::crypto { } void save(const std::string filename, bytes buf) { + fs::path p(filename); + if(!fs::exists(p.parent_path())){ + fs::create_directory(p.parent_path()); + } std::ofstream ofs(filename, std::ios::out | std::ios::binary); ofs.write((char *) buf.data(), buf.size()); ofs.close(); @@ -180,7 +184,7 @@ namespace shepherd::crypto { file->nonce, pw_key.key) != 0) { /* message forged! */ - std::cerr << "errör" << std::endl; + std::cerr << "could not decrypting file" << std::endl; exit(1); } diff --git a/src/memdb.h b/src/memdb.h index 79195f9..92cdde4 100644 --- a/src/memdb.h +++ b/src/memdb.h @@ -27,9 +27,13 @@ namespace shepherd{ std::cerr << "no dbfile found" << std::endl; exit(1); } - }else{ - std::cerr << "Error: No such file" << std::endl; + }else if(std::filesystem::exists("/home/jedi/.shepherd/passwd.db")){ + std::cerr << "Error: No such file " << path_ << std::endl; + std::cerr << "importing old version " << std::endl; buf_ = crypto::load("/home/jedi/.shepherd/passwd.db"); + }else{ + std::cerr << "Error: No such file" << path_ << std::endl; + std::cerr << "creating new db" << std::endl; } mem_->total = mem_->used = buf_.size(); diff --git a/src/shepherd.cpp b/src/shepherd.cpp index b40b2e5..ab3211d 100644 --- a/src/shepherd.cpp +++ b/src/shepherd.cpp @@ -12,17 +12,12 @@ using namespace std; -constexpr unsigned int arg(const char* str, int h = 0) { - return !str[h] ? 5381 : (arg(str, h + 1) * 33) ^ str[h]; -} - using namespace shepherd; int main(int argc, char *argv[]) { - srand(time(NULL)); int opt, index; - string file = getenv("HOME"); - file += "/.shepherd/passwd.herd"; + const string home = getenv("HOME"); + string file = home + "/.shepherd/passwd.herd"; const struct option longopts[] = { {"version", no_argument, 0, 'v'}, @@ -88,34 +83,30 @@ int main(int argc, char *argv[]) { std::string pw = crypto::read_pw(); std::cout << std::endl; - //char c; - //while (std::cin.get(c)) // loop getting single characters - // std::cout << c; - - //std::cin.close(); - - /*if(!std::filesystem::exists("~/.shepherd/passwd.herd")){ - std::cerr << "default file not found" << std::endl; - }*/ - //shepherd::memdb db(file,"foo"); - //db.save(); - //exit(0); - { + try { Manager mg(file, pw); switch (argc - optind) { case 0: - mg.show(); + cerr << "Usage: "<< endl; + cerr << "\t" << argv[0] << " " << endl; + cerr << "\t" << argv[0] << " gen " << endl; + cerr << "\t" << argv[0] << " add " << endl; + cerr << "\t" << argv[0] << " del " << endl; + cerr << "\t" << argv[0] << " all" << endl; + cerr << "\t" << argv[0] << " clear all" << endl; break; case 1: mg.get(argv[optind]); break; case 2: - if (!strcmp(argv[optind], "clear")) { + if (!strcmp(argv[optind], "all")) { + mg.show(); + } else if (!strcmp(argv[optind], "clear")) { if (!strcmp(argv[optind + 1], "all")) { mg.clear(); cerr << file << " cleared" << endl; @@ -134,7 +125,11 @@ int main(int argc, char *argv[]) { } break; } + } catch(...){ + cerr << "unhandled error" << endl; + return 1; } - exit (EXIT_SUCCESS); + + return 0; }