-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Show update nag for non admin user - Defer updater to background QOS
- Loading branch information
Showing
7 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// User.swift | ||
// Pareto Security | ||
// | ||
// Created by Janez Troha on 25/08/2022. | ||
// | ||
// https://stackoverflow.com/a/64034073 | ||
|
||
import Cocoa | ||
import CoreServices | ||
import Foundation | ||
|
||
enum QueryError: Swift.Error { | ||
case queryExecutionFailed | ||
case queriedWithoutResult | ||
} | ||
|
||
struct SystemUser { | ||
static let current = SystemUser() | ||
|
||
private func getUser() throws -> CSIdentity { | ||
let query = CSIdentityQueryCreateForCurrentUser(kCFAllocatorDefault).takeRetainedValue() | ||
let flags = CSIdentityQueryFlags() | ||
guard CSIdentityQueryExecute(query, flags, nil) else { throw QueryError.queryExecutionFailed } | ||
|
||
let users = CSIdentityQueryCopyResults(query).takeRetainedValue() as! [CSIdentity] | ||
|
||
guard let currentUser = users.first else { throw QueryError.queriedWithoutResult } | ||
|
||
return currentUser | ||
} | ||
|
||
private func getAdminGroup() throws -> CSIdentity { | ||
let privilegeGroup = "admin" as CFString | ||
let authority = CSGetDefaultIdentityAuthority().takeRetainedValue() | ||
let query = CSIdentityQueryCreateForName(kCFAllocatorDefault, | ||
privilegeGroup, | ||
kCSIdentityQueryStringEquals, | ||
kCSIdentityClassGroup, | ||
authority).takeRetainedValue() | ||
let flags = CSIdentityQueryFlags() | ||
|
||
guard CSIdentityQueryExecute(query, flags, nil) else { throw QueryError.queryExecutionFailed } | ||
let groups = CSIdentityQueryCopyResults(query).takeRetainedValue() as! [CSIdentity] | ||
|
||
guard let adminGroup = groups.first else { throw QueryError.queriedWithoutResult } | ||
|
||
return adminGroup | ||
} | ||
|
||
var isAdmin: Bool { | ||
do { | ||
let user = try getUser() | ||
let group = try getAdminGroup() | ||
return CSIdentityIsMemberOfGroup(user, group) | ||
} catch { | ||
return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters