aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/c
diff options
context:
space:
mode:
authorpacien2020-01-20 17:07:12 +0100
committerpacien2020-01-20 17:07:12 +0100
commit883b5abc7b2a770146683e7e27bf275bd4064511 (patch)
tree81dd200fc2cea8e2030b5b5b68c39abe3c32ab46 /app/src/main/c
parent3fc8a2ed3bfbcbd29bc22c2c73416e2708cd7615 (diff)
downloadtincapp-883b5abc7b2a770146683e7e27bf275bd4064511.tar.gz
pass network device fd via unix socket instead of inheritance
Workaround for new shared memory restrictions added in Android 10 preventing file descriptor leakage to sub-processes. This change set BREAKS ENCRYPTED PRIVATE KEYS SUPPORT. GitHub: https://github.com/pacien/tincapp/issues/92
Diffstat (limited to 'app/src/main/c')
-rw-r--r--app/src/main/c/exec.c60
-rw-r--r--app/src/main/c/main.c1
2 files changed, 1 insertions, 60 deletions
diff --git a/app/src/main/c/exec.c b/app/src/main/c/exec.c
deleted file mode 100644
index c335b20..0000000
--- a/app/src/main/c/exec.c
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19#include <jni.h>
20#include <unistd.h>
21#include <stdlib.h>
22#include <sys/wait.h>
23
24static inline const char **to_string_array(JNIEnv *env, jobjectArray ja) {
25 const int len = (*env)->GetArrayLength(env, ja);
26 const char **ca = calloc((size_t) len + 1, sizeof(char *));
27
28 for (int i = 0; i < len; ++i) {
29 jstring jstr = (jstring) (*env)->GetObjectArrayElement(env, ja, i);
30 ca[i] = (*env)->GetStringUTFChars(env, jstr, NULL);
31 }
32
33 ca[len] = NULL;
34 return ca;
35}
36
37static inline void exec(const char **argcv) {
38 execv(argcv[0], (char *const *) argcv);
39 exit(1);
40}
41
42JNIEXPORT jint JNICALL
43Java_org_pacien_tincapp_commands_Executor_forkExec(JNIEnv *env, __attribute__((unused)) jclass class, jobjectArray args) {
44 pid_t pid = fork();
45 switch (pid) {
46 case 0:
47 exec(to_string_array(env, args));
48 return 0;
49
50 default:
51 return pid;
52 }
53}
54
55JNIEXPORT jint JNICALL
56Java_org_pacien_tincapp_commands_Executor_wait(__attribute__((unused))JNIEnv *env, __attribute__((unused)) jclass class, jint pid) {
57 int status;
58 waitpid(pid, &status, 0);
59 return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
60}
diff --git a/app/src/main/c/main.c b/app/src/main/c/main.c
new file mode 100644
index 0000000..68007d8
--- /dev/null
+++ b/app/src/main/c/main.c
@@ -0,0 +1 @@
// This file intentionally left blank.