Skip to content

Commit 375680e

Browse files
committed
修改MacOS 10.14权限不够导致创建目录文件失败bug
1 parent 96bd50e commit 375680e

File tree

12 files changed

+101
-103
lines changed

12 files changed

+101
-103
lines changed

HelpTool/HelpTool-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<string>1.0</string>
1515
<key>SMAuthorizedClients</key>
1616
<array>
17-
<string>identifier "com.cxy.PPTPVPN" and anchor apple generic and certificate leaf[subject.CN] = "Mac Developer: [email protected] (A6N22GWPU9)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
17+
<string>identifier "com.cxy.PPTPVPN" and anchor apple generic and certificate leaf[subject.CN] = "Mac Developer: xianyin Chen (A6N22GWPU9)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
1818
</array>
1919
</dict>
2020
</plist>

HelpTool/HelperTool.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ - (id)init {
1919
if (self = [super init]) {
2020
// Set up our XPC listener to handle requests on our Mach service.
2121
self->_listener = [[NSXPCListener alloc] initWithMachServiceName:@"com.cxy.PPTPVPN.HelpTool"];
22-
self->_listener.delegate = self;
22+
self->_listener.delegate = self;
23+
24+
25+
2326
}
2427
return self;
2528
}
2629

2730
- (void)run {
2831
// Tell the XPC listener to start processing requests.
2932
[self.listener resume];
30-
33+
3134
// Run the run loop forever.
3235
[[NSRunLoop currentRunLoop] run];
3336
}
@@ -50,6 +53,7 @@ - (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConne
5053

5154
#pragma mark - protocol
5255
- (void)executeShellPath:(NSString*)path arguments:(NSArray*)args withReply:(void(^)(NSError *error, NSString *outputString))reply {
56+
5357
dispatch_async(dispatch_get_global_queue(0, 0), ^{
5458
NSTask *task = [NSTask new];
5559
task.launchPath = path;
@@ -81,6 +85,7 @@ - (void)executeShellCommand:(NSString*)command withReply:(void(^)(NSDictionary *
8185
}
8286

8387
- (void)executeShellSystemCommand:(NSString *)command withReply:(void (^)(NSInteger))reply {
88+
8489
dispatch_async(dispatch_get_global_queue(0, 0), ^{
8590
int res = system([command UTF8String]);
8691
!reply?:reply(res);

PPTPVPN.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
742FB4EE21154CEB000FEB1E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
6666
742FB4F321154CEC000FEB1E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6767
742FB4F421154CEC000FEB1E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
68-
742FB4F621154CEC000FEB1E /* PPTPVPN.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PPTPVPN.entitlements; sourceTree = "<group>"; };
6968
742FB50021154D2D000FEB1E /* com.cxy.PPTPVPN.HelpTool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = com.cxy.PPTPVPN.HelpTool; sourceTree = BUILT_PRODUCTS_DIR; };
7069
742FB50221154D2D000FEB1E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
7170
742FB50721154DCF000FEB1E /* HelpTool-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "HelpTool-Info.plist"; sourceTree = "<group>"; };
@@ -141,7 +140,6 @@
141140
742FB4EE21154CEB000FEB1E /* Assets.xcassets */,
142141
742FB4F321154CEC000FEB1E /* Info.plist */,
143142
742FB4F421154CEC000FEB1E /* main.m */,
144-
742FB4F621154CEC000FEB1E /* PPTPVPN.entitlements */,
145143
);
146144
path = PPTPVPN;
147145
sourceTree = "<group>";

PPTPVPN.xcodeproj/xcuserdata/chen.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<key>orderHint</key>
2020
<integer>1</integer>
2121
</dict>
22+
<key>com.cxy.PPTPVPN.HelpTool.xcscheme_^#shared#^_</key>
23+
<dict>
24+
<key>orderHint</key>
25+
<integer>1</integer>
26+
</dict>
2227
</dict>
2328
<key>SuppressBuildableAutocreation</key>
2429
<dict>

PPTPVPN/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ - (void)setupVPNItem {
6464
self.wait.hidden = NO;
6565
break;
6666
case VPNStatusConnected:
67-
self.vpnItem.image = [NSImage imageNamed:@"vpn_connect"];
67+
self.vpnItem.image = [NSImage imageNamed:@"vpn_disconnect"];
6868
self.connectSwitch.checked = YES;
6969
self.connectSwitch.hidden = NO;
7070
self.wait.hidden = YES;
@@ -165,7 +165,7 @@ - (BOOL)blessHelperWithLabel:(NSString *)label error:(NSError **)errorPtr; {
165165
error = CFBridgingRelease(cfError);
166166
}
167167
}
168-
if ( ! result && (errorPtr != NULL) ) {
168+
if (!result && (errorPtr != NULL) ) {
169169
assert(error != nil);
170170
*errorPtr = error;
171171
}

PPTPVPN/Info.plist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>NSAppleEventsUsageDescription</key>
6+
<string>use pptp vpn</string>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>$(DEVELOPMENT_LANGUAGE)</string>
79
<key>CFBundleExecutable</key>
@@ -35,7 +37,7 @@
3537
<key>SMPrivilegedExecutables</key>
3638
<dict>
3739
<key>com.cxy.PPTPVPN.HelpTool</key>
38-
<string>identifier "com.cxy.PPTPVPN.HelpTool" and anchor apple generic and certificate leaf[subject.CN] = "Mac Developer: [email protected] (A6N22GWPU9)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
40+
<string>identifier &quot;com.cxy.PPTPVPN.HelpTool&quot; and anchor apple generic and certificate leaf[subject.CN] = &quot;Mac Developer: xianyin Chen (A6N22GWPU9)&quot; and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
3941
</dict>
4042
</dict>
4143
</plist>

PPTPVPN/PPTPVPN.entitlements

Lines changed: 0 additions & 5 deletions
This file was deleted.

PPTPVPN/PreferencesWindow.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ - (IBAction)confirmClick:(id)sender {
4141
[VPNFiler writeVPNFileHost:shared.host user:shared.username password:shared.password block:^(NSError *error) {
4242
if (error) {
4343
self.errorTip.hidden = NO;
44-
self.errorTip.stringValue = error.localizedDescription;
44+
self.errorTip.stringValue = error.localizedDescription?:@"";
4545
} else {
46+
4647
[shared connect:^(NSError *err) {
4748
// if (err) {
4849
// self.errorTip.hidden = NO;

PPTPVPN/PreferencesWindow.xib

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
4+
<deployment identifier="macosx"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
56
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
67
</dependencies>
78
<objects>
@@ -16,7 +17,7 @@
1617
</customObject>
1718
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
1819
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
19-
<window title="Setting" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5">
20+
<window title="Setting" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5">
2021
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
2122
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
2223
<rect key="contentRect" x="740" y="391" width="295" height="227"/>
@@ -30,7 +31,7 @@
3031
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
3132
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="vpn.ihongren.com" drawsBackground="YES" id="BZ6-ZQ-RN4">
3233
<font key="font" metaFont="system"/>
33-
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
34+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
3435
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
3536
</textFieldCell>
3637
</textField>
@@ -39,7 +40,7 @@
3940
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
4041
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="12345678" drawsBackground="YES" usesSingleLineMode="YES" id="GoG-GJ-2du">
4142
<font key="font" metaFont="system"/>
42-
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
43+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
4344
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
4445
<allowedInputSourceLocales>
4546
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
@@ -51,7 +52,7 @@
5152
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
5253
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="ihongren" drawsBackground="YES" id="3jt-fL-H8F">
5354
<font key="font" metaFont="system"/>
54-
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
55+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
5556
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
5657
</textFieldCell>
5758
</textField>
@@ -114,7 +115,7 @@ Gw
114115
<textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="THs-S4-SfF">
115116
<rect key="frame" x="6" y="2" width="282" height="17"/>
116117
<constraints>
117-
<constraint firstAttribute="height" constant="17" id="EqU-mg-Oja"/>
118+
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="17" id="EqU-mg-Oja"/>
118119
</constraints>
119120
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="err" id="6tU-bp-UI6">
120121
<font key="font" metaFont="system"/>
@@ -137,7 +138,7 @@ Gw
137138
<connections>
138139
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
139140
</connections>
140-
<point key="canvasLocation" x="-764" y="85"/>
141+
<point key="canvasLocation" x="-999" y="88"/>
141142
</window>
142143
</objects>
143144
</document>

PPTPVPN/VPNFiler.m

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// https://github.com/iHongRen/pptp-vpn
88

99
#import "VPNFiler.h"
10+
#import "VPNManager.h"
1011

1112
NSString *const PPTPVPNFileDirectory = @"/etc/ppp/peers";
1213
NSString *const PPTPVPNConfigFileName = @"this_is_a_pptp_vpn_config_file_0";
@@ -18,32 +19,7 @@ + (NSString*)VPNFilePath {
1819
return [PPTPVPNFileDirectory stringByAppendingPathComponent: PPTPVPNConfigFileName];
1920
}
2021

21-
+ (BOOL)createVPNFileDirectoryIfNeed {
22-
NSFileManager *fileManager = [NSFileManager defaultManager];
23-
BOOL isDir;
24-
BOOL isExistFile = [fileManager fileExistsAtPath:PPTPVPNFileDirectory isDirectory:&isDir];
25-
26-
if(isExistFile && isDir) {
27-
return YES;
28-
}
29-
30-
return [fileManager createDirectoryAtPath:PPTPVPNFileDirectory withIntermediateDirectories:YES attributes:nil error:nil];
31-
}
3222

33-
+ (BOOL)createVPNFileIfNeed {
34-
if(![self createVPNFileDirectoryIfNeed]) {
35-
return NO;
36-
}
37-
38-
NSFileManager *fileManager = [NSFileManager defaultManager];
39-
BOOL isExistFile = [fileManager fileExistsAtPath:[self VPNFilePath]];
40-
41-
if(isExistFile) {
42-
return YES;
43-
}
44-
45-
return [fileManager createFileAtPath:[self VPNFilePath] contents:nil attributes:nil];
46-
}
4723

4824
/**
4925
--- config ---
@@ -55,25 +31,24 @@ + (void)writeVPNFileHost:(NSString*)remoteaddress
5531
user:(NSString*)user
5632
password:(NSString*)password
5733
block:(void(^)(NSError *error))complete {
58-
if(![self createVPNFileIfNeed]) {
59-
NSError *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:0 userInfo:nil];
60-
complete(err);
61-
return;
62-
}
63-
64-
NSString *_remoteaddress = [NSString stringWithFormat:@"remoteaddress \"%@\"\n",remoteaddress?:@""];
65-
NSString *_user = [NSString stringWithFormat:@"user \"%@\"\n",user?:@""];
66-
NSString *_password = [NSString stringWithFormat:@"password \"%@\"\n",password?:@""];
67-
NSString *logfile = [NSString stringWithFormat:@"logfile %@", PPTPVPNLogFile];
68-
NSString *vpnConfig = [NSString stringWithFormat:@"%@%@%@%@",_remoteaddress,_user,_password, logfile];
69-
70-
NSError *err;
71-
NSString *script = [vpnConfig stringByAppendingString:[self VPNFileOtherScript]];
7234

73-
[script writeToFile:[self VPNFilePath] atomically:YES encoding:NSUTF8StringEncoding error:&err];
74-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
75-
!complete?:complete(err);
76-
});
35+
NSString *cmd = [NSString stringWithFormat:@"sudo mkdir -p -m=rwx %@", PPTPVPNFileDirectory];
36+
[[VPNManager shared] executeShellCommand:cmd block:^(NSError *err) {
37+
if (!err) {
38+
NSString *_remoteaddress = [NSString stringWithFormat:@"remoteaddress \"%@\"\n",remoteaddress?:@""];
39+
NSString *_user = [NSString stringWithFormat:@"user \"%@\"\n",user?:@""];
40+
NSString *_password = [NSString stringWithFormat:@"password \"%@\"\n",password?:@""];
41+
NSString *logfile = [NSString stringWithFormat:@"logfile %@\n", PPTPVPNLogFile];
42+
NSString *vpnConfig = [NSString stringWithFormat:@"%@%@%@%@",_remoteaddress,_user,_password, logfile];
43+
44+
NSString *scriptFile = [vpnConfig stringByAppendingString:[self VPNFileOtherScript]];
45+
46+
NSString *cmdx = [NSString stringWithFormat:@"echo \"%@\" > %@",scriptFile, [self VPNFilePath]];
47+
[[VPNManager shared] executeSystemShellCommand:cmdx block:complete];
48+
} else {
49+
!complete?:complete(err);
50+
}
51+
}];
7752
}
7853

7954
// https://github.com/davidjosefson/lex-integrity-mac
@@ -82,7 +57,7 @@ + (NSString*)VPNFileOtherScript {
8257
@"## Other settings\n\
8358
plugin PPTP.ppp\n\
8459
noauth\n\
85-
redialcount 1\n\
60+
redialcount 5\n\
8661
redialtimer 5\n\
8762
idle 1800\n\
8863
mru 1436\n\

0 commit comments

Comments
 (0)