summaryrefslogtreecommitdiff
path: root/openvpn
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-05-09 02:06:17 +0200
committerArne Schwabe <arne@rfc2549.org>2012-05-09 02:06:17 +0200
commitb2b46c1867bd7282c91f43e80e0763f86ec791d4 (patch)
tree8612dfd7101b3fe8b527367090e4818184b6bb2d /openvpn
parent271a9073948f1a47786ae40f5af6e58e7992a767 (diff)
Openvpn as external external program is coming nearer ....
Diffstat (limited to 'openvpn')
-rw-r--r--openvpn/Android.mk8
-rw-r--r--openvpn/src/openvpn/error.c5
-rw-r--r--openvpn/src/openvpn/jniglue.c130
-rw-r--r--openvpn/src/openvpn/jniglue.h3
-rw-r--r--openvpn/src/openvpn/manage.c10
5 files changed, 15 insertions, 141 deletions
diff --git a/openvpn/Android.mk b/openvpn/Android.mk
index 13f23a78..78849702 100644
--- a/openvpn/Android.mk
+++ b/openvpn/Android.mk
@@ -8,8 +8,9 @@ LOCAL_C_INCLUDES := openssl/include lzo/include openssl/crypto openssl openvpn/s
-LOCAL_SHARED_LIBRARIES := libssl libcrypto liblzo
-#LOCAL_STATIC_LIBRARIES := libssl libcrypto liblzo
+#LOCAL_SHARED_LIBRARIES := libssl libcrypto liblzo
+LOCAL_STATIC_LIBRARIES := libssl_static libcrypto_static liblzo-static
+
LOCAL_CFLAGS= -DHAVE_CONFIG_H
LOCAL_MODULE = openvpn
@@ -87,4 +88,5 @@ LOCAL_SRC_FILES:= src/openvpn/jniglue.c \
src/openvpn/status.c \
src/openvpn/tun.c
-include $(BUILD_SHARED_LIBRARY)
+#include $(BUILD_SHARED_LIBRARY)
+include $(BUILD_EXECUTABLE)
diff --git a/openvpn/src/openvpn/error.c b/openvpn/src/openvpn/error.c
index 68497941..83a9eb4b 100644
--- a/openvpn/src/openvpn/error.c
+++ b/openvpn/src/openvpn/error.c
@@ -714,10 +714,7 @@ openvpn_exit (const int status)
if (status == OPENVPN_EXIT_STATUS_GOOD)
perf_output_results ();
}
-#ifdef TARGET_ANDROID
- android_openvpn_exit(status);
-#endif
-
+
exit (status);
}
diff --git a/openvpn/src/openvpn/jniglue.c b/openvpn/src/openvpn/jniglue.c
index e11cabd4..c79272d7 100644
--- a/openvpn/src/openvpn/jniglue.c
+++ b/openvpn/src/openvpn/jniglue.c
@@ -5,144 +5,14 @@
#include "jniglue.h"
-JNIEXPORT jint Java_de_blinkt_OpenVPN_startOpenVPNThread(JNIEnv* env, jclass jc);
-
-
-extern int main (int argc, char *argv[]);
-
-static jmp_buf jump_buffer;
-
-int callmain (int argc, char *argv[]) {
- if(!setjmp(jump_buffer))
- main(argc,argv);
-}
-
-
-void android_openvpn_exit(int status) {
- longjmp(jump_buffer,status+1);
-}
-
-
-// Store env and class, we allow only one instance
-// so make these variables global for now
-jclass openvpnclass;
-JNIEnv* openvpnjenv;
-
-//Lde/blinkt/openvpn/OpenVPN startOpenVPNThread startOpenVPNThread
- jint Java_de_blinkt_openvpn_OpenVPN_startOpenVPNThread(JNIEnv* env, jclass jc){
- char* argv[] = {"openvpn", "--client",
- "--dev","tun",
- "--comp-lzo",
-// "--redirect-gateway","def1",
-// "--pkcs12","/mnt/sdcard/Network_Certificate.p12",
- "--remote-cert-eku", "TLS Web Server Authentication",
- "--remote","openvpn.uni-paderborn.de",
- "--ca","/mnt/sdcard/ca.pem",
- "--key","/mnt/sdcard/schwabe.key",
- "--cert","/mnt/sdcard/schwabe.pem",
- "--verb","4"
- };
-
- openvpnclass = jc;
- openvpnjenv= env;
- int argc=17;
-
- return callmain(argc,argv);
- }
-
-void Java_de_blinkt_openvpn_OpenVPN_startOpenVPNThreadArgs(JNIEnv *env,jclass jc, jobjectArray stringArray) {
- openvpnclass = jc;
- openvpnjenv= env;
-
- int stringCount = (*env)->GetArrayLength(env, stringArray);
-
-
- const char** argv = calloc(stringCount,sizeof(const char*));
-
- int i;
- for (i=0; i<stringCount; i++) {
- jstring string = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i);
- jboolean isCopy;
- const char* rawString = (*env)->GetStringUTFChars(env, string, &isCopy);
-
- // Copy the string to able to release it
- argv[i] = rawString;
-
- }
-
- // Call main
- callmain(stringCount,argv);
-
- // Release the Strings
- for(i=0; i<stringCount;i++){
- jstring string = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i);
- (*env)->ReleaseStringUTFChars(env,string,argv[i]);
- }
- free(argv);
-}
-
-
-
-
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
__android_log_write(ANDROID_LOG_DEBUG,"openvpn", "Loading openvpn native library $id$ compiled on " __DATE__ " " __TIME__ );
return JNI_VERSION_1_2;
}
-void addInterfaceInformation(int mtu,const char* ifconfig_local, const char* ifconfig_remote)
-{
- jstring jlocal = (*openvpnjenv)->NewStringUTF(openvpnjenv, ifconfig_local);
- jstring jremote = (*openvpnjenv)->NewStringUTF(openvpnjenv, ifconfig_remote);
-
- jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "addInterfaceInfo",
- "(ILjava/lang/String;Ljava/lang/String;)V");
- (*openvpnjenv)->CallStaticVoidMethod(openvpnjenv,openvpnclass,aMethodID,mtu,jlocal,jremote);
-
- (*openvpnjenv)->DeleteLocalRef(openvpnjenv,jlocal);
- (*openvpnjenv)->DeleteLocalRef(openvpnjenv,jremote);
-
-
-}
void android_openvpn_log(int level,const char* prefix,const char* prefix_sep,const char* m1)
{
__android_log_print(ANDROID_LOG_DEBUG,"openvpn","%s%s%s",prefix,prefix_sep,m1);
-
- jstring jprefix = (*openvpnjenv)->NewStringUTF(openvpnjenv, prefix);
- jstring jmessage = (*openvpnjenv)->NewStringUTF(openvpnjenv, m1);
-
- jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "logMessage",
- "(ILjava/lang/String;Ljava/lang/String;)V");
-
- (*openvpnjenv)->CallStaticVoidMethod(openvpnjenv,openvpnclass,aMethodID,level,jprefix,jmessage);
-
- (*openvpnjenv)->DeleteLocalRef(openvpnjenv,jprefix);
- (*openvpnjenv)->DeleteLocalRef(openvpnjenv,jmessage);
-
-}
-
-int android_open_tun () {
- jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "openTunDevice",
- "()I");
- return (*openvpnjenv)->CallStaticIntMethod(openvpnjenv,openvpnclass,aMethodID);
-
-}
-
-
-void addRouteInformation(const char* dest, const char* mask, const char* gw) {
-
- jstring jmask = (*openvpnjenv)->NewStringUTF(openvpnjenv, mask);
- jstring jdest = (*openvpnjenv)->NewStringUTF(openvpnjenv, dest);
- jstring jgw = (*openvpnjenv)->NewStringUTF(openvpnjenv, gw);
- jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "addRoute",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
- (*openvpnjenv)->CallStaticVoidMethod(openvpnjenv,openvpnclass,aMethodID,jdest,jmask,jgw);
-
- (*openvpnjenv)->DeleteLocalRef(openvpnjenv,jmask);
- (*openvpnjenv)->DeleteLocalRef(openvpnjenv,jdest);
- (*openvpnjenv)->DeleteLocalRef(openvpnjenv,jgw);
-
-
}
-
diff --git a/openvpn/src/openvpn/jniglue.h b/openvpn/src/openvpn/jniglue.h
index 236c0323..a86d52da 100644
--- a/openvpn/src/openvpn/jniglue.h
+++ b/openvpn/src/openvpn/jniglue.h
@@ -8,8 +8,5 @@
#ifndef xcopenvpn_jniglue_h
#define xcopenvpn_jniglue_h
-
-void addInterfaceInformation(int mtu,const char* ifconfig_local, const char* ifconfig_remote);
void android_openvpn_log(int level,const char* prefix,const char* prefix_sep,const char* m1);
-void android_openvpn_exit(int status);
#endif
diff --git a/openvpn/src/openvpn/manage.c b/openvpn/src/openvpn/manage.c
index 96ca6eaa..f7ca8e15 100644
--- a/openvpn/src/openvpn/manage.c
+++ b/openvpn/src/openvpn/manage.c
@@ -58,6 +58,9 @@
#define MANAGEMENT_ECHO_FLAGS 0
#endif
+#include <android/log.h>
+
+
/* tag for blank username/password */
static const char blank_up[] = "[[BLANK]]";
@@ -1808,6 +1811,7 @@ man_io_error (struct management *man, const char *prefix)
return false;
}
+
static int
man_read (struct management *man)
{
@@ -1820,8 +1824,12 @@ man_read (struct management *man)
#ifdef TARGET_ANDROID
len = read_fd (man->connection.sd_cli, buf, sizeof (buf), MSG_NOSIGNAL, &fd);
- if(fd >= 0)
+ __android_log_print(ANDROID_LOG_DEBUG,"openvpn-dbg","read_fd %d %d", len, fd);
+ if(fd >= 0) {
man->connection.lastfdreceived = fd;
+ if(len == 0) // No data message but a fd, return without resetting socket...
+ return 0;
+ }
#else
len = recv (man->connection.sd_cli, buf, sizeof (buf), MSG_NOSIGNAL);
#endif