[tor-commits] [orbot/master] small changes to naming of iptables methods

n8fr8 at torproject.org n8fr8 at torproject.org
Thu Jan 12 20:49:44 UTC 2012


commit 2b1969fea075de5a3441c5394d1b6d0b61a60be3
Author: Nathan Freitas <nathan at freitas.net>
Date:   Mon Jan 9 00:23:54 2012 -0500

    small changes to naming of iptables methods
---
 .../android/service/TorBinaryInstaller.java        |   18 ++++++++++++++++--
 src/org/torproject/android/service/TorService.java |    8 ++++----
 .../android/service/TorServiceUtils.java           |    4 ++--
 .../torproject/android/service/TorTransProxy.java  |    9 ++++-----
 4 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/org/torproject/android/service/TorBinaryInstaller.java b/src/org/torproject/android/service/TorBinaryInstaller.java
index a3b1995..ff1e720 100644
--- a/src/org/torproject/android/service/TorBinaryInstaller.java
+++ b/src/org/torproject/android/service/TorBinaryInstaller.java
@@ -10,6 +10,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -65,7 +66,20 @@ public class TorBinaryInstaller implements TorServiceConstants {
 		return true;
 	}
 	
-
+	private static void copyAssetFile(Context ctx, String asset, File file) throws IOException, InterruptedException
+	{
+    	
+		DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
+		InputStream is = new GZIPInputStream(ctx.getAssets().open(asset));
+		
+		byte buf[] = new byte[8172];
+		int len;
+		while ((len = is.read(buf)) > 0) {
+			out.write(buf, 0, len);
+		}
+		out.close();
+		is.close();
+	}
 	/*
 	 * Write the inputstream contents to the file
 	 */
@@ -97,7 +111,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
         }
 
         stmOut.close();
-
+        stm.close();
         
         return true;
 
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 25d415b..df2990d 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -275,7 +275,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
     		showToolbarNotification (getString(R.string.status_disabled),NOTIFY_ID,R.drawable.tornotificationoff);
     		sendCallbackStatusMessage(getString(R.string.status_disabled));
 
-    		clearTransparentProxy();
+    		disableTransparentProxy();
     	}
     	catch (Exception e)
     	{
@@ -597,7 +597,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
      * 
      * the idea is that if Tor is off then transproxy is off
      */
-    private boolean clearTransparentProxy () throws Exception
+    private boolean disableTransparentProxy () throws Exception
  	{
     	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
     	
@@ -609,7 +609,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	 		
 	     	TorService.logMessage ("Clearing TransProxy rules");
 	     	
-	     	TorTransProxy.purgeIptables(this);
+	     	TorTransProxy.flushIptables(this);
 	     	
 			showAlert(getString(R.string.status), getString(R.string.transproxy_rules_cleared));
 	     	
@@ -1095,7 +1095,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		        
 					try
 					{
-						clearTransparentProxy();
+						disableTransparentProxy();
 			    		enableTransparentProxy();
 					}
 					catch (Exception e)
diff --git a/src/org/torproject/android/service/TorServiceUtils.java b/src/org/torproject/android/service/TorServiceUtils.java
index 51d6378..fa27c58 100644
--- a/src/org/torproject/android/service/TorServiceUtils.java
+++ b/src/org/torproject/android/service/TorServiceUtils.java
@@ -24,13 +24,13 @@ public class TorServiceUtils implements TorServiceConstants {
 		try {
 			
 			// Check if Superuser.apk exists
-			File file = new File("/system/app/Superuser.apk");
+			//File file = new File("/system/app/Superuser.apk");
 			
 			//Check for 'su' binary 
 			String[] cmd = {"which su"};
 			int exitCode = TorServiceUtils.doShellCommand(cmd, log, false, true);
 			
-			if (file.exists() && exitCode == 0) {
+			if (exitCode == 0) {
 				TorService.logMessage("Can acquire root permissions");
 		    	 return true;
 		     
diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java
index 73dac7c..bf5fee2 100644
--- a/src/org/torproject/android/service/TorTransProxy.java
+++ b/src/org/torproject/android/service/TorTransProxy.java
@@ -13,7 +13,7 @@ public class TorTransProxy implements TorServiceConstants {
 	private final static String TAG = TorConstants.TAG;
 		
 	
-	public static int purgeIptables(Context context) throws Exception {
+	public static int flushIptables(Context context) throws Exception {
 		
 	String ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
 		
@@ -21,7 +21,6 @@ public class TorTransProxy implements TorServiceConstants {
     	
     	StringBuilder res = new StringBuilder();
     	int code = -1;
-    	
 
 		script.append(ipTablesPath);
 		script.append(" -t nat");
@@ -177,7 +176,7 @@ public class TorTransProxy implements TorServiceConstants {
     	StringBuilder res = new StringBuilder();
     	int code = -1;
     	
-    	purgeIptables(context);
+    	flushIptables(context);
 				
 		//build up array of shell cmds to execute under one root context
 		for (int i = 0; i < apps.length; i++)
@@ -276,7 +275,7 @@ public class TorTransProxy implements TorServiceConstants {
     	
     	StringBuilder res = new StringBuilder();
     	int code = -1;
-    	purgeIptables(context);
+    	flushIptables(context);
 		
 		//TCP
 		//iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumbe
@@ -375,7 +374,7 @@ public class TorTransProxy implements TorServiceConstants {
     	StringBuilder res = new StringBuilder();
     	int code = -1;
     	
-    	purgeIptables(context);
+    	flushIptables(context);
     	
     	int torUid = context.getApplicationInfo().uid;
 





More information about the tor-commits mailing list