【问题标题】:Reset AD user account password using a privileged account使用特权帐户重置 AD 用户帐户密码
【发布时间】:2019-01-29 04:07:12
【问题描述】:

我正在尝试编写一种方法,通过在代码中嵌入另一个帐户,让没有足够权限的帐户的帮助台人员重置密码。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://something.com/OU=COW,DC=spmething,DC=com")
    Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
    Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & "DC=something,DC=com")
    Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)

    If RadioButton1.Checked = True Then
        ADSearch.Filter = ("(samAccountName=" & Loginnames.Text & ")")
        ADSearch.SearchScope = SearchScope.Subtree
        Dim UserFound As SearchResult = ADSearch.FindOne()
        If Not IsNothing(UserFound) Then
            Dim UserDirectoryEntry As DirectoryEntry = UserFound.GetDirectoryEntry
            UserDirectoryEntry.Invoke("SetPassword", New Object() {TextBox2.Text})
            '...
            email = UserFound.GetDirectoryEntry.Properties("userPrincipalName").Value
            MsgBox("Password has been rest!")

        End If
    End If

我需要使用帮助台以外的用户来执行此操作,因为帮助台用户无权执行此操作。而且我们不想将任何事情委托给他。

他现在得到的错误是:0x80070005 (E_ACCESSDENIED)

【问题讨论】:

    标签: vb.net active-directory ldap impersonation


    【解决方案1】:

    我在 VB6 中做过一次(很久以前)

    Dim objDSO     As IADsOpenDSObject
    Dim objUser    As IADsUser
    
    Set objDSO = GetObject("LDAP:")
    Set objUser = objDSO.OpenDSObject("LDAP://" & strUser, DELEGATE_ACCOUNTNAME, DELEGATE_PASSWORD, ADS_SECURE_AUTHENTICATION)
    

    所以它在 VB.Net 中也必须是可行的,因为 IADs 接口定义了任何 ADSI 对象的基本对象(属性和方法)。 根据thisDirectoryEntryDirectorySearcher 都使用 Active Directory 服务接口 (ADSI) 技术

    确实,DirectoryEntry 构造函数可以扩展为用于绑定的用户名和密码,而不是当前运行脚本或应用程序的用户。所以不是

    Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & "DC=something,DC=com")
    

    试试这个

    Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & "DC=something,DC=com", DELEGATE_ACCOUNTNAME, DELEGATE_PASSWORD, 1)
    

    其中“1”是 System.DirectoryServices AuthenticationType“安全”的值。

    此 DELEGATE 是您在您的域中设置的用户,您可以确保他/她/它有权重置密码和解锁用户帐户(请参阅下面的注释)。

    DELEGATE_PASSWORD 以纯文本 的形式给出,因此您需要通过某种方式向帮助台用户隐藏它! 现在,Button1_Click 子程序中的其余代码应使用此委托的凭据来查找和设置密码。

    注意:用户通常只有在尝试了太多次并且他们的帐户已被锁定后才向帮助台询问他们的密码。因此,您的函数还应在设置新密码之前解锁帐户。您可以通过检查用户的 (int64) lockoutTime ldap 属性来检查帐户是否被锁定。要解锁帐户,只需将此值设置为0L

    【讨论】:

      猜你喜欢
      • 2019-07-27
      • 2020-05-31
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 2019-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多