简体   繁体   English

如何使用 LDAP 请求启用或禁用 AD 用户帐户?

[英]How can I enable or disable an AD user account with an LDAP request?

So far I was able to find users in LDAP but I don't know how can I enable or disable them.到目前为止,我能够在 LDAP 中找到用户,但我不知道如何启用或禁用它们。

As a second question, if my account has Domain Admin rights, I will be able to enable or disable account from LDAP or not?作为第二个问题,如果我的帐户具有域管理员权限,我是否能够启用或禁用来自 LDAP 的帐户?

Note: This is about a Microsoft Active Directory running on Windows 2003.注意:这是关于在 Windows 2003 上运行的 Microsoft Active Directory。

I know that I can check active uses with:我知道我可以通过以下方式检查有效用途

(!(useraccountcontrol:1.2.840.113556.1.4.803:=2))

Disabled useds:禁用用途:

(useraccountcontrol:1.2.840.113556.1.4.803:=2)

The question is how do I set the attribute in such way that it will not loose other binary flags inside.问题是我如何以不会丢失内部其他二进制标志的方式设置属性。

You need to use a bit of logic here.您需要在这里使用一些逻辑。 So to disable a user, you set the disable bit (2).因此,要禁用用户,您可以设置禁用位 (2)。 So:所以:

const long ADS_UF_ACCOUNTDISABLE = 0x00000002;
long userAccountControl = //currentUacValue
long newUserAccountControl = (userAccountControl | ADS_UF_ACCOUNTDISABLE);

To enable an account, we need to clear the disable bit:要启用帐户,我们需要清除禁用位:

long userAccountControl = //currentUacValue
long newUserAccountControl = (userAccountControl & ~ADS_UF_ACCOUNTDISABLE)

If you're on Linux using ldapsearch and ldapmodify, and you don't know C deeply to understand the above answer, you can also just subtract 2 from the current value.如果您在 Linux 上使用 ldapsearch 和 ldapmodify,并且您不深入了解 C 以理解上述答案,您也可以从当前值中减去 2。

$id="accountname"
USERCN=$(ldapsearch sAMAccountName=$id 2>/dev/null|grep "cn: " | sed 's/cn: //g')
USERDN="CN=${USERCN},CN=Users,DC=example,DC=com"

uac=$(ldapsearch sAMAccountName="$id" -LLL userAccountControl 2>/dev/null |grep userAccountControl: | awk '{print $2}')

uac="$(($uac-2))"
echo "dn: $USERDN
changetype: modify
replace: userAccountControl
userAccountControl: $uac" | ldapmodify -Q

Granted, we're using kerberos here to authenticate to AD.当然,我们在这里使用 kerberos 对 AD 进行身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM