From 79f88bdf8d54a84b7bb727b0c28b2dfcdc3d14d5 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Fri, 9 Dec 2016 14:52:12 -0600 Subject: Support backup/restore of FBE policies Change-Id: Iba8ef20f57b0fb57bb9406c53148a806441d0b59 --- libtar/append.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libtar/append.c') diff --git a/libtar/append.c b/libtar/append.c index 4be679ccd..438829753 100644 --- a/libtar/append.c +++ b/libtar/append.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef STDC_HEADERS # include @@ -34,6 +35,10 @@ # include "selinux/selinux.h" #endif +#ifdef HAVE_EXT4_CRYPT +# include "ext4crypt_tar.h" +#endif + struct tar_dev { dev_t td_dev; @@ -122,6 +127,33 @@ tar_append_file(TAR *t, const char *realname, const char *savename) } #endif +#ifdef HAVE_EXT4_CRYPT + if (TH_ISDIR(t) && t->options & TAR_STORE_EXT4_POL) + { + if (t->th_buf.e4crypt_policy != NULL) + { + free(t->th_buf.e4crypt_policy); + t->th_buf.e4crypt_policy = NULL; + } + + char e4crypt_policy[EXT4_KEY_DESCRIPTOR_SIZE]; + if (e4crypt_policy_get(realname, e4crypt_policy, EXT4_KEY_DESCRIPTOR_SIZE, 0)) + { + char tar_policy[EXT4_KEY_DESCRIPTOR_SIZE]; + memset(tar_policy, 0, sizeof(tar_policy)); + char policy_hex[EXT4_KEY_DESCRIPTOR_HEX]; + policy_to_hex(e4crypt_policy, policy_hex); + if (lookup_ref_key(e4crypt_policy, &tar_policy)) { + printf("found policy '%s' - '%s' - '%s'\n", realname, tar_policy, policy_hex); + t->th_buf.e4crypt_policy = strdup(tar_policy); + } else { + printf("failed to lookup tar policy for '%s' - '%s'\n", realname, policy_hex); + return -1; + } + } // else no policy found, but this is not an error as not all dirs will have a policy + } +#endif + /* check if it's a hardlink */ #ifdef DEBUG puts("tar_append_file(): checking inode cache for hardlink..."); -- cgit v1.2.3