mtpd: switch to use the new control protocol.
Now L2TP secret is passed via control socket,
so mtpd no longer depends on keystore.
Change-Id: I7a353ce9dc3f69778534a61a209e62a590425c34
diff --git a/Android.mk b/Android.mk
index 2c2a2f6..67a9911 100644
--- a/Android.mk
+++ b/Android.mk
@@ -22,7 +22,7 @@
LOCAL_SRC_FILES := mtpd.c l2tp.c pptp.c
LOCAL_SHARED_LIBRARIES := libcutils libcrypto
LOCAL_CFLAGS := -DANDROID_CHANGES
-LOCAL_C_INCLUDES := external/openssl/include frameworks/base/cmds/keystore
+LOCAL_C_INCLUDES := external/openssl/include
LOCAL_MODULE := mtpd
diff --git a/mtpd.c b/mtpd.c
index 902fcc0..1198d9d 100644
--- a/mtpd.c
+++ b/mtpd.c
@@ -32,7 +32,6 @@
#ifdef ANDROID_CHANGES
#include <android/log.h>
#include <cutils/sockets.h>
-#include "keystore_get.h"
#endif
#include "mtpd.h"
@@ -114,15 +113,18 @@
args[0] = (*argv)[0];
for (i = 1; i < 32; ++i) {
- unsigned char length;
- if (recv(control, &length, 1, 0) != 1) {
+ unsigned char bytes[2];
+ if (recv(control, &bytes[0], 1, 0) != 1
+ || recv(control, &bytes[1], 1, 0) != 1) {
log_print(FATAL, "Cannot get argument length");
exit(SYSTEM_ERROR);
- }
- if (length == 0xFF) {
- break;
} else {
+ int length = bytes[0] << 8 | bytes[1];
int offset = 0;
+
+ if (length == 0xFFFF) {
+ break;
+ }
args[i] = malloc(length + 1);
while (offset < length) {
int n = recv(control, &args[i][offset], length - offset, 0);
@@ -138,21 +140,6 @@
}
log_print(DEBUG, "Received %d arguments", i - 1);
- /* L2TP secret is the only thing stored in keystore. We do the query here
- * so other files are clean and free from android specific code. */
- if (i > 4 && !strcmp("l2tp", args[1]) && args[4][0]) {
- char value[KEYSTORE_MESSAGE_SIZE];
- int length = keystore_get(args[4], strlen(args[4]), value);
- if (length == -1) {
- log_print(FATAL, "Cannot get L2TP secret from keystore");
- exit(SYSTEM_ERROR);
- }
- free(args[4]);
- args[4] = malloc(length + 1);
- memcpy(args[4], value, length);
- args[4][length] = 0;
- }
-
*argc = i;
*argv = args;
return control;