diff --git a/plugins/services/ldap.go b/plugins/services/ldap.go index 933f386..daee1af 100644 --- a/plugins/services/ldap.go +++ b/plugins/services/ldap.go @@ -65,9 +65,20 @@ func (p *LDAPPlugin) testCredential(ctx context.Context, info *common.HostInfo, } defer conn.Close() - // 简单的绑定测试 - if err := conn.Bind(cred.Username, cred.Password); err == nil { - return true + // 尝试多种DN格式进行绑定测试 + dnFormats := []string{ + fmt.Sprintf("cn=%s,dc=example,dc=com", cred.Username), // 标准格式 + fmt.Sprintf("uid=%s,dc=example,dc=com", cred.Username), // uid格式 + fmt.Sprintf("cn=%s,ou=users,dc=example,dc=com", cred.Username), // ou格式 + cred.Username, // 直接用户名(某些配置) + } + + for _, dn := range dnFormats { + if err := conn.Bind(dn, cred.Password); err == nil { + common.LogDebug(fmt.Sprintf("LDAP绑定成功,DN: %s", dn)) + return true + } + common.LogDebug(fmt.Sprintf("LDAP绑定失败,DN: %s, 错误: %v", dn, err)) } return false }