Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: remoting/host/mac/me2me_preference_pane.mm

Issue 1778763002: Prepare remoting/ for compilation with OS X 10.7 deployment target. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp89_107_base4
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "remoting/host/mac/me2me_preference_pane.h" 5 #import "remoting/host/mac/me2me_preference_pane.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <CommonCrypto/CommonHMAC.h> 8 #include <CommonCrypto/CommonHMAC.h>
9 #include <errno.h> 9 #include <errno.h>
10 #include <launch.h> 10 #include <launch.h>
11 #import <PreferencePanes/PreferencePanes.h> 11 #import <PreferencePanes/PreferencePanes.h>
12 #import <SecurityInterface/SFAuthorizationView.h> 12 #import <SecurityInterface/SFAuthorizationView.h>
13 #include <stddef.h> 13 #include <stddef.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <unistd.h> 15 #include <unistd.h>
16 16
17 #include <fstream> 17 #include <fstream>
18 18
19 #include "base/mac/authorization_util.h"
20 #include "base/mac/launchd.h"
19 #include "base/mac/mac_logging.h" 21 #include "base/mac/mac_logging.h"
20 #include "base/mac/scoped_launch_data.h" 22 #include "base/mac/scoped_launch_data.h"
21 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
22 #include "base/posix/eintr_wrapper.h" 24 #include "base/posix/eintr_wrapper.h"
23 #include "remoting/host/constants_mac.h" 25 #include "remoting/host/constants_mac.h"
24 #include "remoting/host/host_config.h" 26 #include "remoting/host/host_config.h"
25 #include "remoting/host/pin_hash.h" 27 #include "remoting/host/pin_hash.h"
26 #import "remoting/host/mac/me2me_preference_pane_confirm_pin.h" 28 #import "remoting/host/mac/me2me_preference_pane_confirm_pin.h"
27 #import "remoting/host/mac/me2me_preference_pane_disable.h" 29 #import "remoting/host/mac/me2me_preference_pane_disable.h"
28 #include "third_party/jsoncpp/source/include/json/reader.h" 30 #include "third_party/jsoncpp/source/include/json/reader.h"
(...skipping 13 matching lines...) Expand all
42 44
43 bool IsConfigValid(const remoting::JsonHostConfig* config) { 45 bool IsConfigValid(const remoting::JsonHostConfig* config) {
44 std::string value; 46 std::string value;
45 return (config->GetString(remoting::kHostIdConfigPath, &value) && 47 return (config->GetString(remoting::kHostIdConfigPath, &value) &&
46 config->GetString(remoting::kHostSecretHashConfigPath, &value) && 48 config->GetString(remoting::kHostSecretHashConfigPath, &value) &&
47 config->GetString(remoting::kXmppLoginConfigPath, &value)); 49 config->GetString(remoting::kXmppLoginConfigPath, &value));
48 } 50 }
49 51
50 } // namespace 52 } // namespace
51 53
52 // These methods are copied from base/mac, but with the logging changed to use
53 // NSLog().
54 //
55 // TODO(lambroslambrou): Once the "base" target supports building for 64-bit
56 // on Mac OS X, remove these implementations and use the ones in base/mac.
57 namespace base {
58 namespace mac {
59
60 // MessageForJob sends a single message to launchd with a simple dictionary
61 // mapping |operation| to |job_label|, and returns the result of calling
62 // launch_msg to send that message. On failure, returns nullptr. The caller
63 // assumes ownership of the returned launch_data_t object.
64 launch_data_t MessageForJob(const std::string& job_label,
65 const char* operation) {
66 // launch_data_alloc returns something that needs to be freed.
67 ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
68 if (!message.is_valid()) {
69 NSLog(@"launch_data_alloc");
70 return nullptr;
71 }
72
73 // launch_data_new_string returns something that needs to be freed, but
74 // the dictionary will assume ownership when launch_data_dict_insert is
75 // called, so put it in a scoper and .release() it when given to the
76 // dictionary.
77 ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
78 if (!job_label_launchd.is_valid()) {
79 NSLog(@"launch_data_new_string");
80 return nullptr;
81 }
82
83 if (!launch_data_dict_insert(message.get(),
84 job_label_launchd.release(),
85 operation)) {
86 return nullptr;
87 }
88
89 return launch_msg(message.get());
90 }
91
92 pid_t PIDForJob(const std::string& job_label) {
93 ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
94 if (!response.is_valid()) {
95 return -1;
96 }
97
98 launch_data_type_t response_type = launch_data_get_type(response.get());
99 if (response_type != LAUNCH_DATA_DICTIONARY) {
100 if (response_type == LAUNCH_DATA_ERRNO) {
101 NSLog(@"PIDForJob: error %d", launch_data_get_errno(response.get()));
102 } else {
103 NSLog(@"PIDForJob: expected dictionary, got %d", response_type);
104 }
105 return -1;
106 }
107
108 launch_data_t pid_data = launch_data_dict_lookup(response.get(),
109 LAUNCH_JOBKEY_PID);
110 if (!pid_data)
111 return 0;
112
113 if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) {
114 NSLog(@"PIDForJob: expected integer");
115 return -1;
116 }
117
118 return launch_data_get_integer(pid_data);
119 }
120
121 OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization,
122 const char* tool_path,
123 AuthorizationFlags options,
124 const char** arguments,
125 FILE** pipe,
126 pid_t* pid) {
127 // pipe may be nullptr, but this function needs one. In that case, use a
128 // local pipe.
129 FILE* local_pipe;
130 FILE** pipe_pointer;
131 if (pipe) {
132 pipe_pointer = pipe;
133 } else {
134 pipe_pointer = &local_pipe;
135 }
136
137 // AuthorizationExecuteWithPrivileges wants |char* const*| for |arguments|,
138 // but it doesn't actually modify the arguments, and that type is kind of
139 // silly and callers probably aren't dealing with that. Put the cast here
140 // to make things a little easier on callers.
141 OSStatus status = AuthorizationExecuteWithPrivileges(authorization,
142 tool_path,
143 options,
144 (char* const*)arguments,
145 pipe_pointer);
146 if (status != errAuthorizationSuccess) {
147 return status;
148 }
149
150 long line_pid = -1;
151 size_t line_length = 0;
152 char* line_c = fgetln(*pipe_pointer, &line_length);
153 if (line_c) {
154 if (line_length > 0 && line_c[line_length - 1] == '\n') {
155 // line_c + line_length is the start of the next line if there is one.
156 // Back up one character.
157 --line_length;
158 }
159 std::string line(line_c, line_length);
160
161 // The version in base/mac used base::StringToInt() here.
162 line_pid = strtol(line.c_str(), nullptr, 10);
163 if (line_pid == 0) {
164 NSLog(@"ExecuteWithPrivilegesAndGetPid: funny line: %s", line.c_str());
165 line_pid = -1;
166 }
167 } else {
168 NSLog(@"ExecuteWithPrivilegesAndGetPid: no line");
169 }
170
171 if (!pipe) {
172 fclose(*pipe_pointer);
173 }
174
175 if (pid) {
176 *pid = line_pid;
177 }
178
179 return status;
180 }
181
182 } // namespace mac
183 } // namespace base
184
185 namespace remoting { 54 namespace remoting {
186 55
187 JsonHostConfig::JsonHostConfig(const std::string& filename) 56 JsonHostConfig::JsonHostConfig(const std::string& filename)
188 : filename_(filename) { 57 : filename_(filename) {
189 } 58 }
190 59
191 JsonHostConfig::~JsonHostConfig() { 60 JsonHostConfig::~JsonHostConfig() {
192 } 61 }
193 62
194 bool JsonHostConfig::Read() { 63 bool JsonHostConfig::Read() {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; 580 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil];
712 [task setLaunchPath:command]; 581 [task setLaunchPath:command];
713 [task setArguments:arguments]; 582 [task setArguments:arguments];
714 [task setStandardInput:[NSPipe pipe]]; 583 [task setStandardInput:[NSPipe pipe]];
715 [task launch]; 584 [task launch];
716 [task release]; 585 [task release];
717 [NSApp terminate:nil]; 586 [NSApp terminate:nil];
718 } 587 }
719 588
720 @end 589 @end
OLDNEW
« no previous file with comments | « remoting/host/installer/mac/uninstaller/remoting_uninstaller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698