diff options
author | Mark Salyzyn <salyzyn@google.com> | 2017-05-05 14:44:35 -0700 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2017-05-08 14:04:13 -0700 |
commit | b066fccc5c977f3e464676d58a7fa550d368f426 (patch) | |
tree | 5371a7e99c4ab965fcdc7c77342631c184083285 /init/util.cpp | |
parent | 823816ee9f3ee7519a282d3a089d23f0e96018ef (diff) | |
download | system_core-b066fccc5c977f3e464676d58a7fa550d368f426.tar.gz system_core-b066fccc5c977f3e464676d58a7fa550d368f426.tar.bz2 system_core-b066fccc5c977f3e464676d58a7fa550d368f426.zip |
init: add "+passcred" for socket to set SO_PASSCRED
In the init scripts for socket, the type can have a suffix of
"+passcred" to request that the socket be bound to report SO_PASSCRED
credentials as part of socket transactions.
Test: gTest logd-unit-tests --gtest_filter=logd.statistics right after boot
(fails without logd.rc change)
Bug: 37985222
Change-Id: Ie5b50e99fb92fa9bec9a32463a0e6df26a968bfd
Diffstat (limited to 'init/util.cpp')
-rw-r--r-- | init/util.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/init/util.cpp b/init/util.cpp index e7f724b8f..5afe28554 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -78,13 +78,13 @@ bool DecodeUid(const std::string& name, uid_t* uid, std::string* err) { } /* - * create_socket - creates a Unix domain socket in ANDROID_SOCKET_DIR + * CreateSocket - creates a Unix domain socket in ANDROID_SOCKET_DIR * ("/dev/socket") as dictated in init.rc. This socket is inherited by the * daemon. We communicate the file descriptor's value via the environment * variable ANDROID_SOCKET_ENV_PREFIX<name> ("ANDROID_SOCKET_foo"). */ -int create_socket(const char* name, int type, mode_t perm, uid_t uid, gid_t gid, - const char* socketcon, selabel_handle* sehandle) { +int CreateSocket(const char* name, int type, bool passcred, mode_t perm, uid_t uid, gid_t gid, + const char* socketcon, selabel_handle* sehandle) { if (socketcon) { if (setsockcreatecon(socketcon) == -1) { PLOG(ERROR) << "setsockcreatecon(\"" << socketcon << "\") failed"; @@ -118,6 +118,14 @@ int create_socket(const char* name, int type, mode_t perm, uid_t uid, gid_t gid, } } + if (passcred) { + int on = 1; + if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on))) { + PLOG(ERROR) << "Failed to set SO_PASSCRED '" << name << "'"; + return -1; + } + } + int ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr)); int savederrno = errno; |