Files
BlockBlock/Installer/Source/main.m
T
Patrick Wardle b30304ba96 new file monitor library, bug fixes, etc
-wrapped logging in try/catch
-updated Sentry.io (crash reporting) version
-linked against file monitor library that now uses caching
-improved cs checks ("anchor trusted" → "anchor apple generic"), thanks Thijs!
2020-10-14 15:33:48 -10:00

141 lines
2.8 KiB
Objective-C

//
// file: main.m
// project: blockblock (config app)
// description: main interface, for config
//
// created by Patrick Wardle
// copyright (c) 2018 Objective-See. All rights reserved.
//
@import Cocoa;
@import Sentry;
#import "main.h"
#import "consts.h"
#import "logging.h"
#import "utilities.h"
#import "Configure.h"
//main interface
int main(int argc, char *argv[])
{
//status
int status = -1;
//init crash reporting
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = SENTRY_DSN;
options.debug = YES;
}];
//cmdline install?
if(YES == [[[NSProcessInfo processInfo] arguments] containsObject:CMD_INSTALL])
{
//dbg msg
logMsg(LOG_DEBUG, @"performing commandline install");
//install
if(YES != cmdlineInterface(ACTION_INSTALL_FLAG))
{
//err msg
printf("\nBLOCKBLOCK ERROR: install failed\n\n");
//bail
goto bail;
}
//dbg msg
printf("BLOCKBLOCK: install ok!\n\n");
//happy
status = 0;
//done
goto bail;
}
//cmdline uninstall?
else if(YES == [[[NSProcessInfo processInfo] arguments] containsObject:CMD_UNINSTALL])
{
//dbg msg
logMsg(LOG_DEBUG, @"performing commandline uninstall");
//install
if(YES != cmdlineInterface(ACTION_UNINSTALL_FLAG))
{
//err msg
printf("\nBLOCKBLOCK ERROR: uninstall failed\n\n");
//bail
goto bail;
}
//dbg msg
printf("BLOCKBLOCK: uninstall ok!\n\n");
//happy
status = 0;
//done
goto bail;
}
//default run mode
// just kick off main app logic
status = NSApplicationMain(argc, (const char **)argv);
bail:
return status;
}
//cmdline interface
// install or uninstall
BOOL cmdlineInterface(int action)
{
//flag
BOOL wasConfigured = NO;
//configure obj
Configure* configure = nil;
//ignore SIGPIPE
signal(SIGPIPE, SIG_IGN);
//alloc/init
configure = [[Configure alloc] init];
//first check root
if(0 != geteuid())
{
//err msg
printf("\nBLOCKBLOCK ERROR: cmdline interface actions require root!\n\n");
//bail
goto bail;
}
//configure
wasConfigured = [configure configure:action];
if(YES != wasConfigured)
{
//bail
goto bail;
}
//happy
wasConfigured = YES;
bail:
//cleanup
if(nil != configure)
{
//cleanup
[configure removeHelper];
}
return wasConfigured;
}