我想在Mac上授权USB/CD。现在我使用DiskArbitration框架在用户模式下获得MountApprovalCallback。但是,这种回调的问题是,没有任何保证。如果我将得到回调,我将使用CFUserNotificationReceiveResponse()来接受用户的密码。但是当同时显示提示符时,用户可以打开DiskUtility并挂载设备。
所以,
提前谢谢。
发布于 2015-01-03 12:36:27
在kext中,您可以通过MAC ( mpo_mount_check_mount )策略框架中的mpo_mount_check_mount回调获得文件系统挂载回调的授权回调。你可以决定坐骑是否应该在那里前进。我怀疑您不会从cred参数中获得任何有关登录用户的信息,因为安装syscall很可能是由以root身份运行的守护进程发起的。我不知道你到底想做什么,所以这可能不是解决你的具体情况的最好方法。
/**
@brief Access control check for mounting a file system
@param cred Subject credential
@param vp Vnode that is to be the mount point
@param vlabel Label associated with the vnode
@param cnp Component name for vp
@param vfc_name Filesystem type name
Determine whether the subject identified by the credential can perform
the mount operation on the target vnode.
@return Return 0 if access is granted, otherwise an appropriate value for
errno should be returned.
*/
typedef int mpo_mount_check_mount_t(
kauth_cred_t cred,
struct vnode *vp,
struct label *vlabel,
struct componentname *cnp,
const char *vfc_name
);请注意,这是一个不支持的 KPI,所以苹果说它可能会在未来的版本中消失或中断。实际上,策略回调函数签名在主要OS版本之间经常发生变化,因此您可能需要在运行时检查OS版本,并对不同版本使用不同的函数。您还需要了解苹果发布的任何betas,看看它们是否破坏了您的代码。
有了这些之后,下面是您实际使用它的方式:
com.apple.kpi.dsep添加到kext的OSBundleLibraries字典中。(它使用达尔文版本控制,所以使用与其他com.apple.kpi.* bundle相同的版本)#include 在您的代码中(它已经在Kernel.framework中提供)struct mac_policy_ops,并初始化您感兴趣的任何函数指针字段,例如mpo_mount_check_mount。mac_policy_register()注册您的策略并保存它返回的句柄。您需要使用mac_policy_conf结构来配置您的策略,其中您将mpc_ops设置为指向您的策略结构,将mpc_loadtime_flags设置为MPC_LOADTIME_FLAG_UNLOADOK,将mpc_name设置为您的kext的反向DNS标识符,将mpc_fullname设置为一个人类可读的字符串,并将其设置为零初始化其他所有内容。mac_policy_unregister()和从mac_policy_register()收到的句柄取消注册。更多的信息可以找到在头文件中。
https://stackoverflow.com/questions/27702967
复制相似问题