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 extern "C" { | 9 extern "C" { |
10 #include <sandbox.h> | 10 #include <sandbox.h> |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 403 } |
404 | 404 |
405 // static | 405 // static |
406 bool Sandbox::PostProcessSandboxProfile( | 406 bool Sandbox::PostProcessSandboxProfile( |
407 NSString* sandbox_template, | 407 NSString* sandbox_template, |
408 NSArray* comments_to_remove, | 408 NSArray* comments_to_remove, |
409 SandboxVariableSubstitions& substitutions, | 409 SandboxVariableSubstitions& substitutions, |
410 std::string *final_sandbox_profile_str) { | 410 std::string *final_sandbox_profile_str) { |
411 NSString* sandbox_data = [[sandbox_template copy] autorelease]; | 411 NSString* sandbox_data = [[sandbox_template copy] autorelease]; |
412 | 412 |
413 // Remove comments, e.g. ;10.6_ONLY . | 413 // Remove comments, e.g. ;10.7_OR_ABOVE . |
414 for (NSString* to_remove in comments_to_remove) { | 414 for (NSString* to_remove in comments_to_remove) { |
415 sandbox_data = [sandbox_data stringByReplacingOccurrencesOfString:to_remove | 415 sandbox_data = [sandbox_data stringByReplacingOccurrencesOfString:to_remove |
416 withString:@""]; | 416 withString:@""]; |
417 } | 417 } |
418 | 418 |
419 // Split string on "@" characters. | 419 // Split string on "@" characters. |
420 std::vector<std::string> raw_sandbox_pieces; | 420 std::vector<std::string> raw_sandbox_pieces; |
421 if (Tokenize([sandbox_data UTF8String], "@", &raw_sandbox_pieces) == 0) { | 421 if (Tokenize([sandbox_data UTF8String], "@", &raw_sandbox_pieces) == 0) { |
422 DLOG(FATAL) << "Bad Sandbox profile, should contain at least one token (" | 422 DLOG(FATAL) << "Bad Sandbox profile, should contain at least one token (" |
423 << [sandbox_data UTF8String] | 423 << [sandbox_data UTF8String] |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 508 |
509 // Enable verbose logging if enabled on the command line. (See common.sb | 509 // Enable verbose logging if enabled on the command line. (See common.sb |
510 // for details). | 510 // for details). |
511 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 511 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
512 bool enable_logging = | 512 bool enable_logging = |
513 command_line->HasSwitch(switches::kEnableSandboxLogging);; | 513 command_line->HasSwitch(switches::kEnableSandboxLogging);; |
514 if (enable_logging) { | 514 if (enable_logging) { |
515 [tokens_to_remove addObject:@";ENABLE_LOGGING"]; | 515 [tokens_to_remove addObject:@";ENABLE_LOGGING"]; |
516 } | 516 } |
517 | 517 |
518 bool snow_leopard_or_later = base::mac::IsOSSnowLeopardOrLater(); | |
519 bool lion_or_later = base::mac::IsOSLionOrLater(); | 518 bool lion_or_later = base::mac::IsOSLionOrLater(); |
520 | 519 |
521 // Without this, the sandbox will print a message to the system log every | 520 // Without this, the sandbox will print a message to the system log every |
522 // time it denies a request. This floods the console with useless spew. The | 521 // time it denies a request. This floods the console with useless spew. |
523 // (with no-log) syntax is only supported on 10.6+ | 522 if (!enable_logging) { |
524 if (snow_leopard_or_later && !enable_logging) { | |
525 substitutions["DISABLE_SANDBOX_DENIAL_LOGGING"] = | 523 substitutions["DISABLE_SANDBOX_DENIAL_LOGGING"] = |
526 SandboxSubstring("(with no-log)"); | 524 SandboxSubstring("(with no-log)"); |
527 } else { | 525 } else { |
528 substitutions["DISABLE_SANDBOX_DENIAL_LOGGING"] = SandboxSubstring(""); | 526 substitutions["DISABLE_SANDBOX_DENIAL_LOGGING"] = SandboxSubstring(""); |
529 } | 527 } |
530 | 528 |
531 // Splice the path of the user's home directory into the sandbox profile | 529 // Splice the path of the user's home directory into the sandbox profile |
532 // (see renderer.sb for details). | 530 // (see renderer.sb for details). |
533 std::string home_dir = [NSHomeDirectory() fileSystemRepresentation]; | 531 std::string home_dir = [NSHomeDirectory() fileSystemRepresentation]; |
534 | 532 |
535 FilePath home_dir_canonical = GetCanonicalSandboxPath(FilePath(home_dir)); | 533 FilePath home_dir_canonical = GetCanonicalSandboxPath(FilePath(home_dir)); |
536 | 534 |
537 substitutions["USER_HOMEDIR_AS_LITERAL"] = | 535 substitutions["USER_HOMEDIR_AS_LITERAL"] = |
538 SandboxSubstring(home_dir_canonical.value(), | 536 SandboxSubstring(home_dir_canonical.value(), |
539 SandboxSubstring::LITERAL); | 537 SandboxSubstring::LITERAL); |
540 | 538 |
541 if (lion_or_later) { | 539 if (lion_or_later) { |
542 // >=10.7 Sandbox rules. | 540 // >=10.7 Sandbox rules. |
543 [tokens_to_remove addObject:@";10.7_OR_ABOVE"]; | 541 [tokens_to_remove addObject:@";10.7_OR_ABOVE"]; |
544 } | 542 } |
545 | 543 |
546 if (snow_leopard_or_later) { | |
547 // >=10.6 Sandbox rules. | |
548 [tokens_to_remove addObject:@";10.6_OR_ABOVE"]; | |
549 } else { | |
550 // Sandbox rules only for versions before 10.6. | |
551 [tokens_to_remove addObject:@";BEFORE_10.6"]; | |
552 } | |
553 | |
554 substitutions["COMPONENT_BUILD_WORKAROUND"] = SandboxSubstring(""); | 544 substitutions["COMPONENT_BUILD_WORKAROUND"] = SandboxSubstring(""); |
555 #if defined(COMPONENT_BUILD) | 545 #if defined(COMPONENT_BUILD) |
556 // dlopen() fails without file-read-metadata access if the executable image | 546 // dlopen() fails without file-read-metadata access if the executable image |
557 // contains LC_RPATH load commands. The components build uses those. | 547 // contains LC_RPATH load commands. The components build uses those. |
558 // See http://crbug.com/127465 | 548 // See http://crbug.com/127465 |
559 if (base::mac::IsOSSnowLeopardOrEarlier()) { | 549 if (base::mac::IsOSSnowLeopardOrEarlier()) { |
560 FilePath bundle_executable = base::mac::NSStringToFilePath( | 550 FilePath bundle_executable = base::mac::NSStringToFilePath( |
561 [base::mac::MainBundle() executablePath]); | 551 [base::mac::MainBundle() executablePath]); |
562 NSString* sandbox_command = AllowMetadataForPath( | 552 NSString* sandbox_command = AllowMetadataForPath( |
563 GetCanonicalSandboxPath(bundle_executable)); | 553 GetCanonicalSandboxPath(bundle_executable)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 if (HANDLE_EINTR(fcntl(fd, F_GETPATH, canonical_path)) != 0) { | 590 if (HANDLE_EINTR(fcntl(fd, F_GETPATH, canonical_path)) != 0) { |
601 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " | 591 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " |
602 << path.value(); | 592 << path.value(); |
603 return path; | 593 return path; |
604 } | 594 } |
605 | 595 |
606 return FilePath(canonical_path); | 596 return FilePath(canonical_path); |
607 } | 597 } |
608 | 598 |
609 } // namespace sandbox | 599 } // namespace sandbox |
OLD | NEW |