forked from SelfControlApp/selfcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCDaemonXPC.m
More file actions
77 lines (64 loc) · 3.11 KB
/
SCDaemonXPC.m
File metadata and controls
77 lines (64 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// SCDaemonXPC.m
// selfcontrold
//
// Created by Charlie Stigler on 5/30/20.
//
#import "SCDaemonXPC.h"
#import "SCDaemonBlockMethods.h"
#import "SCXPCAuthorization.h"
@implementation SCDaemonXPC
- (void)startBlockWithControllingUID:(uid_t)controllingUID blocklist:(NSArray<NSString*>*)blocklist isAllowlist:(BOOL)isAllowlist endDate:(NSDate*)endDate blockSettings:(NSDictionary*)blockSettings authorization:(NSData *)authData reply:(void(^)(NSError* error))reply {
NSLog(@"XPC method called: startBlockWithControllingUID");
NSError* error = [SCXPCAuthorization checkAuthorization: authData command: _cmd];
if (error != nil) {
if (![SCMiscUtilities errorIsAuthCanceled: error]) {
NSLog(@"ERROR: XPC authorization failed due to error %@", error);
[SCSentry captureError: error];
}
reply(error);
return;
} else {
NSLog(@"AUTHORIZATION ACCEPTED for startBlock with authData %@ and command %s", authData, sel_getName(_cmd));
}
[SCDaemonBlockMethods startBlockWithControllingUID: controllingUID blocklist: blocklist isAllowlist:isAllowlist endDate: endDate blockSettings:blockSettings authorization: authData reply: reply];
}
- (void)updateBlocklist:(NSArray<NSString*>*)newBlocklist authorization:(NSData *)authData reply:(void(^)(NSError* error))reply {
NSLog(@"XPC method called: updateBlocklist");
NSError* error = [SCXPCAuthorization checkAuthorization: authData command: _cmd];
if (error != nil) {
if (![SCMiscUtilities errorIsAuthCanceled: error]) {
NSLog(@"ERROR: XPC authorization failed due to error %@", error);
[SCSentry captureError: error];
}
reply(error);
return;
} else {
NSLog(@"AUTHORIZATION ACCEPTED for updateBlocklist with authData %@ and command %s", authData, sel_getName(_cmd));
}
[SCDaemonBlockMethods updateBlocklist: newBlocklist authorization: authData reply: reply];
}
- (void)updateBlockEndDate:(NSDate*)newEndDate authorization:(NSData *)authData reply:(void(^)(NSError* error))reply {
NSLog(@"XPC method called: updateBlockEndDate");
NSError* error = [SCXPCAuthorization checkAuthorization: authData command: _cmd];
if (error != nil) {
if (![SCMiscUtilities errorIsAuthCanceled: error]) {
NSLog(@"ERROR: XPC authorization failed due to error %@", error);
[SCSentry captureError: error];
}
reply(error);
return;
} else {
NSLog(@"AUTHORIZATION ACCEPTED for updateBlockENdDate with authData %@ and command %s", authData, sel_getName(_cmd));
}
[SCDaemonBlockMethods updateBlockEndDate: newEndDate authorization: authData reply: reply];
}
// Part of the HelperToolProtocol. Returns the version number of the tool. Note that never
// requires authorization.
- (void)getVersionWithReply:(void(^)(NSString * version))reply {
NSLog(@"XPC method called: getVersionWithReply");
// We specifically don't check for authorization here. Everyone is always allowed to get
// the version of the helper tool.
reply(SELFCONTROL_VERSION_STRING);
}
@end