-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented swiching back to mac login window
- Loading branch information
Showing
14 changed files
with
215 additions
and
88 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
150 changes: 150 additions & 0 deletions
150
XCredsLoginPlugIn/LoginWindow/AuthorizationDBManager.swift
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,150 @@ | ||
// | ||
// AuthorizationDBManager.swift | ||
// XCredsLoginPlugin | ||
// | ||
// Created by Timothy Perfitt on 7/3/22. | ||
// | ||
|
||
import Foundation | ||
import Security.AuthorizationDB | ||
|
||
class AuthorizationDBManager: NSObject { | ||
static let shared = AuthorizationDBManager() | ||
private func getAuth() -> AuthorizationRef? { | ||
if NSUserName() != "root" { | ||
print("Not Running as root, please execute with sudo privilege to do this function") | ||
exit(1) | ||
} | ||
var authRef : AuthorizationRef? = nil | ||
let err = AuthorizationCreate(nil, nil, AuthorizationFlags(rawValue: 0), &authRef) | ||
|
||
if err != noErr { | ||
|
||
TCSLog("error getting rights to write authdb") | ||
return nil | ||
} | ||
return authRef! | ||
} | ||
func rightsInfo() -> Dictionary<String,Any>? { | ||
var rightsInfo: CFDictionary? | ||
|
||
let err = AuthorizationRightGet("system.login.console", &rightsInfo) | ||
|
||
if err != noErr { | ||
TCSLog("eror getting right") | ||
return nil | ||
} | ||
let rightInfo = rightsInfo as? Dictionary<String, Any> | ||
|
||
return rightInfo | ||
} | ||
func consoleRights() -> Array <String> { | ||
|
||
guard let rightInfo = rightsInfo() else { | ||
TCSLog("error getting rightsInfo") | ||
|
||
return [] | ||
} | ||
|
||
guard let rightsArray = rightInfo["mechanisms"] else{ | ||
TCSLog("error getting mechanisms") | ||
|
||
return [] | ||
} | ||
guard let rightsArray = rightsArray as? Array<String> else { | ||
TCSLog("error getting rightsArray") | ||
|
||
return [] | ||
|
||
} | ||
return rightsArray | ||
} | ||
func setConsoleRights(rights:Array<String>) -> Bool { | ||
|
||
var rightInfo: CFDictionary? | ||
|
||
let err = AuthorizationRightGet("system.login.console", &rightInfo) | ||
|
||
if err != noErr { | ||
TCSLog("error AuthorizationRightGet") | ||
|
||
return false | ||
} | ||
|
||
guard var rightInfo = rightInfo as? Dictionary<String, Any> else { | ||
TCSLog("error rightInfo") | ||
|
||
return false | ||
} | ||
rightInfo["mechanisms"] = rights | ||
guard let auth = getAuth() else { | ||
TCSLog("error getAuth") | ||
|
||
return false | ||
} | ||
let r = rightInfo as CFTypeRef | ||
let err2 = AuthorizationRightSet(auth, "system.login.console",r, nil, nil, nil) | ||
|
||
if err2 != noErr { | ||
TCSLog("error AuthorizationRightSet") | ||
|
||
return false | ||
} | ||
return true | ||
} | ||
func replace(right:String, withNewRight newRight:String) -> Bool { | ||
|
||
var consoleRights = consoleRights() | ||
let positionOfOldRight = consoleRights.firstIndex(of: right) | ||
|
||
guard let positionOfOldRight = positionOfOldRight else { | ||
TCSLog("error positionOfOldRight") | ||
|
||
return false | ||
} | ||
|
||
consoleRights[positionOfOldRight] = newRight | ||
|
||
return setConsoleRights(rights: consoleRights) | ||
|
||
} | ||
func rightExists(right:String)->Bool{ | ||
let consoleRights = consoleRights() | ||
let positionOfRight = consoleRights.firstIndex(of: right) | ||
|
||
if positionOfRight == nil { | ||
TCSLog("did not find \(right)") | ||
return false | ||
} | ||
TCSLog("found \(right)") | ||
|
||
return true | ||
} | ||
func insertRight(newRight:String, afterRight right:String) -> Bool { | ||
var consoleRights = consoleRights() | ||
let positionOfRight = consoleRights.firstIndex(of: right) | ||
|
||
guard let positionOfRight = positionOfRight else { | ||
TCSLog("error positionOfRight") | ||
|
||
return false | ||
} | ||
consoleRights.insert(newRight, at: positionOfRight+1) | ||
|
||
return true | ||
} | ||
func insertRight(newRight:String, beforeRight right:String) -> Bool { | ||
var consoleRights = consoleRights() | ||
let positionOfRight = consoleRights.firstIndex(of: right) | ||
|
||
guard let positionOfRight = positionOfRight else { | ||
TCSLog("error positionOfRight2") | ||
|
||
return false | ||
} | ||
consoleRights.insert(newRight, at: positionOfRight) | ||
|
||
let success = setConsoleRights(rights: consoleRights) | ||
return success | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -49,6 +49,9 @@ | |
76BEF7F328724F120013E2A1 /* XCredsPowerControlMechanism.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7F228724F120013E2A1 /* XCredsPowerControlMechanism.swift */; }; | ||
76BEF7F628724FA80013E2A1 /* NSTaskWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7F528724FA80013E2A1 /* NSTaskWrapper.swift */; }; | ||
76BEF7F82872504C0013E2A1 /* ContextAndHintHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7F72872504C0013E2A1 /* ContextAndHintHandling.swift */; }; | ||
76BEF7FA28726C700013E2A1 /* AuthorizationDBManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7F928726C700013E2A1 /* AuthorizationDBManager.swift */; }; | ||
76BEF8002872A3030013E2A1 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 76BEF7FE2872A3030013E2A1 /* [email protected] */; }; | ||
76BEF8012872A3030013E2A1 /* loginwindow.png in Resources */ = {isa = PBXBuildFile; fileRef = 76BEF7FF2872A3030013E2A1 /* loginwindow.png */; }; | ||
76D7ADFB284EB15100332EBC /* TCSUnifiedLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADF9284EB15000332EBC /* TCSUnifiedLogger.m */; }; | ||
76D7ADFE284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */; }; | ||
76DD6D17285997F300A700ED /* OIDCLite in Frameworks */ = {isa = PBXBuildFile; productRef = 76DD6D16285997F300A700ED /* OIDCLite */; }; | ||
|
@@ -131,6 +134,9 @@ | |
76BEF7F228724F120013E2A1 /* XCredsPowerControlMechanism.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCredsPowerControlMechanism.swift; sourceTree = "<group>"; }; | ||
76BEF7F528724FA80013E2A1 /* NSTaskWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSTaskWrapper.swift; sourceTree = "<group>"; }; | ||
76BEF7F72872504C0013E2A1 /* ContextAndHintHandling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContextAndHintHandling.swift; sourceTree = "<group>"; }; | ||
76BEF7F928726C700013E2A1 /* AuthorizationDBManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AuthorizationDBManager.swift; path = XCredsLoginPlugIn/LoginWindow/AuthorizationDBManager.swift; sourceTree = SOURCE_ROOT; }; | ||
76BEF7FE2872A3030013E2A1 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; }; | ||
76BEF7FF2872A3030013E2A1 /* loginwindow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = loginwindow.png; sourceTree = "<group>"; }; | ||
76D7ADF9284EB15000332EBC /* TCSUnifiedLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TCSUnifiedLogger.m; sourceTree = "<group>"; }; | ||
76D7ADFA284EB15100332EBC /* TCSUnifiedLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCSUnifiedLogger.h; sourceTree = "<group>"; }; | ||
76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+TCSRealHomeFolder.m"; sourceTree = "<group>"; }; | ||
|
@@ -218,6 +224,7 @@ | |
76BEF7F028724E520013E2A1 /* LoginWindow */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
76BEF7F928726C700013E2A1 /* AuthorizationDBManager.swift */, | ||
76BEF7F128724EB60013E2A1 /* images */, | ||
76BEF7DC2871F5F00013E2A1 /* TCSReturnWindow.h */, | ||
76BEF7DB2871F5F00013E2A1 /* TCSReturnWindow.m */, | ||
|
@@ -233,6 +240,8 @@ | |
76BEF7F128724EB60013E2A1 /* images */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
76BEF7FF2872A3030013E2A1 /* loginwindow.png */, | ||
76BEF7FE2872A3030013E2A1 /* [email protected] */, | ||
76BEF7E6287202AF0013E2A1 /* ShutdownX.png */, | ||
76BEF7E7287202AF0013E2A1 /* [email protected] */, | ||
76BEF7E2287202080013E2A1 /* RestartX.png */, | ||
|
@@ -436,9 +445,11 @@ | |
isa = PBXResourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
76BEF8002872A3030013E2A1 /* [email protected] in Resources */, | ||
766355D928711C51002E3867 /* defaults.plist in Resources */, | ||
766355D52870F29A002E3867 /* TestWindowController.xib in Resources */, | ||
76BEF7E4287202090013E2A1 /* RestartX.png in Resources */, | ||
76BEF8012872A3030013E2A1 /* loginwindow.png in Resources */, | ||
766355D12870EBAD002E3867 /* VerifyOIDCPassword.xib in Resources */, | ||
76BEF7E8287202AF0013E2A1 /* ShutdownX.png in Resources */, | ||
766355DE28713486002E3867 /* LoginWebView.xib in Resources */, | ||
|
@@ -483,6 +494,7 @@ | |
766355D42870F29A002E3867 /* TestWindowController.swift in Sources */, | ||
766355C32870CB6F002E3867 /* XCredsLoginPlugin.m in Sources */, | ||
766355CB2870E5E9002E3867 /* NSFileManager+TCSRealHomeFolder.m in Sources */, | ||
76BEF7FA28726C700013E2A1 /* AuthorizationDBManager.swift in Sources */, | ||
76BEF7E12871F74D0013E2A1 /* LoginWindowControlsWindowController.swift in Sources */, | ||
76BEF7F628724FA80013E2A1 /* NSTaskWrapper.swift in Sources */, | ||
766355DB287132E9002E3867 /* LoginWebViewController.swift in Sources */, | ||
|
Binary file modified
BIN
+9.83 KB
(100%)
...deproj/project.xcworkspace/xcuserdata/tperfitt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
Oops, something went wrong.