Skip to content
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

Retrieve Schema version (objectVersion) of LDAP server #524

Closed
gustavoluvizotto opened this issue Aug 12, 2024 · 2 comments
Closed

Retrieve Schema version (objectVersion) of LDAP server #524

gustavoluvizotto opened this issue Aug 12, 2024 · 2 comments
Labels

Comments

@gustavoluvizotto
Copy link
Contributor

Hi,

I've been looking for ways to retrieve the property value of an LDAP server by searching the Root DSE. However, the library does not provide such functionality. I'm looking specifically at the schema version (object version). In fact, I found only an AD client that can do it: https://support.globalsign.com/Certificate-Automation-Manager/how-check-active-directory-schema-version

Any pointers on how to implement that? I tried to querying my local LDAP server with ldapsearch without success.

Thank you!

@FlipB
Copy link
Contributor

FlipB commented Oct 22, 2024

You can just search for the rootDSE properties, eg ldap.NewSearchRequest("", ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false, "(&(objectClass=*))", []string{"dnsHostName"}, nil)

Not sure if there's an objectVersion though, going by https://learn.microsoft.com/en-us/windows/win32/adschema/rootdse

@cpuschma
Copy link
Member

@gustavoluvizotto You need to perform a search reques in the Configuration partition of your Active Directory:

For example:

package ldap

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

func main() {
	conn, err := ldap.DialURL("ldap://example.com:389")
	if err != nil {
		// ...
	}
	defer conn.Close()

	conn.Bind("", "") // Authentication might be required, depending on your configuration
	searchResult, err := conn.Search(&ldap.SearchRequest{
		BaseDN:     "CN=Schema,CN=Configuration,DC=example,DC=com",
		Scope:      ScopeBaseObject,
		Filter:     "(objectClass=*)",
		Attributes: []string{"objectVersion"},
	})
	if err != nil {
		// ..
	}
	
	version := searchResult.Entries[0].GetAttributeValue("objectVersion")
	fmt.Printf("Schema Version is: %s\n", version)
}

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

No branches or pull requests

3 participants