diff --git a/.build.yml b/.build.yml new file mode 100644 index 0000000..2cb5845 --- /dev/null +++ b/.build.yml @@ -0,0 +1,17 @@ +image: debian/sid +packages: + - clang + - pkg-config + - ronn +tasks: + - get-zfs: | + sudo sed -i 's/main/main contrib non-free/' /etc/apt/sources.list + sudo apt update + sudo apt install -y libzfslinux-dev + - build-gcc: | + cd tzpfms + make + make clean + - build-clang: | + cd tzpfms + CC=clang CXX=clang++ make diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..872174a --- /dev/null +++ b/.clang-format @@ -0,0 +1,23 @@ +--- +Language : Cpp +BasedOnStyle : LLVM +AlignAfterOpenBracket : true +AlignEscapedNewlinesLeft : true +AlignConsecutiveAssignments : true +AllowShortFunctionsOnASingleLine : Inline +AlwaysBreakTemplateDeclarations : true +ColumnLimit : 160 +ConstructorInitializerIndentWidth : 6 +IndentCaseLabels : true +MaxEmptyLinesToKeep : 2 +KeepEmptyLinesAtTheStartOfBlocks : false +NamespaceIndentation : All +PointerAlignment : Middle +SpacesBeforeTrailingComments : 2 +IndentWidth : 2 +TabWidth : 2 +UseTab : ForIndentation +SpaceBeforeParens : Never +FixNamespaceComments : false +... + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc1fd43 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +* +!.git* +!.git*/** +!.build.yml +!.travis.yml +!gh_rsa.enc +!LICENSE +!.clang-format +!*Makefile +!*.sublime-project +!*.md +!src +!src/** +!man +!man/** +!ext +!ext/** +!test +!test/** +!test-data +!test-data/** diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6aa237b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 наб + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ca948d3 --- /dev/null +++ b/Makefile @@ -0,0 +1,75 @@ +# The MIT License (MIT) + +# Copyright (c) 2020 наб + +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +include configMakefile + + +LDDLLS := rt $(OS_LD_LIBS) +PKGS := libzfs libzfs_core +LDAR := $(LNCXXAR) $(foreach l,,-L$(BLDDIR)$(l)) $(foreach dll,$(LDDLLS),-l$(dll)) $(shell pkg-config --libs $(PKGS)) +INCAR := $(foreach l,$(foreach l,,$(l)/include),-isystemext/$(l)) $(foreach l,,-isystem$(BLDDIR)$(l)/include) $(shell pkg-config --cflags $(PKGS)) +VERAR := $(foreach l,TZPFMS,-D$(l)_VERSION='$($(l)_VERSION)') +BINARY_SOURCES := $(sort $(wildcard $(SRCDIR)bin/*.cpp $(SRCDIR)bin/**/*.cpp)) +COMMON_SOURCES := $(filter-out $(BINARY_SOURCES),$(sort $(wildcard $(SRCDIR)*.cpp $(SRCDIR)**/*.cpp $(SRCDIR)**/**/*.cpp $(SRCDIR)**/**/**/*.cpp))) +# TEST_SOURCES := $(sort $(wildcard $(TSTDIR)*.cpp $(TSTDIR)**/*.cpp $(TSTDIR)**/**/*.cpp $(TSTDIR)**/**/**/*.cpp)) +MANPAGE_SOURCES := $(sort $(wildcard $(MANDIR)*.md $(MANDIR)**/*.md)) + + +.PHONY : all clean build build-test man +.SECONDARY: + + +all : build man # build-test test + +#test: build-test +# $(OUTDIR)tzpfms-test$(EXE) + +clean : + rm -rf $(OUTDIR) + +build : $(subst $(SRCDIR)bin/,$(OUTDIR),$(subst .cpp,$(EXE),$(BINARY_SOURCES))) +#build-test : $(OUTDIR)tzpfms-test$(EXE) +man : $(subst $(MANDIR),$(OUTDIR)man/,$(MANPAGE_SOURCES)) + + +#$(OUTDIR)tzpfms-test$(EXE) : $(subst $(TSTDIR),$(BLDDIR)test/,$(subst .cpp,$(OBJ),$(TEST_SOURCES))) $(subst $(SRCDIR),$(OBJDIR),$(subst .cpp,$(OBJ),$(filter-out $(SRCDIR)main.cpp,$(SOURCES)))) $(patsubst ext/fmt/src/%.cc,$(BLDDIR)fmt/obj/%$(OBJ),$(wildcard ext/fmt/src/*.cc)) +# $(CXX) $(CXXAR) -o$@ $^ $(PIC) $(LDAR) + +$(subst $(MANDIR),$(OUTDIR)man/,$(MANPAGE_SOURCES)) : $(MANDIR)index.txt $(MANPAGE_SOURCES) + @rm -rf $(dir $@) && mkdir -p $(dir $@) + cp $^ $(dir $@) + ronn $@ + ronn -f $@ + + +$(OUTDIR)%$(EXE) : $(subst $(SRCDIR),$(OBJDIR),$(subst .cpp,$(OBJ),$(SRCDIR)bin/%.cpp $(COMMON_SOURCES))) + @mkdir -p $(dir $@) + $(CXX) $(CXXAR) -o$@ $^ $(PIC) $(LDAR) + $(STRIP) $(STRIPAR) $@ + +$(OBJDIR)%$(OBJ) : $(SRCDIR)%.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXAR) $(INCAR) $(VERAR) -c -o$@ $^ + +$(BLDDIR)test/%$(OBJ) : $(TSTDIR)%.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXAR) $(INCAR) -I$(SRCDIR) $(VERAR) -c -o$@ $^ diff --git a/README.md b/README.md new file mode 100644 index 0000000..da638d2 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# tzpfms [![builds.sr.ht badge](//builds.sr.ht/~nabijaczleweli/tzpfms.svg)](https://builds.sr.ht/~nabijaczleweli/tzpfms) [![Licence](//img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) +TPM-based encryption keys for ZFS datasets. + +## [Manpage](//git.sr.ht/~nabijaczleweli/tzpfms-man#NAME) + +### Why? + +``` +T P M + Z F S +``` + +Plus it's a pretty good annoyed sigh onomatopoeia. + +### Building + +You'll need `pkg-config` and `libzfslinux-dev`, and `make` should hopefully Just Work™ if you have a C++17-capable compiler. + +### Installation + +Copy `out/tzpfms` to `/sbin` and write a `/etc/tzpfms/{description,cmdline}`, as seen in the [manpage](//git.sr.ht/~nabijaczleweli/tzpfms/tree/trunk/man/tzpfms.md), + + + +## Reporting bugs + + + +## Contributing + + + +## Discussion + +Please use the tracker, the list, or [Twitter](//twitter.com/nabijaczleweli/status/1315137083380559873). + +## Special thanks + +To all who support further development on Patreon, in particular: + + * ThePhD + * Embark Studios diff --git a/configMakefile b/configMakefile new file mode 100644 index 0000000..e60a394 --- /dev/null +++ b/configMakefile @@ -0,0 +1,65 @@ +# The MIT License (MIT) + +# Copyright (c) 2020 наб + +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +EXE := +DLL := .so +PIC := -fPIC +OS_LD_LIBS := + +CXXVER := $(shell $(CXX) --version) +ifneq "$(findstring clang,$(CXXVER))" "" + # GCC doesn't have this granularity + CXXSPECIFIC := -flto=full -pedantic -Wno-gnu-statement-expression -Wno-gnu-include-next +else + CXXSPECIFIC := -flto +endif + + +ifneq "$(ADDITIONAL_INCLUDE_DIR)" "" + INCCXXAR := -isystem$(ADDITIONAL_INCLUDE_DIR) +else + INCCXXAR := +endif + +ifneq "$(ADDITIONAL_LINK_DIR)" "" + LNCXXAR := -L$(ADDITIONAL_LINK_DIR) +else + LNCXXAR := +endif + +# TZPFMS_VERSION := "$(patsubst v%,%,$(shell git describe))" +TZPFMS_VERSION := "0.0.0-$(shell git rev-list HEAD --count)" + +INCCMAKEAR := CXXFLAGS="$(INCCXXAR)" +LNCMAKEAR := LDFLAGS="$(LNCXXAR)" + +OBJ := .o +CXXAR := -O3 -std=c++17 -fno-exceptions -Wall -Wextra $(CXXSPECIFIC) -pipe $(INCCXXAR) $(PIC) +STRIP ?= strip +STRIPAR := --strip-all --remove-section=.comment --remove-section=.note + +OUTDIR := out/ +BLDDIR := out/build/ +OBJDIR := $(BLDDIR)obj/ +SRCDIR := src/ +TSTDIR := test/ +MANDIR := man/ diff --git a/tzpfms.sublime-project b/tzpfms.sublime-project new file mode 100644 index 0000000..accad71 --- /dev/null +++ b/tzpfms.sublime-project @@ -0,0 +1,56 @@ +{ + "build_systems": + [ + { + "working_dir": "$project_path", + "shell_cmd": "make -j10", + "name": "Build tzpfms", + + "target": "ansi_color_build", + "syntax": "Packages/ANSIescape/ANSI.sublime-syntax" + }, + { + "working_dir": "$project_path", + "shell_cmd": "make clean", + "name": "Clean tzpfms", + + "target": "ansi_color_build", + "syntax": "Packages/ANSIescape/ANSI.sublime-syntax" + } + ], + "folders": + [ + { + "follow_symlinks": true, + "name": "Source", + "path": "src" + }, + { + "follow_symlinks": true, + "name": "Test", + "path": "test" + }, + { + "follow_symlinks": true, + "name": "Test data", + "path": "test-data" + }, + { + "follow_symlinks": true, + "name": "External code", + "path": "ext" + }, + { + "follow_symlinks": true, + "name": "Manpages", + "path": "man" + }, + { + "follow_symlinks": true, + "name": "Build scripts", + "path": ".", + "file_include_patterns": [".build.yml", "*Makefile"], + "folder_exclude_patterns": ["*"] + }, + ] +}