OSDN Git Service

Enable properties in ext4enc
authorPaul Lawrence <paullawrence@google.com>
Wed, 15 Apr 2015 21:12:00 +0000 (14:12 -0700)
committerPaul Lawrence <paullawrence@google.com>
Fri, 1 May 2015 15:03:39 +0000 (08:03 -0700)
Enables OwnerInfo and pattern suppression

Bug: 18151196

Change-Id: I46144e16cb00319deeb5492ab82c67f5dd43d6d3

Ext4Crypt.cpp
Ext4Crypt.h
cryptfs.c

index 0c7b351..0f6af6b 100644 (file)
@@ -46,14 +46,6 @@ namespace {
         uint32_t size;
     };
 
-    // ext4enc:TODO Get from somewhere good
-    struct ext4_encryption_policy {
-        char version;
-        char contents_encryption_mode;
-        char filenames_encryption_mode;
-        char master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE];
-    } __attribute__((__packed__));
-
     namespace tag {
         const char* magic = "magic";
         const char* major_version = "major_version";
@@ -440,3 +432,28 @@ int e4crypt_get_password_type(const char* path)
     return GetPropsOrAltProps(path).GetChild(properties::key)
       .Get<int>(tag::crypt_type, CRYPT_TYPE_DEFAULT);
 }
+
+int e4crypt_get_field(const char* path, const char* fieldname,
+                      char* value, size_t len)
+{
+    auto v = GetPropsOrAltProps(path).GetChild(properties::props)
+      .Get<std::string>(fieldname);
+
+    if (v == "") {
+        return CRYPTO_GETFIELD_ERROR_NO_FIELD;
+    }
+
+    if (v.length() >= len) {
+        return CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL;
+    }
+
+    strlcpy(value, v.c_str(), len);
+    return 0;
+}
+
+int e4crypt_set_field(const char* path, const char* fieldname,
+                      const char* value)
+{
+    return GetPropsOrAltProps(path).GetChild(properties::props)
+        .Set(fieldname, std::string(value)) ? 0 : -1;
+}
index 301639d..68e0fb2 100644 (file)
@@ -1,3 +1,4 @@
+#include <stddef.h>
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
@@ -12,5 +13,9 @@ int e4crypt_check_passwd(const char* path, const char* password);
 int e4crypt_get_password_type(const char* path);
 const char* e4crypt_get_password(const char* path);
 int e4crypt_restart(const char* path);
+int e4crypt_get_field(const char* path, const char* fieldname,
+                      char* value, size_t len);
+int e4crypt_set_field(const char* path, const char* fieldname,
+                      const char* value);
 
 __END_DECLS
index 7398995..13ccd6c 100644 (file)
--- a/cryptfs.c
+++ b/cryptfs.c
@@ -3578,6 +3578,10 @@ static int persist_count_keys(const char *fieldname)
 /* Return the value of the specified field. */
 int cryptfs_getfield(const char *fieldname, char *value, int len)
 {
+    if (e4crypt_crypto_complete(DATA_MNT_POINT) == 0) {
+        return e4crypt_get_field(DATA_MNT_POINT, fieldname, value, len);
+    }
+
     char temp_value[PROPERTY_VALUE_MAX];
     /* CRYPTO_GETFIELD_OK is success,
      * CRYPTO_GETFIELD_ERROR_NO_FIELD is value not set,
@@ -3639,6 +3643,10 @@ out:
 /* Set the value of the specified field. */
 int cryptfs_setfield(const char *fieldname, const char *value)
 {
+    if (e4crypt_crypto_complete(DATA_MNT_POINT) == 0) {
+        return e4crypt_set_field(DATA_MNT_POINT, fieldname, value);
+    }
+
     char encrypted_state[PROPERTY_VALUE_MAX];
     /* 0 is success, negative values are error */
     int rc = CRYPTO_SETFIELD_ERROR_OTHER;