Files
BlockBlock/Installer/Source/main.m
T
Patrick Wardle 397699c1d0 switched to universal logging
remove old log file #74
switch to os_log_* APIs
2024-03-19 20:12:11 -10:00

155 lines
3.1 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 OSLog;
#import "main.h"
#import "consts.h"
#import "utilities.h"
#import "Configure.h"
/* To build:
1. Comment out Installer's 'Run Script' (no need to copy in app/helper)
2. Build Installer in 'Release Mode'
3. Copy Installer to Application 'Uninstaller' folder
4. Comment in Installer's 'Run Script'
5. Build Installer in 'Archive Mode'
*/
/* GLOBALS */
//log handle
os_log_t logHandle = nil;
//main interface
int main(int argc, char *argv[])
{
//status
int status = -1;
//init log
logHandle = os_log_create(BUNDLE_ID, "installer");
//dbg msg
os_log_debug(logHandle, "BlockBlock (in/unin)staller launched with %{public}@", NSProcessInfo.processInfo.arguments);
//cmdline install?
if(YES == [NSProcessInfo.processInfo.arguments containsObject:CMD_INSTALL])
{
//dbg msg
os_log_debug(logHandle, "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
os_log_debug(logHandle, "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;
}