From 7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 21 Jul 2021 00:27:43 +0800 Subject: strings in LDAP are case-insensitive (#8) Thank you @wxiaoguang ! * strings in LDAP are case-insensitive * optmize routeFunc (faster, case-insensitive) * small optimiztion to routeFunc * request the directory server to return operational attributes by adding + (the plus sign) in your ldapsearch command. * request the directory server to return operational attributes by adding + (the plus sign) in your ldapsearch command. * request the directory server to return operational attributes by adding + (the plus sign) in your ldapsearch command. * remove operational attributes --- server.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'server.go') diff --git a/server.go b/server.go index 3576475..24b1e77 100644 --- a/server.go +++ b/server.go @@ -376,14 +376,20 @@ func sendPacket(conn net.Conn, packet *ber.Packet) error { // func routeFunc(dn string, funcNames []string) string { bestPick := "" + bestPickWeight := 0 + dnMatch := "," + strings.ToLower(dn) + var weight int for _, fn := range funcNames { - if strings.HasSuffix(dn, fn) { - l := len(strings.Split(bestPick, ",")) - if bestPick == "" { - l = 0 + if strings.HasSuffix(dnMatch, "," + fn) { + // empty string as 0, no-comma string 1 , etc + if fn == "" { + weight = 0 + } else { + weight = strings.Count(fn, ",") + 1 } - if len(strings.Split(fn, ",")) > l { + if weight > bestPickWeight { bestPick = fn + bestPickWeight = weight } } } -- cgit v1.2.3