如何发现"NT AUTHORITY"不是AD服务器?

How to find that "NT AUTHORITY" it is not an AD server?

我正在尝试读取 msExchMailboxSecurityDescriptor,以确定它是否包含对另一个人的完全访问权限。访问控制条目包含 netbios 格式的受托者 (DOMAIN\Username).

SecurityDescriptor secDesc = (SecurityDescriptor)userDirectoryEntry.Properties["msExchMailboxSecurityDescriptor"].Value;
AccessControlList usrAcl = (AccessControlList)secDesc.DiscretionaryAcl;
foreach (AccessControlEntry ace in (IEnumerable)usrAcl)
{
    var netbiosDn = ace.Trustee.Split('\')[0];
    var netbiosUser = ace.Trustee.Split('\')[1];
    // now, the problem:
    UserPrincipal user = UserPrincipal.FindByIdentity(
        new PrincipalContext(ContextType.Domain, netbiosDn), 
        netbiosUser
    );

直到最后一行,我必须连接到正确的 AD 服务器并获取一些用户信息。显然,当该域没有可用的服务器时,这会失败,例如 "NT AUTHORITY" 或 "BUILTIN" "domains" 中的任何一个。它不仅失败了,还需要相当长的时间才能成功。

到底怎么区分哪些是AD域,哪些可以连接到AD服务器,哪些不是?

我可能会在安全描述符中找到一些示例用户,仅供您感受一下问题:

看看SecurityIdentifier.IsWellKnown

您可以传递各种值,包括 WellKnownSidType.NTAuthoritySid 以确定您拥有哪种 SID。

(另请参阅 this PowerShell 将名称翻译成可读名称的代码。)