| 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 #ifndef BASE_MAC_AUTHORIZATION_UTIL_H_ | 5 #ifndef BASE_MAC_AUTHORIZATION_UTIL_H_ |
| 6 #define BASE_MAC_AUTHORIZATION_UTIL_H_ | 6 #define BASE_MAC_AUTHORIZATION_UTIL_H_ |
| 7 | 7 |
| 8 // AuthorizationExecuteWithPrivileges fork()s and exec()s the tool, but it | 8 // AuthorizationExecuteWithPrivileges fork()s and exec()s the tool, but it |
| 9 // does not wait() for it. It also doesn't provide the caller with access to | 9 // does not wait() for it. It also doesn't provide the caller with access to |
| 10 // the forked pid. If used irresponsibly, zombie processes will accumulate. | 10 // the forked pid. If used irresponsibly, zombie processes will accumulate. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include <CoreFoundation/CoreFoundation.h> | 26 #include <CoreFoundation/CoreFoundation.h> |
| 27 #include <Security/Authorization.h> | 27 #include <Security/Authorization.h> |
| 28 #include <stdio.h> | 28 #include <stdio.h> |
| 29 #include <sys/types.h> | 29 #include <sys/types.h> |
| 30 | 30 |
| 31 #include "base/base_export.h" | 31 #include "base/base_export.h" |
| 32 | 32 |
| 33 namespace base { | 33 namespace base { |
| 34 namespace mac { | 34 namespace mac { |
| 35 | 35 |
| 36 // Obtains an AuthorizationRef that can be used to run commands as root. If | 36 // Obtains an AuthorizationRef for the rights indicated by |rights|. If |
| 37 // necessary, prompts the user for authentication. If the user is prompted, | 37 // necessary, prompts the user for authentication. If the user is prompted, |
| 38 // |prompt| will be used as the prompt string and an icon appropriate for the | 38 // |prompt| will be used as the prompt string and an icon appropriate for the |
| 39 // application will be displayed in a prompt dialog. Note that the system | 39 // application will be displayed in a prompt dialog. Note that the system |
| 40 // appends its own text to the prompt string. Returns NULL on failure. | 40 // appends its own text to the prompt string. |extraFlags| will be ORed |
| 41 // together with the default flags. Returns NULL on failure. |
| 42 BASE_EXPORT |
| 43 AuthorizationRef GetAuthorizationRightsWithPrompt( |
| 44 AuthorizationRights* rights, |
| 45 CFStringRef prompt, |
| 46 AuthorizationFlags extraFlags); |
| 47 |
| 48 // Obtains an AuthorizationRef (using |GetAuthorizationRightsWithPrompt|) that |
| 49 // can be used to run commands as root. |
| 41 BASE_EXPORT | 50 BASE_EXPORT |
| 42 AuthorizationRef AuthorizationCreateToRunAsRoot(CFStringRef prompt); | 51 AuthorizationRef AuthorizationCreateToRunAsRoot(CFStringRef prompt); |
| 43 | 52 |
| 44 // Calls straight through to AuthorizationExecuteWithPrivileges. If that | 53 // Calls straight through to AuthorizationExecuteWithPrivileges. If that |
| 45 // call succeeds, |pid| will be set to the pid of the executed tool. If the | 54 // call succeeds, |pid| will be set to the pid of the executed tool. If the |
| 46 // pid can't be determined, |pid| will be set to -1. |pid| must not be NULL. | 55 // pid can't be determined, |pid| will be set to -1. |pid| must not be NULL. |
| 47 // |pipe| may be NULL, but the tool will always be executed with a pipe in | 56 // |pipe| may be NULL, but the tool will always be executed with a pipe in |
| 48 // order to read the pid from its stdout. | 57 // order to read the pid from its stdout. |
| 49 BASE_EXPORT | 58 BASE_EXPORT |
| 50 OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization, | 59 OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 const char* tool_path, | 73 const char* tool_path, |
| 65 AuthorizationFlags options, | 74 AuthorizationFlags options, |
| 66 const char** arguments, | 75 const char** arguments, |
| 67 FILE** pipe, | 76 FILE** pipe, |
| 68 int* exit_status); | 77 int* exit_status); |
| 69 | 78 |
| 70 } // namespace mac | 79 } // namespace mac |
| 71 } // namespace base | 80 } // namespace base |
| 72 | 81 |
| 73 #endif // BASE_MAC_AUTHORIZATION_UTIL_H_ | 82 #endif // BASE_MAC_AUTHORIZATION_UTIL_H_ |
| OLD | NEW |