I am currently working on a Mac Application where I need to delete files(potentially malicious) from /Library/LaunchDaemons directory and other similar directories where I would need administrator privileges. Using the FileManager.default.removeItem
was not fruitful. I have come across articles pointing me towards EvenBetterAuthorizationSample
and SMJobBless
and I find the documentation to be rather confusing. Am I on the right track and if so, how should I proceed?
Asked
Active
Viewed 237 times
0

SaudiSheep
- 35
- 6
-
Look at [SwiftPrivilegedHelper](https://github.com/erikberglund/SwiftPrivilegedHelper) – vadian Mar 31 '21 at 20:49
2 Answers
0
One idea is to look at the init(authorization:)
method of the FileManager. It is available since 10.14. I think it is the easiest way to perform the operation.
https://developer.apple.com/documentation/foundation/filemanager/3025773-init
Also, it worth checking if the directories you want to delete are not protected by SIP. In this case on SIP-enabled machines there is no way to remove them.
Good luck!

julia_v
- 593
- 3
- 18
-
Thank you for the answer Julia. This way certainly seems to be the easiest. But, I am unable to figure out the right way to use it. Can you give me an example, say to perform a privileged removeItem() operation using FileManager? – SaudiSheep Apr 02 '21 at 11:45
0
The documentation for SMJobBless
is indeed confusing. I've put together the SwiftAuthorizationSample along with a pretty extensive README. So even if the sample isn't quite what you're looking for, hopefully the README will be of some help.

Joshua Kaplan
- 843
- 5
- 9