1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tunblick/installer.m Wed Jul 29 11:23:17 2009 +0200 1.3 @@ -0,0 +1,77 @@ 1.4 +/* 1.5 + * Copyright (c) 2004 Angelo Laub 1.6 + * 1.7 + * This program is free software; you can redistribute it and/or modify 1.8 + * it under the terms of the GNU General Public License version 2 1.9 + * as published by the Free Software Foundation. 1.10 + * 1.11 + * This program is distributed in the hope that it will be useful, 1.12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.14 + * GNU General Public License for more details. 1.15 + * 1.16 + * You should have received a copy of the GNU General Public License 1.17 + * along with this program (see the file COPYING included with this 1.18 + * distribution); if not, write to the Free Software Foundation, Inc., 1.19 + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1.20 + */ 1.21 + 1.22 +#include "installer.h" 1.23 + 1.24 +int main(int argc, char *argv[]) 1.25 +{ 1.26 + NSAutoreleasePool *pool = [NSAutoreleasePool new]; 1.27 + NSString *thisBundle = [[NSString stringWithUTF8String:argv[0]] stringByDeletingLastPathComponent]; 1.28 + 1.29 + NSString *tunPath = [thisBundle stringByAppendingPathComponent:@"/tun.kext"]; 1.30 + NSString *tapPath = [thisBundle stringByAppendingPathComponent:@"/tap.kext"]; 1.31 + 1.32 + NSString *tunExecutable = [tunPath stringByAppendingPathComponent:@"/Contents/MacOS/tun"]; 1.33 + NSString *tapExecutable = [tapPath stringByAppendingPathComponent:@"/Contents/MacOS/tap"]; 1.34 + 1.35 + NSString *helperPath = [thisBundle stringByAppendingPathComponent:@"/openvpnstart"]; 1.36 + NSString *openvpnPath = [thisBundle stringByAppendingPathComponent:@"/openvpn"]; 1.37 + 1.38 + runTask( 1.39 + @"/usr/sbin/chown", 1.40 + [NSArray arrayWithObjects:@"-R",@"root:wheel",thisBundle,nil] 1.41 + ); 1.42 + 1.43 + 1.44 + runTask( 1.45 + @"/bin/chmod", 1.46 + [NSArray arrayWithObjects:@"-R",@"755",tunPath,tapPath,nil] 1.47 + ); 1.48 + 1.49 + runTask( 1.50 + @"/bin/chmod", 1.51 + [NSArray arrayWithObjects:@"744", 1.52 + tunExecutable, 1.53 + tapExecutable, 1.54 + helperPath, 1.55 + openvpnPath, 1.56 + nil] 1.57 + ); 1.58 + runTask( 1.59 + @"/bin/chmod", 1.60 + [NSArray arrayWithObjects:@"4111",helperPath,nil] 1.61 + ); 1.62 + [pool release]; 1.63 + return 0; 1.64 +} 1.65 + 1.66 +void runTask(NSString *launchPath,NSArray *arguments) 1.67 +{ 1.68 + NSTask* task = [[[NSTask alloc] init] autorelease]; 1.69 + [task setArguments:arguments]; 1.70 + [task setLaunchPath:launchPath]; 1.71 + 1.72 + NS_DURING { 1.73 + [task launch]; 1.74 + } NS_HANDLER { 1.75 + NSLog(@"Exception raised while executing helper %@: %@",launchPath, localException); 1.76 + exit(EXIT_FAILURE); 1.77 + } 1.78 + NS_ENDHANDLER 1.79 + [task waitUntilExit]; 1.80 +}