[tor-commits] [orbot/master] use Java methods for setting permissions on native executables
n8fr8 at torproject.org
n8fr8 at torproject.org
Thu Jun 25 14:59:58 UTC 2015
commit 73658ce3cfdee85d0d4d1eacf4881f87648e8d1f
Author: Hans-Christoph Steiner <hans at eds.org>
Date: Mon Jun 8 23:21:21 2015 -0400
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.
---
.../android/service/TorResourceInstaller.java | 15 ++++++--
src/org/torproject/android/service/TorService.java | 40 +-------------------
2 files changed, 14 insertions(+), 41 deletions(-)
diff --git a/src/org/torproject/android/service/TorResourceInstaller.java b/src/org/torproject/android/service/TorResourceInstaller.java
index 3d99225..648f752 100644
--- a/src/org/torproject/android/service/TorResourceInstaller.java
+++ b/src/org/torproject/android/service/TorResourceInstaller.java
@@ -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);
+ }
+
}
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 9baf723..599d8c8 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -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);
-
-
}
}
More information about the tor-commits
mailing list