Gui*_*ers 18 c# samba security-identifier
Samba3在用户S-1-22-1的范围内使用SID,在组中使用S-1-22-2.例如,S-1-22-1-1-10042是具有uid 10042的UNIX用户.我希望能够将这样的SID映射到名称,如'myunixaccount',类似于Windows帐户的此功能制图:
SecurityIdentifier sid = ...; // For instance from FileSystemAccessRule.
name = sid.Translate(typeof(NTAccount)).Value;
Run Code Online (Sandbox Code Playgroud)
Windows本身能够进行此映射,但我似乎无法找到映射算法.
增加:环境描述
测试了在C#中将SID转换为用户名的建议解决方案.它没有帮助.因此一些额外的环境描述:
piece of ldap.conf
nss_base_passwd=OU=nl,OU=xxx,dc=yyy,dc=local?sub(objectCategory=user)
nss_map_objectclass posixAccount User
nss_map_objectclass shadowAccount User
nss_map_attribute uid sAMAccountName
nss_map_attribute uidNumber uidNumber
nss_map_attribute gidNumber gidNumber
nss_map_attribute cn sAMAccountName
nss_map_attribute uniqueMember member
nss_map_attribute userPassword msSFUPassword
nss_map_attribute homeDirectory unixHomeDirectory
nss_map_attribute loginShell loginShell
nss_map_attribute gecos cn
nss_map_objectclass posixGroup Group
nss_map_attribute shadowLastChange pwdLastSet
Run Code Online (Sandbox Code Playgroud)
使用Windows身份验证的UNIX上的交互式登录工作正常,适用于Samba共享的dito.在域上使用PC时,它不会要求凭据.
一些样本,用户gle3(在1中突出显示)也存在于域中但具有不同的SID.这里使用的SID是Samba SID,如S-1-22-1-1-10001.
在(2)中,您可以看到用户存在于使用过的passwd配置中.以下当然不会产生任何结果:grep gle3 /etc/passwd因为条目是从远程服务器使用的.远程服务器将gle3的用户SID映射到UNIX uid 10001和默认组10003.
在(3)中,您可以看到默认组不存在,这就是权限无法将其解析为名称的原因.
所以很明显Windows会以某种方式询问文件服务器:"给我这些SID上的数据"和Samba文件服务器以某种方式响应:好的,那就是"Unix User\gle3"和"Unix Group\10003",但我没有一个组最后一个的名称.

前一段时间我一直在考虑这个问题,以便在 2000 多台计算机网络上构建本地 LAN 爬虫。我很确定你问的不是 SMB 协议的一部分。您实际上可以看到:如果 Windows 无法解析凭据,它将在安全属性中显示 SID。
基本上,SID 是映射到唯一 ID 的对象 ID(如用户名/组)。它们的工作方式类似于 GUID。通常 PC 使用 SID 进行通信,而不是使用用户名。
现在,您需要考虑不同类型的 SID:
实际上还有很多东西......证书凭证、保留用户等都是可用于登录的对象 ID - 但我只是简单地讲一下。此评论的关键要点是,虽然所有用户名都有一个 SID,但并非所有 SID 也都有一个 username。
如果您在某处有 AD(您似乎确实如此),则正确的设置将包含此处的所有用户。获取完整映射的最简单方法是简单地枚举完整的活动目录。那应该包含所有映射。基本上是这样工作的:
DirectoryEntry root = new DirectoryEntry("LDAP://dc=MyCompany,dc=com");
DirectorySearcher search = new DirectorySearcher(root);
search.Filter = "(objectCategory=Person)";
search.SearchScope = SearchScope.Subtree;
search.PropertiesToLoad.Add("objectSid");
search.PropertiesToLoad.Add("displayName");
foreach(SearchResult result in search.FindAll())
{
// grab the data - if present
if(result.Properties["objectSid"] != null && result.Properties["objectSid"].Count > 1)
{
var sid = result.Properties["objectSid"][0];
}
if(result.Properties["displayName"] != null && result.Properties["displayName"].Count > 0)
{
var userName = result.Properties["displayName"][0].ToString();
}
}
Run Code Online (Sandbox Code Playgroud)