Here is a sample code to get you started. The server.mm project is probably the best way to upload it to LaunchDaemon . I did some tests with the daemon running as root and, of course, the client application that ran as "mike" ran the code in the daemon as "root". Thus, it allows you to increase the privilege. Please note that this IPC does not provide any protocol encryption or authentication requirements, so you should add this yourself. You will probably be able to get a key / list message, XML or JSON, encrypted using AES256 + Base64 encoding with a long hard passphrase both when sending and receiving. Remember that with privilege escalation it is very important that you put on some protection mechanisms.
, , . , , , , . , .
, , . , , Apple oneway
. , . , oneway
, void, . , , , , . , , oneway
:
- (oneway void)runTaskAsync:(NSString *)sParam;
...
server.m
#import <Foundation/Foundation.h>
#define cat stringByAppendingString
@interface MyService : NSObject {
NSConnection *connection;
}
@end
@implementation MyService
- (NSString *)testResponse:(NSString *)s {
NSLog(@"...connection:%@", s);
s = [s cat:@"-response"];
return s;
}
- (void)runService {
connection = [[NSConnection alloc] init];
[connection setRootObject:self];
[connection registerName:@"com.acme.myservice"];
[[NSRunLoop currentRunLoop] run];
}
@end
int main (int argc, const char *argv[]) {
@autoreleasepool {
NSLog(@"ACME MyService 1.0\n");
MyService *svc = [[MyService alloc] init];
[svc runService];
}
return 0;
}
client.m
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[]) {
@autoreleasepool {
NSLog(@"building proxy object");
id proxy = [NSConnection rootProxyForConnectionWithRegisteredName:@"com.acme.myservice" host:nil];
NSLog(@"calling test response thru proxy object");
NSString *sResult = [proxy testResponse:@"sent"];
NSLog(@"RESULT=%@", sResult);
}
return 0;
}