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?
Deleting files using Swift that require admin privileges
326 Views Asked by SaudiSheep At
2
There are 2 best solutions below
0
Joshua Kaplan
On
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.
Related Questions in SWIFT
- Overlapping UICollectionView in storyboard
- Cannot pod spec lint because of undeclared type errors
- Swift code with multiple NSDateFormatter - optimization
- How do I add multiple in app purchases in Swift Spritekit?
- cellForRowAtIndexPath and prepareForSegue return different label colors
- Getting this message in my console in xcode "Ignoring restoreCompletedTransactionsWithApplicationUsername: because already restoring transactions"?
- Change background of an Accessory View in a UITableViewCell
- fade in an bounce animation subview
- Create a PFObject and PFRelation after PFUser Sign Up
- Swift 2 - Pattern matching in "if"
- How do I give inputs through NSURL
- How do I add custom cells to TableView in Swift?
- UIWebView not loading URL in simulator
- Compiler complains that 'Expression resolved to unused function' when removing index in array of functions
- Cast from 'Int?' to unrelated type 'NSNumber' always fails
Related Questions in ADMIN
- Django Admin tables not displaying correctly
- How to do excel sheet like calculations in django Admin?
- Script that runs "reg add" as admin
- django admin view on site don't use get_absolute_url
- Is it possible to create a cmd script that prevents users from deleting a file located in the desktop?
- Batch - Check admin right, run as admin
- Sonata Admin: Prevent a persist for a specific condition
- Can't get access to configuration.php Joomla 2.5
- Sonata Admin: How to change the form redirect from inside the admin class
- Error in laravel 4
- Prestashop 1.6 create admin module
- How do you create a basic Wordpress admin pointer?
- Displaying table header even when there is no content? (django admin page)
- Creating second database/domain in OpenLDAP
- django admin view and edit only what the user has create
Related Questions in DELETE-FILE
- Win API - Delete all files except some
- Del command in command prompt
- How to debug a recursive directory search script in PHP?
- Remove everything in the path except some files in Windows CMD
- Unable to delete files of certain extension
- Deleting docker files after uninstall
- React Native file handling - delete image
- how to delete an image from android when its URI is known?
- PHP unlink files after read them
- how to change __consumer_offsets cleanup plicy to delete from compact?
- Deleting file beginning with period
- Get permission denied error when trying to remove file
- Can't delete file after calling FontFactory.getFont() method
- Deleting file from folder
- Thread safe creating and deleting file in Java
Related Questions in NSFILEMANAGER
- NSData dataWithContentsOfURL returning nil specifically in iOS 8
- Downloading a PDF file and saving it to temporary directory iOS
- Saveguard against device removal in os x
- How do I count a number of images in a folder reference in swift
- Files returned by NSFileManager.contentsOfDirectoryAtURL do not exist according to NSFileManager.fileExistsAtPath?
- How to know a file is writing via NSFileManager
- Cannot find my file
- How to get list of all Image files in Watchkit Extension
- NSFileManager moveItem: Comment field missing
- How can I avoid having NSFileWrapper use lots memory when writing the file
- Read/Write .string files from/to Directory
- Correct way to get Application directory path in Mac App
- xCode playground and writing files to Documents
- How to open local file in a view controller
- Load image from the file after rewrite it - UIImage
Related Questions in SMJOBBLESS
- SMJobBless gives error CFErrorDomainLaunchd Code=8
- Gain administration privileges with swift for a Mac Application
- SMJobBless Apple sample code keep asking password
- How to embed info.plist in privileged helper for SMJobBless?
- How to access a packaged CLI tool using Swift on OSX
- Deleting files using Swift that require admin privileges
- SMJobBless failed with CFErrorDomainLaunchd Code 9
- Lazarus Pascal: Writing a privileged helper tool with SMJobBless()
- how to use privileged helper tool(installed using SMJobless) to launch other application in root privileges on osx
- Using common privilege helper tool across workspace- SMJobBless
- OS X - Truly 'On Demand' Privileged Helper Tool
- SMJobBless works only with kSMDomainSystemLaunchd, need kSMDomainUserLaunchd
- SMJobBless is for Privileged Helper tool, but what if I want to have launchd plist to get copied to /Users/<user>/Library/LaunchAgents
- SMJobBless.py script doesn't work on M1 Macs
- Understanding Priviledged Helper Tools in OSX
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
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!