diff options
Diffstat (limited to '')
-rw-r--r-- | libtar/append.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/libtar/append.c b/libtar/append.c index 8896764f2..66e3aa1e7 100644 --- a/libtar/append.c +++ b/libtar/append.c @@ -131,27 +131,39 @@ tar_append_file(TAR *t, const char *realname, const char *savename) #ifdef HAVE_EXT4_CRYPT if (TH_ISDIR(t) && t->options & TAR_STORE_EXT4_POL) { - if (t->th_buf.e4crypt_policy != NULL) + if (t->th_buf.eep != NULL) { - free(t->th_buf.e4crypt_policy); - t->th_buf.e4crypt_policy = NULL; + free(t->th_buf.eep); + t->th_buf.eep = NULL; } - char e4crypt_policy[EXT4_KEY_DESCRIPTOR_SIZE]; - if (e4crypt_policy_get(realname, e4crypt_policy, EXT4_KEY_DESCRIPTOR_SIZE, 0)) + t->th_buf.eep = (struct ext4_encryption_policy*)malloc(sizeof(struct ext4_encryption_policy)); + if (!t->th_buf.eep) { + printf("malloc ext4_encryption_policy\n"); + return -1; + } + if (e4crypt_policy_get_struct(realname, t->th_buf.eep)) { 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)) { + char policy_hex[EXT4_KEY_DESCRIPTOR_SIZE_HEX]; + policy_to_hex(t->th_buf.eep->master_key_descriptor, policy_hex); + if (lookup_ref_key(t->th_buf.eep->master_key_descriptor, &tar_policy[0])) { printf("found policy '%s' - '%s' - '%s'\n", realname, tar_policy, policy_hex); - t->th_buf.e4crypt_policy = strdup(tar_policy); + memcpy(t->th_buf.eep->master_key_descriptor, tar_policy, EXT4_KEY_DESCRIPTOR_SIZE); } else { printf("failed to lookup tar policy for '%s' - '%s'\n", realname, policy_hex); + free(t->th_buf.eep); + t->th_buf.eep = NULL; return -1; } - } // else no policy found, but this is not an error as not all dirs will have a policy + } + else + { + // no policy found, but this is not an error as not all dirs will have a policy + free(t->th_buf.eep); + t->th_buf.eep = NULL; + } } #endif |