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/browser/child_process_security_policy_impl.h" | 5 #include "content/browser/child_process_security_policy_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Used internally only. These bit positions have no relationship to any | 34 // Used internally only. These bit positions have no relationship to any |
35 // underlying OS and can be changed to accommodate finer-grained permissions. | 35 // underlying OS and can be changed to accommodate finer-grained permissions. |
36 enum ChildProcessSecurityPermissions { | 36 enum ChildProcessSecurityPermissions { |
37 READ_FILE_PERMISSION = 1 << 0, | 37 READ_FILE_PERMISSION = 1 << 0, |
38 WRITE_FILE_PERMISSION = 1 << 1, | 38 WRITE_FILE_PERMISSION = 1 << 1, |
39 CREATE_NEW_FILE_PERMISSION = 1 << 2, | 39 CREATE_NEW_FILE_PERMISSION = 1 << 2, |
40 CREATE_OVERWRITE_FILE_PERMISSION = 1 << 3, | 40 CREATE_OVERWRITE_FILE_PERMISSION = 1 << 3, |
41 DELETE_FROM_FILE_PERMISSION = 1 << 4, | |
tommycli
2013/10/21 14:16:09
probably just DELETE_FILE right?
Lei Zhang
2013/10/21 21:35:38
Done.
| |
41 | 42 |
42 // Used by Media Galleries API | 43 // Used by Media Galleries API |
43 COPY_INTO_FILE_PERMISSION = 1 << 4, | 44 COPY_INTO_FILE_PERMISSION = 1 << 5, |
44 }; | 45 }; |
45 | 46 |
46 // Used internally only. Bitmasks that are actually used by the Grant* and Can* | 47 // Used internally only. Bitmasks that are actually used by the Grant* and Can* |
47 // methods. These contain one or more ChildProcessSecurityPermissions. | 48 // methods. These contain one or more ChildProcessSecurityPermissions. |
48 enum ChildProcessSecurityGrants { | 49 enum ChildProcessSecurityGrants { |
49 READ_FILE_GRANT = READ_FILE_PERMISSION, | 50 READ_FILE_GRANT = READ_FILE_PERMISSION, |
50 WRITE_FILE_GRANT = WRITE_FILE_PERMISSION, | 51 WRITE_FILE_GRANT = WRITE_FILE_PERMISSION, |
51 | 52 |
52 CREATE_NEW_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | | 53 CREATE_NEW_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | |
53 COPY_INTO_FILE_PERMISSION, | 54 COPY_INTO_FILE_PERMISSION, |
54 | 55 |
55 CREATE_READ_WRITE_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | | 56 CREATE_READ_WRITE_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | |
56 CREATE_OVERWRITE_FILE_PERMISSION | | 57 CREATE_OVERWRITE_FILE_PERMISSION | |
57 READ_FILE_PERMISSION | | 58 READ_FILE_PERMISSION | |
58 WRITE_FILE_PERMISSION | | 59 WRITE_FILE_PERMISSION | |
59 COPY_INTO_FILE_PERMISSION, | 60 COPY_INTO_FILE_PERMISSION | |
61 DELETE_FROM_FILE_PERMISSION, | |
60 | 62 |
61 COPY_INTO_FILE_GRANT = COPY_INTO_FILE_PERMISSION, | 63 COPY_INTO_FILE_GRANT = COPY_INTO_FILE_PERMISSION, |
64 DELETE_FROM_FILE_GRANT = DELETE_FROM_FILE_PERMISSION, | |
tommycli
2013/10/21 14:16:09
here too
Lei Zhang
2013/10/21 21:35:38
Done.
| |
62 }; | 65 }; |
63 | 66 |
64 } // namespace | 67 } // namespace |
65 | 68 |
66 // The SecurityState class is used to maintain per-child process security state | 69 // The SecurityState class is used to maintain per-child process security state |
67 // information. | 70 // information. |
68 class ChildProcessSecurityPolicyImpl::SecurityState { | 71 class ChildProcessSecurityPolicyImpl::SecurityState { |
69 public: | 72 public: |
70 SecurityState() | 73 SecurityState() |
71 : enabled_bindings_(0), | 74 : enabled_bindings_(0), |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 void ChildProcessSecurityPolicyImpl::GrantCreateFileForFileSystem( | 474 void ChildProcessSecurityPolicyImpl::GrantCreateFileForFileSystem( |
472 int child_id, const std::string& filesystem_id) { | 475 int child_id, const std::string& filesystem_id) { |
473 GrantPermissionsForFileSystem(child_id, filesystem_id, CREATE_NEW_FILE_GRANT); | 476 GrantPermissionsForFileSystem(child_id, filesystem_id, CREATE_NEW_FILE_GRANT); |
474 } | 477 } |
475 | 478 |
476 void ChildProcessSecurityPolicyImpl::GrantCopyIntoFileSystem( | 479 void ChildProcessSecurityPolicyImpl::GrantCopyIntoFileSystem( |
477 int child_id, const std::string& filesystem_id) { | 480 int child_id, const std::string& filesystem_id) { |
478 GrantPermissionsForFileSystem(child_id, filesystem_id, COPY_INTO_FILE_GRANT); | 481 GrantPermissionsForFileSystem(child_id, filesystem_id, COPY_INTO_FILE_GRANT); |
479 } | 482 } |
480 | 483 |
484 void ChildProcessSecurityPolicyImpl::GrantDeleteFromFileSystem( | |
485 int child_id, const std::string& filesystem_id) { | |
486 GrantPermissionsForFileSystem(child_id, filesystem_id, | |
487 DELETE_FROM_FILE_GRANT); | |
488 } | |
489 | |
481 void ChildProcessSecurityPolicyImpl::GrantSendMIDISysExMessage(int child_id) { | 490 void ChildProcessSecurityPolicyImpl::GrantSendMIDISysExMessage(int child_id) { |
482 base::AutoLock lock(lock_); | 491 base::AutoLock lock(lock_); |
483 | 492 |
484 SecurityStateMap::iterator state = security_state_.find(child_id); | 493 SecurityStateMap::iterator state = security_state_.find(child_id); |
485 if (state == security_state_.end()) | 494 if (state == security_state_.end()) |
486 return; | 495 return; |
487 | 496 |
488 state->second->GrantPermissionForMIDISysEx(); | 497 state->second->GrantPermissionForMIDISysEx(); |
489 } | 498 } |
490 | 499 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 return HasPermissionsForFileSystem(child_id, filesystem_id, | 629 return HasPermissionsForFileSystem(child_id, filesystem_id, |
621 READ_FILE_GRANT | WRITE_FILE_GRANT); | 630 READ_FILE_GRANT | WRITE_FILE_GRANT); |
622 } | 631 } |
623 | 632 |
624 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystem( | 633 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystem( |
625 int child_id, const std::string& filesystem_id) { | 634 int child_id, const std::string& filesystem_id) { |
626 return HasPermissionsForFileSystem(child_id, filesystem_id, | 635 return HasPermissionsForFileSystem(child_id, filesystem_id, |
627 COPY_INTO_FILE_GRANT); | 636 COPY_INTO_FILE_GRANT); |
628 } | 637 } |
629 | 638 |
639 bool ChildProcessSecurityPolicyImpl::CanDeleteFromFileSystem( | |
640 int child_id, const std::string& filesystem_id) { | |
641 return HasPermissionsForFileSystem(child_id, filesystem_id, | |
642 DELETE_FROM_FILE_GRANT); | |
643 } | |
644 | |
630 bool ChildProcessSecurityPolicyImpl::HasPermissionsForFile( | 645 bool ChildProcessSecurityPolicyImpl::HasPermissionsForFile( |
631 int child_id, const base::FilePath& file, int permissions) { | 646 int child_id, const base::FilePath& file, int permissions) { |
632 base::AutoLock lock(lock_); | 647 base::AutoLock lock(lock_); |
633 bool result = ChildProcessHasPermissionsForFile(child_id, file, permissions); | 648 bool result = ChildProcessHasPermissionsForFile(child_id, file, permissions); |
634 if (!result) { | 649 if (!result) { |
635 // If this is a worker thread that has no access to a given file, | 650 // If this is a worker thread that has no access to a given file, |
636 // let's check that its renderer process has access to that file instead. | 651 // let's check that its renderer process has access to that file instead. |
637 WorkerToMainProcessMap::iterator iter = worker_map_.find(child_id); | 652 WorkerToMainProcessMap::iterator iter = worker_map_.find(child_id); |
638 if (iter != worker_map_.end() && iter->second != 0) { | 653 if (iter != worker_map_.end() && iter->second != 0) { |
639 result = ChildProcessHasPermissionsForFile(iter->second, | 654 result = ChildProcessHasPermissionsForFile(iter->second, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 return HasPermissionsForFileSystemFile(child_id, url, | 724 return HasPermissionsForFileSystemFile(child_id, url, |
710 CREATE_READ_WRITE_FILE_GRANT); | 725 CREATE_READ_WRITE_FILE_GRANT); |
711 } | 726 } |
712 | 727 |
713 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystemFile( | 728 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystemFile( |
714 int child_id, | 729 int child_id, |
715 const fileapi::FileSystemURL& url) { | 730 const fileapi::FileSystemURL& url) { |
716 return HasPermissionsForFileSystemFile(child_id, url, COPY_INTO_FILE_GRANT); | 731 return HasPermissionsForFileSystemFile(child_id, url, COPY_INTO_FILE_GRANT); |
717 } | 732 } |
718 | 733 |
734 bool ChildProcessSecurityPolicyImpl::CanDeleteFileSystemFile( | |
735 int child_id, | |
736 const fileapi::FileSystemURL& url) { | |
737 return HasPermissionsForFileSystemFile(child_id, url, DELETE_FROM_FILE_GRANT); | |
738 } | |
739 | |
719 bool ChildProcessSecurityPolicyImpl::HasWebUIBindings(int child_id) { | 740 bool ChildProcessSecurityPolicyImpl::HasWebUIBindings(int child_id) { |
720 base::AutoLock lock(lock_); | 741 base::AutoLock lock(lock_); |
721 | 742 |
722 SecurityStateMap::iterator state = security_state_.find(child_id); | 743 SecurityStateMap::iterator state = security_state_.find(child_id); |
723 if (state == security_state_.end()) | 744 if (state == security_state_.end()) |
724 return false; | 745 return false; |
725 | 746 |
726 return state->second->has_web_ui_bindings(); | 747 return state->second->has_web_ui_bindings(); |
727 } | 748 } |
728 | 749 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 base::AutoLock lock(lock_); | 848 base::AutoLock lock(lock_); |
828 | 849 |
829 SecurityStateMap::iterator state = security_state_.find(child_id); | 850 SecurityStateMap::iterator state = security_state_.find(child_id); |
830 if (state == security_state_.end()) | 851 if (state == security_state_.end()) |
831 return false; | 852 return false; |
832 | 853 |
833 return state->second->can_send_midi_sysex(); | 854 return state->second->can_send_midi_sysex(); |
834 } | 855 } |
835 | 856 |
836 } // namespace content | 857 } // namespace content |
OLD | NEW |