|
| 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 <unistd.h> |
| 19 | + |
| 20 | +#include "su.h" |
| 21 | + |
| 22 | +int send_intent(const struct su_context *ctx, |
| 23 | + const char *socket_path, int allow, const char *action) |
| 24 | +{ |
| 25 | + char command[PATH_MAX]; |
| 26 | + |
| 27 | + sprintf(command, "/system/bin/am broadcast -a %s --es socket %s --ei version_code %d > /dev/null", |
| 28 | + action, socket_path, VERSION_CODE); |
| 29 | + |
| 30 | + // before sending the intent, make sure the (uid and euid) and (gid and egid) match, |
| 31 | + // otherwise LD_LIBRARY_PATH is wiped in Android 4.0+. |
| 32 | + // Also, sanitize all secure environment variables (from linker_environ.c in linker). |
| 33 | + |
| 34 | + /* The same list than GLibc at this point */ |
| 35 | + static const char* const unsec_vars[] = { |
| 36 | + "GCONV_PATH", |
| 37 | + "GETCONF_DIR", |
| 38 | + "HOSTALIASES", |
| 39 | + "LD_AUDIT", |
| 40 | + "LD_DEBUG", |
| 41 | + "LD_DEBUG_OUTPUT", |
| 42 | + "LD_DYNAMIC_WEAK", |
| 43 | + "LD_LIBRARY_PATH", |
| 44 | + "LD_ORIGIN_PATH", |
| 45 | + "LD_PRELOAD", |
| 46 | + "LD_PROFILE", |
| 47 | + "LD_SHOW_AUXV", |
| 48 | + "LD_USE_LOAD_BIAS", |
| 49 | + "LOCALDOMAIN", |
| 50 | + "LOCPATH", |
| 51 | + "MALLOC_TRACE", |
| 52 | + "MALLOC_CHECK_", |
| 53 | + "NIS_PATH", |
| 54 | + "NLSPATH", |
| 55 | + "RESOLV_HOST_CONF", |
| 56 | + "RES_OPTIONS", |
| 57 | + "TMPDIR", |
| 58 | + "TZDIR", |
| 59 | + "LD_AOUT_LIBRARY_PATH", |
| 60 | + "LD_AOUT_PRELOAD", |
| 61 | + // not listed in linker, used due to system() call |
| 62 | + "IFS", |
| 63 | + }; |
| 64 | + const char* const* cp = unsec_vars; |
| 65 | + const char* const* endp = cp + sizeof(unsec_vars)/sizeof(unsec_vars[0]); |
| 66 | + while (cp < endp) { |
| 67 | + unsetenv(*cp); |
| 68 | + cp++; |
| 69 | + } |
| 70 | + |
| 71 | + // sane value so "am" works |
| 72 | + setenv("LD_LIBRARY_PATH", "/vendor/lib:/system/lib", 1); |
| 73 | + setegid(getgid()); |
| 74 | + seteuid(getuid()); |
| 75 | + return system(command); |
| 76 | +} |
0 commit comments