dedup

deduplicating backup program
git clone git://git.2f30.org/dedup.git
Log | Files | Refs | README | LICENSE

commit a1037d78c0b5a6d557e520a87d484e77168610b9
parent d0213e5514ecb4a49986054e94943ff3016c5766
Author: sin <sin@2f30.org>
Date:   Thu,  2 May 2019 23:32:12 +0100

Add -k option to dup-init(1)

Diffstat:
Mdup-init.1 | 5++++-
Mdup-init.c | 26++++++++++++++++++++++++--
Mtest006 | 2+-
3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/dup-init.1 b/dup-init.1 @@ -9,6 +9,7 @@ .Op Fl v .Op Fl E Ar algo .Op Fl Z Ar algo +.Op Fl k Ar keyfile .Op repo .Sh DESCRIPTION .Nm @@ -17,7 +18,7 @@ If no .Ar repo is specified the current working directory is used. .Sh OPTIONS -.Bl -tag -width "-Z algo" +.Bl -tag -width "-k keyfile" .It Fl E Ar algo The encryption algorithm used to encrypt the blocks in the store. @@ -30,6 +31,8 @@ in the store. The supported compressor algorithms are none and snappy. This flag only has an effect when initializing the repository. By default snappy is used. +.It Fl k Ar keyfile +Path to encryption key. .It Fl v Enable verbose mode. .El diff --git a/dup-init.c b/dup-init.c @@ -2,13 +2,15 @@ #include <sys/stat.h> #include <err.h> +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include "arg.h" -#include "config.h" #include "block.h" +#include "config.h" +#include "key.h" #include "snap.h" int verbose; @@ -17,21 +19,26 @@ char *argv0; static void usage(void) { - fprintf(stderr, "usage: %s [-v] [-E algo] [-Z algo] [repo]\n", argv0); + fprintf(stderr, "usage: %s [-v] [-E algo] [-Z algo] [-k keyfile] [repo]\n", argv0); exit(1); } int main(int argc, char *argv[]) { + unsigned char key[KEYSIZE]; struct bctx *bctx; /* block context */ struct bparam bpar; + char *keyfile = NULL; char *repo; bpar.calgo = bparamdef()->calgo; bpar.ealgo = bparamdef()->ealgo; ARGBEGIN { + case 'k': + keyfile = EARGF(usage()); + break; case 'E': bpar.ealgo = EARGF(usage()); break; @@ -56,6 +63,21 @@ main(int argc, char *argv[]) usage(); }; + if (keyfile != NULL) { + int fd; + + fd = open(keyfile, O_RDONLY); + if (fd < 0) + err(1, "open: %s", keyfile); + if (loadkey(fd, key, sizeof(key)) < 0) + errx(1, "loadkey: failed"); + bpar.key = key; + if (close(fd) < 0) + err(1, "close: %s", keyfile); + } else { + bpar.key = NULL; + } + mkdir(repo, 0700); if (chdir(repo) < 0) err(1, "chdir: %s", repo); diff --git a/test006 b/test006 @@ -6,7 +6,7 @@ repo=`mktemp -d` data=`mktemp` dd if=/dev/urandom of="$data" bs=1M count=64 ./dup-keygen "$keyfile" -./dup-init -E XChaCha20-Poly1305 "$repo" +./dup-init -E XChaCha20-Poly1305 -k "$keyfile" "$repo" ./dup-pack -k "$keyfile" -r "$repo" snap0 < "$data" ./dup-gc -k "$keyfile" "$repo" ./dup-rm -k "$keyfile" -r "$repo" snap0 < "$data"