[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] re-enabled root permission request and shell



commit ef57341c6ee39784eb4faba107442875a80c7e33
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Sat Oct 29 11:33:26 2016 -0400

    re-enabled root permission request and shell
---
 .../org/torproject/android/service/TorService.java | 32 +++++++++-------
 .../android/service/transproxy/TorTransProxy.java  | 43 +++++++++++++++++-----
 2 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
index d1ae1fd..87d814d 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -805,21 +805,25 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
     }
 
     private boolean flushTransparentProxyRules () {
-        if (Prefs.useRoot())
-        {
-             if (mTransProxy == null)
-                 mTransProxy = new TorTransProxy(this, fileXtables);
-
-             try {
-                 mTransProxy.flushTransproxyRules(this);
-             } catch (Exception e) {
-                 e.printStackTrace();
-                 return false;
-             }
-         
-             return true;
+
+        try {
+            if (Prefs.useRoot()) {
+                if (mTransProxy == null)
+                    mTransProxy = new TorTransProxy(this, fileXtables);
+
+                try {
+                    mTransProxy.flushTransproxyRules(this);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    return false;
+                }
+
+                return true;
+            } else {
+                return false;
+            }
         }
-        else
+        catch (IOException ioe)
         {
             return false;
         }
diff --git a/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorTransProxy.java b/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorTransProxy.java
index 2aeb58d..037868a 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorTransProxy.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorTransProxy.java
@@ -1,6 +1,8 @@
 package org.torproject.android.service.transproxy;
 
+import java.io.DataOutputStream;
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -29,12 +31,27 @@ public class TorTransProxy implements TorServiceConstants {
 
 	private int mTransProxyPort = TOR_TRANSPROXY_PORT_DEFAULT;
 	private int mDNSPort = TOR_DNS_PORT_DEFAULT;
-	
-	public TorTransProxy (TorService torService, File fileXTables)
+
+	private Process mProcess = null;
+
+    private DataOutputStream mProcessOutput = null;
+
+
+    public TorTransProxy (TorService torService, File fileXTables) throws IOException
 	{
 		mTorService = torService;
-		mFileXtables = fileXTables;	
+		mFileXtables = fileXTables;
+
+		mProcess = Runtime.getRuntime().exec("su");
+        mProcessOutput = new DataOutputStream(mProcess.getOutputStream());
+
 	}
+
+    public static boolean testRoot () throws IOException
+    {
+        Runtime.getRuntime().exec("su");
+        return true;
+    }
 	
 	public void setTransProxyPort (int transProxyPort)
 	{
@@ -545,16 +562,22 @@ public class TorTransProxy implements TorServiceConstants {
 	
 	private int executeCommand (String cmdString) throws Exception {
 
-		Process proc = Runtime.getRuntime().exec(cmdString);
-		proc.waitFor();
-		int exitCode = proc.exitValue();
-		//String output = cmd.getOutput();
+        mProcessOutput.writeBytes(cmdString + "\n");
+        mProcessOutput.flush();
 
+		logMessage(cmdString);
 		
-		logMessage(cmdString + "; exit=" + exitCode);
-		
-		return exitCode;
+		return 0;
 	}
+
+    public int doExit () throws Exception
+    {
+        mProcessOutput.writeBytes("exit\n");
+        mProcessOutput.flush();
+
+        return mProcess.waitFor();
+
+    }
 	
 	
 	public int enableTetheringRules (Context context) throws Exception



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits