| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" | 5 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/wait.h> | 9 #include <sys/wait.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/environment.h" | 15 #include "base/environment.h" |
| 16 #include "base/files/scoped_file.h" | 16 #include "base/files/scoped_file.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/posix/eintr_wrapper.h" | 18 #include "base/posix/eintr_wrapper.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "sandbox/linux/suid/common/sandbox.h" | 20 #include "sandbox/linux/suid/common/sandbox.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 bool IsFileSystemAccessDenied() { | 24 bool IsFileSystemAccessDenied() { |
| 25 base::ScopedFD root_dir(HANDLE_EINTR(open("/", O_RDONLY))); | 25 // We would rather check "/" instead of "/proc/self/exe" here, but |
| 26 return !root_dir.is_valid(); | 26 // that gives false positives when running as root. See |
| 27 // https://codereview.chromium.org/2578483002/#msg3 |
| 28 base::ScopedFD proc_self_exe(HANDLE_EINTR(open("/proc/self/exe", O_RDONLY))); |
| 29 return !proc_self_exe.is_valid(); |
| 27 } | 30 } |
| 28 | 31 |
| 29 int GetHelperApi(base::Environment* env) { | 32 int GetHelperApi(base::Environment* env) { |
| 30 std::string api_string; | 33 std::string api_string; |
| 31 int api_number = 0; // Assume API version 0 if no environment was found. | 34 int api_number = 0; // Assume API version 0 if no environment was found. |
| 32 if (env->GetVar(sandbox::kSandboxEnvironmentApiProvides, &api_string) && | 35 if (env->GetVar(sandbox::kSandboxEnvironmentApiProvides, &api_string) && |
| 33 !base::StringToInt(api_string, &api_number)) { | 36 !base::StringToInt(api_string, &api_number)) { |
| 34 // It's an error if we could not convert the API number. | 37 // It's an error if we could not convert the API number. |
| 35 api_number = -1; | 38 api_number = -1; |
| 36 } | 39 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 145 |
| 143 bool SetuidSandboxClient::IsInNewNETNamespace() const { | 146 bool SetuidSandboxClient::IsInNewNETNamespace() const { |
| 144 return env_->HasVar(kSandboxNETNSEnvironmentVarName); | 147 return env_->HasVar(kSandboxNETNSEnvironmentVarName); |
| 145 } | 148 } |
| 146 | 149 |
| 147 bool SetuidSandboxClient::IsSandboxed() const { | 150 bool SetuidSandboxClient::IsSandboxed() const { |
| 148 return sandboxed_; | 151 return sandboxed_; |
| 149 } | 152 } |
| 150 | 153 |
| 151 } // namespace sandbox | 154 } // namespace sandbox |
| OLD | NEW |