| 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/services/credentials.h" | 5 #include "sandbox/linux/services/credentials.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 #include <pthread.h> | 10 #include <pthread.h> |
| 11 #include <signal.h> | 11 #include <signal.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <sys/capability.h> | 13 #include <sys/capability.h> |
| 14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
| 15 #include <sys/types.h> | 15 #include <sys/types.h> |
| 16 #include <unistd.h> | 16 #include <unistd.h> |
| 17 | 17 |
| 18 #include <memory> |
| 18 #include <vector> | 19 #include <vector> |
| 19 | 20 |
| 20 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
| 21 #include "base/files/file_util.h" | 22 #include "base/files/file_util.h" |
| 22 #include "base/files/scoped_file.h" | 23 #include "base/files/scoped_file.h" |
| 23 #include "base/logging.h" | 24 #include "base/logging.h" |
| 24 #include "base/memory/scoped_ptr.h" | |
| 25 #include "sandbox/linux/services/proc_util.h" | 25 #include "sandbox/linux/services/proc_util.h" |
| 26 #include "sandbox/linux/services/syscall_wrappers.h" | 26 #include "sandbox/linux/services/syscall_wrappers.h" |
| 27 #include "sandbox/linux/system_headers/capability.h" | 27 #include "sandbox/linux/system_headers/capability.h" |
| 28 #include "sandbox/linux/tests/unit_tests.h" | 28 #include "sandbox/linux/tests/unit_tests.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 namespace sandbox { | 31 namespace sandbox { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 struct CapFreeDeleter { | 35 struct CapFreeDeleter { |
| 36 inline void operator()(cap_t cap) const { | 36 inline void operator()(cap_t cap) const { |
| 37 int ret = cap_free(cap); | 37 int ret = cap_free(cap); |
| 38 CHECK_EQ(0, ret); | 38 CHECK_EQ(0, ret); |
| 39 } | 39 } |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // Wrapper to manage libcap2's cap_t type. | 42 // Wrapper to manage libcap2's cap_t type. |
| 43 typedef scoped_ptr<typeof(*((cap_t)0)), CapFreeDeleter> ScopedCap; | 43 typedef std::unique_ptr<typeof(*((cap_t)0)), CapFreeDeleter> ScopedCap; |
| 44 | 44 |
| 45 bool WorkingDirectoryIsRoot() { | 45 bool WorkingDirectoryIsRoot() { |
| 46 char current_dir[PATH_MAX]; | 46 char current_dir[PATH_MAX]; |
| 47 char* cwd = getcwd(current_dir, sizeof(current_dir)); | 47 char* cwd = getcwd(current_dir, sizeof(current_dir)); |
| 48 PCHECK(cwd); | 48 PCHECK(cwd); |
| 49 if (strcmp("/", cwd)) return false; | 49 if (strcmp("/", cwd)) return false; |
| 50 | 50 |
| 51 // The current directory is the root. Add a few paranoid checks. | 51 // The current directory is the root. Add a few paranoid checks. |
| 52 struct stat current; | 52 struct stat current; |
| 53 CHECK_EQ(0, stat(".", ¤t)); | 53 CHECK_EQ(0, stat(".", ¤t)); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 action.sa_handler = &SignalHandler; | 261 action.sa_handler = &SignalHandler; |
| 262 PCHECK(sigaction(SIGUSR1, &action, nullptr) == 0); | 262 PCHECK(sigaction(SIGUSR1, &action, nullptr) == 0); |
| 263 | 263 |
| 264 PCHECK(raise(SIGUSR1) == 0); | 264 PCHECK(raise(SIGUSR1) == 0); |
| 265 CHECK_EQ(1, signal_handler_called); | 265 CHECK_EQ(1, signal_handler_called); |
| 266 } | 266 } |
| 267 | 267 |
| 268 } // namespace. | 268 } // namespace. |
| 269 | 269 |
| 270 } // namespace sandbox. | 270 } // namespace sandbox. |
| OLD | NEW |