Description
Problem:
- Adding elevated operation "Execute" which calls launchctl load <plist_file> loads the plist as normal user and thus the plist is loaded as LaunchAgent and not LaunchDaemon
DoD:
- Adding elevated operation "Execute" which calls launchctl load <plist_file> will load a plist as root and thus load it as LaunchDaemon
- Adding operation (without elevation) "Execute" which calls launchctl load <plist_file> will load a plist as normal user and thus load it as LaunchAgent
How to reproduce:
- Extract the plist file into /Library/LaunchDaemons
- Set permissions (644, root:wheel)
- Load the plist file
component.addElevatedOperation("Extract", archive, "/Library/LaunchDaemons"); component.addElevatedOperation("Execute", "chmod", "644", "/Library/LaunchDaemons/com.example.daemon.plist"); component.addElevatedOperation("Execute", "chown", "root:wheel", "/Library/LaunchDaemons/com.example.daemon.plist"); component.addElevatedOperation("Execute", "launchctl", "load", "/Library/LaunchDaemons/com.example.daemon.plist");
- Open terminal and run launchctl list and sudo launchctl list -> it should be listed in sudo launchctl list and not launchctl list
Note:
- Elevated:
addElevatedOperation("Execute", "launchctl", "load", "<plist_file>")
equals
# This loads a plist as a LaunchDaemon sudo launchctl load <plist_file>
- Normal:
addOperation("Execute", "launchctl", "load", "<plist_file>")
equals
# This loads a plist as a LaunchAgent launchctl load <plist_file>