| OLD | NEW |
| 1 // Copyright (c) 2011 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 "chrome/browser/mac/authorization_util.h" | 5 #include "chrome/browser/mac/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 #include "base/mac/bundle_locations.h" | 15 #include "base/mac/bundle_locations.h" |
| 16 #include "base/mac/mac_logging.h" |
| 16 #import "base/mac/mac_util.h" | 17 #import "base/mac/mac_util.h" |
| 17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 #include "chrome/browser/mac/scoped_authorizationref.h" | 20 #include "chrome/browser/mac/scoped_authorizationref.h" |
| 20 | 21 |
| 21 namespace authorization_util { | 22 namespace authorization_util { |
| 22 | 23 |
| 23 AuthorizationRef AuthorizationCreateToRunAsRoot(CFStringRef prompt) { | 24 AuthorizationRef AuthorizationCreateToRunAsRoot(CFStringRef prompt) { |
| 24 // Create an empty AuthorizationRef. | 25 // Create an empty AuthorizationRef. |
| 25 ScopedAuthorizationRef authorization; | 26 ScopedAuthorizationRef authorization; |
| 26 OSStatus status = AuthorizationCreate(NULL, | 27 OSStatus status = AuthorizationCreate(NULL, |
| 27 kAuthorizationEmptyEnvironment, | 28 kAuthorizationEmptyEnvironment, |
| 28 kAuthorizationFlagDefaults, | 29 kAuthorizationFlagDefaults, |
| 29 &authorization); | 30 &authorization); |
| 30 if (status != errAuthorizationSuccess) { | 31 if (status != errAuthorizationSuccess) { |
| 31 LOG(ERROR) << "AuthorizationCreate: " << status; | 32 OSSTATUS_LOG(ERROR, status) << "AuthorizationCreate"; |
| 32 return NULL; | 33 return NULL; |
| 33 } | 34 } |
| 34 | 35 |
| 35 // Specify the "system.privilege.admin" right, which allows | 36 // Specify the "system.privilege.admin" right, which allows |
| 36 // AuthorizationExecuteWithPrivileges to run commands as root. | 37 // AuthorizationExecuteWithPrivileges to run commands as root. |
| 37 AuthorizationItem right_items[] = { | 38 AuthorizationItem right_items[] = { |
| 38 {kAuthorizationRightExecute, 0, NULL, 0} | 39 {kAuthorizationRightExecute, 0, NULL, 0} |
| 39 }; | 40 }; |
| 40 AuthorizationRights rights = {arraysize(right_items), right_items}; | 41 AuthorizationRights rights = {arraysize(right_items), right_items}; |
| 41 | 42 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 66 kAuthorizationFlagExtendRights | | 67 kAuthorizationFlagExtendRights | |
| 67 kAuthorizationFlagPreAuthorize; | 68 kAuthorizationFlagPreAuthorize; |
| 68 | 69 |
| 69 status = AuthorizationCopyRights(authorization, | 70 status = AuthorizationCopyRights(authorization, |
| 70 &rights, | 71 &rights, |
| 71 &environment, | 72 &environment, |
| 72 flags, | 73 flags, |
| 73 NULL); | 74 NULL); |
| 74 if (status != errAuthorizationSuccess) { | 75 if (status != errAuthorizationSuccess) { |
| 75 if (status != errAuthorizationCanceled) { | 76 if (status != errAuthorizationCanceled) { |
| 76 LOG(ERROR) << "AuthorizationCopyRights: " << status; | 77 OSSTATUS_LOG(ERROR, status) << "AuthorizationCopyRights"; |
| 77 } | 78 } |
| 78 return NULL; | 79 return NULL; |
| 79 } | 80 } |
| 80 | 81 |
| 81 return authorization.release(); | 82 return authorization.release(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization, | 85 OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization, |
| 85 const char* tool_path, | 86 const char* tool_path, |
| 86 AuthorizationFlags options, | 87 AuthorizationFlags options, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 *exit_status_pointer = -1; | 176 *exit_status_pointer = -1; |
| 176 } | 177 } |
| 177 } else { | 178 } else { |
| 178 *exit_status_pointer = -1; | 179 *exit_status_pointer = -1; |
| 179 } | 180 } |
| 180 | 181 |
| 181 return status; | 182 return status; |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace authorization_util | 185 } // namespace authorization_util |
| OLD | NEW |