我正在尝试检查特定文件的特定文件的权限 受托人和我正在使用win32 API GetEffectiveRightsFromAcl()。什么时候 该文件可由域组访问,该功能 当本地帐户(admin或其他)时,返回5(拒绝访问) 用于执行该功能。
这三个陈述总结了我所看到的行为 GetEffectiveRightsFromAcl():
有谁知道这背后的原因?它看起来像我这样 与Active Directory安全性相关。什么设置可能会影响这个 什么是调试这个的好方法?
另外,我听说GetEffectiveRightsFromAcl()可能通常有问题并且使用AccessCheck()代替。但是我需要能够获取任意SID并检查它对文件的访问权限,因为AccessCheck()需要模拟令牌,我不知道如何从任意SID中获取令牌......任何想法?感谢
鲍勃
答案 0 :(得分:3)
我使用过C#,对我来说效果很好。
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security.AccessControl;
namespace DACL
{
class Class1
{
private enum MULTIPLE_TRUSTEE_OPERATION
{
NO_MULTIPLE_TRUSTEE,
TRUSTEE_IS_IMPERSONATE
}
private enum TRUSTEE_FORM
{
TRUSTEE_IS_SID,
TRUSTEE_IS_NAME,
TRUSTEE_BAD_FORM,
TRUSTEE_IS_OBJECTS_AND_SID,
TRUSTEE_IS_OBJECTS_AND_NAME
}
private enum TRUSTEE_TYPE
{
TRUSTEE_IS_UNKNOWN,
TRUSTEE_IS_USER,
TRUSTEE_IS_GROUP,
TRUSTEE_IS_DOMAIN,
TRUSTEE_IS_ALIAS,
TRUSTEE_IS_WELL_KNOWN_GROUP,
TRUSTEE_IS_DELETED,
TRUSTEE_IS_INVALID,
TRUSTEE_IS_COMPUTER
}
private struct TRUSTEE
{
public IntPtr pMultipleTrustee;
public MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation;
public TRUSTEE_FORM TrusteeForm;
public TRUSTEE_TYPE TrusteeType;
public IntPtr ptstrName;
}
[DllImport("advapi32.dll", SetLastError = true)]
private static extern void BuildTrusteeWithSid(
ref TRUSTEE pTrustee,
byte[] sid
);
[DllImport("advapi32.dll")]
private static extern uint GetEffectiveRightsFromAcl(byte[] pacl, ref TRUSTEE pTrustee, ref uint pAccessRights);
public bool HasAccess(SecurityIdentifier sid)
{
DiscretionaryAcl dacl = <DACL from somewhere>;
byte[] daclBuffer = new byte[dacl.BinaryLength];
dacl.GetBinaryForm(daclBuffer, 0);
byte[] sidBuffer = new byte[sid.BinaryLength];
sid.GetBinaryForm(sidBuffer, 0);
TRUSTEE t = new TRUSTEE();
BuildTrusteeWithSid(ref t, sidBuffer);
uint access = 0;
uint hr = GetEffectiveRightsFromAcl(daclBuffer, ref t, ref access);
int i = Marshal.Release(t.ptstrName);
return ((access & <Desired Access>) == <Desired Access>) ? true : false;
}
}
}
答案 1 :(得分:2)