2016-09-12 01:21:14 +01:00
|
|
|
//
|
|
|
|
// Configure.m
|
|
|
|
// OverSight
|
|
|
|
//
|
|
|
|
// Created by Patrick Wardle on 9/01/16.
|
|
|
|
// Copyright (c) 2016 Objective-See. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
#import "Consts.h"
|
|
|
|
#import "Logging.h"
|
|
|
|
#import "Utilities.h"
|
|
|
|
#import "Configure.h"
|
|
|
|
|
|
|
|
|
|
|
|
@implementation Configure
|
|
|
|
|
|
|
|
//invokes appropriate install || uninstall logic
|
|
|
|
-(BOOL)configure:(NSUInteger)parameter
|
|
|
|
{
|
|
|
|
//return var
|
|
|
|
BOOL wasConfigured = NO;
|
|
|
|
|
|
|
|
//install extension
|
|
|
|
if(ACTION_INSTALL_FLAG == parameter)
|
|
|
|
{
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, @"installing...");
|
|
|
|
|
|
|
|
//if already installed though
|
|
|
|
// ->uninstall everything first
|
|
|
|
if(YES == [self isInstalled])
|
|
|
|
{
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, @"already installed, so uninstalling...");
|
|
|
|
|
|
|
|
//uninstall
|
|
|
|
if(YES != [self uninstall])
|
|
|
|
{
|
|
|
|
//bail
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, @"uninstalled");
|
|
|
|
}
|
|
|
|
|
|
|
|
//install
|
|
|
|
if(YES != [self install])
|
|
|
|
{
|
|
|
|
//bail
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, @"installed!");
|
|
|
|
}
|
|
|
|
//uninstall extension
|
|
|
|
else if(ACTION_UNINSTALL_FLAG == parameter)
|
|
|
|
{
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, @"uninstalling...");
|
|
|
|
|
|
|
|
//uninstall
|
|
|
|
if(YES != [self uninstall])
|
|
|
|
{
|
|
|
|
//bail
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, @"uninstalled!");
|
|
|
|
}
|
|
|
|
|
|
|
|
//no errors
|
|
|
|
wasConfigured = YES;
|
|
|
|
|
|
|
|
//bail
|
|
|
|
bail:
|
|
|
|
|
|
|
|
return wasConfigured;
|
|
|
|
}
|
|
|
|
|
|
|
|
//determine if installed
|
|
|
|
// ->simply checks if extension binary exists
|
|
|
|
-(BOOL)isInstalled
|
|
|
|
{
|
|
|
|
//check if extension exists
|
2016-09-15 09:15:30 +01:00
|
|
|
return [[NSFileManager defaultManager] fileExistsAtPath:[APPS_FOLDER stringByAppendingPathComponent:APP_NAME]];
|
2016-09-12 01:21:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//install
|
2016-09-15 09:15:30 +01:00
|
|
|
// a) copy to /Applications
|
|
|
|
// b) chown/chmod XPC component
|
2016-09-12 01:21:14 +01:00
|
|
|
-(BOOL)install
|
|
|
|
{
|
|
|
|
//return/status var
|
|
|
|
BOOL wasInstalled = NO;
|
|
|
|
|
|
|
|
//error
|
|
|
|
NSError* error = nil;
|
|
|
|
|
2016-09-15 09:15:30 +01:00
|
|
|
//path to app (src)
|
|
|
|
NSString* appPathSrc = nil;
|
2016-09-12 01:21:14 +01:00
|
|
|
|
2016-09-15 09:15:30 +01:00
|
|
|
//path to app (dest)
|
|
|
|
NSString* appPathDest = nil;
|
2016-09-12 01:21:14 +01:00
|
|
|
|
|
|
|
//set src path
|
|
|
|
// ->orginally stored in installer app's /Resource bundle
|
2016-09-15 09:15:30 +01:00
|
|
|
appPathSrc = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:APP_NAME];
|
2016-09-12 01:21:14 +01:00
|
|
|
|
|
|
|
//set dest path
|
2016-09-15 09:15:30 +01:00
|
|
|
appPathDest = [APPS_FOLDER stringByAppendingPathComponent:APP_NAME];
|
2016-09-12 01:21:14 +01:00
|
|
|
|
2016-09-15 09:15:30 +01:00
|
|
|
//move app into /Applications
|
|
|
|
if(YES != [[NSFileManager defaultManager] copyItemAtPath:appPathSrc toPath:appPathDest error:&error])
|
2016-09-12 01:21:14 +01:00
|
|
|
{
|
|
|
|
//err msg
|
2016-09-15 09:15:30 +01:00
|
|
|
logMsg(LOG_ERR, [NSString stringWithFormat:@"failed to copy %@ -> %@ (%@)", appPathSrc, appPathDest, error]);
|
2016-09-12 01:21:14 +01:00
|
|
|
|
|
|
|
//bail
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
//dbg msg
|
2016-09-15 09:15:30 +01:00
|
|
|
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"copied %@ -> %@", appPathSrc, appPathDest]);
|
2016-09-12 01:21:14 +01:00
|
|
|
|
2016-09-15 09:15:30 +01:00
|
|
|
//always set group/owner to root/wheel
|
|
|
|
setFileOwner(appPathDest, @0, @0, YES);
|
|
|
|
|
2016-09-12 01:21:14 +01:00
|
|
|
//no error
|
|
|
|
wasInstalled = YES;
|
|
|
|
|
|
|
|
//bail
|
|
|
|
bail:
|
|
|
|
|
|
|
|
return wasInstalled;
|
|
|
|
}
|
|
|
|
|
|
|
|
//uninstall
|
|
|
|
// a) remove it (pluginkit -r <path 2 ext>)
|
|
|
|
// b) delete binary & folder; /Library/WhatsYourSign
|
|
|
|
-(BOOL)uninstall
|
|
|
|
{
|
|
|
|
//return/status var
|
|
|
|
BOOL wasUninstalled = NO;
|
|
|
|
|
|
|
|
//status var
|
|
|
|
// ->since want to try all uninstall steps, but record if any fail
|
|
|
|
BOOL bAnyErrors = NO;
|
|
|
|
|
|
|
|
//path to finder sync
|
2016-09-15 09:15:30 +01:00
|
|
|
NSString* appPath = nil;
|
2016-09-12 01:21:14 +01:00
|
|
|
|
|
|
|
//error
|
|
|
|
NSError* error = nil;
|
|
|
|
|
|
|
|
//init path
|
2016-09-15 09:15:30 +01:00
|
|
|
appPath = [APPS_FOLDER stringByAppendingPathComponent:APP_NAME];
|
2016-09-12 01:21:14 +01:00
|
|
|
|
|
|
|
//delete folder
|
2016-09-15 09:15:30 +01:00
|
|
|
if(YES != [[NSFileManager defaultManager] removeItemAtPath:appPath error:&error])
|
2016-09-12 01:21:14 +01:00
|
|
|
{
|
|
|
|
//err msg
|
2016-09-15 09:15:30 +01:00
|
|
|
logMsg(LOG_ERR, [NSString stringWithFormat:@"failed to delete app %@ (%@)", appPath, error]);
|
2016-09-12 01:21:14 +01:00
|
|
|
|
|
|
|
//set flag
|
|
|
|
bAnyErrors = YES;
|
|
|
|
|
|
|
|
//keep uninstalling...
|
|
|
|
}
|
|
|
|
|
|
|
|
//only success when there were no errors
|
|
|
|
if(YES != bAnyErrors)
|
|
|
|
{
|
|
|
|
//happy
|
|
|
|
wasUninstalled = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wasUninstalled;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|