Forráskód Böngészése

过滤objectClass=*的东西

huangrf 6 éve
szülő
commit
2f8b683609
1 módosított fájl, 19 hozzáadás és 5 törlés
  1. 19 5
      utils/auth/ldap_auth.go

+ 19 - 5
utils/auth/ldap_auth.go

@@ -84,11 +84,25 @@ func (h ldapHandler) Search(boundDN string, searchReq ldap.SearchRequest, conn n
 	fmt.Printf("%s,search......%s\n", boundDN, searchReq)
 	userName := ""
 	if boundDN == "cn=qianqiuiot" {
-		start := strings.Index(searchReq.Filter, "uid=")
-		end := strings.Index(searchReq.Filter[start:], ")")
-		fmt.Println("%d,%d", start, end)
-		userName = searchReq.Filter[start+4 : start+end]
-		fmt.Println(userName)
+		if searchReq.Filter == "(objectClass=*)" {
+			uid := searchReq.BaseDN
+			dn := uid
+			if dn == "" {
+				dn = boundDN
+			}
+			entries := []*ldap.Entry{
+				&ldap.Entry{dn, []*ldap.EntryAttribute{
+					&ldap.EntryAttribute{"uid", []string{}},
+				}},
+			}
+			return ldap.ServerSearchResult{entries, []string{}, []ldap.Control{}, ldap.LDAPResultSuccess}, nil
+		}else {
+			start := strings.Index(searchReq.Filter, "uid=")
+			end := strings.Index(searchReq.Filter[start:], ")")
+			fmt.Println("%d,%d", start, end)
+			userName = searchReq.Filter[start+4 : start+end]
+			fmt.Println(userName)
+		}
 	}else {
 		userName = boundDN[3:]
 	}