OSDN Git Service

add sqlite. fixes for multiuser.
[android-x86/external-koush-Superuser.git] / Superuser / jni / su / su.c
1 /*
2 ** Copyright 2010, Adam Shanks (@ChainsDD)
3 ** Copyright 2008, Zinx Verituse (@zinxv)
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <sys/un.h>
21 #include <sys/wait.h>
22 #include <sys/select.h>
23 #include <sys/time.h>
24 #include <unistd.h>
25 #include <limits.h>
26 #include <fcntl.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <getopt.h>
30 #include <stdint.h>
31 #include <pwd.h>
32 #include <sys/stat.h>
33 #include <stdarg.h>
34 #include <sys/types.h>
35 #include <pwd.h>
36
37 #include "su.h"
38 #include "utils.h"
39
40 int get_shell_uid() {
41   struct passwd* ppwd = getpwnam("shell");
42   if (NULL == ppwd) {
43     return -1;
44   }
45   
46   return ppwd->pw_uid;
47 }
48
49 void exec_log(char *priority, char* logline) {
50   int pid;
51   if ((pid = fork()) == 0) {
52     execl("/system/bin/log", "/system/bin/log", "-p", priority, "-t", LOG_TAG, logline);
53     exit(0);
54   }
55 }
56
57 void exec_loge(const char* fmt, ...) {
58   va_list args;
59
60   char logline[PATH_MAX];
61   va_start(args, fmt);
62   vsnprintf(logline, PATH_MAX, fmt, args);
63   va_end(args);
64   exec_log("e", logline);
65 }
66
67 void exec_logw(const char* fmt, ...) {
68   va_list args;
69
70   char logline[PATH_MAX];
71   va_start(args, fmt);
72   vsnprintf(logline, PATH_MAX, fmt, args);
73   va_end(args);
74   exec_log("w", logline);
75 }
76
77 void exec_logd(const char* fmt, ...) {
78   va_list args;
79
80   char logline[PATH_MAX];
81   va_start(args, fmt);
82   vsnprintf(logline, PATH_MAX, fmt, args);
83   va_end(args);
84   exec_log("d", logline);
85 }
86
87 static int from_init(struct su_initiator *from) {
88     char path[PATH_MAX], exe[PATH_MAX];
89     char args[4096], *argv0, *argv_rest;
90     int fd;
91     ssize_t len;
92     int i;
93     int err;
94
95     from->uid = getuid();
96     from->pid = getppid();
97
98     /* Get the command line */
99     snprintf(path, sizeof(path), "/proc/%u/cmdline", from->pid);
100     fd = open(path, O_RDONLY);
101     if (fd < 0) {
102         PLOGE("Opening command line");
103         return -1;
104     }
105     len = read(fd, args, sizeof(args));
106     err = errno;
107     close(fd);
108     if (len < 0 || len == sizeof(args)) {
109         PLOGEV("Reading command line", err);
110         return -1;
111     }
112
113     argv0 = args;
114     argv_rest = NULL;
115     for (i = 0; i < len; i++) {
116         if (args[i] == '\0') {
117             if (!argv_rest) {
118                 argv_rest = &args[i+1];
119             } else {
120                 args[i] = ' ';
121             }
122         }
123     }
124     args[len] = '\0';
125
126     if (argv_rest) {
127         strncpy(from->args, argv_rest, sizeof(from->args));
128         from->args[sizeof(from->args)-1] = '\0';
129     } else {
130         from->args[0] = '\0';
131     }
132
133     /* If this isn't app_process, use the real path instead of argv[0] */
134     snprintf(path, sizeof(path), "/proc/%u/exe", from->pid);
135     len = readlink(path, exe, sizeof(exe));
136     if (len < 0) {
137         PLOGE("Getting exe path");
138         return -1;
139     }
140     exe[len] = '\0';
141     if (strcmp(exe, "/system/bin/app_process")) {
142         argv0 = exe;
143     }
144
145     strncpy(from->bin, argv0, sizeof(from->bin));
146     from->bin[sizeof(from->bin)-1] = '\0';
147
148     return 0;
149 }
150
151 static void read_options(struct su_context *ctx) {
152     char mode[12];
153     FILE *fp;
154     if ((fp = fopen(REQUESTOR_MULTIUSER_MODE, "r"))) {
155         fgets(mode, sizeof(mode), fp);
156         if (strcmp(mode, "user\n") == 0) {
157             ctx->user.multiuser_mode = MULTIUSER_MODE_USER;
158         } else if (strcmp(mode, "owner\n") == 0) {
159             ctx->user.multiuser_mode = MULTIUSER_MODE_OWNER;
160         }
161         fclose(fp);
162     }
163 }
164
165 static void user_init(struct su_context *ctx) {
166     if (ctx->from.uid > 99999) {
167         ctx->user.android_user_id = ctx->from.uid / 100000;
168         if (ctx->user.multiuser_mode == MULTIUSER_MODE_USER) {
169             snprintf(ctx->user.database_path, PATH_MAX, "%s/%d/%s", REQUESTOR_USER_PATH, ctx->user.android_user_id, REQUESTOR_DATABASE_PATH);
170         }
171     }
172 }
173
174 static void populate_environment(const struct su_context *ctx) {
175     struct passwd *pw;
176
177     if (ctx->to.keepenv)
178         return;
179
180     pw = getpwuid(ctx->to.uid);
181     if (pw) {
182         setenv("HOME", pw->pw_dir, 1);
183         setenv("SHELL", ctx->to.shell, 1);
184         if (ctx->to.login || ctx->to.uid) {
185             setenv("USER", pw->pw_name, 1);
186             setenv("LOGNAME", pw->pw_name, 1);
187         }
188     }
189 }
190
191 void set_identity(unsigned int uid) {
192     /*
193      * Set effective uid back to root, otherwise setres[ug]id will fail
194      * if uid isn't root.
195      */
196     if (seteuid(0)) {
197         PLOGE("seteuid (root)");
198         exit(EXIT_FAILURE);
199     }
200     if (setresgid(uid, uid, uid)) {
201         PLOGE("setresgid (%u)", uid);
202         exit(EXIT_FAILURE);
203     }
204     if (setresuid(uid, uid, uid)) {
205         PLOGE("setresuid (%u)", uid);
206         exit(EXIT_FAILURE);
207     }
208 }
209
210 static void socket_cleanup(struct su_context *ctx) {
211     if (ctx && ctx->sock_path[0]) {
212         if (unlink(ctx->sock_path))
213             PLOGE("unlink (%s)", ctx->sock_path);
214         ctx->sock_path[0] = 0;
215     }
216 }
217
218 /*
219  * For use in signal handlers/atexit-function
220  * NOTE: su_ctx points to main's local variable.
221  *       It's OK due to the program uses exit(3), not return from main()
222  */
223 static struct su_context *su_ctx = NULL;
224
225 static void cleanup(void) {
226     socket_cleanup(su_ctx);
227 }
228
229 static void cleanup_signal(int sig) {
230     socket_cleanup(su_ctx);
231     exit(128 + sig);
232 }
233
234 void sigchld_handler(int sig) {
235     child_cleanup(su_ctx);
236     (void)sig;
237 }
238
239 static int socket_create_temp(char *path, size_t len) {
240     int fd;
241     struct sockaddr_un sun;
242
243     fd = socket(AF_LOCAL, SOCK_STREAM, 0);
244     if (fd < 0) {
245         PLOGE("socket");
246         return -1;
247     }
248     if (fcntl(fd, F_SETFD, FD_CLOEXEC)) {
249         PLOGE("fcntl FD_CLOEXEC");
250         goto err;
251     }
252
253     memset(&sun, 0, sizeof(sun));
254     sun.sun_family = AF_LOCAL;
255     snprintf(path, len, "%s/.socket%d", REQUESTOR_CACHE_PATH, getpid());
256     memset(sun.sun_path, 0, sizeof(sun.sun_path));
257     snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", path);
258
259     /*
260      * Delete the socket to protect from situations when
261      * something bad occured previously and the kernel reused pid from that process.
262      * Small probability, isn't it.
263      */
264     unlink(sun.sun_path);
265
266     if (bind(fd, (struct sockaddr*)&sun, sizeof(sun)) < 0) {
267         PLOGE("bind");
268         goto err;
269     }
270
271     if (listen(fd, 1) < 0) {
272         PLOGE("listen");
273         goto err;
274     }
275
276     return fd;
277 err:
278     close(fd);
279     return -1;
280 }
281
282 static int socket_accept(int serv_fd) {
283     struct timeval tv;
284     fd_set fds;
285     int fd, rc;
286
287     /* Wait 20 seconds for a connection, then give up. */
288     tv.tv_sec = 20;
289     tv.tv_usec = 0;
290     FD_ZERO(&fds);
291     FD_SET(serv_fd, &fds);
292     do {
293         rc = select(serv_fd + 1, &fds, NULL, NULL, &tv);
294     } while (rc < 0 && errno == EINTR);
295     if (rc < 1) {
296         PLOGE("select");
297         return -1;
298     }
299
300     fd = accept(serv_fd, NULL, NULL);
301     if (fd < 0) {
302         PLOGE("accept");
303         return -1;
304     }
305
306     return fd;
307 }
308
309 static int socket_send_request(int fd, const struct su_context *ctx) {
310     size_t len;
311     size_t bin_size, cmd_size;
312     char *cmd;
313
314 #define write_token(fd, data)                \
315 do {                            \
316     uint32_t __data = htonl(data);            \
317     size_t __count = sizeof(__data);        \
318     size_t __len = write((fd), &__data, __count);    \
319     if (__len != __count) {                \
320         PLOGE("write(" #data ")");        \
321         return -1;                \
322     }                        \
323 } while (0)
324
325     write_token(fd, PROTO_VERSION);
326     write_token(fd, PATH_MAX);
327     write_token(fd, ARG_MAX);
328     write_token(fd, ctx->from.uid);
329     write_token(fd, ctx->to.uid);
330     bin_size = strlen(ctx->from.bin) + 1;
331     write_token(fd, bin_size);
332     len = write(fd, ctx->from.bin, bin_size);
333     if (len != bin_size) {
334         PLOGE("write(bin)");
335         return -1;
336     }
337     cmd = get_command(&ctx->to);
338     cmd_size = strlen(cmd) + 1;
339     write_token(fd, cmd_size);
340     len = write(fd, cmd, cmd_size);
341     if (len != cmd_size) {
342         PLOGE("write(cmd)");
343         return -1;
344     }
345     return 0;
346 }
347
348 static int socket_receive_result(int fd, char *result, ssize_t result_len) {
349     ssize_t len;
350     
351     len = read(fd, result, result_len-1);
352     if (len < 0) {
353         PLOGE("read(result)");
354         return -1;
355     }
356     result[len] = '\0';
357
358     return 0;
359 }
360
361 static void usage(int status) {
362     FILE *stream = (status == EXIT_SUCCESS) ? stdout : stderr;
363
364     fprintf(stream,
365     "Usage: su [options] [--] [-] [LOGIN] [--] [args...]\n\n"
366     "Options:\n"
367     "  -c, --command COMMAND         pass COMMAND to the invoked shell\n"
368     "  -h, --help                    display this help message and exit\n"
369     "  -, -l, --login                pretend the shell to be a login shell\n"
370     "  -m, -p,\n"
371     "  --preserve-environment        do not change environment variables\n"
372     "  -s, --shell SHELL             use SHELL instead of the default " DEFAULT_SHELL "\n"
373     "  -v, --version                 display version number and exit\n"
374     "  -V                            display version code and exit,\n"
375     "                                this is used almost exclusively by Superuser.apk\n");
376     exit(status);
377 }
378
379 static __attribute__ ((noreturn)) void deny(struct su_context *ctx) {
380     char *cmd = get_command(&ctx->to);
381
382     // No send to UI denied requests for shell and root users (they are in the log)
383     if( ctx->from.uid != AID_SHELL && ctx->from.uid != AID_ROOT ) {
384         send_result(ctx, DENY);
385     }
386     LOGW("request rejected (%u->%u %s)", ctx->from.uid, ctx->to.uid, cmd);
387     fprintf(stderr, "%s\n", strerror(EACCES));
388     exit(EXIT_FAILURE);
389 }
390
391 static __attribute__ ((noreturn)) void allow(struct su_context *ctx) {
392     char *arg0;
393     int argc, err;
394
395     umask(ctx->umask);
396     // No send to UI accepted requests for shell and root users (they are in the log)
397     if( ctx->from.uid != AID_SHELL && ctx->from.uid != AID_ROOT ) {
398         send_result(ctx, ALLOW);
399     }
400
401     arg0 = strrchr (ctx->to.shell, '/');
402     arg0 = (arg0) ? arg0 + 1 : ctx->to.shell;
403     if (ctx->to.login) {
404         int s = strlen(arg0) + 2;
405         char *p = malloc(s);
406
407         if (!p)
408             exit(EXIT_FAILURE);
409
410         *p = '-';
411         strcpy(p + 1, arg0);
412         arg0 = p;
413     }
414
415     populate_environment(ctx);
416     set_identity(ctx->to.uid);
417
418 #define PARG(arg)                                    \
419     (ctx->to.optind + (arg) < ctx->to.argc) ? " " : "",                    \
420     (ctx->to.optind + (arg) < ctx->to.argc) ? ctx->to.argv[ctx->to.optind + (arg)] : ""
421
422     LOGD("%u %s executing %u %s using shell %s : %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
423             ctx->from.uid, ctx->from.bin,
424             ctx->to.uid, get_command(&ctx->to), ctx->to.shell,
425             arg0, PARG(0), PARG(1), PARG(2), PARG(3), PARG(4), PARG(5),
426             (ctx->to.optind + 6 < ctx->to.argc) ? " ..." : "");
427
428     argc = ctx->to.optind;
429     if (ctx->to.command) {
430         ctx->to.argv[--argc] = ctx->to.command;
431         ctx->to.argv[--argc] = "-c";
432     }
433     ctx->to.argv[--argc] = arg0;
434     execv(ctx->to.shell, ctx->to.argv + argc);
435     err = errno;
436     PLOGE("exec");
437     fprintf(stderr, "Cannot execute %s: %s\n", ctx->to.shell, strerror(err));
438     exit(EXIT_FAILURE);
439 }
440
441 /*
442  * CyanogenMod-specific behavior
443  *
444  * we can't simply use the property service, since we aren't launched from init
445  * and can't trust the location of the property workspace.
446  * Find the properties ourselves.
447  */
448 int access_disabled(const struct su_initiator *from) {
449     char *data;
450     char build_type[PROPERTY_VALUE_MAX];
451     char debuggable[PROPERTY_VALUE_MAX], enabled[PROPERTY_VALUE_MAX];
452     size_t len;
453
454     data = read_file("/system/build.prop");
455     if (check_property(data, "ro.cm.version")) {
456         get_property(data, build_type, "ro.build.type", "");
457         free(data);
458
459         data = read_file("/default.prop");
460         get_property(data, debuggable, "ro.debuggable", "0");
461         free(data);
462         /* only allow su on debuggable builds */
463         if (strcmp("1", debuggable) != 0) {
464             LOGE("Root access is disabled on non-debug builds");
465             return 1;
466         }
467
468         data = read_file("/data/property/persist.sys.root_access");
469         if (data != NULL) {
470             len = strlen(data);
471             if (len >= PROPERTY_VALUE_MAX)
472                 memcpy(enabled, "1", 2);
473             else
474                 memcpy(enabled, data, len + 1);
475             free(data);
476         } else
477             memcpy(enabled, "1", 2);
478
479         /* enforce persist.sys.root_access on non-eng builds for apps */
480         if (strcmp("eng", build_type) != 0 &&
481                 from->uid != AID_SHELL && from->uid != AID_ROOT &&
482                 (atoi(enabled) & CM_ROOT_ACCESS_APPS_ONLY) != CM_ROOT_ACCESS_APPS_ONLY ) {
483             LOGE("Apps root access is disabled by system setting - "
484                  "enable it under settings -> developer options");
485             return 1;
486         }
487
488         /* disallow su in a shell if appropriate */
489         if (from->uid == AID_SHELL &&
490                 (atoi(enabled) & CM_ROOT_ACCESS_ADB_ONLY) != CM_ROOT_ACCESS_ADB_ONLY ) {
491             LOGE("Shell root access is disabled by a system setting - "
492                  "enable it under settings -> developer options");
493             return 1;
494         }
495         
496     }
497     return 0;
498 }
499
500 int main(int argc, char *argv[]) {
501     // Sanitize all secure environment variables (from linker_environ.c in AOSP linker).
502     /* The same list than GLibc at this point */
503     static const char* const unsec_vars[] = {
504         "GCONV_PATH",
505         "GETCONF_DIR",
506         "HOSTALIASES",
507         "LD_AUDIT",
508         "LD_DEBUG",
509         "LD_DEBUG_OUTPUT",
510         "LD_DYNAMIC_WEAK",
511         "LD_LIBRARY_PATH",
512         "LD_ORIGIN_PATH",
513         "LD_PRELOAD",
514         "LD_PROFILE",
515         "LD_SHOW_AUXV",
516         "LD_USE_LOAD_BIAS",
517         "LOCALDOMAIN",
518         "LOCPATH",
519         "MALLOC_TRACE",
520         "MALLOC_CHECK_",
521         "NIS_PATH",
522         "NLSPATH",
523         "RESOLV_HOST_CONF",
524         "RES_OPTIONS",
525         "TMPDIR",
526         "TZDIR",
527         "LD_AOUT_LIBRARY_PATH",
528         "LD_AOUT_PRELOAD",
529         // not listed in linker, used due to system() call
530         "IFS",
531     };
532     const char* const* cp   = unsec_vars;
533     const char* const* endp = cp + sizeof(unsec_vars)/sizeof(unsec_vars[0]);
534     while (cp < endp) {
535         unsetenv(*cp);
536         cp++;
537     }
538
539     /*
540      * set LD_LIBRARY_PATH if the linker has wiped out it due to we're suid.
541      * This occurs on Android 4.0+
542      */
543     setenv("LD_LIBRARY_PATH", "/vendor/lib:/system/lib", 0);
544
545     LOGD("su invoked.");
546
547     struct su_context ctx = {
548         .from = {
549             .pid = -1,
550             .uid = 0,
551             .bin = "",
552             .args = "",
553         },
554         .to = {
555             .uid = AID_ROOT,
556             .login = 0,
557             .keepenv = 0,
558             .shell = DEFAULT_SHELL,
559             .command = NULL,
560             .argv = argv,
561             .argc = argc,
562             .optind = 0,
563         },
564         .user = {
565             .android_user_id = 0,
566             .multiuser_mode = MULTIUSER_MODE_OWNER_ONLY,
567             .database_path = REQUESTOR_DATA_PATH REQUESTOR_DATABASE_PATH,
568         },
569     };
570     struct stat st;
571     int c, socket_serv_fd, fd;
572     char buf[64], *result;
573     allow_t dballow;
574     struct option long_opts[] = {
575         { "command",            required_argument,    NULL, 'c' },
576         { "help",            no_argument,        NULL, 'h' },
577         { "login",            no_argument,        NULL, 'l' },
578         { "preserve-environment",    no_argument,        NULL, 'p' },
579         { "shell",            required_argument,    NULL, 's' },
580         { "version",            no_argument,        NULL, 'v' },
581         { NULL, 0, NULL, 0 },
582     };
583
584     while ((c = getopt_long(argc, argv, "+c:hlmps:Vv", long_opts, NULL)) != -1) {
585         switch(c) {
586         case 'c':
587             ctx.to.command = optarg;
588             break;
589         case 'h':
590             usage(EXIT_SUCCESS);
591             break;
592         case 'l':
593             ctx.to.login = 1;
594             break;
595         case 'm':
596         case 'p':
597             ctx.to.keepenv = 1;
598             break;
599         case 's':
600             ctx.to.shell = optarg;
601             break;
602         case 'V':
603             printf("%d\n", VERSION_CODE);
604             exit(EXIT_SUCCESS);
605         case 'v':
606             printf("%s\n", VERSION);
607             exit(EXIT_SUCCESS);
608         default:
609             /* Bionic getopt_long doesn't terminate its error output by newline */
610             fprintf(stderr, "\n");
611             usage(2);
612         }
613     }
614     if (optind < argc && !strcmp(argv[optind], "-")) {
615         ctx.to.login = 1;
616         optind++;
617     }
618     /* username or uid */
619     if (optind < argc && strcmp(argv[optind], "--")) {
620         struct passwd *pw;
621         pw = getpwnam(argv[optind]);
622         if (!pw) {
623             char *endptr;
624
625             /* It seems we shouldn't do this at all */
626             errno = 0;
627             ctx.to.uid = strtoul(argv[optind], &endptr, 10);
628             if (errno || *endptr) {
629                 LOGE("Unknown id: %s\n", argv[optind]);
630                 fprintf(stderr, "Unknown id: %s\n", argv[optind]);
631                 exit(EXIT_FAILURE);
632             }
633         } else {
634             ctx.to.uid = pw->pw_uid;
635         }
636         optind++;
637     }
638     if (optind < argc && !strcmp(argv[optind], "--")) {
639         optind++;
640     }
641     ctx.to.optind = optind;
642
643     su_ctx = &ctx;
644     if (from_init(&ctx.from) < 0) {
645         deny(&ctx);
646     }
647         
648     read_options(&ctx);
649     user_init(&ctx);
650     
651     if (ctx.user.multiuser_mode == MULTIUSER_MODE_OWNER_ONLY && ctx.user.android_user_id != 0)
652         deny(&ctx);
653
654     if (access_disabled(&ctx.from))
655         deny(&ctx);
656
657     ctx.umask = umask(027);
658
659     if (ctx.from.uid == AID_ROOT || ctx.from.uid == AID_SHELL)
660         allow(&ctx);
661
662     if (stat(ctx.user.database_path, &st) < 0) {
663         PLOGE("stat");
664         deny(&ctx);
665     }
666
667     if (st.st_gid != st.st_uid)
668     {
669         LOGE("Bad uid/gid %d/%d for Superuser Requestor application",
670                 (int)st.st_uid, (int)st.st_gid);
671         deny(&ctx);
672     }
673
674     mkdir(REQUESTOR_CACHE_PATH, 0770);
675     if (chown(REQUESTOR_CACHE_PATH, st.st_uid, st.st_gid)) {
676         PLOGE("chown (%s, %ld, %ld)", REQUESTOR_CACHE_PATH, st.st_uid, st.st_gid);
677         deny(&ctx);
678     }
679
680     if (setgroups(0, NULL)) {
681         PLOGE("setgroups");
682         deny(&ctx);
683     }
684     if (setegid(st.st_gid)) {
685         PLOGE("setegid (%lu)", st.st_gid);
686         deny(&ctx);
687     }
688     if (seteuid(st.st_uid)) {
689         PLOGE("seteuid (%lu)", st.st_uid);
690         deny(&ctx);
691     }
692
693     dballow = database_check(&ctx);
694     switch (dballow) {
695         case INTERACTIVE: break;
696         case ALLOW: allow(&ctx);    /* never returns */
697         case DENY:
698         default: deny(&ctx);        /* never returns too */
699     }
700     
701     socket_serv_fd = socket_create_temp(ctx.sock_path, sizeof(ctx.sock_path));
702     LOGD(ctx.sock_path);
703     if (socket_serv_fd < 0) {
704         deny(&ctx);
705     }
706
707     signal(SIGHUP, cleanup_signal);
708     signal(SIGPIPE, cleanup_signal);
709     signal(SIGTERM, cleanup_signal);
710     signal(SIGQUIT, cleanup_signal);
711     signal(SIGINT, cleanup_signal);
712     signal(SIGABRT, cleanup_signal);
713
714     if (send_request(&ctx) < 0) {
715         deny(&ctx);
716     }
717
718     atexit(cleanup);
719
720     fd = socket_accept(socket_serv_fd);
721     if (fd < 0) {
722         deny(&ctx);
723     }
724     if (socket_send_request(fd, &ctx)) {
725         deny(&ctx);
726     }
727     if (socket_receive_result(fd, buf, sizeof(buf))) {
728         deny(&ctx);
729     }
730
731     close(fd);
732     close(socket_serv_fd);
733     socket_cleanup(&ctx);
734
735     result = buf;
736
737 #define SOCKET_RESPONSE    "socket:"
738     if (strncmp(result, SOCKET_RESPONSE, sizeof(SOCKET_RESPONSE) - 1))
739         LOGW("SECURITY RISK: Requestor still receives credentials in intent");
740     else
741         result += sizeof(SOCKET_RESPONSE) - 1;
742
743     if (!strcmp(result, "DENY")) {
744         deny(&ctx);
745     } else if (!strcmp(result, "ALLOW")) {
746         allow(&ctx);
747     } else {
748         LOGE("unknown response from Superuser Requestor: %s", result);
749         deny(&ctx);
750     }
751 }