fscrypt policy: don't bail restore if we cannot lookup policy
When TWRP is unable to lookup a fscrypt policy, we should not bail
the entire restore. Let's note that we had an issue with the lookup
in the log and continue restoring.
Change-Id: Ida80458356c12f81ff47f583beb05dd392486a0d
diff --git a/libtar/append.c b/libtar/append.c
index 6f0b252..dff0f88 100755
--- a/libtar/append.c
+++ b/libtar/append.c
@@ -185,7 +185,6 @@
printf("failed to lookup fscrypt tar policy for '%s' - '%s'\n", realname, policy_hex);
free(t->th_buf.fep);
t->th_buf.fep = NULL;
- return -1;
}
}
else {
diff --git a/libtar/extract.c b/libtar/extract.c
index 65ea1d1..08e2914 100755
--- a/libtar/extract.c
+++ b/libtar/extract.c
@@ -570,6 +570,7 @@
#endif
printf("tar_extract_dir(): restoring fscrypt policy %s to dir %s\n", (char *)policy_hex, realname);
#endif
+ bool policy_lookup_error = false;
#ifdef USE_FSCRYPT_POLICY_V1
uint8_t binary_policy[FS_KEY_DESCRIPTOR_SIZE];
memset(&binary_policy, 0, FS_KEY_DESCRIPTOR_SIZE);
@@ -581,24 +582,28 @@
#ifdef USE_FSCRYPT_POLICY_V1
if (!lookup_ref_tar(t->th_buf.fep->master_key_descriptor, &binary_policy[0])) {
printf("error looking up fscrypt policy for '%s' - %s\n", realname, t->th_buf.fep->master_key_descriptor);
- return -1;
+ policy_lookup_error = true;
}
memcpy(&t->th_buf.fep->master_key_descriptor, binary_policy, FS_KEY_DESCRIPTOR_SIZE);
bytes_to_hex(t->th_buf.fep->master_key_descriptor, FS_KEY_DESCRIPTOR_SIZE, policy_hex);
#else
if (!lookup_ref_tar(t->th_buf.fep->master_key_identifier, &binary_policy[0])) {
printf("error looking up fscrypt policy for '%s' - %s\n", realname, t->th_buf.fep->master_key_identifier);
- return -1;
+ policy_lookup_error = true;
}
memcpy(&t->th_buf.fep->master_key_identifier, binary_policy, FSCRYPT_KEY_IDENTIFIER_SIZE);
bytes_to_hex(t->th_buf.fep->master_key_identifier, FSCRYPT_KEY_IDENTIFIER_SIZE, policy_hex);
#endif
- printf("attempting to restore policy: %s\n", policy_hex);
- if (!fscrypt_policy_set_struct(realname, t->th_buf.fep))
+ if (!policy_lookup_error)
{
- printf("tar_extract_file(): failed to restore fscrypt policy to dir '%s' '%s'!!!\n", realname, policy_hex);
- //return -1; // This may not be an error in some cases, so log and ignore
- }
+ printf("attempting to restore policy: %s\n", policy_hex);
+ if (!fscrypt_policy_set_struct(realname, t->th_buf.fep))
+ {
+ printf("tar_extract_file(): failed to restore fscrypt policy to dir '%s' '%s'!!!\n", realname, policy_hex);
+ //return -1; // This may not be an error in some cases, so log and ignore
+ }
+ } else
+ printf("No policy was found. Continuing restore.");
}
else
printf("NULL FSCRYPT\n");