| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/ui/cocoa/authorization_util.h" | 5 #include "chrome/browser/ui/cocoa/authorization_util.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/eintr_wrapper.h" | 13 #include "base/eintr_wrapper.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #import "base/mac_util.h" | 15 #import "base/mac/mac_util.h" |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "chrome/browser/ui/cocoa/scoped_authorizationref.h" | 18 #include "chrome/browser/ui/cocoa/scoped_authorizationref.h" |
| 19 | 19 |
| 20 namespace authorization_util { | 20 namespace authorization_util { |
| 21 | 21 |
| 22 AuthorizationRef AuthorizationCreateToRunAsRoot(CFStringRef prompt) { | 22 AuthorizationRef AuthorizationCreateToRunAsRoot(CFStringRef prompt) { |
| 23 // Create an empty AuthorizationRef. | 23 // Create an empty AuthorizationRef. |
| 24 scoped_AuthorizationRef authorization; | 24 scoped_AuthorizationRef authorization; |
| 25 OSStatus status = AuthorizationCreate(NULL, | 25 OSStatus status = AuthorizationCreate(NULL, |
| 26 kAuthorizationEmptyEnvironment, | 26 kAuthorizationEmptyEnvironment, |
| 27 kAuthorizationFlagDefaults, | 27 kAuthorizationFlagDefaults, |
| 28 &authorization); | 28 &authorization); |
| 29 if (status != errAuthorizationSuccess) { | 29 if (status != errAuthorizationSuccess) { |
| 30 LOG(ERROR) << "AuthorizationCreate: " << status; | 30 LOG(ERROR) << "AuthorizationCreate: " << status; |
| 31 return NULL; | 31 return NULL; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Specify the "system.privilege.admin" right, which allows | 34 // Specify the "system.privilege.admin" right, which allows |
| 35 // AuthorizationExecuteWithPrivileges to run commands as root. | 35 // AuthorizationExecuteWithPrivileges to run commands as root. |
| 36 AuthorizationItem right_items[] = { | 36 AuthorizationItem right_items[] = { |
| 37 {kAuthorizationRightExecute, 0, NULL, 0} | 37 {kAuthorizationRightExecute, 0, NULL, 0} |
| 38 }; | 38 }; |
| 39 AuthorizationRights rights = {arraysize(right_items), right_items}; | 39 AuthorizationRights rights = {arraysize(right_items), right_items}; |
| 40 | 40 |
| 41 // product_logo_32.png is used instead of app.icns because Authorization | 41 // product_logo_32.png is used instead of app.icns because Authorization |
| 42 // Services can't deal with .icns files. | 42 // Services can't deal with .icns files. |
| 43 NSString* icon_path = | 43 NSString* icon_path = |
| 44 [mac_util::MainAppBundle() pathForResource:@"product_logo_32" | 44 [base::mac::MainAppBundle() pathForResource:@"product_logo_32" |
| 45 ofType:@"png"]; | 45 ofType:@"png"]; |
| 46 const char* icon_path_c = [icon_path fileSystemRepresentation]; | 46 const char* icon_path_c = [icon_path fileSystemRepresentation]; |
| 47 size_t icon_path_length = icon_path_c ? strlen(icon_path_c) : 0; | 47 size_t icon_path_length = icon_path_c ? strlen(icon_path_c) : 0; |
| 48 | 48 |
| 49 // The OS will append " Type an administrator's name and password to allow | 49 // The OS will append " Type an administrator's name and password to allow |
| 50 // <CFBundleDisplayName> to make changes." | 50 // <CFBundleDisplayName> to make changes." |
| 51 NSString* prompt_ns = mac_util::CFToNSCast(prompt); | 51 NSString* prompt_ns = base::mac::CFToNSCast(prompt); |
| 52 const char* prompt_c = [prompt_ns UTF8String]; | 52 const char* prompt_c = [prompt_ns UTF8String]; |
| 53 size_t prompt_length = prompt_c ? strlen(prompt_c) : 0; | 53 size_t prompt_length = prompt_c ? strlen(prompt_c) : 0; |
| 54 | 54 |
| 55 AuthorizationItem environment_items[] = { | 55 AuthorizationItem environment_items[] = { |
| 56 {kAuthorizationEnvironmentIcon, icon_path_length, (void*)icon_path_c, 0}, | 56 {kAuthorizationEnvironmentIcon, icon_path_length, (void*)icon_path_c, 0}, |
| 57 {kAuthorizationEnvironmentPrompt, prompt_length, (void*)prompt_c, 0} | 57 {kAuthorizationEnvironmentPrompt, prompt_length, (void*)prompt_c, 0} |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 AuthorizationEnvironment environment = {arraysize(environment_items), | 60 AuthorizationEnvironment environment = {arraysize(environment_items), |
| 61 environment_items}; | 61 environment_items}; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 *exit_status_pointer = -1; | 174 *exit_status_pointer = -1; |
| 175 } | 175 } |
| 176 } else { | 176 } else { |
| 177 *exit_status_pointer = -1; | 177 *exit_status_pointer = -1; |
| 178 } | 178 } |
| 179 | 179 |
| 180 return status; | 180 return status; |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace authorization_util | 183 } // namespace authorization_util |
| OLD | NEW |