OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 10 #pragma once |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // Append the data to |fd|. Does not close |fd| when done. | 370 // Append the data to |fd|. Does not close |fd| when done. |
371 BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); | 371 BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); |
372 #endif | 372 #endif |
373 | 373 |
374 // Gets the current working directory for the process. | 374 // Gets the current working directory for the process. |
375 BASE_EXPORT bool GetCurrentDirectory(FilePath* path); | 375 BASE_EXPORT bool GetCurrentDirectory(FilePath* path); |
376 | 376 |
377 // Sets the current working directory for the process. | 377 // Sets the current working directory for the process. |
378 BASE_EXPORT bool SetCurrentDirectory(const FilePath& path); | 378 BASE_EXPORT bool SetCurrentDirectory(const FilePath& path); |
379 | 379 |
| 380 #if defined(OS_POSIX) |
| 381 // Test that |path| can only be changed by a specific user and group. |
| 382 // Specifically, test that all parts of |path| under (and including) |base|: |
| 383 // * Exist. |
| 384 // * Are owned by a specific user and group. |
| 385 // * Are not writable by all users. |
| 386 // * Are not symbolic links. |
| 387 // This is useful for checking that a config file is administrator-controlled. |
| 388 // |base| must contain |path|. |
| 389 BASE_EXPORT bool VerifyPathControlledByUser(const FilePath& base, |
| 390 const FilePath& path, |
| 391 uid_t owner_uid, |
| 392 gid_t group_gid); |
| 393 #endif // defined(OS_POSIX) |
| 394 |
| 395 #if defined(OS_MACOSX) |
| 396 // Is |path| writable only by a user with administrator privileges? |
| 397 // This function uses Mac OS conventions. The super user is assumed to have |
| 398 // uid 0, and the administrator group is assumed to be named "admin". |
| 399 // Testing that |path|, and every parent directory including the root of |
| 400 // the filesystem, are owned by the superuser, controlled by the group |
| 401 // "admin", are not writable by all users, and contain no symbolic links. |
| 402 // Will return false if |path| does not exist. |
| 403 BASE_EXPORT bool VerifyPathControlledByAdmin(const FilePath& path); |
| 404 #endif // defined(OS_MACOSX) |
| 405 |
380 // A class to handle auto-closing of FILE*'s. | 406 // A class to handle auto-closing of FILE*'s. |
381 class ScopedFILEClose { | 407 class ScopedFILEClose { |
382 public: | 408 public: |
383 inline void operator()(FILE* x) const { | 409 inline void operator()(FILE* x) const { |
384 if (x) { | 410 if (x) { |
385 fclose(x); | 411 fclose(x); |
386 } | 412 } |
387 } | 413 } |
388 }; | 414 }; |
389 | 415 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); | 624 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); |
599 #endif | 625 #endif |
600 | 626 |
601 } // namespace file_util | 627 } // namespace file_util |
602 | 628 |
603 // Deprecated functions have been moved to this separate header file, | 629 // Deprecated functions have been moved to this separate header file, |
604 // which must be included last after all the above definitions. | 630 // which must be included last after all the above definitions. |
605 #include "base/file_util_deprecated.h" | 631 #include "base/file_util_deprecated.h" |
606 | 632 |
607 #endif // BASE_FILE_UTIL_H_ | 633 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |