| 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 "content/common/sandbox_mac.h" | 5 #include "content/common/sandbox_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include <CoreFoundation/CFTimeZone.h> | 9 #include <CoreFoundation/CFTimeZone.h> |
| 10 extern "C" { | 10 extern "C" { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 DLOG(FATAL) << "String quoting failed " << bad_string; | 107 DLOG(FATAL) << "String quoting failed " << bad_string; |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace | 110 } // namespace |
| 111 | 111 |
| 112 // static | 112 // static |
| 113 NSString* Sandbox::AllowMetadataForPath(const base::FilePath& allowed_path) { | 113 NSString* Sandbox::AllowMetadataForPath(const base::FilePath& allowed_path) { |
| 114 // Collect a list of all parent directories. | 114 // Collect a list of all parent directories. |
| 115 base::FilePath last_path = allowed_path; | 115 base::FilePath last_path = allowed_path; |
| 116 std::vector<base::FilePath> subpaths; | 116 std::vector<base::FilePath> subpaths; |
| 117 | 117 for (base::FilePath path = allowed_path; |
| 118 base::FilePath path = allowed_path; | 118 path.value() != last_path.value(); |
| 119 do { | 119 path = path.DirName()) { |
| 120 subpaths.push_back(path); | 120 subpaths.push_back(path); |
| 121 | |
| 122 last_path = path; | 121 last_path = path; |
| 123 path = path.DirName(); | 122 } |
| 124 } while (path.value() != last_path.value()); | |
| 125 | 123 |
| 126 // Iterate through all parents and allow stat() on them explicitly. | 124 // Iterate through all parents and allow stat() on them explicitly. |
| 127 NSString* sandbox_command = @"(allow file-read-metadata "; | 125 NSString* sandbox_command = @"(allow file-read-metadata "; |
| 128 for (std::vector<base::FilePath>::reverse_iterator i = subpaths.rbegin(); | 126 for (std::vector<base::FilePath>::reverse_iterator i = subpaths.rbegin(); |
| 129 i != subpaths.rend(); | 127 i != subpaths.rend(); |
| 130 ++i) { | 128 ++i) { |
| 131 std::string subdir_escaped; | 129 std::string subdir_escaped; |
| 132 if (!QuotePlainString(i->value(), &subdir_escaped)) { | 130 if (!QuotePlainString(i->value(), &subdir_escaped)) { |
| 133 FatalStringQuoteException(i->value()); | 131 FatalStringQuoteException(i->value()); |
| 134 return nil; | 132 return nil; |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 substitutions["COMPONENT_BUILD_WORKAROUND"] = SandboxSubstring(""); | 563 substitutions["COMPONENT_BUILD_WORKAROUND"] = SandboxSubstring(""); |
| 566 #if defined(COMPONENT_BUILD) | 564 #if defined(COMPONENT_BUILD) |
| 567 // dlopen() fails without file-read-metadata access if the executable image | 565 // dlopen() fails without file-read-metadata access if the executable image |
| 568 // contains LC_RPATH load commands. The components build uses those. | 566 // contains LC_RPATH load commands. The components build uses those. |
| 569 // See http://crbug.com/127465 | 567 // See http://crbug.com/127465 |
| 570 if (base::mac::IsOSSnowLeopard()) { | 568 if (base::mac::IsOSSnowLeopard()) { |
| 571 base::FilePath bundle_executable = base::mac::NSStringToFilePath( | 569 base::FilePath bundle_executable = base::mac::NSStringToFilePath( |
| 572 [base::mac::MainBundle() executablePath]); | 570 [base::mac::MainBundle() executablePath]); |
| 573 NSString* sandbox_command = AllowMetadataForPath( | 571 NSString* sandbox_command = AllowMetadataForPath( |
| 574 GetCanonicalSandboxPath(bundle_executable)); | 572 GetCanonicalSandboxPath(bundle_executable)); |
| 575 | |
| 576 // In addition to the workaround above, for OS X <= 10.6 we also need to | |
| 577 // allow reading file metadata for all the dylibs under the same directory | |
| 578 // containing the Chrome bundle. It requires to go 5 levels up from main | |
| 579 // bundle path because the main bundle here is the Helper.app bundle. | |
| 580 base::FilePath product_path = base::mac::MainBundlePath() | |
| 581 .DirName() | |
| 582 .DirName() | |
| 583 .DirName() | |
| 584 .DirName() | |
| 585 .DirName(); | |
| 586 sandbox_command = [sandbox_command | |
| 587 stringByAppendingFormat: | |
| 588 @"(allow file-read-metadata (regex #\"^%@/.*\\.dylib$\"))", | |
| 589 base::mac::FilePathToNSString(product_path)]; | |
| 590 | |
| 591 substitutions["COMPONENT_BUILD_WORKAROUND"] = | 573 substitutions["COMPONENT_BUILD_WORKAROUND"] = |
| 592 SandboxSubstring(base::SysNSStringToUTF8(sandbox_command)); | 574 SandboxSubstring(base::SysNSStringToUTF8(sandbox_command)); |
| 593 } | 575 } |
| 594 #endif | 576 #endif |
| 595 | 577 |
| 596 // All information needed to assemble the final profile has been collected. | 578 // All information needed to assemble the final profile has been collected. |
| 597 // Merge it all together. | 579 // Merge it all together. |
| 598 std::string final_sandbox_profile_str; | 580 std::string final_sandbox_profile_str; |
| 599 if (!PostProcessSandboxProfile(sandbox_data, tokens_to_remove, substitutions, | 581 if (!PostProcessSandboxProfile(sandbox_data, tokens_to_remove, substitutions, |
| 600 &final_sandbox_profile_str)) { | 582 &final_sandbox_profile_str)) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 if (HANDLE_EINTR(fcntl(fd.get(), F_GETPATH, canonical_path)) != 0) { | 614 if (HANDLE_EINTR(fcntl(fd.get(), F_GETPATH, canonical_path)) != 0) { |
| 633 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " | 615 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " |
| 634 << path.value(); | 616 << path.value(); |
| 635 return path; | 617 return path; |
| 636 } | 618 } |
| 637 | 619 |
| 638 return base::FilePath(canonical_path); | 620 return base::FilePath(canonical_path); |
| 639 } | 621 } |
| 640 | 622 |
| 641 } // namespace content | 623 } // namespace content |
| OLD | NEW |