1From 8d54a6af365571f59ecc4414a46580648b11d095 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Wed, 13 May 2020 11:00:40 +0800
4Subject: [PATCH 16/20] adbd: Support requiring login for adb shell
5
6Run /usr/bin/adbd-auth for "adb shell auth" to login.
7
8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9---
10 core/adbd/services.c | 23 +++++++++++++++++++++++
11 1 file changed, 23 insertions(+)
12
13diff --git a/core/adbd/services.c b/core/adbd/services.c
14index 03140e7..b4c94cb 100644
15--- a/core/adbd/services.c
16+++ b/core/adbd/services.c
17@@ -408,10 +408,33 @@ static int create_subproc_thread(const char *name)
18 }
19 #endif
20
21+void require_auth_service(int fd, void *data)
22+{
23+    char buf[100];
24+
25+    snprintf(buf, sizeof(buf),
26+             "login with \"adb shell auth\" to continue.\r\n");
27+    writex(fd, buf, strlen(buf));
28+    adb_close(fd);
29+}
30+
31 int service_to_fd(const char *name)
32 {
33     int ret = -1;
34
35+#define ADBD_AUTH "/usr/bin/adbd-auth"
36+    if (!access(ADBD_AUTH, X_OK)) {
37+        if(!strcmp(name, "shell:auth")) {
38+            name = "shell:" ADBD_AUTH;
39+        } else if(system(ADBD_AUTH " check")) {
40+            ret = create_service_thread(require_auth_service, NULL);
41+            if (ret >= 0) {
42+                close_on_exec(ret);
43+            }
44+            return ret;
45+        }
46+    }
47+
48     if(!strncmp(name, "tcp:", 4)) {
49         int port = atoi(name + 4);
50         name = strchr(name + 4, ':');
51--
522.20.1
53
54