Skip to content

Commit f9edb02

Browse files
committed
Fix up processing for on-demand and on-demand-privileged tasks
1 parent 0e4ff18 commit f9edb02

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed

Outset/Globals.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let scriptPayloads = getScriptPayloads()
3838

3939
enum Trigger: String {
4040
case onDemand = "/private/tmp/.io.macadmins.outset.ondemand.launchd"
41+
case onDemandPrivileged = "/private/tmp/.io.macadmins.outset.ondemand-privileged.launchd"
4142
case loginPrivileged = "/private/tmp/.io.macadmins.outset.login-privileged.launchd"
4243
case cleanup = "/private/tmp/.io.macadmins.outset.cleanup.launchd"
4344

Outset/Outset.swift

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct Outset: ParsableCommand {
186186
if loginPrivileged {
187187
writeLog("Processing scheduled runs for privileged login", logLevel: .info)
188188
if checkFileExists(path: Trigger.loginPrivileged.path) {
189-
pathCleanup(pathname: Trigger.loginPrivileged.path)
189+
pathCleanup(Trigger.loginPrivileged.path)
190190
}
191191
if !prefs.ignoredUsers.contains(consoleUser) {
192192
if !scriptPayloads.processPayloadScripts(ofType: .loginPrivilegedOnce, runOnceData: prefs.overrideLoginOnce) &&
@@ -208,10 +208,8 @@ struct Outset: ParsableCommand {
208208
if !["root", "loginwindow"].contains(consoleUser) {
209209
let currentUser = NSUserName()
210210
if consoleUser == currentUser {
211-
if !scriptPayloads.processPayloadScripts(ofType: .onDemand) {
212-
processItems(.onDemand)
213-
}
214-
createTrigger(Trigger.onDemand.path)
211+
processItems(.onDemand)
212+
createTrigger(Trigger.cleanup.path)
215213
} else {
216214
writeLog("User \(currentUser) is not the current console user. Skipping on-demand run.")
217215
}
@@ -222,26 +220,16 @@ struct Outset: ParsableCommand {
222220
}
223221

224222
if onDemandPrivileged {
223+
ensureRoot("execute on-demand-privileged")
225224
writeLog("Processing on-demand-privileged", logLevel: .debug)
226-
if !folderContents(path: PayloadType.onDemandPrivileged.directoryPath).isEmpty {
227-
if !["root", "loginwindow"].contains(consoleUser) {
228-
let currentUser = NSUserName()
229-
if consoleUser == currentUser {
230-
if !scriptPayloads.processPayloadScripts(ofType: .onDemandPrivileged) {
231-
processItems(.onDemandPrivileged)
232-
}
233-
} else {
234-
writeLog("User \(currentUser) is not the current console user. Skipping on-demand-privileged run.")
235-
}
236-
} else {
237-
writeLog("No current user session. Skipping on-demand run.")
238-
}
239-
FileManager.default.createFile(atPath: Trigger.onDemand.path, contents: nil)
240-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
241-
if checkFileExists(path: Trigger.onDemand.path) {
242-
pathCleanup(pathname: Trigger.onDemand.path)
243-
}
225+
if !["loginwindow"].contains(consoleUser) {
226+
if !folderContents(path: PayloadType.onDemandPrivileged.directoryPath).isEmpty {
227+
processItems(.onDemandPrivileged)
228+
pathCleanup(Trigger.onDemandPrivileged.path)
229+
pathCleanup(PayloadType.onDemandPrivileged.directoryPath)
244230
}
231+
} else {
232+
writeLog("No current user session. Skipping on-demand-privileged run.")
245233
}
246234
}
247235

@@ -268,10 +256,12 @@ struct Outset: ParsableCommand {
268256
}
269257

270258
if cleanup {
271-
writeLog("Cleaning up on-demand directory.", logLevel: .info)
272-
if checkFileExists(path: Trigger.onDemand.path) { pathCleanup(pathname: Trigger.onDemand.path) }
273-
if checkFileExists(path: Trigger.cleanup.path) { pathCleanup(pathname: Trigger.cleanup.path) }
274-
if !folderContents(path: PayloadType.onDemand.directoryPath).isEmpty { pathCleanup(pathname: PayloadType.onDemand.directoryPath) }
259+
writeLog("Cleaning up on-demand directories.", logLevel: .info)
260+
pathCleanup(Trigger.onDemand.path)
261+
pathCleanup(Trigger.onDemandPrivileged.path)
262+
pathCleanup(PayloadType.onDemand.directoryPath)
263+
pathCleanup(PayloadType.onDemandPrivileged.directoryPath)
264+
pathCleanup(Trigger.cleanup.path)
275265
}
276266

277267
if !addIgnoredUser.isEmpty {

Outset/UserDefaults/Payloads.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class ScriptPayloadManager {
163163

164164
// Loads and decodes ScriptPayloads from UserDefaults
165165
func loadScriptPayloads() -> ScriptPayloads? {
166-
let forced = CFPreferencesAppValueIsForced("script_payloads" as CFString, appBundle)
166+
// let forced = CFPreferencesAppValueIsForced("script_payloads" as CFString, appBundle)
167167
var payloads: [ScriptPayloads] = []
168168
var currentPayload: ScriptPayloads = ScriptPayloads()
169169
// we will want to limit returning payloads to managed profiles only

Outset/Utils/FileUtils/CoreFileUtils.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func ensureWorkingFolders() {
1818
PayloadType.loginPrivilegedEvery.directoryPath,
1919
PayloadType.loginPrivilegedOnce.directoryPath,
2020
PayloadType.onDemand.directoryPath,
21+
PayloadType.onDemandPrivileged.directoryPath,
2122
logDirectory
2223
]
2324

@@ -105,7 +106,7 @@ func getFileProperties(pathname: String) -> (ownerID: Int, permissions: NSNumber
105106
return (ownerID, mode)
106107
}
107108

108-
func pathCleanup(pathname: String) {
109+
func pathCleanup(_ pathname: String) {
109110
// check if folder and clean all files in that folder
110111
// Deletes given script or cleans folder
111112
writeLog("Cleaning up \(pathname)", logLevel: .debug)

Outset/Utils/ItemProcessing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func processPackages(packages: [String], once: Bool=false, override: RunOnce = [
8585
_ = installPackage(pkg: package)
8686
}
8787
if deleteItems {
88-
pathCleanup(pathname: package)
88+
pathCleanup(package)
8989
}
9090
}
9191

@@ -153,7 +153,7 @@ func processScripts(scripts: [String], altName: String = "", once: Bool=false, o
153153
}
154154
}
155155
if deleteItems {
156-
pathCleanup(pathname: script)
156+
pathCleanup(script)
157157
}
158158
}
159159

0 commit comments

Comments
 (0)