Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 689266d | 2012-08-07 12:52:20 | [diff] [blame] | 2 | // 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] | fe928be9 | 2014-08-08 09:17:41 | [diff] [blame] | 7 | #include <pwd.h> |
[email protected] | c00187d | 2014-07-29 12:41:47 | [diff] [blame] | 8 | #include <sys/types.h> |
[email protected] | fe928be9 | 2014-08-08 09:17:41 | [diff] [blame] | 9 | #include <unistd.h> |
[email protected] | c00187d | 2014-07-29 12:41:47 | [diff] [blame] | 10 | |
Tom Sepez | 40add7f | 2025-03-19 06:32:02 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | 689266d | 2012-08-07 12:52:20 | [diff] [blame] | 12 | #include "base/logging.h" |
13 | |||||
14 | namespace content { | ||||
15 | |||||
[email protected] | fe928be9 | 2014-08-08 09:17:41 | [diff] [blame] | 16 | bool CanUserConnectToDevTools( |
17 | const net::UnixDomainServerSocket::Credentials& credentials) { | ||||
18 | struct passwd* creds = getpwuid(credentials.user_id); | ||||
[email protected] | 689266d | 2012-08-07 12:52:20 | [diff] [blame] | 19 | if (!creds || !creds->pw_name) { |
[email protected] | fe928be9 | 2014-08-08 09:17:41 | [diff] [blame] | 20 | LOG(WARNING) << "DevTools: can't obtain creds for uid " |
21 | << credentials.user_id; | ||||
[email protected] | 689266d | 2012-08-07 12:52:20 | [diff] [blame] | 22 | return false; |
23 | } | ||||
[email protected] | fe928be9 | 2014-08-08 09:17:41 | [diff] [blame] | 24 | if (credentials.group_id == credentials.user_id && |
Tom Sepez | 40add7f | 2025-03-19 06:32:02 | [diff] [blame] | 25 | (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] | fe928be9 | 2014-08-08 09:17:41 | [diff] [blame] | 29 | |
30 | // From processes signed with the same key | ||||
31 | credentials.user_id == getuid())) { | ||||
[email protected] | 689266d | 2012-08-07 12:52:20 | [diff] [blame] | 32 | return true; |
33 | } | ||||
34 | LOG(WARNING) << "DevTools: connection attempt from " << creds->pw_name; | ||||
35 | return false; | ||||
36 | } | ||||
37 | |||||
38 | } // namespace content |