Giter Site home page Giter Site logo

Search returns each result twice? about ldap HOT 8 CLOSED

mmitton avatar mmitton commented on July 4, 2024
Search returns each result twice?

from ldap.

Comments (8)

msabramo avatar msabramo commented on July 4, 2024

I don't see duplicate entries being returned when I use the ldapsearch command, but I do notice this at the bottom of the output:

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

Could the numResponses: 2 be relevant? Perhaps multiple servers are responding and the client is supposed to know how to uniquify or merge? I don't know much about LDAP.

from ldap.

msabramo avatar msabramo commented on July 4, 2024

I think above theory about numResponses: 2 is wrong because I did a search that returned a lot more results and got:

# search result
search: 2
result: 0 Success

# numResponses: 661
# numEntries: 660

So it's not getting twice as many responses as entries. There's just one extra response, which I am guessing is for a header or something.

from ldap.

msabramo avatar msabramo commented on July 4, 2024

This is still true even after changing the code to use NeverDerefAliases:

  search_request := ldap.NewSearchRequest(
    base_dn,
    ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
    filter[0],
    attributes,
    nil)

from ldap.

msabramo avatar msabramo commented on July 4, 2024

Also and I don't know if this is a related issue or completely separate, it is not finding records that I definitely know to be there.

TestSearch: (&(objectClass=user)(cn=Marc*)) -> num of entries = 2
       0 - entry: &{DN:CN=Marcus H.,OU=Portland,... Attributes:[0xc208191110 0xc208191140]}
       1 - entry: &{DN:CN=Marcus H.,OU=Portland,... Attributes:[0xc2081911a0 0xc2081911d0]}
2015-01-12T09:01:19.503034381-08:00 POST /users/marca/tokens 500 in 13.973487ms

My own name starts with "Marc" and it doesn't show up here, but it shows up with the ldapsearch command:

$ ldapsearch -H ldap://ldapserver.corp.mycompany.com -x -b "OU=MyCompany,DC=corp,DC=mycompany,DC=com" -D "me" -W '(&(objectClass=user)(cn=Marc*))' name
...
# Marc A. ...
dn: CN=Marc A., ...
name: Marc A.

# Marcus H. ...
dn: CN=Marcus H., ...
name: Marcus H.

# search result
search: 2
result: 0 Success

# numResponses: 3
# numEntries: 2

from ldap.

msabramo avatar msabramo commented on July 4, 2024

I turned on the Debug flag for the connection and it looks like at a fairly low level it is processing the same data twice.

Receiving message 2
Receiving message 2
2: got response 0xc2082bb400
LDAP Response: (Universal, Constructed, Sequence and Sequence of) Len=186 "<nil>"
 Message ID: (Universal, Primative, Integer) Len=1 "2"
 Search Result Entry: (Application, Constructed, 0x04) Len=180 "<nil>"
  Object Name: (Universal, Primative, Octet String) Len=61 "CN=Marcus H...."
  Attributes: (Universal, Constructed, Sequence and Sequence of) Len=115 "<nil>"
   Attribute: (Universal, Constructed, Sequence and Sequence of) Len=84 "<nil>"
    Attribute Name: (Universal, Primative, Octet String) Len=17 "distinguishedName"
    Attribute Values: (Universal, Constructed, Set and Set OF) Len=63 "<nil>"
     Attribute Value: (Universal, Primative, Octet String) Len=61 "CN=Marcus H...
   Attribute: (Universal, Constructed, Sequence and Sequence of) Len=27 "<nil>"
    Attribute Name: (Universal, Primative, Octet String) Len=14 "sAMAccountName"
    Attribute Values: (Universal, Constructed, Set and Set OF) Len=9 "<nil>"
     Attribute Value: (Universal, Primative, Octet String) Len=7 "marcush"
2: waiting for response
2: got response 0xc2082bb400
LDAP Response: (Universal, Constructed, Sequence and Sequence of) Len=186 "<nil>"
 Message ID: (Universal, Primative, Integer) Len=1 "2"
 Search Result Entry: (Application, Constructed, 0x04) Len=180 "<nil>"
  Object Name: (Universal, Primative, Octet String) Len=61 "CN=Marcus H...."
  Attributes: (Universal, Constructed, Sequence and Sequence of) Len=115 "<nil>"
   Attribute: (Universal, Constructed, Sequence and Sequence of) Len=84 "<nil>"
    Attribute Name: (Universal, Primative, Octet String) Len=17 "distinguishedName"
    Attribute Values: (Universal, Constructed, Set and Set OF) Len=63 "<nil>"
     Attribute Value: (Universal, Primative, Octet String) Len=61 "CN=Marcus H...."
   Attribute: (Universal, Constructed, Sequence and Sequence of) Len=27 "<nil>"
    Attribute Name: (Universal, Primative, Octet String) Len=14 "sAMAccountName"
    Attribute Values: (Universal, Constructed, Set and Set OF) Len=9 "<nil>"
     Attribute Value: (Universal, Primative, Octet String) Len=7 "marcush"

from ldap.

msabramo avatar msabramo commented on July 4, 2024

FWIW, https://github.com/mavricknz/ldap doesn't seem to have this problem.

from ldap.

ejona86 avatar ejona86 commented on July 4, 2024

I encountered the same issue. I tracked it down to a bug in conn.go. Mutations to message_packet are seen by the goroutine, so the two goroutines race and messages are dropped or duplicated.

Not using the goroutine (and using the commented out line) worked for me, or to continue using the goroutine you just need to make another variable or pass it as a parameter:

go func(message_packet *messagePacket) {
    chanResult <- message_packet.Packet
}(message_packet)

from ldap.

seanhagen avatar seanhagen commented on July 4, 2024

@ejona86 same thing here. With the goroutine, nothing. Using the commented out line instead, I get results.

from ldap.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.