Merge "Switch to libkeyutils." am: 70c39c84be
am: 2cb7eeed03

Change-Id: I631fe660ef8a38558d5653ee2d64e274837286ea
diff --git a/ext4_utils/Android.bp b/ext4_utils/Android.bp
index a2987aa..493fae5 100644
--- a/ext4_utils/Android.bp
+++ b/ext4_utils/Android.bp
@@ -41,11 +41,11 @@
 
         android: {
             srcs: [
-                "key_control.cpp",
                 "ext4_crypt.cpp",
             ],
             shared_libs: [
                 "libbase",
+                "libkeyutils",
                 "libselinux",
             ],
 
diff --git a/ext4_utils/ext4_crypt_init_extensions.cpp b/ext4_utils/ext4_crypt_init_extensions.cpp
index 732060d..04d7119 100644
--- a/ext4_utils/ext4_crypt_init_extensions.cpp
+++ b/ext4_utils/ext4_crypt_init_extensions.cpp
@@ -30,10 +30,10 @@
 #include <android-base/stringprintf.h>
 #include <cutils/properties.h>
 #include <cutils/sockets.h>
+#include <keyutils.h>
 #include <logwrap/logwrap.h>
 
 #include "ext4_utils/ext4_crypt.h"
-#include "ext4_utils/key_control.h"
 
 #define TAG "ext4_utils"
 
diff --git a/ext4_utils/include/ext4_utils/key_control.h b/ext4_utils/include/ext4_utils/key_control.h
deleted file mode 100644
index fe6a6b5..0000000
--- a/ext4_utils/include/ext4_utils/key_control.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef _KEY_CONTROL_H_
-#define _KEY_CONTROL_H_
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-__BEGIN_DECLS
-
-// ext4enc:TODO - get these keyring standard definitions from proper system file
-// keyring serial number type
-typedef int32_t key_serial_t;
-
-// special process keyring shortcut IDs
-#define KEY_SPEC_THREAD_KEYRING       (-1) // key ID for thread-specific keyring
-#define KEY_SPEC_PROCESS_KEYRING      (-2) // key ID for process-specific keyring
-#define KEY_SPEC_SESSION_KEYRING      (-3) // key ID for session-specific keyring
-#define KEY_SPEC_USER_KEYRING         (-4) // key ID for UID-specific keyring
-#define KEY_SPEC_USER_SESSION_KEYRING (-5) // key ID for UID-session keyring
-#define KEY_SPEC_GROUP_KEYRING        (-6) // key ID for GID-specific keyring
-
-key_serial_t add_key(const char *type,
-                     const char *description,
-                     const void *payload,
-                     size_t plen,
-                     key_serial_t ringid);
-
-long keyctl_revoke(key_serial_t id);
-
-long keyctl_setperm(key_serial_t id, int permissions);
-
-long keyctl_search(key_serial_t ringid, const char *type,
-                   const char *description, key_serial_t destringid);
-
-__END_DECLS
-
-#endif // _KEY_CONTROL_H_
diff --git a/ext4_utils/key_control.cpp b/ext4_utils/key_control.cpp
deleted file mode 100644
index de6bde2..0000000
--- a/ext4_utils/key_control.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "ext4_utils/key_control.h"
-
-#include <stdarg.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <linux/keyctl.h>
-
-static long keyctl(int cmd, ...)
-{
-    va_list va;
-    unsigned long arg2, arg3, arg4, arg5;
-
-    va_start(va, cmd);
-    arg2 = va_arg(va, unsigned long);
-    arg3 = va_arg(va, unsigned long);
-    arg4 = va_arg(va, unsigned long);
-    arg5 = va_arg(va, unsigned long);
-    va_end(va);
-    return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
-}
-
-key_serial_t add_key(const char *type,
-                     const char *description,
-                     const void *payload,
-                     size_t plen,
-                     key_serial_t ringid)
-{
-    return syscall(__NR_add_key, type, description, payload, plen, ringid);
-}
-
-long keyctl_revoke(key_serial_t id)
-{
-    return keyctl(KEYCTL_REVOKE, id);
-}
-
-long keyctl_setperm(key_serial_t id, int permissions)
-{
-    return keyctl(KEYCTL_SETPERM, id, permissions);
-}
-
-long keyctl_search(key_serial_t ringid, const char *type,
-                   const char *description, key_serial_t destringid)
-{
-    return keyctl(KEYCTL_SEARCH, ringid, type, description, destringid);
-}