Security ID Structure Invalid , Getting this error when setting the new SecurityDescriptor for AD user properties(安全 ID 结构无效,为 AD 用户属性设置新的 SecurityDescriptor 时出现此错误)
问题描述
我试图在 AD 帐户中设置用户选项,在创建帐户时我试图设置选项用户无法更改密码".
I am trying to set a user option in an AD Account, while creating the account i am trying to set the option "User Cannot Change Password".
但我在尝试设置新安全描述符的值时收到错误安全 ID 结构无效"错误.
But I am getting the error "Security ID Structure invalid" error, when trying to set the value of new security descriptor.
这是示例代码,
string[] trustees = new string[] { @"NT AUTHORITYSELF", "EVERYONE" };
IADsSecurityDescriptor sd = (IADsSecurityDescriptor)usr.Properties["ntSecurityDescriptor"].Value;
IADsAccessControlList acl = (IADsAccessControlList)sd.DiscretionaryAcl;
IADsAccessControlEntry ace = new AccessControlEntry();
foreach (string trustee in trustees)
{
ace.Trustee = trustee;
ace.AceFlags = 0;
//For remove 'User cannot change password' selection
//ace.AceType = (int) ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOWED_OBJECT;
ace.AceType = (int)ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_DENIED_OBJECT;
ace.Flags = (int)ADS_FLAGTYPE_ENUM.ADS_FLAG_OBJECT_TYPE_PRESENT;
ace.ObjectType = PASSWORD_GUID;
ace.AccessMask = (int)ADS_RIGHTS_ENUM.ADS_RIGHT_DS_CONTROL_ACCESS;
acl.AddAce(ace);
ace.Trustee = trustee;
ace.AceFlags = 0;
ace.AceType = (int)ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_DENIED_OBJECT;
ace.Flags = (int)ActiveDs.ADS_FLAGTYPE_ENUM.ADS_FLAG_OBJECT_TYPE_PRESENT;
ace.ObjectType = PASSWORD_GUID;
ace.AccessMask = (int)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_DS_CONTROL_ACCESS;
acl.AddAce(ace);
}
sd.DiscretionaryAcl = acl;
usr.Properties["ntSecurityDescriptor"].Value = (ActiveDs.IADsSecurityDescriptor)sd;
usr.CommitChanges();
知道为什么我会收到此安全 ID 结构无效"错误.
Any Idea why i am getting this "Security ID structure is invalid" error.
推荐答案
我用谷歌搜索并在网上找到了类似的代码.我相信上面的代码应该可以工作.我确实看到有人有类似的抱怨.它似乎与您使用的帐户有关.您使用什么帐户来运行上述代码?
I googled and found similar codes on the web. I believe the above code should work. I did see somebody have similar complaints. It seems to be related to the account that you are using. What account are you using to run the above code?
另外,如果您可以使用 .NET 3.5 或更高版本,请尝试使用以下代码.
Also, if you can use .NET 3.5 or above, try using the following code.
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "YourDomain"))
{
UserPrincipal up = UserPrincipal.FindByIdentity(context, "Domain\YourUser");
up.UserCannotChangePassword = false;
up.Save();
}
这篇关于安全 ID 结构无效,为 AD 用户属性设置新的 SecurityDescriptor 时出现此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:安全 ID 结构无效,为 AD 用户属性设置新的 Secu
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
