Skip to content

RFC: Persistent Search #70

@vetinari

Description

@vetinari

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions