mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Changed: Allow connections from root o sockets.
This commit is contained in:
committed by
agnostic-apollo
parent
33b88b5d4b
commit
3dee2eb486
@@ -188,6 +188,7 @@ extern "C"
|
|||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_com_termux_shared_shell_LocalFilesystemSocket_getpeeruid(JNIEnv *env, jclass clazz, jint fd) {
|
Java_com_termux_shared_shell_LocalFilesystemSocket_getpeeruid(JNIEnv *env, jclass clazz, jint fd) {
|
||||||
struct ucred cred = {};
|
struct ucred cred = {};
|
||||||
|
cred.uid = 1; // initialize uid to 1 here because I'm paranoid and a failed getsockopt that somehow doesn't report as failed would report the uid of root
|
||||||
socklen_t len = sizeof(cred);
|
socklen_t len = sizeof(cred);
|
||||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) {
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@@ -209,16 +209,20 @@ public class LocalFilesystemSocket
|
|||||||
if (backlog <= 0) {
|
if (backlog <= 0) {
|
||||||
throw new IllegalArgumentException("Backlog has to be at least 1");
|
throw new IllegalArgumentException("Backlog has to be at least 1");
|
||||||
}
|
}
|
||||||
if (path == null) {
|
if (path == null || path.length() == 0) {
|
||||||
throw new IllegalArgumentException("path cannot be null");
|
throw new IllegalArgumentException("path cannot be null or empty");
|
||||||
}
|
}
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
if (path.getBytes(StandardCharsets.UTF_8)[0] != 0) {
|
||||||
|
// not a socket in the abstract linux namespace, make sure the path is accessible and clear
|
||||||
File f = new File(path);
|
File f = new File(path);
|
||||||
File parent = f.getParentFile();
|
File parent = f.getParentFile();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parent.mkdirs();
|
parent.mkdirs();
|
||||||
}
|
}
|
||||||
f.delete();
|
f.delete();
|
||||||
|
}
|
||||||
|
|
||||||
fd = createserversocket(path.getBytes(StandardCharsets.UTF_8), backlog);
|
fd = createserversocket(path.getBytes(StandardCharsets.UTF_8), backlog);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
throw new IOException("Could not create UNIX server socket at \""+path+"\"");
|
throw new IOException("Could not create UNIX server socket at \""+path+"\"");
|
||||||
@@ -246,8 +250,8 @@ public class LocalFilesystemSocket
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peeruid == app.getApplicationInfo().uid) {
|
// if the peer has the same uid or is root, allow the connection
|
||||||
// if the peer has the same uid, allow the connection
|
if (peeruid == app.getApplicationInfo().uid || peeruid == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
Logger.logWarn("LocalFilesystemSocket.ServerSocket", "WARNING: An app with the uid of "+peeruid+" tried to connect to the socket at \""+path+"\", closing connection.");
|
Logger.logWarn("LocalFilesystemSocket.ServerSocket", "WARNING: An app with the uid of "+peeruid+" tried to connect to the socket at \""+path+"\", closing connection.");
|
||||||
|
@@ -77,7 +77,6 @@ public class LocalSocketListener
|
|||||||
while ((c = r.read()) > 0) {
|
while ((c = r.read()) > 0) {
|
||||||
b.append((char) c);
|
b.append((char) c);
|
||||||
}
|
}
|
||||||
Logger.logDebug(LOG_TAG, b.toString());
|
|
||||||
String outString;
|
String outString;
|
||||||
String errString;
|
String errString;
|
||||||
int ret;
|
int ret;
|
||||||
|
Reference in New Issue
Block a user