michael@1: /* michael@1: * Copyright (c) 2004 Angelo Laub michael@1: * michael@1: * This program is free software; you can redistribute it and/or modify michael@1: * it under the terms of the GNU General Public License version 2 michael@1: * as published by the Free Software Foundation. michael@1: * michael@1: * This program is distributed in the hope that it will be useful, michael@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of michael@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the michael@1: * GNU General Public License for more details. michael@1: * michael@1: * You should have received a copy of the GNU General Public License michael@1: * along with this program (see the file COPYING included with this michael@1: * distribution); if not, write to the Free Software Foundation, Inc., michael@1: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA michael@1: */ michael@1: michael@1: #include "installer.h" michael@1: michael@1: int main(int argc, char *argv[]) michael@1: { michael@1: NSAutoreleasePool *pool = [NSAutoreleasePool new]; michael@1: NSString *thisBundle = [[NSString stringWithUTF8String:argv[0]] stringByDeletingLastPathComponent]; michael@1: michael@1: NSString *tunPath = [thisBundle stringByAppendingPathComponent:@"/tun.kext"]; michael@1: NSString *tapPath = [thisBundle stringByAppendingPathComponent:@"/tap.kext"]; michael@1: michael@1: NSString *tunExecutable = [tunPath stringByAppendingPathComponent:@"/Contents/MacOS/tun"]; michael@1: NSString *tapExecutable = [tapPath stringByAppendingPathComponent:@"/Contents/MacOS/tap"]; michael@1: michael@1: NSString *helperPath = [thisBundle stringByAppendingPathComponent:@"/openvpnstart"]; michael@1: NSString *openvpnPath = [thisBundle stringByAppendingPathComponent:@"/openvpn"]; michael@1: michael@1: runTask( michael@1: @"/usr/sbin/chown", michael@1: [NSArray arrayWithObjects:@"-R",@"root:wheel",thisBundle,nil] michael@1: ); michael@1: michael@1: runTask( michael@1: @"/bin/chmod", michael@6: [NSArray arrayWithObjects:@"755", michael@1: tunExecutable, michael@1: tapExecutable, michael@6: tunPath, michael@6: tapPath, michael@1: openvpnPath, michael@1: nil] michael@1: ); michael@1: runTask( michael@1: @"/bin/chmod", michael@6: [NSArray arrayWithObjects:@"4555",helperPath,nil] michael@1: ); michael@1: [pool release]; michael@1: return 0; michael@1: } michael@1: michael@1: void runTask(NSString *launchPath,NSArray *arguments) michael@1: { michael@1: NSTask* task = [[[NSTask alloc] init] autorelease]; michael@1: [task setArguments:arguments]; michael@1: [task setLaunchPath:launchPath]; michael@1: michael@1: NS_DURING { michael@1: [task launch]; michael@1: } NS_HANDLER { michael@1: NSLog(@"Exception raised while executing helper %@: %@",launchPath, localException); michael@1: exit(EXIT_FAILURE); michael@1: } michael@1: NS_ENDHANDLER michael@1: [task waitUntilExit]; michael@1: }