Search code examples
goldapldap-query

How can I fix GoLang's LDAP Filter Operations Error?


So I am new to GoLang and I am trying to make a LDAP filter. However, I keep getting the following error:

LDAP Result Code 1 "Operations Error": 000020D6: SvcErr: DSID-031007E5, problem 5012 (DIR_ERROR), data 0

I read in here (LDAP Errors) that "Operations Error" happens when either not all the necessary calls have been made or the order of operation of the calls is wrong.

I am honestly not sure, what I might be missing and or what I am doing wrong.

My code is the following

 import (
    "crypto/tls"
    "fmt"
    "github.com/go-ldap/ldap/v3"
    "log"
)


func ApiCaller(){
    // The username and password we want to check
    username := "username"
    password := "password"

    //Establishing connection to the LDAP server
    l, err := ldap.Dial("tcp", "exampleURL.com:389")
    if err != nil {
        log.Fatal(err)
    }

    // Closing connection in case of error
    defer l.Close()

    // Reconnect with TLS
    err = l.StartTLS(&tls.Config{InsecureSkipVerify: true})
    if err != nil {
        log.Fatal(err)
    }

    // Bind as the user to verify their password
    err = l.Bind(username, password)
    if err != nil {
        log.Fatal(err)
    }
    // Setting up the search criterias with filter
    searchRequest := ldap.NewSearchRequest(
        "OU=OUg_Applications",
        ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
        fmt.Sprintf("(&(OU=OUg_Applications))"),
        []string{""},
        nil,
    )

    // Performing search in the LDAP Server
    sr, err := l.Search(searchRequest)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(sr.Entries)
}

Solution

  • The question comments helped me figure it out. My base-DN was off. It was supposed to be "DC=example,DC=com", instead of "OU=OUg_Applications".