0x80005000 OU中带特殊字符的UserPrincipal.GetGroups出现未知错误 [英] 0x80005000 Unknown Error on UserPrincipal.GetGroups with Special Characters in OU

查看:90
本文介绍了0x80005000 OU中带特殊字符的UserPrincipal.GetGroups出现未知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用UserPrincipal的GetGroups方法。如果用户帐户位于包含正斜杠的OU中,则对GetGroups的调用将失败,并出现COM未知错误0x80005000。找到该用户帐户只是找到,我可以访问其他属性。如果我在OU名称中删除了斜杠,那么一切正常。我找到了一个在名称中转义斜杠的引用,但这是用GetGroups方法包装的。我还发现一定要使用已完成的PrincipalContext(ContextType,String)构造函数。我还尝试将FQDN与转义斜杠一起使用,并获得相同的结果。我在C#中有一些示例代码:



我正在使用Visual Studio2012。该代码在Windows 10 Enterprise x64上运行。 .net目标版本为4.5

 (使用系统); 
使用System.Linq;
使用System.DirectoryServices.AccountManagement;

字符串SamAccountName = user1;
//用户所在的OU:
//损坏的OU: OU =测试/测试,DC = contoso,DC = com
//工作的OU: OU =测试& Test,DC = contoso,DC = com

PrincipalContext domainContext =新的PrincipalContext(ContextType.Domain,Environment.UserDomainName);
UserPrincipal用户= UserPrincipal.FindByIdentity(domainContext,IdentityType.SamAccountName,SamAccountName);

//找到了该用户,因此可以使用
Console.WriteLine( User Found:{0},user.DistinguishedName);

//这将导致COM异常:未知错误0x80005000
字符串输出= string.Join(Environment.NewLine,user.GetGroups()。Select(x => x.Name)。 ToArray());
Console.WriteLine(output);

最后,我只是替换了OU名称中的任何此类特殊字符,因为到目前为止这是最简单的解。我主要只是想确保我编写的代码不会在将来爆炸。

解决方案

我相信



AccountManagement 命名空间的.NET Core实现的源代码现已在线可用。 。我可以想象.NET Framework版本是相同的。



我相信问题出在 ADStoreCtx.cs的第1218行

  roots.Add(new DirectoryEntry( GC:// + gc.Name + / + p.DistinguishedName,this.credentials != null?this.credentials.UserName:null,this.credentials!= null?this.credentials.Password:null,this.AuthTypes)); 

这会将用户的专有名称放入LDAP路径,该路径使用斜杠作为分隔符,而不会转义任何



我知道.NET Core的错误可以在GitHub中报告,但是我不确定在哪里报告.NET Framework的错误。 / p>

I'm trying to use the GetGroups method of UserPrincipal. If the User account is in an OU that contains a forward slash, the call to GetGroups fails with the COM Unknown Error 0x80005000. The user account is found just find and I can access other properties. If I remove the slash in the OU name then everything works. I found a reference to escaping the slash in the name but that's wrapped under the GetGroups method. I also found making sure to use the PrincipalContext(ContextType, String) constructor which I've done. I've also tried using the FQDN with an escaped slash and get the same results. I have some example code below in C#:

I'm using Visual Studio 2012. The code is running on Windows 10 Enterprise x64. The .net Target version is 4.5

using System;
using System.Linq;
using System.DirectoryServices.AccountManagement;

string SamAccountName = "user1";
//The OUs the user is in:
//Broken OU:  "OU=Test / Test,DC=contoso,DC=com"
//Working OU: "OU=Test & Test,DC=contoso,DC=com"

PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, Environment.UserDomainName);
UserPrincipal user = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, SamAccountName);

//The user was found so this works
Console.WriteLine("User Found: {0}", user.DistinguishedName);

//This causes COM Exception: Unknown Error 0x80005000                
string output = string.Join(Environment.NewLine, user.GetGroups().Select(x => x.Name).ToArray());
Console.WriteLine(output);

Ultimately I just replace any of these types of special characters in the OU name because that's by far the easiest solution. I'm mainly just curious about making sure the code I'm writing doesn't explode down the road.

解决方案

I believe this is a bug.

The source code of the .NET Core implementation of the AccountManagement namespace is available online now. I would imagine the .NET Framework version is much the same.

I believe the problem is on line 1218 of ADStoreCtx.cs:

roots.Add(new DirectoryEntry("GC://" + gc.Name + "/" + p.DistinguishedName, this.credentials != null ? this.credentials.UserName : null, this.credentials != null ? this.credentials.Password : null, this.AuthTypes));

That is dropping the user's distinguished name into an LDAP path, which uses slashes as separators, without escaping any slashes in the DN.

I know bugs for .NET Core can be reported in GitHub, but I'm not sure where to report a bug with .NET Framework.

这篇关于0x80005000 OU中带特殊字符的UserPrincipal.GetGroups出现未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆