如何使用ADSSO身份验证在macOS上装载AFP共享?

2024-05-16 04:46:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用NetFSMountURLSync在macOS机器上装载AFP网络共享,使用ADSSO对服务器进行身份验证

当使用mount_afp二进制文件进行装载时,将共享URL指定为afp://;AUTH=Client%20Krb%20v2@<hostname>/<share>就足够了,如man mount_afp中所述。但是,我找不到关于如何使用NetFSMountURLSync实现这一点的文档。与mount_afp相比,我更喜欢基于NetFS的方法,因为它不要求挂载之前存在挂载点目录

我尝试将Client Krb v2指定为NetFSMountURLSync调用的username参数,但似乎没有任何效果。以前有人偶然解决过这个问题吗

对于完整的上下文,我通过Python的objc调用例程,加载NetFS框架如下(受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:]))

脚本的参数是URL、装载路径、用户名、密码;我正在指定一个空的装载路径以装载到/Volumes的子文件夹中


Tags: pathimportnoneurlshareifusernameat