Skip to content

Commit

Permalink
initial implementation of allow user to select account to map to #98
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Nov 26, 2023
1 parent a16e2f5 commit 9b4b781
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 179 deletions.
73 changes: 73 additions & 0 deletions NomadLogin/DSQueryable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,41 @@ public extension DSQueryable {
return true
}


/// Searches DSLocal for an account short name and returns the `ODRecord` for the group if found.
///
/// - Parameter name: The name of the group to search for as a `String`.
/// - Returns: The `ODRecord` of the group if one is found in DSLocal.
/// - Throws: Either an `ODFrameworkErrors` or a `DSQueryableErrors` if there is an error or the user is not local.
func getLocalGroupRecord(_ name: String) throws -> ODRecord {
do {
os_log("Building OD query for name %{public}@", type: .default, name)
let query = try ODQuery.init(node: localNode,
forRecordTypes: kODRecordTypeGroups,
attribute: kODAttributeTypeRecordName,
matchType: ODMatchType(kODMatchEqualTo),
queryValues: name,
returnAttributes: kODAttributeTypeNativeOnly,
maximumResults: 1)
let records = try query.resultsAllowingPartial(false) as! [ODRecord]

if records.count > 1 {
os_log("More than one local group found for name.", type: .default)
throw DSQueryableErrors.multipleUsersFound
}
guard let record = records.first else {
os_log("No local group found.", type: .default)
throw DSQueryableErrors.notLocalUser
}
// os_log("Found local user: %{public}@", record)
return record
} catch {
os_log("ODError while trying to check for local user: %{public}@", type: .error, error.localizedDescription)
throw error
}
}


/// Searches DSLocal for an account short name and returns the `ODRecord` for the user if found.
///
/// - Parameter shortName: The name of the user to search for as a `String`.
Expand Down Expand Up @@ -182,4 +217,42 @@ public extension DSQueryable {
throw error
}
}

func isAdmin(_ user:ODRecord) -> Bool {
let adminGroup = try? getLocalGroupRecord("admin")
do{
if let adminGroup = adminGroup {
try adminGroup.isMemberRecord(user)
return true
}
}
catch {
}
return false

}

func getAllStandardUsers() throws -> [ODRecord] {
let allRecords = try getAllNonSystemUsers()
let nonSystem = allRecords.filter { (record) -> Bool in


let adminGroup = try? getLocalGroupRecord("admin")

do{

if let adminGroup = adminGroup {
try adminGroup.isMemberRecord(record)
return false
}
}
catch {

}

return true
}
return nonSystem
}

}
2 changes: 1 addition & 1 deletion XCreds/PrefKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

enum PrefKeys: String {
case clientID, clientSecret, password="xcreds local password",discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours,refreshRateMinutes, showDebug, verifyPassword, shouldShowQuitMenu, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline, passwordChangeURL, shouldShowAboutMenu, username, idpHostName, passwordElementID, shouldFindPasswordElement, shouldShowVersionInfo, shouldShowSupportStatus,shouldShowConfigureWifiButton,shouldShowMacLoginButton, loginWindowBackgroundImageURL, shouldShowCloudLoginByDefault, shouldPreferLocalLoginInsteadOfCloudLogin, idpHostNames,autoRefreshLoginTimer, loginWindowWidth, loginWindowHeight, shouldShowRefreshBanner, shouldSwitchToLoginWindowWhenLocked,accounts = "Accounts",
windowSignIn = "WindowSignIn", settingsOverrideScriptPath, localAdminUserName, localAdminPassword, usernamePlaceholder, passwordPlaceholder, shouldShowLocalOnlyCheckbox, shouldShowTokenUpdateStatus, shouldDetectNetworkToDetermineLoginWindow, showLoginWindowDelaySeconds
windowSignIn = "WindowSignIn", settingsOverrideScriptPath, localAdminUserName, localAdminPassword, usernamePlaceholder, passwordPlaceholder, shouldShowLocalOnlyCheckbox, shouldShowTokenUpdateStatus, shouldDetectNetworkToDetermineLoginWindow, showLoginWindowDelaySeconds, shouldPromptForMigration
//, filePathToPreventShowingUI
case ropgClientID
case ropgClientSecret
Expand Down
1 change: 1 addition & 0 deletions XCreds/XCreds-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
#import "TCSUnifiedLogger.h"
#import <ProductLicense/ProductLicense.h>
#import "TCSLoginWindowUtilities.h"
#include <membership.h>

#endif /* XCreds_Bridging_Header_h */
1 change: 1 addition & 0 deletions XCreds/XCredsLoginPlugin-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
#import "TCSReturnWindow.h"
#import "TCSKeychain.h"
#import <ProductLicense/ProductLicense.h>
#include <membership.h>

0 comments on commit 9b4b781

Please sign in to comment.