joshua-d-miller / macOSLAPS

Swift binary that will change a local administrator password to a random generated password. Similar behavior to LAPS for Windows
MIT License
387 stars 58 forks source link

-getPassword fails if `/var/root/Library/Application Support` does not exist #69

Closed MagerValp closed 2 years ago

MagerValp commented 2 years ago

I'm testing macOSLAPS on a fresh install of macOS 12.3b1, and -getPassword fails as /var/root/Library/Application Support has not yet been created by the system. The directory exists on my other machines, but it doesn't look like we can rely on it being there.

Error|2022-03-07 12:04:10|macOSLAPS|Unable to extract password from keychain. Error: Error Domain=NSCocoaErrorDomain Code=4 "The folder “macOSLAPS-password” doesn’t exist." UserInfo={NSFilePath=/var/root/Library/Application Support/macOSLAPS-password, NSUserStringVariant=Folder, NSUnderlyingError=0x6000007f0de0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2022-03-07 12:04:10,040|ERROR:[Errno 2] No such file or directory: '/var/root/Library/Application Support/macOSLAPS-password'

Before writing the files at https://github.com/joshua-d-miller/macOSLAPS/blob/c67bd288c891283c880cdc61e7772a788dd8205c/macOSLAPS/main.swift#L72 maybe something along the lines of:

do {
    try fm.createDirectory(atPath: "/var/root/Library/Application Support", withIntermediateDirectories: true, attributes: [.posixPermissions: 0o755, .ownerAccountID: 0, .groupOwnerAccountID: 0])
    print("Created")
} catch {
    print("Error: \(error).")
}

to ensure the directory exists?

joshua-d-miller commented 2 years ago

Interesting. It appears that the directory isn't automatically created when using a fresh build of 12.3. Thank you for bringing this to my attention. I'll be sure to code this in.

joshua-d-miller commented 2 years ago

This has been coded in and is now accounted for in the prerelease 3.0.0. Please give it a try and let me know. https://github.com/joshua-d-miller/macOSLAPS/releases/tag/3.0.0(752)

joshua-d-miller commented 2 years ago

This has been addressed in the 3.0.0 Release Candidate. 3.0.1 Release Candidate is releasing tonight and should be the final version as long as there are no issues.