OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller_app.h" |
| 6 |
| 7 #import <Cocoa/Cocoa.h> |
| 8 |
| 9 #include "base/mac/scoped_authorizationref.h" |
| 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "remoting/host/installer/mac/uninstaller/remoting_uninstaller.h" |
| 12 |
| 13 @implementation RemotingUninstallerAppDelegate |
| 14 |
| 15 - (void)dealloc { |
| 16 [super dealloc]; |
| 17 } |
| 18 |
| 19 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { |
| 20 } |
| 21 |
| 22 - (void)messageBox:(const char*)message { |
| 23 base::mac::ScopedCFTypeRef<CFStringRef> message_ref( |
| 24 CFStringCreateWithCString(kCFAllocatorDefault, message, |
| 25 kCFStringEncodingUTF8)); |
| 26 CFOptionFlags result; |
| 27 CFUserNotificationDisplayAlert(0, kCFUserNotificationNoteAlertLevel, |
| 28 NULL, NULL, NULL, |
| 29 CFSTR("Chrome Remote Desktop Uninstaller"), |
| 30 message_ref, NULL, NULL, NULL, &result); |
| 31 } |
| 32 |
| 33 - (IBAction)uninstall:(NSButton*)sender { |
| 34 base::mac::ScopedAuthorizationRef authRef; |
| 35 |
| 36 NSLog(@"Chrome Remote Desktop uninstall starting."); |
| 37 |
| 38 @try { |
| 39 OSStatus status; |
| 40 status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, |
| 41 kAuthorizationFlagDefaults, &authRef); |
| 42 if (status != errAuthorizationSuccess) { |
| 43 [NSException raise:@"AuthorizationCreate Failure" |
| 44 format:@"Error during AuthorizationCreate status=%ld", status]; |
| 45 } |
| 46 |
| 47 AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0}; |
| 48 AuthorizationRights rights = {1, &right}; |
| 49 AuthorizationFlags flags = kAuthorizationFlagDefaults | |
| 50 kAuthorizationFlagInteractionAllowed | |
| 51 kAuthorizationFlagPreAuthorize | |
| 52 kAuthorizationFlagExtendRights; |
| 53 status = AuthorizationCopyRights(authRef, &rights, NULL, flags, NULL); |
| 54 if (status == errAuthorizationCanceled) { |
| 55 NSLog(@"Chrome Remote Desktop Host uninstall canceled."); |
| 56 const char* message = "Chrome Remote Desktop Host uninstall canceled."; |
| 57 [self messageBox:message]; |
| 58 } else if (status == errAuthorizationSuccess) { |
| 59 RemotingUninstaller* uninstaller = |
| 60 [[[RemotingUninstaller alloc] init] autorelease]; |
| 61 [uninstaller remotingUninstallUsingAuth:authRef]; |
| 62 |
| 63 NSLog(@"Chrome Remote Desktop Host uninstall complete."); |
| 64 const char* message = |
| 65 "Chrome Remote Desktop Host was successfully uninstalled."; |
| 66 [self messageBox:message]; |
| 67 } else { |
| 68 [NSException raise:@"AuthorizationCopyRights Failure" |
| 69 format:@"Error during AuthorizationCopyRights status=%ld", status]; |
| 70 } |
| 71 } |
| 72 @catch (NSException* exception) { |
| 73 NSLog(@"Exception %@ %@", [exception name], [exception reason]); |
| 74 const char* message = |
| 75 "Error! Unable to uninstall Chrome Remote Desktop Host."; |
| 76 [self messageBox:message]; |
| 77 } |
| 78 |
| 79 [NSApp terminate:self]; |
| 80 } |
| 81 |
| 82 - (IBAction)cancel:(id)sender { |
| 83 [NSApp terminate:self]; |
| 84 } |
| 85 |
| 86 - (IBAction)handleMenuClose:(NSMenuItem*)sender { |
| 87 [NSApp terminate:self]; |
| 88 } |
| 89 |
| 90 @end |
| 91 |
| 92 int main(int argc, char* argv[]) |
| 93 { |
| 94 // If we're launched as root, then skip the elevation and UI confirmations. |
| 95 // This is provided as a convenience for our automated testing. |
| 96 int euid = geteuid(); |
| 97 if (euid == 0) { |
| 98 @autoreleasepool { |
| 99 NSLog(@"Running as euid=0. Suppressing UI and elevation prompts."); |
| 100 |
| 101 RemotingUninstaller* uninstaller = |
| 102 [[[RemotingUninstaller alloc] init] autorelease]; |
| 103 [uninstaller remotingUninstallUsingAuth:nil]; |
| 104 |
| 105 NSLog(@"Chrome Remote Desktop Host uninstall complete."); |
| 106 return 0; |
| 107 } |
| 108 } else { |
| 109 return NSApplicationMain(argc, (const char**)argv); |
| 110 } |
| 111 } |
| 112 |
OLD | NEW |