diff options
author | erikchen <erikchen@chromium.org> | 2016-03-08 17:50:34 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-09 01:52:22 +0000 |
commit | 8aef985913eecbaec3866825f4d502d96a321c2e (patch) | |
tree | 173fdbae515cd062e298202b37dcf058134383f3 /remoting/host | |
parent | b5e21461a3ca9bb8e59f53870883e84c7229c47c (diff) | |
download | chromium_src-8aef985913eecbaec3866825f4d502d96a321c2e.zip chromium_src-8aef985913eecbaec3866825f4d502d96a321c2e.tar.gz chromium_src-8aef985913eecbaec3866825f4d502d96a321c2e.tar.bz2 |
Prepare remoting/ for compilation with OS X 10.7 deployment target.
Now that base/ compiles as a 64-bit target, there is no reason for remoting/ to
duplicate logic. The logic in base/ has been updated to not emit compile
warning when compiling with a OS X 10.7 deployment target.
BUG=592663
Review URL: https://codereview.chromium.org/1778763002
Cr-Commit-Position: refs/heads/master@{#380027}
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm | 8 | ||||
-rw-r--r-- | remoting/host/mac/me2me_preference_pane.mm | 135 |
2 files changed, 5 insertions, 138 deletions
diff --git a/remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm b/remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm index 7734d23..119f1b3 100644 --- a/remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm +++ b/remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm @@ -6,6 +6,7 @@ #import <Cocoa/Cocoa.h> +#include "base/mac/authorization_util.h" #include "base/mac/scoped_authorizationref.h" #include "remoting/host/constants_mac.h" @@ -86,11 +87,8 @@ const char kKeystonePID[] = "com.google.chrome_remote_desktop"; NSLog(@"Executing (as Admin): %s %@", cmd, [arg_array componentsJoinedByString:@" "]); FILE* pipe = nullptr; - OSStatus status; - status = AuthorizationExecuteWithPrivileges(authRef, cmd, - kAuthorizationFlagDefaults, - (char* const*)args, - &pipe); + OSStatus status = base::mac::ExecuteWithPrivilegesAndGetPID( + authRef, cmd, kAuthorizationFlagDefaults, args, &pipe, nullptr); if (status == errAuthorizationToolExecuteFailure) { NSLog(@"Error errAuthorizationToolExecuteFailure"); diff --git a/remoting/host/mac/me2me_preference_pane.mm b/remoting/host/mac/me2me_preference_pane.mm index 508f5cd..c4d8317 100644 --- a/remoting/host/mac/me2me_preference_pane.mm +++ b/remoting/host/mac/me2me_preference_pane.mm @@ -16,6 +16,8 @@ #include <fstream> +#include "base/mac/authorization_util.h" +#include "base/mac/launchd.h" #include "base/mac/mac_logging.h" #include "base/mac/scoped_launch_data.h" #include "base/memory/scoped_ptr.h" @@ -49,139 +51,6 @@ bool IsConfigValid(const remoting::JsonHostConfig* config) { } // namespace -// These methods are copied from base/mac, but with the logging changed to use -// NSLog(). -// -// TODO(lambroslambrou): Once the "base" target supports building for 64-bit -// on Mac OS X, remove these implementations and use the ones in base/mac. -namespace base { -namespace mac { - -// MessageForJob sends a single message to launchd with a simple dictionary -// mapping |operation| to |job_label|, and returns the result of calling -// launch_msg to send that message. On failure, returns nullptr. The caller -// assumes ownership of the returned launch_data_t object. -launch_data_t MessageForJob(const std::string& job_label, - const char* operation) { - // launch_data_alloc returns something that needs to be freed. - ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY)); - if (!message.is_valid()) { - NSLog(@"launch_data_alloc"); - return nullptr; - } - - // launch_data_new_string returns something that needs to be freed, but - // the dictionary will assume ownership when launch_data_dict_insert is - // called, so put it in a scoper and .release() it when given to the - // dictionary. - ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str())); - if (!job_label_launchd.is_valid()) { - NSLog(@"launch_data_new_string"); - return nullptr; - } - - if (!launch_data_dict_insert(message.get(), - job_label_launchd.release(), - operation)) { - return nullptr; - } - - return launch_msg(message.get()); -} - -pid_t PIDForJob(const std::string& job_label) { - ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB)); - if (!response.is_valid()) { - return -1; - } - - launch_data_type_t response_type = launch_data_get_type(response.get()); - if (response_type != LAUNCH_DATA_DICTIONARY) { - if (response_type == LAUNCH_DATA_ERRNO) { - NSLog(@"PIDForJob: error %d", launch_data_get_errno(response.get())); - } else { - NSLog(@"PIDForJob: expected dictionary, got %d", response_type); - } - return -1; - } - - launch_data_t pid_data = launch_data_dict_lookup(response.get(), - LAUNCH_JOBKEY_PID); - if (!pid_data) - return 0; - - if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) { - NSLog(@"PIDForJob: expected integer"); - return -1; - } - - return launch_data_get_integer(pid_data); -} - -OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization, - const char* tool_path, - AuthorizationFlags options, - const char** arguments, - FILE** pipe, - pid_t* pid) { - // pipe may be nullptr, but this function needs one. In that case, use a - // local pipe. - FILE* local_pipe; - FILE** pipe_pointer; - if (pipe) { - pipe_pointer = pipe; - } else { - pipe_pointer = &local_pipe; - } - - // AuthorizationExecuteWithPrivileges wants |char* const*| for |arguments|, - // but it doesn't actually modify the arguments, and that type is kind of - // silly and callers probably aren't dealing with that. Put the cast here - // to make things a little easier on callers. - OSStatus status = AuthorizationExecuteWithPrivileges(authorization, - tool_path, - options, - (char* const*)arguments, - pipe_pointer); - if (status != errAuthorizationSuccess) { - return status; - } - - long line_pid = -1; - size_t line_length = 0; - char* line_c = fgetln(*pipe_pointer, &line_length); - if (line_c) { - if (line_length > 0 && line_c[line_length - 1] == '\n') { - // line_c + line_length is the start of the next line if there is one. - // Back up one character. - --line_length; - } - std::string line(line_c, line_length); - - // The version in base/mac used base::StringToInt() here. - line_pid = strtol(line.c_str(), nullptr, 10); - if (line_pid == 0) { - NSLog(@"ExecuteWithPrivilegesAndGetPid: funny line: %s", line.c_str()); - line_pid = -1; - } - } else { - NSLog(@"ExecuteWithPrivilegesAndGetPid: no line"); - } - - if (!pipe) { - fclose(*pipe_pointer); - } - - if (pid) { - *pid = line_pid; - } - - return status; -} - -} // namespace mac -} // namespace base - namespace remoting { JsonHostConfig::JsonHostConfig(const std::string& filename) |