2

I am trying to use NetFSMountURLSync to mount an AFP network share on a macOS machine, using ADSSO to authenticate against the server.

When using the mount_afp binary to do the mounting, it is sufficient to specify the share URL as afp://;AUTH=Client%20Krb%20v2@<hostname>/<share>, as documented in man mount_afp. However, I cannot find documentation on how to achieve that with NetFSMountURLSync. I prefer the NetFS-based method compared to mount_afp, because it does not require the mount point directory to exist before the mount.

I tried specifying Client Krb v2 as the username parameter of the NetFSMountURLSync call but nothing like that seems to work. Has anyone solved this before by any chance?

For full context, I'm calling the routine via Python's objc, loading the NetFS Framework as follows (inspired by this Gist):

import CoreFoundation
import Foundation
import objc
import sys

NetFS = {}
objc.initFrameworkWrapper('NetFS', frameworkIdentifier=None, frameworkPath=objc.pathForFramework('NetFS.framework'), globals=NetFS, scan_classes=False)

def mount_share_at_path_with_credentials(share_path, mount_path, username, password):
    # Mounts a share at the specified path, returns the mount point or raises an error 

    sh_url = CoreFoundation.CFURLCreateWithString(None, share_path, None)
    mo_url = CoreFoundation.CFURLCreateWithString(None, mount_path, None) if mount_path else None

    # Set UI to reduced interaction                                                                                                                                                                              
    open_options  = {
        NetFS["kNAUIOptionKey"]: NetFS["kNAUIOptionNoUI"],
    }
    # Allow mounting sub-directories of root shares 
    # Also specify the share should be mounted directly at (not under) mount_path 
    mount_options = {
                     NetFS["kNetFSMountAtMountDirKey"]: bool(mount_path),
                     "SoftMount": False,
                     NetFS["kNetFSMountFlagsKey"]: 0,
                    }
    # Mount! 
    result = NetFS["NetFSMountURLSync"](sh_url, mo_url, username or None, password or None, open_options, mount_options, None)

    # Check if it worked 
    print "OPEN OPTIONS: {}".format(open_options)
    print "MOUNT OPTIONS: {}".format(mount_options)
    if result != 0:
         raise Exception('Error mounting url "%s" at path "%s": %s' % (share_path, mount_path, result))

if __name__ == "__main__":
    print sys.argv
    mount_share_at_path_with_credentials(*(sys.argv[1:]))

The arguments to the script are URL, mount-path, username, password; I'm specifying an empty mount-path to mount into a subfolder of /Volumes.

4

0 回答 0