Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finding executables based on bundle identifier from profile services.
  • Loading branch information
adku committed Aug 29, 2019
commit b416a4b6f101e5d785cf48edee25da02fa4fcc5c
20 changes: 20 additions & 0 deletions Source/Model/Executable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,25 @@ class Executable: NSObject {
@objc dynamic var networkVolumesPolicyString: String = "-"
@objc dynamic var removableVolumesPolicyString: String = "-"

@objc dynamic var policy: [String : String] = ["addressBook": "-",
"photos": "-",
"reminders": "-",
"calendar": "-",
"accessibility": "-",
"postEvents": "-",
"adminFiles": "-",
"allFiles": "-",
"camera": "-",
"microphone": "-",
"fileProvider": "-",
"listenEvent": "-",
"mediaLibrary": "-",
"screenCapture": "-",
"speechRecognition": "-",
"desktopFolder": "-",
"documentsFolder": "-",
"downloadsFolder": "-",
"networkVolumes": "-",
"removableVolumes": "-"]
@objc dynamic var appleEvents: [AppleEventRule] = []
}
57 changes: 57 additions & 0 deletions Source/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,34 @@ extension Model {
services: services)
}

func importProfile(tccProfile: TCCProfile) {

if let content = tccProfile.content.first {

let mirroredServices = Mirror(reflecting: content.services)

for (_, attr) in mirroredServices.children.enumerated() {
if let policy = attr.value as? [TCCPolicy] {
checkAllPolicies(policies: policy)
print(attr.label)
}
}

// we have all executables now we can adjust services and others for them based on tccprofile
if let addressBook = content.services.addressBook {
for book in addressBook {
var executable = getExecutable(bundleIdentifier: book.identifier)
if book.allowed {
executable?.addressBookPolicyString = "Allow"
} else {
executable?.addressBookPolicyString = "Deny"
}
}
}

}
}

func policyFromString(executable: Executable, value: String) -> TCCPolicy? {
let allowed: Bool
switch value {
Expand All @@ -260,4 +288,33 @@ extension Model {
codeRequirement: executable.codeRequirement,
allowed: allowed)
}

func findExecutableUsing(bundleIdentifier: String) -> Executable? {
if let path = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleIdentifier) {
if let fileURL = URL(string: "file://\(path)") {
let executable = self.loadExecutable(url: fileURL)
return executable
}
}
return nil
}

func checkAllPolicies(policies: [TCCPolicy]) {
for tccPolicy in policies {
if let executable = findExecutableUsing(bundleIdentifier: tccPolicy.identifier) {
if getExecutable(bundleIdentifier: tccPolicy.identifier) == nil {
self.selectedExecutables.append(executable)
}
}
}
}

func getExecutable(bundleIdentifier: String) -> Executable? {
for executable in selectedExecutables {
if (executable.identifier == bundleIdentifier) {
return executable
}
}
return nil
}
}
4 changes: 2 additions & 2 deletions Source/View Controllers/TCCProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ class TCCProfileViewController: NSViewController {
tccProfileImporter.loadTCCProfileFromFile(window: window, { [weak self] tccProfileResult in
switch tccProfileResult {
case .success(let tccProfile):
print(tccProfile)
//configureUI
self?.model.importProfile(tccProfile: tccProfile)
case .failure(let tccProfileImportError):
print(tccProfileImportError)
if let error = tccProfileImportError {
//error
}
Expand Down