use Java methods for setting permissions on native executables
As of android-9, java.io.File has native methods for setting permissions, inherited from Java 1.6. Using these will help deal with compatibility across devices, since some devices might not have chmod installed.
This commit is contained in:
parent
a3d37e8b2a
commit
73658ce3cf
|
@ -8,12 +8,10 @@ import java.io.DataOutputStream;
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringBufferInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
@ -96,11 +94,13 @@ public class TorResourceInstaller implements TorServiceConstants {
|
|||
outFile = new File(installFolder, OBFSCLIENT_ASSET_KEY);
|
||||
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
|
||||
streamToFile(is,outFile, false, true);
|
||||
setExecutable(outFile);
|
||||
|
||||
is = context.getResources().openRawResource(R.raw.meek);
|
||||
outFile = new File(installFolder, MEEK_ASSET_KEY);
|
||||
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
|
||||
streamToFile(is,outFile, false, true);
|
||||
setExecutable(outFile);
|
||||
|
||||
cpuPath = "armeabi";
|
||||
}
|
||||
|
@ -111,17 +111,19 @@ public class TorResourceInstaller implements TorServiceConstants {
|
|||
outFile = new File(installFolder, TOR_ASSET_KEY);
|
||||
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
|
||||
streamToFile(is,outFile, false, true);
|
||||
setExecutable(outFile);
|
||||
|
||||
is = context.getAssets().open(cpuPath + "/polipo.mp3");
|
||||
outFile = new File(installFolder, POLIPO_ASSET_KEY);
|
||||
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
|
||||
streamToFile(is,outFile, false, true);
|
||||
setExecutable(outFile);
|
||||
|
||||
is = context.getAssets().open(cpuPath + "/xtables.mp3");
|
||||
outFile = new File(installFolder, IPTABLES_ASSET_KEY);
|
||||
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
|
||||
streamToFile(is,outFile, false, true);
|
||||
|
||||
setExecutable(outFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -359,4 +361,11 @@ public class TorResourceInstaller implements TorServiceConstants {
|
|||
}*/
|
||||
|
||||
|
||||
private void setExecutable(File fileBin) {
|
||||
fileBin.setReadable(true);
|
||||
fileBin.setExecutable(true);
|
||||
fileBin.setWritable(false);
|
||||
fileBin.setWritable(true, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -649,17 +649,12 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
appCacheHome = getDir(DIRECTORY_TOR_DATA,Application.MODE_PRIVATE);
|
||||
|
||||
fileTor= new File(appBinHome, TOR_ASSET_KEY);
|
||||
|
||||
filePolipo = new File(appBinHome, POLIPO_ASSET_KEY);
|
||||
|
||||
fileObfsclient = new File(appBinHome, OBFSCLIENT_ASSET_KEY);
|
||||
|
||||
fileMeekclient = new File(appBinHome, MEEK_ASSET_KEY);
|
||||
|
||||
fileTorRc = new File(appBinHome, TORRC_ASSET_KEY);
|
||||
|
||||
fileXtables = new File(appBinHome, IPTABLES_ASSET_KEY);
|
||||
|
||||
|
||||
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
|
||||
String version = prefs.getString(PREF_BINARY_TOR_VERSION_INSTALLED,null);
|
||||
|
||||
|
@ -678,8 +673,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
}
|
||||
|
||||
updateTorConfigFile ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean updateTorConfigFile () throws FileNotFoundException, IOException, TimeoutException
|
||||
|
@ -737,28 +730,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
|
||||
return success;
|
||||
}
|
||||
|
||||
private boolean enableBinExec (File fileBin) throws Exception
|
||||
{
|
||||
|
||||
logNotice(fileBin.getName() + ": PRE: Is binary exec? " + fileBin.canExecute());
|
||||
|
||||
if (!fileBin.canExecute())
|
||||
{
|
||||
logNotice("(re)Setting permission on binary: " + fileBin.getCanonicalPath());
|
||||
|
||||
Shell shell = Shell.startShell();
|
||||
shell.add(new SimpleCommand("chmod " + CHMOD_EXE_VALUE + ' ' + fileBin.getCanonicalPath())).waitForFinish();
|
||||
|
||||
File fileTest = new File(fileBin.getCanonicalPath());
|
||||
logNotice(fileTest.getName() + ": POST: Is binary exec? " + fileTest.canExecute());
|
||||
|
||||
shell.close();
|
||||
}
|
||||
|
||||
return fileBin.canExecute();
|
||||
}
|
||||
|
||||
|
||||
private void startTor () throws Exception
|
||||
{
|
||||
|
||||
|
@ -767,12 +739,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
|
||||
if (fileTor == null)
|
||||
initBinariesAndDirectories();
|
||||
|
||||
enableBinExec(fileTor);
|
||||
enableBinExec(filePolipo);
|
||||
enableBinExec(fileObfsclient);
|
||||
enableBinExec(fileMeekclient);
|
||||
enableBinExec(fileXtables);
|
||||
|
||||
logNotice(getString(R.string.status_starting_up));
|
||||
sendCallbackLogMessage(getString(R.string.status_starting_up));
|
||||
|
@ -1361,8 +1327,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
|
||||
mCurrentStatus = STATUS_OFF;
|
||||
sendCallbackStatus(mCurrentStatus);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue