blob: 37d31e873ce275e40f1cbd2bdd1bcc1bd5d2be41 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]689266d2012-08-07 12:52:202// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/public/browser/android/devtools_auth.h"
6
[email protected]fe928be92014-08-08 09:17:417#include <pwd.h>
[email protected]c00187d2014-07-29 12:41:478#include <sys/types.h>
[email protected]fe928be92014-08-08 09:17:419#include <unistd.h>
[email protected]c00187d2014-07-29 12:41:4710
Tom Sepez40add7f2025-03-19 06:32:0211#include "base/compiler_specific.h"
[email protected]689266d2012-08-07 12:52:2012#include "base/logging.h"
13
14namespace content {
15
[email protected]fe928be92014-08-08 09:17:4116bool CanUserConnectToDevTools(
17 const net::UnixDomainServerSocket::Credentials& credentials) {
18 struct passwd* creds = getpwuid(credentials.user_id);
[email protected]689266d2012-08-07 12:52:2019 if (!creds || !creds->pw_name) {
[email protected]fe928be92014-08-08 09:17:4120 LOG(WARNING) << "DevTools: can't obtain creds for uid "
21 << credentials.user_id;
[email protected]689266d2012-08-07 12:52:2022 return false;
23 }
[email protected]fe928be92014-08-08 09:17:4124 if (credentials.group_id == credentials.user_id &&
Tom Sepez40add7f2025-03-19 06:32:0225 (UNSAFE_TODO(strcmp("root", creds->pw_name)) ==
26 0 || // For rooted devices
27 UNSAFE_TODO(strcmp("shell", creds->pw_name)) ==
28 0 || // For non-rooted devices
[email protected]fe928be92014-08-08 09:17:4129
30 // From processes signed with the same key
31 credentials.user_id == getuid())) {
[email protected]689266d2012-08-07 12:52:2032 return true;
33 }
34 LOG(WARNING) << "DevTools: connection attempt from " << creds->pw_name;
35 return false;
36}
37
38} // namespace content