v.1.1.0 (final?) commit
-fixed issue where uninstaller wouldn't remove app support directory
This commit is contained in:
parent
56ebbf8bb7
commit
9b8f2fea0f
|
@ -31,6 +31,9 @@
|
||||||
//uninstall
|
//uninstall
|
||||||
-(BOOL)uninstall:(NSUInteger)type;
|
-(BOOL)uninstall:(NSUInteger)type;
|
||||||
|
|
||||||
|
//build path to logged in user's app support directory + '/Objective-See'
|
||||||
|
-(NSString*)appSupportPath:(NSString*)user;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -157,6 +157,9 @@ bail:
|
||||||
//logged in user
|
//logged in user
|
||||||
NSString* user = nil;
|
NSString* user = nil;
|
||||||
|
|
||||||
|
//white list
|
||||||
|
NSString* whiteList = nil;
|
||||||
|
|
||||||
//set src path
|
//set src path
|
||||||
// ->orginally stored in installer app's /Resource bundle
|
// ->orginally stored in installer app's /Resource bundle
|
||||||
appPathSrc = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:APP_NAME];
|
appPathSrc = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:APP_NAME];
|
||||||
|
@ -217,6 +220,16 @@ bail:
|
||||||
logMsg(LOG_DEBUG, @"created app support directory");
|
logMsg(LOG_DEBUG, @"created app support directory");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//init path to whitelist
|
||||||
|
whiteList = [[NSString pathWithComponents:@[@"/Users/", user, APP_SUPPORT_DIRECTORY]] stringByAppendingPathComponent:FILE_WHITELIST];
|
||||||
|
|
||||||
|
//if whitelist exists
|
||||||
|
// ->make sure it's owned by root
|
||||||
|
if(YES == [[NSFileManager defaultManager] fileExistsAtPath:whiteList])
|
||||||
|
{
|
||||||
|
//set owner, root
|
||||||
|
setFileOwner(whiteList, @0, @0, NO);
|
||||||
|
}
|
||||||
|
|
||||||
//call into login item to install itself
|
//call into login item to install itself
|
||||||
// ->runs as logged in user, so can access user's login items, etc
|
// ->runs as logged in user, so can access user's login items, etc
|
||||||
|
@ -355,26 +368,23 @@ bail:
|
||||||
//set flag
|
//set flag
|
||||||
bAnyErrors = YES;
|
bAnyErrors = YES;
|
||||||
|
|
||||||
//keep uninstalling...
|
//bail since lots else depends on this
|
||||||
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
//unistall login item
|
//dbg msg
|
||||||
else
|
#ifdef DEBUG
|
||||||
{
|
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"telling login item %@, to uninstall itself", loginItem]);
|
||||||
//dbg msg
|
#endif
|
||||||
#ifdef DEBUG
|
|
||||||
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"telling login item %@, to uninstall itself", loginItem]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//call into login item to uninstall itself
|
//call into login item to uninstall itself
|
||||||
// ->runs as logged in user, so can access user's login items, etc
|
// ->runs as logged in user, so can access user's login items, etc
|
||||||
execTask(SUDO, @[@"-u", user, loginItem, [NSString stringWithUTF8String:CMD_UNINSTALL]], YES);
|
execTask(SUDO, @[@"-u", user, loginItem, [NSString stringWithUTF8String:CMD_UNINSTALL]], YES);
|
||||||
|
|
||||||
//dbg msg
|
//dbg msg
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"unpersisted %@", loginItem]);
|
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"unpersisted %@", loginItem]);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
//dbg msg
|
//dbg msg
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -402,20 +412,30 @@ bail:
|
||||||
logMsg(LOG_DEBUG, @"full uninstall, so also deleting app support directory");
|
logMsg(LOG_DEBUG, @"full uninstall, so also deleting app support directory");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//delete app support folder
|
//delete app's app support folder
|
||||||
if(YES == [[NSFileManager defaultManager] fileExistsAtPath:[APP_SUPPORT_DIRECTORY stringByExpandingTildeInPath]])
|
if(YES == [[NSFileManager defaultManager] fileExistsAtPath:[self appSupportPath:user]])
|
||||||
{
|
{
|
||||||
//delete
|
//delete
|
||||||
if(YES != [self removeAppSupport:user])
|
if(YES != [self removeAppSupport:user])
|
||||||
{
|
{
|
||||||
//err msg
|
//err msg
|
||||||
logMsg(LOG_ERR, [NSString stringWithFormat:@"failed to delete app support directory %@", APP_SUPPORT_DIRECTORY]);
|
logMsg(LOG_ERR, [NSString stringWithFormat:@"failed to delete app support directory %@", [self appSupportPath:user]]);
|
||||||
|
|
||||||
//set flag
|
//set flag
|
||||||
bAnyErrors = YES;
|
bAnyErrors = YES;
|
||||||
|
|
||||||
//keep uninstalling...
|
//keep uninstalling...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//dbg msg
|
||||||
|
#ifdef DEBUG
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//dbg msg
|
||||||
|
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"removed app support directory %@", [self appSupportPath:user]]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,10 +445,21 @@ bail:
|
||||||
//happy
|
//happy
|
||||||
wasUninstalled = YES;
|
wasUninstalled = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//bail
|
||||||
|
bail:
|
||||||
|
|
||||||
return wasUninstalled;
|
return wasUninstalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//build path to logged in user's app support directory + '/Objective-See/OverSight'
|
||||||
|
// ->do this manually, since installer might be run via sudo, etc, so can just expand '~'
|
||||||
|
-(NSString*)appSupportPath:(NSString*)user
|
||||||
|
{
|
||||||
|
//build path
|
||||||
|
return [NSString pathWithComponents:@[@"/Users/", user, APP_SUPPORT_DIRECTORY]];
|
||||||
|
}
|
||||||
|
|
||||||
//create directory app support
|
//create directory app support
|
||||||
// ->store whitelist file, log file, etc
|
// ->store whitelist file, log file, etc
|
||||||
-(BOOL)createAppSupport:(NSString*)user
|
-(BOOL)createAppSupport:(NSString*)user
|
||||||
|
@ -444,7 +475,7 @@ bail:
|
||||||
NSDictionary* userDirAttributes = nil;
|
NSDictionary* userDirAttributes = nil;
|
||||||
|
|
||||||
//build path
|
//build path
|
||||||
appSupportDirectory = [NSString pathWithComponents:@[@"/Users/", user, APP_SUPPORT_DIRECTORY]];
|
appSupportDirectory = [self appSupportPath:user];
|
||||||
|
|
||||||
//create if not present
|
//create if not present
|
||||||
if(YES != [[NSFileManager defaultManager] fileExistsAtPath:appSupportDirectory])
|
if(YES != [[NSFileManager defaultManager] fileExistsAtPath:appSupportDirectory])
|
||||||
|
@ -497,7 +528,7 @@ bail:
|
||||||
NSError* error = nil;
|
NSError* error = nil;
|
||||||
|
|
||||||
//build path
|
//build path
|
||||||
appSupportDirectory = [NSString pathWithComponents:@[@"/Users/", user, APP_SUPPORT_DIRECTORY]];
|
appSupportDirectory = [self appSupportPath:user];
|
||||||
|
|
||||||
//delete OverSight's app support directory
|
//delete OverSight's app support directory
|
||||||
if(YES != [[NSFileManager defaultManager] removeItemAtPath:appSupportDirectory error:&error])
|
if(YES != [[NSFileManager defaultManager] removeItemAtPath:appSupportDirectory error:&error])
|
||||||
|
|
|
@ -54,9 +54,21 @@
|
||||||
|
|
||||||
//dbg msg
|
//dbg msg
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"loading whitelist %@", path]);
|
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"whitelist path %@", path]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//check if it exists
|
||||||
|
if(YES != [[NSFileManager defaultManager] fileExistsAtPath:path])
|
||||||
|
{
|
||||||
|
//dbg msg
|
||||||
|
#ifdef DEBUG
|
||||||
|
logMsg(LOG_DEBUG, @"nothing whitelisted yet, so won't load (file not found)");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//bail
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
|
|
||||||
//since file is created by priv'd XPC, it shouldn't be writeable
|
//since file is created by priv'd XPC, it shouldn't be writeable
|
||||||
// ...unless somebody maliciously creates it, so we check that here
|
// ...unless somebody maliciously creates it, so we check that here
|
||||||
if(YES == [[NSFileManager defaultManager] isWritableFileAtPath:path])
|
if(YES == [[NSFileManager defaultManager] isWritableFileAtPath:path])
|
||||||
|
@ -67,7 +79,7 @@
|
||||||
//bail
|
//bail
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
//load
|
//load
|
||||||
self.whiteList = [NSMutableArray arrayWithContentsOfFile:path];
|
self.whiteList = [NSMutableArray arrayWithContentsOfFile:path];
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,17 @@ int main(int argc, const char * argv[])
|
||||||
setuid(getuid());
|
setuid(getuid());
|
||||||
|
|
||||||
//install
|
//install
|
||||||
toggleLoginItem([NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]], ACTION_INSTALL_FLAG);
|
if(YES != toggleLoginItem([NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]], ACTION_INSTALL_FLAG))
|
||||||
|
{
|
||||||
|
//err msg
|
||||||
|
logMsg(LOG_ERR, @"failed to add login item");
|
||||||
|
|
||||||
|
//set error
|
||||||
|
iReturn = -1;
|
||||||
|
|
||||||
|
//bail
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
|
|
||||||
//dbg msg
|
//dbg msg
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -68,7 +78,7 @@ int main(int argc, const char * argv[])
|
||||||
setuid(getuid());
|
setuid(getuid());
|
||||||
|
|
||||||
//uninstall
|
//uninstall
|
||||||
if(YES == toggleLoginItem([NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]], ACTION_UNINSTALL_FLAG))
|
if(YES != toggleLoginItem([NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]], ACTION_UNINSTALL_FLAG))
|
||||||
{
|
{
|
||||||
//err msg
|
//err msg
|
||||||
logMsg(LOG_ERR, @"failed to remove login item");
|
logMsg(LOG_ERR, @"failed to remove login item");
|
||||||
|
@ -76,13 +86,17 @@ int main(int argc, const char * argv[])
|
||||||
//set error
|
//set error
|
||||||
iReturn = -1;
|
iReturn = -1;
|
||||||
|
|
||||||
//bail
|
//don't bail
|
||||||
goto bail;
|
// ->keep trying to uninstall
|
||||||
}
|
}
|
||||||
|
|
||||||
//dbg msg
|
//dbg msg
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
logMsg(LOG_DEBUG, @"removed login item");
|
else
|
||||||
|
{
|
||||||
|
//dbg msg
|
||||||
|
logMsg(LOG_DEBUG, @"removed login item");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//delete prefs
|
//delete prefs
|
||||||
|
|
|
@ -277,7 +277,14 @@ bail:
|
||||||
loginItem = [NSURL fileURLWithPath:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"/Contents/Library/LoginItems/OverSight Helper.app"]];
|
loginItem = [NSURL fileURLWithPath:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"/Contents/Library/LoginItems/OverSight Helper.app"]];
|
||||||
|
|
||||||
//toggle
|
//toggle
|
||||||
toggleLoginItem(loginItem, (int)[sender state]);
|
if(YES != toggleLoginItem(loginItem, (int)[sender state]))
|
||||||
|
{
|
||||||
|
//err msg
|
||||||
|
logMsg(LOG_ERR, [NSString stringWithFormat:@"failed to toggle login item: %@", loginItem]);
|
||||||
|
|
||||||
|
//bail
|
||||||
|
goto bail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//set 'run in headless mode'
|
//set 'run in headless mode'
|
||||||
|
@ -309,6 +316,9 @@ bail:
|
||||||
//save em
|
//save em
|
||||||
[preferences writeToFile:[APP_PREFERENCES stringByExpandingTildeInPath] atomically:YES];
|
[preferences writeToFile:[APP_PREFERENCES stringByExpandingTildeInPath] atomically:YES];
|
||||||
|
|
||||||
|
//bail
|
||||||
|
bail:
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue