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

Unified Diff: chrome/installer/mac/app/AuthorizedInstall.m

Issue 2243863003: Added authorized install with a script to do the copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed to OO design Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/installer/mac/app/AuthorizedInstall.m
diff --git a/chrome/installer/mac/app/AuthorizedInstall.m b/chrome/installer/mac/app/AuthorizedInstall.m
new file mode 100644
index 0000000000000000000000000000000000000000..550f718daf308d51e9cb542aee9277b34703097f
--- /dev/null
+++ b/chrome/installer/mac/app/AuthorizedInstall.m
@@ -0,0 +1,85 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "AuthorizedInstall.h"
+
+@implementation AuthorizedInstall
+
+// Does the setup needed to authorize a tool to run as admin.
+- (BOOL)setUpAuthorization {
+ status_ = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
+ kAuthorizationFlagDefaults, &authRef_);
+
+ AuthorizationItem items = {kAuthorizationRightExecute, 0, NULL, 0};
+ AuthorizationRights rights = {1, &items};
+ AuthorizationFlags flags =
+ kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed |
+ kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;
+
+ status_ = AuthorizationCopyRights(authRef_, &rights, NULL, flags, NULL);
+ return (status_ == errAuthorizationSuccess);
+}
+
+// Starts up the proccess with privileged permissios.
+- (void)startAuthorizedTool:(const char*)toolPath
+ withArguments:(const char**)args {
+ if (status_ != errAuthorizationSuccess)
+ return;
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Anna Zeng 2016/08/18 15:57:16 Mark (mark@chromium.org): Have we tried NSAppleScr
+ status_ = AuthorizationExecuteWithPrivileges(
+ authRef_, toolPath, kAuthorizationFlagDefaults, (char* const*)args,
+ &communicationPipe_);
+#pragma clang diagnostic pop
+}
+
+// Finds the tool to be authorized, Finds the paths needed for the tool to do
+// its job, and starts the process.
+// TODO: Move attemptAuthorizedInstall body into Unpacker method which will
Anna Zeng 2016/08/18 15:57:16 As discussed, we're actually going to have Authori
ivanhernandez 2016/08/22 15:34:49 Done.
+// provide alternative in the case where authorization failed.
+- (BOOL)authorizeInstallationTool {
+ NSString* toolPath =
+ [[NSBundle mainBundle] pathForResource:@"copy_to_disk" ofType:@"sh"];
+ NSFileManager* manager = [NSFileManager defaultManager];
+ if (![manager fileExistsAtPath:toolPath]) {
+ return false;
+ }
+
+ NSString* appBundleName = @"Google Chrome.app";
+
+ NSArray* applicationDirectories = NSSearchPathForDirectoriesInDomains(
+ NSApplicationDirectory, NSLocalDomainMask, YES);
+ NSString* applicationDirectory = applicationDirectories.firstObject;
+
+ // TODO: Change sourceAppBundlePath to the temporary folder that chrome will
+ // be downloaded and extracted to.
+ NSArray* downloadDirectories = NSSearchPathForDirectoriesInDomains(
+ NSDownloadsDirectory, NSUserDomainMask, YES);
+ NSString* sourceAppBundlePath = [NSString
Anna Zeng 2016/08/18 15:57:16 We can make this a parameter.
ivanhernandez 2016/08/22 15:34:49 We could but we would need to make some changes to
+ pathWithComponents:@[ downloadDirectories.firstObject, appBundleName ]];
+ NSString* destinationAppBundlePath =
Anna Zeng 2016/08/18 15:57:16 If root, this can just be @"/Applications/Google C
ivanhernandez 2016/08/22 15:34:49 I don't know actually. Its true the path will alwa
+ [NSString pathWithComponents:@[ applicationDirectory, appBundleName ]];
+
+ const char* sourcePath = [sourceAppBundlePath UTF8String];
+ const char* destinationPath = [applicationDirectory UTF8String];
+ const char* fullDestinationPath = [destinationAppBundlePath UTF8String];
+ const char* args[] = {sourcePath, destinationPath, fullDestinationPath, NULL};
+
+ if ([self setUpAuthorization]) {
+ [self startAuthorizedTool:[toolPath UTF8String] withArguments:args];
+ AuthorizationFree(authRef_, kAuthorizationFlagDestroyRights);
+ }
+ return (status_ == errAuthorizationSuccess);
+}
+
+// Sends a message to the auhtorized tool's stdin.
+- (void)sendMessageToTool:(NSString*)message {
+ if (communicationPipe_ != NULL) {
+ const char* readyState = message.UTF8String;
+ write(fileno(communicationPipe_), readyState, sizeof(readyState));
+ }
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698