android: Properly handle failures while initializing charon
This commit is contained in:
@@ -589,7 +589,7 @@ static void segv_handler(int signal)
|
|||||||
/**
|
/**
|
||||||
* Initialize charon and the libraries via JNI
|
* Initialize charon and the libraries via JNI
|
||||||
*/
|
*/
|
||||||
JNI_METHOD(CharonVpnService, initializeCharon, void,
|
JNI_METHOD(CharonVpnService, initializeCharon, jboolean,
|
||||||
jobject builder, jstring jlogfile, jboolean byod)
|
jobject builder, jstring jlogfile, jboolean byod)
|
||||||
{
|
{
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
@@ -603,7 +603,7 @@ JNI_METHOD(CharonVpnService, initializeCharon, void,
|
|||||||
if (!library_init(NULL))
|
if (!library_init(NULL))
|
||||||
{
|
{
|
||||||
library_deinit();
|
library_deinit();
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set options before initializing other libraries that might read them */
|
/* set options before initializing other libraries that might read them */
|
||||||
@@ -615,7 +615,7 @@ JNI_METHOD(CharonVpnService, initializeCharon, void,
|
|||||||
{
|
{
|
||||||
libhydra_deinit();
|
libhydra_deinit();
|
||||||
library_deinit();
|
library_deinit();
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!libipsec_init())
|
if (!libipsec_init())
|
||||||
@@ -623,7 +623,7 @@ JNI_METHOD(CharonVpnService, initializeCharon, void,
|
|||||||
libipsec_deinit();
|
libipsec_deinit();
|
||||||
libhydra_deinit();
|
libhydra_deinit();
|
||||||
library_deinit();
|
library_deinit();
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!libcharon_init("charon"))
|
if (!libcharon_init("charon"))
|
||||||
@@ -632,7 +632,7 @@ JNI_METHOD(CharonVpnService, initializeCharon, void,
|
|||||||
libipsec_deinit();
|
libipsec_deinit();
|
||||||
libhydra_deinit();
|
libhydra_deinit();
|
||||||
library_deinit();
|
library_deinit();
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
charon->load_loggers(charon, NULL, FALSE);
|
charon->load_loggers(charon, NULL, FALSE);
|
||||||
@@ -664,7 +664,7 @@ JNI_METHOD(CharonVpnService, initializeCharon, void,
|
|||||||
libipsec_deinit();
|
libipsec_deinit();
|
||||||
libhydra_deinit();
|
libhydra_deinit();
|
||||||
library_deinit();
|
library_deinit();
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
lib->plugins->status(lib->plugins, LEVEL_CTRL);
|
lib->plugins->status(lib->plugins, LEVEL_CTRL);
|
||||||
|
|
||||||
@@ -680,6 +680,7 @@ JNI_METHOD(CharonVpnService, initializeCharon, void,
|
|||||||
|
|
||||||
/* start daemon (i.e. the threads in the thread-pool) */
|
/* start daemon (i.e. the threads in the thread-pool) */
|
||||||
charon->start(charon);
|
charon->start(charon);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -214,12 +214,20 @@ public class CharonVpnService extends VpnService implements Runnable
|
|||||||
mIsDisconnecting = false;
|
mIsDisconnecting = false;
|
||||||
|
|
||||||
BuilderAdapter builder = new BuilderAdapter(mCurrentProfile.getName());
|
BuilderAdapter builder = new BuilderAdapter(mCurrentProfile.getName());
|
||||||
initializeCharon(builder, mLogFile, mCurrentProfile.getVpnType().getEnableBYOD());
|
if (initializeCharon(builder, mLogFile, mCurrentProfile.getVpnType().getEnableBYOD()))
|
||||||
Log.i(TAG, "charon started");
|
{
|
||||||
|
Log.i(TAG, "charon started");
|
||||||
initiate(mCurrentProfile.getVpnType().getIdentifier(),
|
initiate(mCurrentProfile.getVpnType().getIdentifier(),
|
||||||
mCurrentProfile.getGateway(), mCurrentProfile.getUsername(),
|
mCurrentProfile.getGateway(), mCurrentProfile.getUsername(),
|
||||||
mCurrentProfile.getPassword());
|
mCurrentProfile.getPassword());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.e(TAG, "failed to start charon");
|
||||||
|
setError(ErrorState.GENERIC_ERROR);
|
||||||
|
setState(State.DISABLED);
|
||||||
|
mCurrentProfile = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException ex)
|
catch (InterruptedException ex)
|
||||||
@@ -517,8 +525,9 @@ public class CharonVpnService extends VpnService implements Runnable
|
|||||||
* @param builder BuilderAdapter for this connection
|
* @param builder BuilderAdapter for this connection
|
||||||
* @param logfile absolute path to the logfile
|
* @param logfile absolute path to the logfile
|
||||||
* @param boyd enable BYOD features
|
* @param boyd enable BYOD features
|
||||||
|
* @return TRUE if initialization was successful
|
||||||
*/
|
*/
|
||||||
public native void initializeCharon(BuilderAdapter builder, String logfile, boolean byod);
|
public native boolean initializeCharon(BuilderAdapter builder, String logfile, boolean byod);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deinitialize charon, provided by libandroidbridge.so
|
* Deinitialize charon, provided by libandroidbridge.so
|
||||||
|
|||||||
Reference in New Issue
Block a user