From 396bf2109a5ca4f3128c208bf83adda2a42ec46b Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 25 Oct 2018 13:24:08 -0700 Subject: [PATCH] libcutils: lose socket_peer_is_trusted to ART, the only user. Bug: N/A Test: builds Change-Id: I599270729c2037b2c06d7906a5e5f7362fbbaf08 --- libcutils/include/cutils/sockets.h | 16 +--------------- libcutils/sockets_unix.cpp | 28 ---------------------------- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/libcutils/include/cutils/sockets.h b/libcutils/include/cutils/sockets.h index b24468bf4..285f15083 100644 --- a/libcutils/include/cutils/sockets.h +++ b/libcutils/include/cutils/sockets.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef __CUTILS_SOCKETS_H -#define __CUTILS_SOCKETS_H +#pragma once #include #include @@ -141,19 +140,6 @@ ssize_t socket_send_buffers(cutils_socket_t sock, const cutils_socket_buffer_t* buffers, size_t num_buffers); -/* - * socket_peer_is_trusted - Takes a socket which is presumed to be a - * connected local socket (e.g. AF_LOCAL) and returns whether the peer - * (the userid that owns the process on the other end of that socket) - * is one of the two trusted userids, root or shell. - * - * Note: This only works as advertised on the Android OS and always - * just returns true when called on other operating systems. - */ -extern bool socket_peer_is_trusted(int fd); - #ifdef __cplusplus } #endif - -#endif /* __CUTILS_SOCKETS_H */ diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp index 0cb8a4dc5..22488178f 100644 --- a/libcutils/sockets_unix.cpp +++ b/libcutils/sockets_unix.cpp @@ -32,34 +32,6 @@ #include "android_get_control_env.h" -#if defined(__ANDROID__) -/* For the socket trust (credentials) check */ -#include -#define __android_unused -#else -#define __android_unused __attribute__((__unused__)) -#endif - -bool socket_peer_is_trusted(int fd __android_unused) { -#if defined(__ANDROID__) - ucred cr; - socklen_t len = sizeof(cr); - int n = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len); - - if (n != 0) { - ALOGE("could not get socket credentials: %s\n", strerror(errno)); - return false; - } - - if ((cr.uid != AID_ROOT) && (cr.uid != AID_SHELL)) { - ALOGE("untrusted userid on other end of socket: userid %d\n", cr.uid); - return false; - } -#endif - - return true; -} - int socket_close(int sock) { return close(sock); }