Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / android / devtools_auth.cc
blob46314c447684882ea3369eb2985747bfe14b63a6
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/browser/android/devtools_auth.h"
7 #include <pwd.h>
8 #include <sys/types.h>
9 #include <unistd.h>
11 #include "base/logging.h"
13 namespace content {
15 bool CanUserConnectToDevTools(
16 const net::UnixDomainServerSocket::Credentials& credentials) {
17 struct passwd* creds = getpwuid(credentials.user_id);
18 if (!creds || !creds->pw_name) {
19 LOG(WARNING) << "DevTools: can't obtain creds for uid "
20 << credentials.user_id;
21 return false;
23 if (credentials.group_id == credentials.user_id &&
24 (strcmp("root", creds->pw_name) == 0 || // For rooted devices
25 strcmp("shell", creds->pw_name) == 0 || // For non-rooted devices
27 // From processes signed with the same key
28 credentials.user_id == getuid())) {
29 return true;
31 LOG(WARNING) << "DevTools: connection attempt from " << creds->pw_name;
32 return false;
35 } // namespace content