~nabijaczleweli/tzpfms

fb3eb012b6eb896c44e922249e1053fde5cb6881 — наб 8 days ago 2860520
Handle -h and -V
M README.md => README.md +1 -1
@@ 14,7 14,7 @@ Plus it's a pretty good annoyed sigh onomatopoeia.

### Building

You'll need `pkg-config`, `libzfslinux-dev`, `libtss2-dev`, and `make` should hopefully Just Work™ if you have a C++17-capable compiler.
You'll need `pkg-config`, `ronn`, `libzfslinux-dev`, `libtss2-dev`, and `make` should hopefully Just Work™ if you have a C++17-capable compiler.
The output binaries are trimmed of extraneous dependencies, so they're all just libc + libzfs and friends + TPM back-end.

### Installation

M src/bin/zfs-tpm2-change-key.cpp => src/bin/zfs-tpm2-change-key.cpp +1 -1
@@ 44,7 44,7 @@ slice_iter<uint8_t> end(TPM2B_DIGEST & dg) {
int main(int argc, char ** argv) {
	const char * backup{};
	return do_main(
	    argc, argv, "b:", [&](auto) { backup = optarg; },
	    argc, argv, "b:", "[-b backup-file]", [&](auto) { backup = optarg; },
	    [&](auto dataset) {
		    REQUIRE_KEY_LOADED(dataset);


M src/bin/zfs-tpm2-clear-key.cpp => src/bin/zfs-tpm2-clear-key.cpp +1 -1
@@ 15,7 15,7 @@

int main(int argc, char ** argv) {
	return do_main(
	    argc, argv, "", [&](auto) {},
	    argc, argv, "", "", [&](auto) {},
	    [&](auto dataset) {
		    REQUIRE_KEY_LOADED(dataset);


M src/bin/zfs-tpm2-load-key.cpp => src/bin/zfs-tpm2-load-key.cpp +1 -1
@@ 19,7 19,7 @@
int main(int argc, char ** argv) {
	auto noop = B_FALSE;
	return do_main(
	    argc, argv, "n", [&](auto) { noop = B_TRUE; },
	    argc, argv, "n", "[-n]", [&](auto) { noop = B_TRUE; },
	    [&](auto dataset) {
		    TPMI_DH_PERSISTENT handle{};
		    TRY_MAIN(parse_key_props(dataset, THIS_BACKEND, handle));

M src/main.hpp => src/main.hpp +19 -7
@@ 19,7 19,7 @@


template <class G, class M>
int do_main(int argc, char ** argv, const char * getoptions, G && getoptfn, M && main) {
int do_main(int argc, char ** argv, const char * getoptions, const char * usage, G && getoptfn, M && main) {
	const auto libz = TRY_PTR("initialise libzfs", libzfs_init());
	quickscope_wrapper libz_deleter{[=] { libzfs_fini(libz); }};



@@ 28,14 28,26 @@ int do_main(int argc, char ** argv, const char * getoptions, G && getoptfn, M &&
#if __GLIBC__
	setenv("POSIXLY_CORRECT", "1", true);
#endif
	for(int opt; (opt = getopt(argc, argv, getoptions)) != -1;)
		if(opt == '?')
			return __LINE__;
		else
			getoptfn(opt);
	auto gopts = reinterpret_cast<char *>(TRY_PTR("allocate options string", alloca(strlen(getoptions) + 2 + 1)));
	snprintf(gopts, strlen(getoptions) + 2 + 1, "%shV", getoptions);
	for(int opt; (opt = getopt(argc, argv, gopts)) != -1;)
		switch(opt) {
			case '?':
			case 'h':
				fprintf(opt == 'h' ? stdout : stderr, "Usage: %s [-hV] %s%s<dataset>\n", argv[0], usage, strlen(usage) ? " " : "");
				return opt == 'h' ? 0 : __LINE__;
			case 'V':
				printf("tzpfms version %s\n", TZPFMS_VERSION);
				return 0;
			default:
				getoptfn(opt);
		}

	if(optind >= argc) {
		fprintf(stderr, "No dataset to act on?\n");
		fprintf(stderr,
		        "No dataset to act on?\n"
		        "Usage: %s [-hV] %s%s<dataset>\n",
		        argv[0], usage, strlen(usage) ? " " : "");
		return __LINE__;
	}
	auto dataset = TRY_PTR(nullptr, zfs_open(libz, argv[optind], ZFS_TYPE_FILESYSTEM));