diff options
author | Arne Schwabe <arne@rfc2549.org> | 2012-05-09 02:06:17 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2012-05-09 02:06:17 +0200 |
commit | b2b46c1867bd7282c91f43e80e0763f86ec791d4 (patch) | |
tree | 8612dfd7101b3fe8b527367090e4818184b6bb2d /openvpn/src | |
parent | 271a9073948f1a47786ae40f5af6e58e7992a767 (diff) |
Openvpn as external external program is coming nearer ....
Diffstat (limited to 'openvpn/src')
-rw-r--r-- | openvpn/src/openvpn/error.c | 5 | ||||
-rw-r--r-- | openvpn/src/openvpn/jniglue.c | 130 | ||||
-rw-r--r-- | openvpn/src/openvpn/jniglue.h | 3 | ||||
-rw-r--r-- | openvpn/src/openvpn/manage.c | 10 |
4 files changed, 10 insertions, 138 deletions
diff --git a/openvpn/src/openvpn/error.c b/openvpn/src/openvpn/error.c index 6849794..83a9eb4 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 e11cabd..c79272d 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 236c032..a86d52d 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 96ca6ea..f7ca8e1 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 |