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

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

Issue 810133003: replace NULL->nullptr in src/remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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/local_input_monitor_x11.cc ('k') | remoting/host/mouse_clamping_filter.cc » ('j') | 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>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // These methods are copied from base/mac, but with the logging changed to use 95 // These methods are copied from base/mac, but with the logging changed to use
96 // NSLog(). 96 // NSLog().
97 // 97 //
98 // TODO(lambroslambrou): Once the "base" target supports building for 64-bit 98 // TODO(lambroslambrou): Once the "base" target supports building for 64-bit
99 // on Mac OS X, remove these implementations and use the ones in base/mac. 99 // on Mac OS X, remove these implementations and use the ones in base/mac.
100 namespace base { 100 namespace base {
101 namespace mac { 101 namespace mac {
102 102
103 // MessageForJob sends a single message to launchd with a simple dictionary 103 // MessageForJob sends a single message to launchd with a simple dictionary
104 // mapping |operation| to |job_label|, and returns the result of calling 104 // mapping |operation| to |job_label|, and returns the result of calling
105 // launch_msg to send that message. On failure, returns NULL. The caller 105 // launch_msg to send that message. On failure, returns nullptr. The caller
106 // assumes ownership of the returned launch_data_t object. 106 // assumes ownership of the returned launch_data_t object.
107 launch_data_t MessageForJob(const std::string& job_label, 107 launch_data_t MessageForJob(const std::string& job_label,
108 const char* operation) { 108 const char* operation) {
109 // launch_data_alloc returns something that needs to be freed. 109 // launch_data_alloc returns something that needs to be freed.
110 ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY)); 110 ScopedLaunchData message(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
111 if (!message) { 111 if (!message) {
112 NSLog(@"launch_data_alloc"); 112 NSLog(@"launch_data_alloc");
113 return NULL; 113 return nullptr;
114 } 114 }
115 115
116 // launch_data_new_string returns something that needs to be freed, but 116 // launch_data_new_string returns something that needs to be freed, but
117 // the dictionary will assume ownership when launch_data_dict_insert is 117 // the dictionary will assume ownership when launch_data_dict_insert is
118 // called, so put it in a scoper and .release() it when given to the 118 // called, so put it in a scoper and .release() it when given to the
119 // dictionary. 119 // dictionary.
120 ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str())); 120 ScopedLaunchData job_label_launchd(launch_data_new_string(job_label.c_str()));
121 if (!job_label_launchd) { 121 if (!job_label_launchd) {
122 NSLog(@"launch_data_new_string"); 122 NSLog(@"launch_data_new_string");
123 return NULL; 123 return nullptr;
124 } 124 }
125 125
126 if (!launch_data_dict_insert(message, 126 if (!launch_data_dict_insert(message,
127 job_label_launchd.release(), 127 job_label_launchd.release(),
128 operation)) { 128 operation)) {
129 return NULL; 129 return nullptr;
130 } 130 }
131 131
132 return launch_msg(message); 132 return launch_msg(message);
133 } 133 }
134 134
135 pid_t PIDForJob(const std::string& job_label) { 135 pid_t PIDForJob(const std::string& job_label) {
136 ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB)); 136 ScopedLaunchData response(MessageForJob(job_label, LAUNCH_KEY_GETJOB));
137 if (!response) { 137 if (!response) {
138 return -1; 138 return -1;
139 } 139 }
(...skipping 20 matching lines...) Expand all
160 160
161 return launch_data_get_integer(pid_data); 161 return launch_data_get_integer(pid_data);
162 } 162 }
163 163
164 OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization, 164 OSStatus ExecuteWithPrivilegesAndGetPID(AuthorizationRef authorization,
165 const char* tool_path, 165 const char* tool_path,
166 AuthorizationFlags options, 166 AuthorizationFlags options,
167 const char** arguments, 167 const char** arguments,
168 FILE** pipe, 168 FILE** pipe,
169 pid_t* pid) { 169 pid_t* pid) {
170 // pipe may be NULL, but this function needs one. In that case, use a local 170 // pipe may be nullptr, but this function needs one. In that case, use a
171 // pipe. 171 // local pipe.
172 FILE* local_pipe; 172 FILE* local_pipe;
173 FILE** pipe_pointer; 173 FILE** pipe_pointer;
174 if (pipe) { 174 if (pipe) {
175 pipe_pointer = pipe; 175 pipe_pointer = pipe;
176 } else { 176 } else {
177 pipe_pointer = &local_pipe; 177 pipe_pointer = &local_pipe;
178 } 178 }
179 179
180 // AuthorizationExecuteWithPrivileges wants |char* const*| for |arguments|, 180 // AuthorizationExecuteWithPrivileges wants |char* const*| for |arguments|,
181 // but it doesn't actually modify the arguments, and that type is kind of 181 // but it doesn't actually modify the arguments, and that type is kind of
(...skipping 13 matching lines...) Expand all
195 char* line_c = fgetln(*pipe_pointer, &line_length); 195 char* line_c = fgetln(*pipe_pointer, &line_length);
196 if (line_c) { 196 if (line_c) {
197 if (line_length > 0 && line_c[line_length - 1] == '\n') { 197 if (line_length > 0 && line_c[line_length - 1] == '\n') {
198 // line_c + line_length is the start of the next line if there is one. 198 // line_c + line_length is the start of the next line if there is one.
199 // Back up one character. 199 // Back up one character.
200 --line_length; 200 --line_length;
201 } 201 }
202 std::string line(line_c, line_length); 202 std::string line(line_c, line_length);
203 203
204 // The version in base/mac used base::StringToInt() here. 204 // The version in base/mac used base::StringToInt() here.
205 line_pid = strtol(line.c_str(), NULL, 10); 205 line_pid = strtol(line.c_str(), nullptr, 10);
206 if (line_pid == 0) { 206 if (line_pid == 0) {
207 NSLog(@"ExecuteWithPrivilegesAndGetPid: funny line: %s", line.c_str()); 207 NSLog(@"ExecuteWithPrivilegesAndGetPid: funny line: %s", line.c_str());
208 line_pid = -1; 208 line_pid = -1;
209 } 209 }
210 } else { 210 } else {
211 NSLog(@"ExecuteWithPrivilegesAndGetPid: no line"); 211 NSLog(@"ExecuteWithPrivilegesAndGetPid: no line");
212 } 212 }
213 213
214 if (!pipe) { 214 if (!pipe) {
215 fclose(*pipe_pointer); 215 fclose(*pipe_pointer);
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 AuthorizationRef authorization = 546 AuthorizationRef authorization =
547 [[authorization_view_ authorization] authorizationRef]; 547 [[authorization_view_ authorization] authorizationRef];
548 if (!authorization) { 548 if (!authorization) {
549 NSLog(@"Failed to obtain authorizationRef"); 549 NSLog(@"Failed to obtain authorizationRef");
550 return NO; 550 return NO;
551 } 551 }
552 552
553 // TODO(lambroslambrou): Replace the deprecated ExecuteWithPrivileges 553 // TODO(lambroslambrou): Replace the deprecated ExecuteWithPrivileges
554 // call with a launchd-based helper tool, which is more secure. 554 // call with a launchd-based helper tool, which is more secure.
555 // http://crbug.com/120903 555 // http://crbug.com/120903
556 const char* arguments[] = { command, NULL }; 556 const char* arguments[] = { command, nullptr };
557 FILE* pipe = NULL; 557 FILE* pipe = nullptr;
558 pid_t pid; 558 pid_t pid;
559 OSStatus status = base::mac::ExecuteWithPrivilegesAndGetPID( 559 OSStatus status = base::mac::ExecuteWithPrivilegesAndGetPID(
560 authorization, 560 authorization,
561 remoting::kHostHelperScriptPath, 561 remoting::kHostHelperScriptPath,
562 kAuthorizationFlagDefaults, 562 kAuthorizationFlagDefaults,
563 arguments, 563 arguments,
564 &pipe, 564 &pipe,
565 &pid); 565 &pid);
566 if (status != errAuthorizationSuccess) { 566 if (status != errAuthorizationSuccess) {
567 NSLog(@"AuthorizationExecuteWithPrivileges: %s (%d)", 567 NSLog(@"AuthorizationExecuteWithPrivileges: %s (%d)",
568 GetMacOSStatusErrorString(status), static_cast<int>(status)); 568 GetMacOSStatusErrorString(status), static_cast<int>(status));
569 return NO; 569 return NO;
570 } 570 }
571 if (pid == -1) { 571 if (pid == -1) {
572 NSLog(@"Failed to get child PID"); 572 NSLog(@"Failed to get child PID");
573 if (pipe) 573 if (pipe)
574 fclose(pipe); 574 fclose(pipe);
575 575
576 return NO; 576 return NO;
577 } 577 }
578 if (!pipe) { 578 if (!pipe) {
579 NSLog(@"Unexpected NULL pipe"); 579 NSLog(@"Unexpected nullptr pipe");
580 return NO; 580 return NO;
581 } 581 }
582 582
583 // Some cleanup is needed (closing the pipe and waiting for the child 583 // Some cleanup is needed (closing the pipe and waiting for the child
584 // process), so flag any errors before returning. 584 // process), so flag any errors before returning.
585 BOOL error = NO; 585 BOOL error = NO;
586 586
587 if (!input_data.empty()) { 587 if (!input_data.empty()) {
588 size_t bytes_written = fwrite(input_data.data(), sizeof(char), 588 size_t bytes_written = fwrite(input_data.data(), sizeof(char),
589 input_data.size(), pipe); 589 input_data.size(), pipe);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil]; 753 NSArray* arguments = [NSArray arrayWithObjects:@"--relaunch-prefpane", nil];
754 [task setLaunchPath:command]; 754 [task setLaunchPath:command];
755 [task setArguments:arguments]; 755 [task setArguments:arguments];
756 [task setStandardInput:[NSPipe pipe]]; 756 [task setStandardInput:[NSPipe pipe]];
757 [task launch]; 757 [task launch];
758 [task release]; 758 [task release];
759 [NSApp terminate:nil]; 759 [NSApp terminate:nil];
760 } 760 }
761 761
762 @end 762 @end
OLDNEW
« no previous file with comments | « remoting/host/local_input_monitor_x11.cc ('k') | remoting/host/mouse_clamping_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698