Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2a1f314 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick
Browse files

Let SocketClient users write binary data to clients.

This is a dependency for the DNS proxy CLs.

This CL also adds a new socket for the netd process to inherit which
is owned by the inet group.  (so only apps with the INTERNET
permission can use the DNS proxy...)

Change-Id: I8a51924e0ed56c6066f77e6f1b02d39bdadac51e
parent f1c2a735
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -28,8 +28,12 @@ public:
    uid_t getUid() const { return mUid; }
    uid_t getUid() const { return mUid; }
    gid_t getGid() const { return mGid; }
    gid_t getGid() const { return mGid; }


    // Send null-terminated C strings:
    int sendMsg(int code, const char *msg, bool addErrno);
    int sendMsg(int code, const char *msg, bool addErrno);
    int sendMsg(const char *msg);
    int sendMsg(const char *msg);

    // Sending binary data:
    int sendData(const void *data, int len);
};
};


typedef android::List<SocketClient *> SocketClientCollection;
typedef android::List<SocketClient *> SocketClientCollection;
+13 −5
Original line number Original line Diff line number Diff line
@@ -50,14 +50,22 @@ int SocketClient::sendMsg(const char *msg) {
    }
    }


    // Send the message including null character
    // Send the message including null character
    if (sendData(msg, strlen(msg) + 1) != 0) {
        SLOGW("Unable to send msg '%s'", msg);
        return -1;
    }
    return 0;
}

int SocketClient::sendData(const void* data, int len) {
    int rc = 0;
    int rc = 0;
    const char *p = msg;
    const char *p = (const char*) data;
    int brtw = strlen(msg) + 1;
    int brtw = len;


    pthread_mutex_lock(&mWriteMutex);
    pthread_mutex_lock(&mWriteMutex);
    while(brtw) {
    while (brtw > 0) {
        if ((rc = write(mSocket, p, brtw)) < 0) {
        if ((rc = write(mSocket, p, brtw)) < 0) {
            SLOGW("Unable to send msg '%s' (%s)", msg, strerror(errno));
            SLOGW("write error (%s)", strerror(errno));
            pthread_mutex_unlock(&mWriteMutex);
            pthread_mutex_unlock(&mWriteMutex);
            return -1;
            return -1;
        } else if (!rc) {
        } else if (!rc) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -320,6 +320,7 @@ service vold /system/bin/vold


service netd /system/bin/netd
service netd /system/bin/netd
    socket netd stream 0660 root system
    socket netd stream 0660 root system
    socket dnsproxyd stream 0660 root inet


service debuggerd /system/bin/debuggerd
service debuggerd /system/bin/debuggerd