在 AD 中搜索 objectGUID

发布于 2024-08-07 11:56:56 字数 644 浏览 5 评论 0 原文

我正在使用 Mark Russinovich 提供的 Active Directory Explorer。 这是一个很棒的工具。

我使用它来导航活动目录,以确保使用 .NET 中的 DirectorySearcher 的程序返回正确的数据。

但是,当我尝试使用 DirectorySearcher 在程序中搜索 objectGUID 时,会发生一些事情,如果我将实际的 GUID 作为字符串传递,它不会返回任何内容,就好像我使用 Active Directory Explorer,当我添加

值为 f8d764ff-9a6a-418e-a641-b6f99661a8d5 的 objectGuid 时,其搜索子句变为: (objectGUID=\FFd\D7\F8j\9A\8EA\A6A\B6\F9\96a\A8\D5*)

我该如何为我的程序中的directorySearcher 执行此操作,我猜它是一个八位字节字符串,但我想不通。

I'm using the Active Directory Explorer from Mark Russinovich.
It is a great tool.

I'm using it to navigate active directory to make sure my program that uses DirectorySearcher from .NET returns correct data.

Something happens though, when I try to search inside my program with DirectorySearcher for objectGUID, if I pass in the actual GUID as a string it doesn't return anything, where as if I use Active Directory Explorer, when I add

objectGuid with value f8d764ff-9a6a-418e-a641-b6f99661a8d5, its search clause becomes:
(objectGUID=\FFd\D7\F8j\9A\8EA\A6A\B6\F9\96a\A8\D5*)

How do I do this for directorySearcher in my program, I'm guessign it's an octet string thing, but I can't figure it out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-08-14 11:56:56

论坛伴随着优秀的目录服务编程 .NET 开发人员指南(Joe Kaplan / Ryan Dunn)是此类信息的绝佳来源。

查看此处标题为 Find the object using objectGuid property 的线程,其中显示了如何转换S.DS“OctetString”格式的“常规”GUID。

internal string ConvertGuidToOctetString(string objectGuid)
{
   System.Guid guid = new Guid(objectGuid);
   byte[] byteGuid = guid.ToByteArray();

   string queryGuid = "";

   foreach (byte b in byteGuid)
   {
       queryGuid += @"\" + b.ToString("x2");
   }

   return queryGuid; 
}

这可以通过使用 StringBuilder 而不是连续连接字符串来稍微优化 - 但否则看起来相当简单。

希望这有帮助。

马克

The forums accompanying the excellent The .NET Developer's Guide to Directory Services Programming (Joe Kaplan / Ryan Dunn) is an excellent source for information like this.

Check out this thread here entitled Find the object using objectGuid property, which shows how you can convert a "regular" GUID to the S.DS "OctetString" format.

internal string ConvertGuidToOctetString(string objectGuid)
{
   System.Guid guid = new Guid(objectGuid);
   byte[] byteGuid = guid.ToByteArray();

   string queryGuid = "";

   foreach (byte b in byteGuid)
   {
       queryGuid += @"\" + b.ToString("x2");
   }

   return queryGuid; 
}

This could be slightly optimized by using a StringBuilder instead of consecutively concatenating together a string - but it seems fairly straightforward otherwise.

Hope this helps.

Marc

壹場煙雨 2024-08-14 11:56:56
...
searcher.PropertiesToLoad.Add("objectGUID");

SearchResultCollection found = found = searcher.FindAll();

foreach (SearchResult result in found)
{
   Guid oGuid = new Guid((byte[])result.Properties["objectGUID"][0]);
}
...
...
searcher.PropertiesToLoad.Add("objectGUID");

SearchResultCollection found = found = searcher.FindAll();

foreach (SearchResult result in found)
{
   Guid oGuid = new Guid((byte[])result.Properties["objectGUID"][0]);
}
...
葬花如无物 2024-08-14 11:56:56

要获取 ADExplorer 可用的八位字节字符串,请将以下步骤应用于 GUID 字符串:

  • 首先将 GUID 大写:

F8D764FF-9A6A-418E-A641-B6F99661A8D5

  • 将每个破折号上的它分成五个部分:

F8D764FF, 9A6A, 418E, A641, B6F99661A8D5

  • 将每个部分拆分为字节(每个字节两个十六进制数字):

{F8, D7, 64, FF}, {9A, 6A}, {41, 8E}, {A6, 41}, {B6, F9, 96, 61, A8, D5}

  • 反转前部分的字节:

{FF, 64, D7, F8 }, {6A, 9A}, {8E, 41}, {A6, 41}, {B6, F9, 96, 61, A8, D5}

  • 忽略分段:

FF, 64, D7, F8, 6A, 9A, 8E, 41, A6, 41, B6, F9, 96, 61, A8, D5

  • 在每个字节前面加上反斜杠:

\FF, \64, \D7, \F8, \6A, \9A, \8E, \41, \A6, \41, \B6, \F9, \96, \61, \A8, \D5

  • 连接字节:

\ FF\64\D7\F8\6A\9A\8E\41\A6\41\B6\F9\96\61\A8\D5

To get an Octet String usable by ADExplorer, apply these steps to the GUID string:

  • first uppercase the GUID:

F8D764FF-9A6A-418E-A641-B6F99661A8D5

  • split it on each dash into five parts:

F8D764FF, 9A6A, 418E, A641, B6F99661A8D5

  • split each part into bytes (two hex digits each):

{F8, D7, 64, FF}, {9A, 6A}, {41, 8E}, {A6, 41}, {B6, F9, 96, 61, A8, D5}

  • reverse the bytes of the first three parts:

{FF, 64, D7, F8}, {6A, 9A}, {8E, 41}, {A6, 41}, {B6, F9, 96, 61, A8, D5}

  • disregard the division into parts:

FF, 64, D7, F8, 6A, 9A, 8E, 41, A6, 41, B6, F9, 96, 61, A8, D5

  • prepend a backslash to every byte:

\FF, \64, \D7, \F8, \6A, \9A, \8E, \41, \A6, \41, \B6, \F9, \96, \61, \A8, \D5

  • concatenate the bytes:

\FF\64\D7\F8\6A\9A\8E\41\A6\41\B6\F9\96\61\A8\D5

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文