简体   繁体   中英

How Write on /Library/Fonts folder on Mac with SMJobBless function

I try to use SMJobBless function to authenticate for my application can do write on /Library/Fonts but not working,

if (![self blessHelperWithLabel:@"com.apple.bsd.SMJobBlessHelper" error:&error]) {
NSLog(@"Something went wrong! %@ / %d", [error domain], (int) [error code]);
} else {
//Access to this point.
/* At this point, the job is available. However, this is a very
 * simple sample, and there is no IPC infrastructure set up to
 * make it launch-on-demand. You would normally achieve this by
 * using XPC (via a MachServices dictionary in your launchd.plist).
 */
   NSLog(@"Job is available!");
   bool result = false;
   result = [[NSFileManager defaultManager] isWritableFileAtPath:@"/Library/Fonts"];
   [self->_textField setHidden:false];
}

My application printed "Job is available" but when i check authorities write on /Library/Fonts, result is false

Please tell me reason and resolve it.

The idea of SMJobBless is that privileged functionality is separated from the main application and run in a helper application.

Therefore, in the case of your example code, you're just using the helper app to test authentication, when in actuality, you should be doing the privileged task of checking if the path is writable from the helper app, as the helper app is provided with the privileged access.

Then if you're going to write to the fonts folder, the privileged helper app should do that, not your main application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM