Skip to content

Commit

Permalink
added ShareMounter and missing KerbUtil filet
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Dec 28, 2023
1 parent 93ac8b9 commit 3f14dc2
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 9 deletions.
30 changes: 30 additions & 0 deletions KerbUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Header.h
// NoMAD
//
// Created by Joel Rennich on 4/26/16.
// Copyright © 2016 Orchard & Grove Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <GSS/GSS.h>
#import <Cocoa/Cocoa.h>
#import <Security/Security.h>
#import <DirectoryService/DirectoryService.h>
#import <OpenDirectory/OpenDirectory.h>

extern OSStatus SecKeychainItemSetAccessWithPassword(SecKeychainItemRef item, SecAccessRef access, UInt32 passLength, const void* password);

@interface KerbUtil : NSObject
@property (nonatomic, assign, readonly) BOOL finished; // observable

- (void)getKerberosCredentials:(NSString *)password :(NSString *)userPrincipal completion:(void(^)(NSString *))callback;
- (NSString *)getKerbCredentials:(NSString *)password :(NSString *)userPrincipal;
- (void)changeKerberosPassword:(NSString *)oldPassword :(NSString *)newPassword :(NSString *)userPrincipal completion:(void(^)(NSString *))callback;
- (NSString *)changeKerbPassword:(NSString *)oldPassword :(NSString *)newPassword :(NSString *)userPrincipal;
- (int)checkPassword:(NSString *)myPassword;
- (int)changeKeychainPassword:(NSString *)oldPassword :(NSString *)newPassword;
- (OSStatus)resetKeychain:(NSString *)password;

@end

2 changes: 1 addition & 1 deletion Profile Manifest/com.twocanoes.xcreds.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>pfm_app_url</key>
<string>https://github.com/twocanoes/xcreds</string>
<key>pfm_description</key>
<string>XCreds 4.0 (6174) OAuth Settings</string>
<string>XCreds 4.0 (6175) OAuth Settings</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_domain</key>
Expand Down
138 changes: 138 additions & 0 deletions ShareMounter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//
// ShareMounter.swift
// NoMAD
//
// Created by Joel Rennich on 8/29/16.
// Copyright © 2016 Trusource Labs. All rights reserved.
//

// mad props to Kyle Crawshaw
// since much of this is cribbed from Share Mounter

import Foundation
import NetFS

struct share_info {
var groups: [String]
var share_url: String
var title: String
}

class ShareMounter {

var all_shares = [share_info]()
let ws = NSWorkspace.init()
var prefs: [String]

init() {
// read in the preference files


if UserDefaults.standard.bool(forKey: PrefKeys.showHome.rawValue) {
//NSLog("Looking for ShareMounter files")
//prefs = try! ["/Library/Preferences/ShareMounter.plist", NSHomeDirectory() + "/Library/Preferences/ShareMounter.plist"]
/*
do {
try! getShares()
}
} else {
prefs = [""]
*/
}
prefs = [""]
}

func mount() {

let myGroups = UserDefaults.standard.array(forKey: PrefKeys.groups.rawValue)

for share in all_shares {
for group in myGroups! {
if share.groups.contains(group as! String) {
// time to mount
NSLog("Attempting to mount: " + share.share_url)
asyncMountShare(share.share_url)
break
}
}
}
}

func getShares() {
for place in prefs {
let myDictionary = NSDictionary.init(contentsOfFile: place)

if myDictionary != nil {
let shares = (myDictionary?.object(forKey: "network_shares"))! as! [AnyObject]

for i in shares {
let currentShare = share_info(groups: i.object(forKey: "groups")! as! Array, share_url: i.object(forKey: "share_url")! as! String, title: i.object(forKey: "title")! as! String)
all_shares.append(currentShare)
}
}
}
}

func openOptionsDict() -> CFMutableDictionary {
let dict = NSMutableDictionary()
dict[kNAUIOptionKey] = kNAUIOptionNoUI
dict[kNetFSUseGuestKey] = true
return dict
}

func mountOptionsDict() -> CFMutableDictionary {
let dict = NSMutableDictionary()
//dict[kNetFSMountFlagsKey] = Int(MNT_DONTBROWSE)
return dict
}

func asyncMountShare(_ serverAddress: String) {

let escapedAddress = serverAddress.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
let shareAddress = URL(string: escapedAddress!)!

// TODO: ensure the URL is reachable before attempting to mount

//let open_options : CFMutableDictionary = openOptionsDict()
let mount_options : CFMutableDictionary = mountOptionsDict()

var requestID: AsyncRequestID? = nil
let queue = DispatchQueue.main

if let userPrinc = UserDefaults.standard.string(forKey: PrefKeys.userPrincipal.rawValue){
NetFSMountURLAsync(shareAddress as CFURL,
nil,
userPrinc as CFString,
nil,
nil,
mount_options,
&requestID,
queue)
{(stat:Int32, requestID:AsyncRequestID?, mountpoints:CFArray?) -> Void in
if let mountpoints = mountpoints as? Array<String>{
myLogger.logit(.base, message: "Mounted \(mountpoints)")
}
}
}



func getNetworkShares() {
let fm = FileManager.default

let myShares = fm.mountedVolumeURLs(includingResourceValuesForKeys: nil, options: FileManager.VolumeEnumerationOptions.skipHiddenVolumes)

for share in myShares! {

var myDes: NSString? = nil
var myType: NSString? = nil

ws.getFileSystemInfo(forPath: share.path, isRemovable: nil, isWritable: nil, isUnmountable: nil, description: &myDes, type: &myType)
print(myType!)
if myType! == "smbfs" {
print("Volume: " + share.path + " is an SMB network volume.")
}
}
}
}
}
16 changes: 10 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
76BEF8002872A3030013E2A1 /* loginwindow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 76BEF7FE2872A3030013E2A1 /* loginwindow@2x.png */; };
76BEF8012872A3030013E2A1 /* loginwindow.png in Resources */ = {isa = PBXBuildFile; fileRef = 76BEF7FF2872A3030013E2A1 /* loginwindow.png */; };
76C0840B2A9A311E008039FA /* ControlsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 76C084092A9A2635008039FA /* ControlsViewController.xib */; };
76C4ACBF2B3D0F8D003B3605 /* ShareMounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76C4ACBE2B3D0F8D003B3605 /* ShareMounter.swift */; };
76C4BAB02B353A30007B2C57 /* KlistUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7657DEC82B350606003A23DB /* KlistUtil.swift */; };
76C4BAB12B353A3A007B2C57 /* DNSResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7657DEBE2B3505A3003A23DB /* DNSResolver.m */; };
76C4BAB32B353AD7007B2C57 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 76C4BAB22B353AD7007B2C57 /* libresolv.tbd */; };
Expand Down Expand Up @@ -439,6 +440,7 @@
76BEF7FE2872A3030013E2A1 /* loginwindow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "loginwindow@2x.png"; sourceTree = "<group>"; };
76BEF7FF2872A3030013E2A1 /* loginwindow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = loginwindow.png; sourceTree = "<group>"; };
76C084092A9A2635008039FA /* ControlsViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ControlsViewController.xib; sourceTree = "<group>"; };
76C4ACBE2B3D0F8D003B3605 /* ShareMounter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShareMounter.swift; sourceTree = "<group>"; };
76C4BAB22B353AD7007B2C57 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; };
76C4BAB52B353AF7007B2C57 /* Kerberos.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Kerberos.framework; path = System/Library/Frameworks/Kerberos.framework; sourceTree = SDKROOT; };
76C4BABA2B353B4B007B2C57 /* KerbUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KerbUtil.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -759,6 +761,7 @@
76EE069127FD1D00009E0F3A = {
isa = PBXGroup;
children = (
76C4ACBE2B3D0F8D003B3605 /* ShareMounter.swift */,
76C4BAB92B353B3F007B2C57 /* NoMAD */,
760148A82B23639D00E119A2 /* NSBundle+FindBundlePath.swift */,
7614D03B2B181A5D006EAF36 /* icon_128x128.png */,
Expand Down Expand Up @@ -1303,6 +1306,7 @@
7657DEAF2B3503BF003A23DB /* SessionManager.swift in Sources */,
7681FEC52A4C8B9000F91CD1 /* AboutWindowController.swift in Sources */,
768633D92AFC4908004065E5 /* WifiManager.swift in Sources */,
76C4ACBF2B3D0F8D003B3605 /* ShareMounter.swift in Sources */,
7657DED92B351B5B003A23DB /* UNIXUtilities.swift in Sources */,
76E74DCF2B3902F0004C6429 /* XCredsMechanismProtocol.swift in Sources */,
76EE06C227FD1F50009E0F3A /* MainMenu.swift in Sources */,
Expand Down Expand Up @@ -1410,7 +1414,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6174;
CURRENT_PROJECT_VERSION = 6175;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1447,7 +1451,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6174;
CURRENT_PROJECT_VERSION = 6175;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1568,7 +1572,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6174;
CURRENT_PROJECT_VERSION = 6175;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1605,7 +1609,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6174;
CURRENT_PROJECT_VERSION = 6175;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1755,7 +1759,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6174;
CURRENT_PROJECT_VERSION = 6175;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1797,7 +1801,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6174;
CURRENT_PROJECT_VERSION = 6175;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<key>auth_mech_fixup.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
<integer>8</integer>
</dict>
<key>authrights.xcscheme_^#shared#^_</key>
<dict>
Expand All @@ -42,7 +42,7 @@
<key>test.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>7</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down

0 comments on commit 3f14dc2

Please sign in to comment.