v0.1.2 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2015 License: BSD-3-Clause, MPL-2.0 Imports: 10 Imported by: 0


GoDoc Build Status

Basic LDAP v3 functionality for the GO programming language.

  • Required library:
  • github.com/vanackere/asn1-ber
  • Working:
  • Connecting to LDAP server
  • Binding to LDAP server
  • Searching for entries
  • Compiling string filters to LDAP filters
  • Paging Search Results
  • Modify Requests / Responses
  • Examples:
  • search
  • modify
  • Tests Implemented:
  • Filter Compile / Decompile
  • TODO:
  • Add Requests / Responses
  • Delete Requests / Responses
  • Modify DN Requests / Responses
  • Compare Requests / Responses
  • Implement Tests / Benchmarks

This feature is disabled at the moment, because in some cases the "Search Request Done" packet will be handled before the last "Search Request Entry":

  • Mulitple internal goroutines to handle network traffic Makes library goroutine safe Can perform multiple search requests at the same time and return the results to the proper goroutine. All requests are blocking requests, so the goroutine does not need special handling




View Source
const (
	MessageQuit     = 0
	MessageRequest  = 1
	MessageResponse = 2
	MessageFinish   = 3
View Source
const (
	FilterAnd             ber.Tag = 0
	FilterOr              ber.Tag = 1
	FilterNot             ber.Tag = 2
	FilterEqualityMatch   ber.Tag = 3
	FilterSubstrings      ber.Tag = 4
	FilterGreaterOrEqual  ber.Tag = 5
	FilterLessOrEqual     ber.Tag = 6
	FilterPresent         ber.Tag = 7
	FilterApproxMatch     ber.Tag = 8
	FilterExtensibleMatch ber.Tag = 9
View Source
const (
	FilterSubstringsInitial = 0
	FilterSubstringsAny     = 1
	FilterSubstringsFinal   = 2
View Source
const (
	ApplicationBindRequest           ber.Tag = 0
	ApplicationBindResponse          ber.Tag = 1
	ApplicationUnbindRequest         ber.Tag = 2
	ApplicationSearchRequest         ber.Tag = 3
	ApplicationSearchResultEntry     ber.Tag = 4
	ApplicationSearchResultDone      ber.Tag = 5
	ApplicationModifyRequest         ber.Tag = 6
	ApplicationModifyResponse        ber.Tag = 7
	ApplicationAddRequest            ber.Tag = 8
	ApplicationAddResponse           ber.Tag = 9
	ApplicationDelRequest            ber.Tag = 10
	ApplicationDelResponse           ber.Tag = 11
	ApplicationModifyDNRequest       ber.Tag = 12
	ApplicationModifyDNResponse      ber.Tag = 13
	ApplicationCompareRequest        ber.Tag = 14
	ApplicationCompareResponse       ber.Tag = 15
	ApplicationAbandonRequest        ber.Tag = 16
	ApplicationSearchResultReference ber.Tag = 19
	ApplicationExtendedRequest       ber.Tag = 23
	ApplicationExtendedResponse      ber.Tag = 24

LDAP Application Codes

View Source
const (
	LDAPResultSuccess                      = 0
	LDAPResultOperationsError              = 1
	LDAPResultProtocolError                = 2
	LDAPResultTimeLimitExceeded            = 3
	LDAPResultSizeLimitExceeded            = 4
	LDAPResultCompareFalse                 = 5
	LDAPResultCompareTrue                  = 6
	LDAPResultAuthMethodNotSupported       = 7
	LDAPResultStrongAuthRequired           = 8
	LDAPResultReferral                     = 10
	LDAPResultAdminLimitExceeded           = 11
	LDAPResultUnavailableCriticalExtension = 12
	LDAPResultConfidentialityRequired      = 13
	LDAPResultSaslBindInProgress           = 14
	LDAPResultNoSuchAttribute              = 16
	LDAPResultUndefinedAttributeType       = 17
	LDAPResultInappropriateMatching        = 18
	LDAPResultConstraintViolation          = 19
	LDAPResultAttributeOrValueExists       = 20
	LDAPResultInvalidAttributeSyntax       = 21
	LDAPResultNoSuchObject                 = 32
	LDAPResultAliasProblem                 = 33
	LDAPResultInvalidDNSyntax              = 34
	LDAPResultAliasDereferencingProblem    = 36
	LDAPResultInappropriateAuthentication  = 48
	LDAPResultInvalidCredentials           = 49
	LDAPResultInsufficientAccessRights     = 50
	LDAPResultBusy                         = 51
	LDAPResultUnavailable                  = 52
	LDAPResultUnwillingToPerform           = 53
	LDAPResultLoopDetect                   = 54
	LDAPResultNamingViolation              = 64
	LDAPResultObjectClassViolation         = 65
	LDAPResultNotAllowedOnNonLeaf          = 66
	LDAPResultNotAllowedOnRDN              = 67
	LDAPResultEntryAlreadyExists           = 68
	LDAPResultObjectClassModsProhibited    = 69
	LDAPResultAffectsMultipleDSAs          = 71
	LDAPResultOther                        = 80

	ErrorNetwork         = 200
	ErrorFilterCompile   = 201
	ErrorFilterDecompile = 202
	ErrorDebugging       = 203

LDAP Result Codes

View Source
const (
	AddAttribute     = 0
	DeleteAttribute  = 1
	ReplaceAttribute = 2
View Source
const (
	ScopeBaseObject   = 0
	ScopeSingleLevel  = 1
	ScopeWholeSubtree = 2
View Source
const (
	NeverDerefAliases   = 0
	DerefInSearching    = 1
	DerefFindingBaseObj = 2
	DerefAlways         = 3
View Source
const (
	ControlTypePaging = "1.2.840.113556.1.4.319"


View Source
var ApplicationMap = map[ber.Tag]string{
	ApplicationBindRequest:           "Bind Request",
	ApplicationBindResponse:          "Bind Response",
	ApplicationUnbindRequest:         "Unbind Request",
	ApplicationSearchRequest:         "Search Request",
	ApplicationSearchResultEntry:     "Search Result Entry",
	ApplicationSearchResultDone:      "Search Result Done",
	ApplicationModifyRequest:         "Modify Request",
	ApplicationModifyResponse:        "Modify Response",
	ApplicationAddRequest:            "Add Request",
	ApplicationAddResponse:           "Add Response",
	ApplicationDelRequest:            "Del Request",
	ApplicationDelResponse:           "Del Response",
	ApplicationModifyDNRequest:       "Modify DN Request",
	ApplicationModifyDNResponse:      "Modify DN Response",
	ApplicationCompareRequest:        "Compare Request",
	ApplicationCompareResponse:       "Compare Response",
	ApplicationAbandonRequest:        "Abandon Request",
	ApplicationSearchResultReference: "Search Result Reference",
	ApplicationExtendedRequest:       "Extended Request",
	ApplicationExtendedResponse:      "Extended Response",
View Source
var ControlTypeMap = map[string]string{
	ControlTypePaging: "Paging",
View Source
var DerefMap = map[int]string{
	NeverDerefAliases:   "NeverDerefAliases",
	DerefInSearching:    "DerefInSearching",
	DerefFindingBaseObj: "DerefFindingBaseObj",
	DerefAlways:         "DerefAlways",
View Source
var LDAPResultCodeMap = map[uint8]string{
	LDAPResultSuccess:                      "Success",
	LDAPResultOperationsError:              "Operations Error",
	LDAPResultProtocolError:                "Protocol Error",
	LDAPResultTimeLimitExceeded:            "Time Limit Exceeded",
	LDAPResultSizeLimitExceeded:            "Size Limit Exceeded",
	LDAPResultCompareFalse:                 "Compare False",
	LDAPResultCompareTrue:                  "Compare True",
	LDAPResultAuthMethodNotSupported:       "Auth Method Not Supported",
	LDAPResultStrongAuthRequired:           "Strong Auth Required",
	LDAPResultReferral:                     "Referral",
	LDAPResultAdminLimitExceeded:           "Admin Limit Exceeded",
	LDAPResultUnavailableCriticalExtension: "Unavailable Critical Extension",
	LDAPResultConfidentialityRequired:      "Confidentiality Required",
	LDAPResultSaslBindInProgress:           "Sasl Bind In Progress",
	LDAPResultNoSuchAttribute:              "No Such Attribute",
	LDAPResultUndefinedAttributeType:       "Undefined Attribute Type",
	LDAPResultInappropriateMatching:        "Inappropriate Matching",
	LDAPResultConstraintViolation:          "Constraint Violation",
	LDAPResultAttributeOrValueExists:       "Attribute Or Value Exists",
	LDAPResultInvalidAttributeSyntax:       "Invalid Attribute Syntax",
	LDAPResultNoSuchObject:                 "No Such Object",
	LDAPResultAliasProblem:                 "Alias Problem",
	LDAPResultInvalidDNSyntax:              "Invalid DN Syntax",
	LDAPResultAliasDereferencingProblem:    "Alias Dereferencing Problem",
	LDAPResultInappropriateAuthentication:  "Inappropriate Authentication",
	LDAPResultInvalidCredentials:           "Invalid Credentials",
	LDAPResultInsufficientAccessRights:     "Insufficient Access Rights",
	LDAPResultBusy:                         "Busy",
	LDAPResultUnavailable:                  "Unavailable",
	LDAPResultUnwillingToPerform:           "Unwilling To Perform",
	LDAPResultLoopDetect:                   "Loop Detect",
	LDAPResultNamingViolation:              "Naming Violation",
	LDAPResultObjectClassViolation:         "Object Class Violation",
	LDAPResultNotAllowedOnNonLeaf:          "Not Allowed On Non Leaf",
	LDAPResultNotAllowedOnRDN:              "Not Allowed On RDN",
	LDAPResultEntryAlreadyExists:           "Entry Already Exists",
	LDAPResultObjectClassModsProhibited:    "Object Class Mods Prohibited",
	LDAPResultAffectsMultipleDSAs:          "Affects Multiple DSAs",
	LDAPResultOther:                        "Other",
View Source
var ScopeMap = map[int]string{
	ScopeBaseObject:   "Base Object",
	ScopeSingleLevel:  "Single Level",
	ScopeWholeSubtree: "Whole Subtree",


func CompileFilter

func CompileFilter(filter string) (*ber.Packet, error)

func DebugBinaryFile

func DebugBinaryFile(fileName string) error

func DecompileFilter

func DecompileFilter(packet *ber.Packet) (ret string, err error)

func NewError

func NewError(resultCode uint8, err error) error


type Conn

type Conn struct {
	Debug debugging
	// contains filtered or unexported fields

Conn represents an LDAP Connection

func Dial

func Dial(network, addr string) (*Conn, error)

Dial connects to the given address on the given network using net.Dial and then returns a new Conn for the connection.

func DialTLS

func DialTLS(network, addr string, config *tls.Config) (*Conn, error)

DialTLS connects to the given address on the given network using tls.Dial and then returns a new Conn for the connection.

func NewConn

func NewConn(conn net.Conn) *Conn

NewConn returns a new Conn using conn for network I/O.

func (*Conn) Bind

func (l *Conn) Bind(username, password string) error

func (*Conn) Close

func (l *Conn) Close()

Close closes the connection.

func (*Conn) Modify

func (l *Conn) Modify(modifyRequest *ModifyRequest) error

func (*Conn) Search

func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error)

func (*Conn) SearchWithPaging

func (l *Conn) SearchWithPaging(searchRequest *SearchRequest, pagingSize uint32) (*SearchResult, error)

func (*Conn) StartTLS

func (l *Conn) StartTLS(config *tls.Config) error

StartTLS sends the command to start a TLS session and then creates a new TLS Client

type Control

type Control interface {
	GetControlType() string
	Encode() *ber.Packet
	String() string

func DecodeControl

func DecodeControl(packet *ber.Packet) Control

func FindControl

func FindControl(controls []Control, controlType string) Control

type ControlPaging

type ControlPaging struct {
	PagingSize uint32
	Cookie     []byte

func NewControlPaging

func NewControlPaging(pagingSize uint32) *ControlPaging

func (*ControlPaging) Encode

func (c *ControlPaging) Encode() *ber.Packet

func (*ControlPaging) GetControlType

func (c *ControlPaging) GetControlType() string

func (*ControlPaging) SetCookie

func (c *ControlPaging) SetCookie(cookie []byte)

func (*ControlPaging) String

func (c *ControlPaging) String() string

type ControlString

type ControlString struct {
	ControlType  string
	Criticality  bool
	ControlValue string

func NewControlString

func NewControlString(controlType string, criticality bool, controlValue string) *ControlString

func (*ControlString) Encode

func (c *ControlString) Encode() *ber.Packet

func (*ControlString) GetControlType

func (c *ControlString) GetControlType() string

func (*ControlString) String

func (c *ControlString) String() string

type Entry

type Entry struct {
	DN         string
	Attributes []*EntryAttribute

func (*Entry) GetAttributeValue

func (e *Entry) GetAttributeValue(attribute string) string

func (*Entry) GetAttributeValues

func (e *Entry) GetAttributeValues(attribute string) []string

func (*Entry) PrettyPrint

func (e *Entry) PrettyPrint(indent int)

func (*Entry) Print

func (e *Entry) Print()

type EntryAttribute

type EntryAttribute struct {
	Name   string
	Values []string

func (*EntryAttribute) PrettyPrint

func (e *EntryAttribute) PrettyPrint(indent int)

func (*EntryAttribute) Print

func (e *EntryAttribute) Print()

type Error

type Error struct {
	Err        error
	ResultCode uint8

func (*Error) Error

func (e *Error) Error() string

type ModifyRequest

type ModifyRequest struct {
	// contains filtered or unexported fields

func NewModifyRequest

func NewModifyRequest(
	dn string,
) *ModifyRequest

func (*ModifyRequest) Add

func (m *ModifyRequest) Add(attrType string, attrVals []string)

func (*ModifyRequest) Delete

func (m *ModifyRequest) Delete(attrType string, attrVals []string)

func (*ModifyRequest) Replace

func (m *ModifyRequest) Replace(attrType string, attrVals []string)

type PartialAttribute

type PartialAttribute struct {
	// contains filtered or unexported fields

type SearchRequest

type SearchRequest struct {
	BaseDN       string
	Scope        int
	DerefAliases int
	SizeLimit    int
	TimeLimit    int
	TypesOnly    bool
	Filter       string
	Attributes   []string
	Controls     []Control

func NewSearchRequest

func NewSearchRequest(
	BaseDN string,
	Scope, DerefAliases, SizeLimit, TimeLimit int,
	TypesOnly bool,
	Filter string,
	Attributes []string,
	Controls []Control,
) *SearchRequest

type SearchResult

type SearchResult struct {
	Entries   []*Entry
	Referrals []string
	Controls  []Control

func (*SearchResult) PrettyPrint

func (s *SearchResult) PrettyPrint(indent int)

func (*SearchResult) Print

func (s *SearchResult) Print()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL