‘Permission denied’ while connecting to abstract unix socket

OS: Android L Server: an native level system server, service through abstract socket. Client: jni in normal 3rd APK Get a 'permission denied' while using APK to connect the socket. I thought abstract socket has no permissions!

And, the same code works when running in a adb shell, rooted shell.

The question is: where is the permisson set?

the code:

char *target_socket_name = "@mobilelogd"; 
int sock_id = 0; 
struct sockaddr_un sun;
int address_len;

sock_id = socket(AF_UNIX, SOCK_STREAM, 0);

if (sock_id < 0) {
    LOG("in %s: Unable to create socket: %s\n", __func__, strerror(errno));
    return -1;
} else {
    LOG("socket created!\n");       
}
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
strncpy(sun.sun_path, target_socket_name, strlen(target_socket_name));
sun.sun_path[0] = 0;
address_len = offsetof(struct sockaddr_un, sun_path) + strlen(target_socket_name);

if (connect(sock_id, (struct sockaddr *)&sun, address_len) == -1) 
{
    LOG("in %s: Connect to socket failed: (%d),%s\n", __func__, errno, strerror(errno));
    close(sock_id);
    return -1;
}

--- EDIT 1 ---: add some initialise code,and change '0' to 0. Same result.

Answers


Okay, here is the scoop it changed on L by a bug introduced..the bug fix is the pipeline:

https://android.googlesource.com/device/moto/shamu/+/b2db40f

Until than do java pipes or native pipes instead


Since Android manipulated the Linux kernel and added Paranoid networking to it, So you should add the following permission to your manifest file.

<uses-permission android:name="android.permission.INTERNET" /> 

Android adds a "paranoid network" option to the Linux kernel, which restricts access to some networking features depending on the group of the calling process.

So, your app's uid (user id; each app is assigned an unique uid once it is installed) must be granted that permission in order to do networking tasks.


Need Your Help

Matlab referencing of part of string in cell array

string matlab cell

I'm looking for a way to reference parts of strings that are stored in a cell array. I need to do so in order to make a logical statement that will match strings I am looking for to the parts of the