Skip to content

RFC: Persistent Search #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vetinari opened this issue Jun 22, 2016 · 1 comment
Open

RFC: Persistent Search #70

vetinari opened this issue Jun 22, 2016 · 1 comment

Comments

@vetinari
Copy link
Contributor

There's an initial implementation of persistent search (https://www.ietf.org/proceedings/50/I-D/ldapext-psearch-03.txt) in https://github.com/vetinari/ldap/tree/persistent-search

That one works e.g. with an OpenDJ (or OpenDS probably) which supports this control(s)

Code to get it running:

package main
import (
    "crypto/tls"
    "fmt"
    "gopkg.in/ldap.v2"
)

func main() {
    l, err := ldap.DialTLS("tcp", "ldap.example.org:636", &tls.Config{InsecureSkipVerify: true})
    if err != nil {
        panic("DialTLS: " + err.Error())
    }
    _, err = l.SimpleBind(ldap.NewSimpleBindRequest("uid=someone,dc=example,dc=org", "MySecret", nil))
    if err != nil {
        panic("SimpleBind(): " + err.Error())
    }
    req := &ldap.SearchRequest{
        BaseDN:     "ou=people,dc=example,dc=org",
        Scope:      ldap.ScopeWholeSubtree,
        Filter:     "(uid=*)",
        Attributes: []string{"uid", "cn"},
    }
    l.Debug = true
    err = l.PersistentSearch(req, []string{"any"}, true, true, callBack)
    if err != nil {
        panic("PersistentSearch(): " + err.Error())
    }
}

func callBack(res *ldap.SearchResult) bool {
    if len(res.Entries) != 0 {
        entry := res.Entries[0]
        fmt.Printf("%s (%s)\n", entry.GetAttributeValue("cn"), entry.GetAttributeValue("uid"))
    }
    if len(res.Controls) != 0 {
        fmt.Printf("CTRL=%s\n", res.Controls[0].String())
    }
    return true
}

Note that the PersistentSearch() will never (except for errors) return.
When this is running any changes on "uid" or "cn" will cause the "callBack()" function to run.

@vetinari
Copy link
Contributor Author

see also #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants