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 #import "chrome/browser/mac/keystone_glue.h" | 5 #import "chrome/browser/mac/keystone_glue.h" |
6 | 6 |
7 #include <sys/param.h> | 7 #include <sys/param.h> |
8 #include <sys/mount.h> | 8 #include <sys/mount.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/mac/authorization_util.h" |
16 #include "base/mac/bundle_locations.h" | 17 #include "base/mac/bundle_locations.h" |
17 #include "base/mac/mac_logging.h" | 18 #include "base/mac/mac_logging.h" |
18 #include "base/mac/mac_util.h" | 19 #include "base/mac/mac_util.h" |
19 #include "base/mac/scoped_nsautorelease_pool.h" | 20 #include "base/mac/scoped_nsautorelease_pool.h" |
20 #include "base/mac/scoped_nsexception_enabler.h" | 21 #include "base/mac/scoped_nsexception_enabler.h" |
21 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
22 #include "base/sys_string_conversions.h" | 23 #include "base/sys_string_conversions.h" |
23 #include "base/threading/worker_pool.h" | 24 #include "base/threading/worker_pool.h" |
24 #include "chrome/browser/mac/authorization_util.h" | |
25 #import "chrome/browser/mac/keystone_registration.h" | 25 #import "chrome/browser/mac/keystone_registration.h" |
26 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
28 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/l10n/l10n_util_mac.h" | 31 #include "ui/base/l10n/l10n_util_mac.h" |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 // Because there are multiple ways of reaching promoteTicket that might | 771 // Because there are multiple ways of reaching promoteTicket that might |
772 // not lock each other out, it may be possible to arrive here while an | 772 // not lock each other out, it may be possible to arrive here while an |
773 // asynchronous operation is pending, or even after promotion has already | 773 // asynchronous operation is pending, or even after promotion has already |
774 // occurred. Just quietly return without doing anything. | 774 // occurred. Just quietly return without doing anything. |
775 return; | 775 return; |
776 } | 776 } |
777 | 777 |
778 NSString* prompt = l10n_util::GetNSStringFWithFixup( | 778 NSString* prompt = l10n_util::GetNSStringFWithFixup( |
779 IDS_PROMOTE_AUTHENTICATION_PROMPT, | 779 IDS_PROMOTE_AUTHENTICATION_PROMPT, |
780 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 780 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
781 ScopedAuthorizationRef authorization( | 781 base::mac::ScopedAuthorizationRef authorization( |
782 authorization_util::AuthorizationCreateToRunAsRoot( | 782 base::mac::AuthorizationCreateToRunAsRoot( |
783 base::mac::NSToCFCast(prompt))); | 783 base::mac::NSToCFCast(prompt))); |
784 if (!authorization.get()) { | 784 if (!authorization.get()) { |
785 return; | 785 return; |
786 } | 786 } |
787 | 787 |
788 [self promoteTicketWithAuthorization:authorization.release() synchronous:NO]; | 788 [self promoteTicketWithAuthorization:authorization.release() synchronous:NO]; |
789 } | 789 } |
790 | 790 |
791 - (void)promoteTicketWithAuthorization:(AuthorizationRef)authorization_arg | 791 - (void)promoteTicketWithAuthorization:(AuthorizationRef)authorization_arg |
792 synchronous:(BOOL)synchronous { | 792 synchronous:(BOOL)synchronous { |
793 ScopedAuthorizationRef authorization(authorization_arg); | 793 base::mac::ScopedAuthorizationRef authorization(authorization_arg); |
794 authorization_arg = NULL; | 794 authorization_arg = NULL; |
795 | 795 |
796 if ([self asyncOperationPending]) { | 796 if ([self asyncOperationPending]) { |
797 // Starting a synchronous operation while an asynchronous one is pending | 797 // Starting a synchronous operation while an asynchronous one is pending |
798 // could be trouble. | 798 // could be trouble. |
799 return; | 799 return; |
800 } | 800 } |
801 if (!synchronous && ![self wantsPromotion]) { | 801 if (!synchronous && ![self wantsPromotion]) { |
802 // If operating synchronously, the call came from the installer, which | 802 // If operating synchronously, the call came from the installer, which |
803 // means that a system ticket is required. Otherwise, only allow | 803 // means that a system ticket is required. Otherwise, only allow |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 const char* userBrandFile = NULL; | 839 const char* userBrandFile = NULL; |
840 const char* systemBrandFile = NULL; | 840 const char* systemBrandFile = NULL; |
841 if (brandFileType_ == kBrandFileTypeUser) { | 841 if (brandFileType_ == kBrandFileTypeUser) { |
842 // Running with user level brand file, promote to the system level. | 842 // Running with user level brand file, promote to the system level. |
843 userBrandFile = [UserBrandFilePath() fileSystemRepresentation]; | 843 userBrandFile = [UserBrandFilePath() fileSystemRepresentation]; |
844 systemBrandFile = [SystemBrandFilePath() fileSystemRepresentation]; | 844 systemBrandFile = [SystemBrandFilePath() fileSystemRepresentation]; |
845 } | 845 } |
846 const char* arguments[] = {userBrandFile, systemBrandFile, NULL}; | 846 const char* arguments[] = {userBrandFile, systemBrandFile, NULL}; |
847 | 847 |
848 int exit_status; | 848 int exit_status; |
849 OSStatus status = authorization_util::ExecuteWithPrivilegesAndWait( | 849 OSStatus status = base::mac::ExecuteWithPrivilegesAndWait( |
850 authorization, | 850 authorization, |
851 preflightPathC, | 851 preflightPathC, |
852 kAuthorizationFlagDefaults, | 852 kAuthorizationFlagDefaults, |
853 arguments, | 853 arguments, |
854 NULL, // pipe | 854 NULL, // pipe |
855 &exit_status); | 855 &exit_status); |
856 if (status != errAuthorizationSuccess) { | 856 if (status != errAuthorizationSuccess) { |
857 OSSTATUS_LOG(ERROR, status) | 857 OSSTATUS_LOG(ERROR, status) |
858 << "AuthorizationExecuteWithPrivileges preflight"; | 858 << "AuthorizationExecuteWithPrivileges preflight"; |
859 [self updateStatus:kAutoupdatePromoteFailed version:nil]; | 859 [self updateStatus:kAutoupdatePromoteFailed version:nil]; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 PerformBridge::PostPerform(self, selector, toolPath); | 927 PerformBridge::PostPerform(self, selector, toolPath); |
928 } | 928 } |
929 | 929 |
930 - (void)changePermissionsForPromotionWithTool:(NSString*)toolPath { | 930 - (void)changePermissionsForPromotionWithTool:(NSString*)toolPath { |
931 const char* toolPathC = [toolPath fileSystemRepresentation]; | 931 const char* toolPathC = [toolPath fileSystemRepresentation]; |
932 | 932 |
933 const char* appPathC = [appPath_ fileSystemRepresentation]; | 933 const char* appPathC = [appPath_ fileSystemRepresentation]; |
934 const char* arguments[] = {appPathC, NULL}; | 934 const char* arguments[] = {appPathC, NULL}; |
935 | 935 |
936 int exit_status; | 936 int exit_status; |
937 OSStatus status = authorization_util::ExecuteWithPrivilegesAndWait( | 937 OSStatus status = base::mac::ExecuteWithPrivilegesAndWait( |
938 authorization_, | 938 authorization_, |
939 toolPathC, | 939 toolPathC, |
940 kAuthorizationFlagDefaults, | 940 kAuthorizationFlagDefaults, |
941 arguments, | 941 arguments, |
942 NULL, // pipe | 942 NULL, // pipe |
943 &exit_status); | 943 &exit_status); |
944 if (status != errAuthorizationSuccess) { | 944 if (status != errAuthorizationSuccess) { |
945 OSSTATUS_LOG(ERROR, status) | 945 OSSTATUS_LOG(ERROR, status) |
946 << "AuthorizationExecuteWithPrivileges postflight"; | 946 << "AuthorizationExecuteWithPrivileges postflight"; |
947 } else if (exit_status != 0) { | 947 } else if (exit_status != 0) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 return [KeystoneGlue defaultKeystoneGlue] != nil; | 1002 return [KeystoneGlue defaultKeystoneGlue] != nil; |
1003 } | 1003 } |
1004 | 1004 |
1005 string16 CurrentlyInstalledVersion() { | 1005 string16 CurrentlyInstalledVersion() { |
1006 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; | 1006 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; |
1007 NSString* version = [keystoneGlue currentlyInstalledVersion]; | 1007 NSString* version = [keystoneGlue currentlyInstalledVersion]; |
1008 return base::SysNSStringToUTF16(version); | 1008 return base::SysNSStringToUTF16(version); |
1009 } | 1009 } |
1010 | 1010 |
1011 } // namespace keystone_glue | 1011 } // namespace keystone_glue |
OLD | NEW |