external/koush/Superuser
Revision | b27031ea499498d2632583c167a7e6126391756d (tree) |
---|---|
Time | 2013-11-24 08:02:58 |
Author | Kevin Cernekee <cernekee@gmai...> |
Commiter | Kevin Cernekee |
Add workaround for Samsung set*id restrictions (bug #196)
@@ -623,6 +623,28 @@ static int is_api_18() { | ||
623 | 623 | return ver >= 18; |
624 | 624 | } |
625 | 625 | |
626 | +static void fork_for_samsung(void) | |
627 | +{ | |
628 | + // Samsung CONFIG_SEC_RESTRICT_SETUID wants the parent process to have | |
629 | + // EUID 0, or else our setresuid() calls will be denied. So make sure | |
630 | + // all such syscalls are executed by a child process. | |
631 | + int rv; | |
632 | + | |
633 | + switch (fork()) { | |
634 | + case 0: | |
635 | + return; | |
636 | + case -1: | |
637 | + PLOGE("fork"); | |
638 | + exit(1); | |
639 | + default: | |
640 | + if (wait(&rv) < 0) { | |
641 | + exit(1); | |
642 | + } else { | |
643 | + exit(WEXITSTATUS(rv)); | |
644 | + } | |
645 | + } | |
646 | +} | |
647 | + | |
626 | 648 | int main(int argc, char *argv[]) { |
627 | 649 | // start up in daemon mode if prompted |
628 | 650 | if (argc == 2 && strcmp(argv[1], "--daemon") == 0) { |
@@ -641,6 +663,8 @@ int main(int argc, char *argv[]) { | ||
641 | 663 | |
642 | 664 | LOGD("skipping daemon client %d %d", getuid(), geteuid()); |
643 | 665 | |
666 | + fork_for_samsung(); | |
667 | + | |
644 | 668 | // Sanitize all secure environment variables (from linker_environ.c in AOSP linker). |
645 | 669 | /* The same list than GLibc at this point */ |
646 | 670 | static const char* const unsec_vars[] = { |