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

Side by Side Diff: remoting/host/installer/mac/uninstaller/remoting_uninstaller.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
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 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller.h" 5 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_authorizationref.h" 9 #include "base/mac/scoped_authorizationref.h"
10 #include "remoting/host/constants_mac.h" 10 #include "remoting/host/constants_mac.h"
11 11
12 12
13 void logOutput(FILE* pipe) { 13 void logOutput(FILE* pipe) {
14 char readBuffer[128]; 14 char readBuffer[128];
15 for (;;) { 15 for (;;) {
16 long bytesRead = read(fileno(pipe), readBuffer, sizeof(readBuffer) - 1); 16 long bytesRead = read(fileno(pipe), readBuffer, sizeof(readBuffer) - 1);
17 if (bytesRead < 1) 17 if (bytesRead < 1)
18 break; 18 break;
19 readBuffer[bytesRead] = '\0'; 19 readBuffer[bytesRead] = '\0';
20 NSLog(@"%s", readBuffer); 20 NSLog(@"%s", readBuffer);
21 } 21 }
22 } 22 }
23 23
24 NSArray* convertToNSArray(const char** array) { 24 NSArray* convertToNSArray(const char** array) {
25 NSMutableArray* ns_array = [[[NSMutableArray alloc] init] autorelease]; 25 NSMutableArray* ns_array = [[[NSMutableArray alloc] init] autorelease];
26 int i = 0; 26 int i = 0;
27 const char* element = array[i++]; 27 const char* element = array[i++];
28 while (element != NULL) { 28 while (element != nullptr) {
29 [ns_array addObject:[NSString stringWithUTF8String:element]]; 29 [ns_array addObject:[NSString stringWithUTF8String:element]];
30 element = array[i++]; 30 element = array[i++];
31 } 31 }
32 return ns_array; 32 return ns_array;
33 } 33 }
34 34
35 @implementation RemotingUninstaller 35 @implementation RemotingUninstaller
36 36
37 // Keystone 37 // Keystone
38 const char kKeystoneAdmin[] = "/Library/Google/GoogleSoftwareUpdate/" 38 const char kKeystoneAdmin[] = "/Library/Google/GoogleSoftwareUpdate/"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 NSLog(@"Exception %@ %@", [exception name], [exception reason]); 78 NSLog(@"Exception %@ %@", [exception name], [exception reason]);
79 } 79 }
80 } 80 }
81 81
82 - (void)sudoCommand:(const char*)cmd 82 - (void)sudoCommand:(const char*)cmd
83 withArguments:(const char**)args 83 withArguments:(const char**)args
84 usingAuth:(AuthorizationRef)authRef { 84 usingAuth:(AuthorizationRef)authRef {
85 NSArray* arg_array = convertToNSArray(args); 85 NSArray* arg_array = convertToNSArray(args);
86 NSLog(@"Executing (as Admin): %s %@", cmd, 86 NSLog(@"Executing (as Admin): %s %@", cmd,
87 [arg_array componentsJoinedByString:@" "]); 87 [arg_array componentsJoinedByString:@" "]);
88 FILE* pipe = NULL; 88 FILE* pipe = nullptr;
89 OSStatus status; 89 OSStatus status;
90 status = AuthorizationExecuteWithPrivileges(authRef, cmd, 90 status = AuthorizationExecuteWithPrivileges(authRef, cmd,
91 kAuthorizationFlagDefaults, 91 kAuthorizationFlagDefaults,
92 (char* const*)args, 92 (char* const*)args,
93 &pipe); 93 &pipe);
94 94
95 if (status == errAuthorizationToolExecuteFailure) { 95 if (status == errAuthorizationToolExecuteFailure) {
96 NSLog(@"Error errAuthorizationToolExecuteFailure"); 96 NSLog(@"Error errAuthorizationToolExecuteFailure");
97 } else if (status != errAuthorizationSuccess) { 97 } else if (status != errAuthorizationSuccess) {
98 NSLog(@"Error while executing %s. Status=%d", 98 NSLog(@"Error while executing %s. Status=%d",
99 cmd, static_cast<int>(status)); 99 cmd, static_cast<int>(status));
100 } else { 100 } else {
101 logOutput(pipe); 101 logOutput(pipe);
102 } 102 }
103 103
104 if (pipe != NULL) 104 if (pipe != nullptr)
105 fclose(pipe); 105 fclose(pipe);
106 } 106 }
107 107
108 - (void)sudoDelete:(const char*)filename 108 - (void)sudoDelete:(const char*)filename
109 usingAuth:(AuthorizationRef)authRef { 109 usingAuth:(AuthorizationRef)authRef {
110 const char* args[] = { "-rf", filename, NULL }; 110 const char* args[] = { "-rf", filename, nullptr };
111 [self sudoCommand:"/bin/rm" withArguments:args usingAuth:authRef]; 111 [self sudoCommand:"/bin/rm" withArguments:args usingAuth:authRef];
112 } 112 }
113 113
114 - (void)shutdownService { 114 - (void)shutdownService {
115 const char* launchCtl = "/bin/launchctl"; 115 const char* launchCtl = "/bin/launchctl";
116 const char* argsStop[] = { "stop", remoting::kServiceName, NULL }; 116 const char* argsStop[] = { "stop", remoting::kServiceName, nullptr };
117 [self runCommand:launchCtl withArguments:argsStop]; 117 [self runCommand:launchCtl withArguments:argsStop];
118 118
119 if ([[NSFileManager defaultManager] fileExistsAtPath: 119 if ([[NSFileManager defaultManager] fileExistsAtPath:
120 [NSString stringWithUTF8String:remoting::kServicePlistPath]]) { 120 [NSString stringWithUTF8String:remoting::kServicePlistPath]]) {
121 const char* argsUnload[] = { "unload", "-w", "-S", "Aqua", 121 const char* argsUnload[] = { "unload", "-w", "-S", "Aqua",
122 remoting::kServicePlistPath, NULL }; 122 remoting::kServicePlistPath, nullptr };
123 [self runCommand:launchCtl withArguments:argsUnload]; 123 [self runCommand:launchCtl withArguments:argsUnload];
124 } 124 }
125 } 125 }
126 126
127 - (void)keystoneUnregisterUsingAuth:(AuthorizationRef)authRef { 127 - (void)keystoneUnregisterUsingAuth:(AuthorizationRef)authRef {
128 const char* args[] = { "--delete", "--productid", kKeystonePID, "-S", NULL }; 128 const char* args[] = {"--delete", "--productid", kKeystonePID, "-S", nullptr};
129 [self sudoCommand:kKeystoneAdmin withArguments:args usingAuth:authRef]; 129 [self sudoCommand:kKeystoneAdmin withArguments:args usingAuth:authRef];
130 } 130 }
131 131
132 - (void)remotingUninstallUsingAuth:(AuthorizationRef)authRef { 132 - (void)remotingUninstallUsingAuth:(AuthorizationRef)authRef {
133 // Remove the enabled file before shutting down the service or else it might 133 // Remove the enabled file before shutting down the service or else it might
134 // restart itself. 134 // restart itself.
135 [self sudoDelete:remoting::kHostEnabledPath usingAuth:authRef]; 135 [self sudoDelete:remoting::kHostEnabledPath usingAuth:authRef];
136 136
137 [self shutdownService]; 137 [self shutdownService];
138 138
139 [self sudoDelete:remoting::kServicePlistPath usingAuth:authRef]; 139 [self sudoDelete:remoting::kServicePlistPath usingAuth:authRef];
140 [self sudoDelete:remoting::kHostBinaryPath usingAuth:authRef]; 140 [self sudoDelete:remoting::kHostBinaryPath usingAuth:authRef];
141 [self sudoDelete:remoting::kHostHelperScriptPath usingAuth:authRef]; 141 [self sudoDelete:remoting::kHostHelperScriptPath usingAuth:authRef];
142 [self sudoDelete:remoting::kHostConfigFilePath usingAuth:authRef]; 142 [self sudoDelete:remoting::kHostConfigFilePath usingAuth:authRef];
143 [self sudoDelete:remoting::kPrefPaneFilePath usingAuth:authRef]; 143 [self sudoDelete:remoting::kPrefPaneFilePath usingAuth:authRef];
144 [self sudoDelete:remoting::kLogFilePath usingAuth:authRef]; 144 [self sudoDelete:remoting::kLogFilePath usingAuth:authRef];
145 [self sudoDelete:remoting::kLogFileConfigPath usingAuth:authRef]; 145 [self sudoDelete:remoting::kLogFileConfigPath usingAuth:authRef];
146 [self sudoDelete:remoting::kNativeMessagingManifestPath usingAuth:authRef]; 146 [self sudoDelete:remoting::kNativeMessagingManifestPath usingAuth:authRef];
147 [self sudoDelete:remoting::kBrandedUninstallerPath usingAuth:authRef]; 147 [self sudoDelete:remoting::kBrandedUninstallerPath usingAuth:authRef];
148 [self sudoDelete:remoting::kUnbrandedUninstallerPath usingAuth:authRef]; 148 [self sudoDelete:remoting::kUnbrandedUninstallerPath usingAuth:authRef];
149 149
150 [self keystoneUnregisterUsingAuth:authRef]; 150 [self keystoneUnregisterUsingAuth:authRef];
151 } 151 }
152 152
153 - (OSStatus)remotingUninstall { 153 - (OSStatus)remotingUninstall {
154 base::mac::ScopedAuthorizationRef authRef; 154 base::mac::ScopedAuthorizationRef authRef;
155 OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, 155 OSStatus status = AuthorizationCreate(nullptr, kAuthorizationEmptyEnvironment,
156 kAuthorizationFlagDefaults, &authRef); 156 kAuthorizationFlagDefaults, &authRef);
157 if (status != errAuthorizationSuccess) { 157 if (status != errAuthorizationSuccess) {
158 [NSException raise:@"AuthorizationCreate Failure" 158 [NSException raise:@"AuthorizationCreate Failure"
159 format:@"Error during AuthorizationCreate status=%d", 159 format:@"Error during AuthorizationCreate status=%d",
160 static_cast<int>(status)]; 160 static_cast<int>(status)];
161 } 161 }
162 162
163 AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0}; 163 AuthorizationItem right = {kAuthorizationRightExecute, 0, nullptr, 0};
164 AuthorizationRights rights = {1, &right}; 164 AuthorizationRights rights = {1, &right};
165 AuthorizationFlags flags = kAuthorizationFlagDefaults | 165 AuthorizationFlags flags = kAuthorizationFlagDefaults |
166 kAuthorizationFlagInteractionAllowed | 166 kAuthorizationFlagInteractionAllowed |
167 kAuthorizationFlagPreAuthorize | 167 kAuthorizationFlagPreAuthorize |
168 kAuthorizationFlagExtendRights; 168 kAuthorizationFlagExtendRights;
169 status = AuthorizationCopyRights(authRef, &rights, NULL, flags, NULL); 169 status = AuthorizationCopyRights(authRef, &rights, nullptr, flags, nullptr);
170 if (status == errAuthorizationSuccess) { 170 if (status == errAuthorizationSuccess) {
171 RemotingUninstaller* uninstaller = 171 RemotingUninstaller* uninstaller =
172 [[[RemotingUninstaller alloc] init] autorelease]; 172 [[[RemotingUninstaller alloc] init] autorelease];
173 [uninstaller remotingUninstallUsingAuth:authRef]; 173 [uninstaller remotingUninstallUsingAuth:authRef];
174 } 174 }
175 return status; 175 return status;
176 } 176 }
177 177
178 @end 178 @end
OLDNEW
« no previous file with comments | « remoting/host/input_injector_x11.cc ('k') | remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698