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 // This file contains utility functions for dealing with the local | 5 // This file contains utility functions for dealing with the local |
6 // filesystem. | 6 // filesystem. |
7 | 7 |
8 #ifndef BASE_FILE_UTIL_H_ | 8 #ifndef BASE_FILE_UTIL_H_ |
9 #define BASE_FILE_UTIL_H_ | 9 #define BASE_FILE_UTIL_H_ |
10 | 10 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 }; | 409 }; |
410 | 410 |
411 // Automatically closes |FILE*|s. | 411 // Automatically closes |FILE*|s. |
412 typedef scoped_ptr<FILE, ScopedFILEClose> ScopedFILE; | 412 typedef scoped_ptr<FILE, ScopedFILEClose> ScopedFILE; |
413 | 413 |
414 #if defined(OS_POSIX) | 414 #if defined(OS_POSIX) |
415 // Functor for |ScopedFD| (below). | 415 // Functor for |ScopedFD| (below). |
416 struct ScopedFDClose { | 416 struct ScopedFDClose { |
417 inline void operator()(int* x) const { | 417 inline void operator()(int* x) const { |
418 if (x && *x >= 0) { | 418 if (x && *x >= 0) { |
419 if (IGNORE_EINTR(close(*x)) < 0) | 419 // It's important to crash here. |
420 DPLOG(ERROR) << "close"; | 420 // There are security implications to not closing a file descriptor |
| 421 // properly. As file descriptors are "capabilities", keeping them open |
| 422 // would make the current process keep access to a resource. Much of |
| 423 // Chrome relies on being able to "drop" such access. |
| 424 // It's especially problematic on Linux with the setuid sandbox, where |
| 425 // a single open directory would bypass the entire security model. |
| 426 PCHECK(0 == IGNORE_EINTR(close(*x))); |
421 } | 427 } |
422 } | 428 } |
423 }; | 429 }; |
424 | 430 |
425 // Automatically closes FDs (note: doesn't store the FD). | 431 // Automatically closes FDs (note: doesn't store the FD). |
426 // TODO(viettrungluu): This is a very odd API, since (unlike |FILE*|s, you'll | 432 // TODO(viettrungluu): This is a very odd API, since (unlike |FILE*|s, you'll |
427 // need to store the FD separately and keep its memory alive). This should | 433 // need to store the FD separately and keep its memory alive). This should |
428 // probably be called |ScopedFDCloser| or something like that. | 434 // probably be called |ScopedFDCloser| or something like that. |
429 typedef scoped_ptr<int, ScopedFDClose> ScopedFD; | 435 typedef scoped_ptr<int, ScopedFDClose> ScopedFD; |
| 436 // Let new users use ScopedFDCloser already, while ScopedFD is replaced. |
| 437 typedef ScopedFD ScopedFDCloser; |
430 #endif // OS_POSIX | 438 #endif // OS_POSIX |
431 | 439 |
432 #if defined(OS_LINUX) | 440 #if defined(OS_LINUX) |
433 // Broad categories of file systems as returned by statfs() on Linux. | 441 // Broad categories of file systems as returned by statfs() on Linux. |
434 enum FileSystemType { | 442 enum FileSystemType { |
435 FILE_SYSTEM_UNKNOWN, // statfs failed. | 443 FILE_SYSTEM_UNKNOWN, // statfs failed. |
436 FILE_SYSTEM_0, // statfs.f_type == 0 means unknown, may indicate AFS. | 444 FILE_SYSTEM_0, // statfs.f_type == 0 means unknown, may indicate AFS. |
437 FILE_SYSTEM_ORDINARY, // on-disk filesystem like ext2 | 445 FILE_SYSTEM_ORDINARY, // on-disk filesystem like ext2 |
438 FILE_SYSTEM_NFS, | 446 FILE_SYSTEM_NFS, |
439 FILE_SYSTEM_SMB, | 447 FILE_SYSTEM_SMB, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // This function simulates Move(), but unlike Move() it works across volumes. | 481 // This function simulates Move(), but unlike Move() it works across volumes. |
474 // This function is not transactional. | 482 // This function is not transactional. |
475 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 483 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
476 const FilePath& to_path); | 484 const FilePath& to_path); |
477 #endif // defined(OS_WIN) | 485 #endif // defined(OS_WIN) |
478 | 486 |
479 } // namespace internal | 487 } // namespace internal |
480 } // namespace base | 488 } // namespace base |
481 | 489 |
482 #endif // BASE_FILE_UTIL_H_ | 490 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |