openldap

package module
v0.0.0-...-20a2ef1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2016 License: MIT Imports: 6 Imported by: 20

README

OpenLDAP

this is Openldap binding in GO language. I don't work any more with golang, so, please fork this project.

Installation :

Installation is easy and very quick, as you can see :

# install openldap library and devel packages
sudo apt-get install libldap libldap2-dev  # debian/ubuntu.
sudo urpmi openldap-devel # fedora, RH, ...

# install go
go get github.com/mqu/openldap

# verify you've got it :
(cd $GOPATH ; go list ./...) | grep openldap

Usage

  • Look a this exemple.
  • a more complex example making LDAP search that mimics ldapsearch command, printing out result on console.

Doc:

  • run go doc openldap,
  • will come soon, complete documentation in this Wiki.
  • look at _examples/*.go to see how to use this library.

Todo :

  • thread-safe test,
  • complete LDAP:GetOption() and LDAP:SetOption() method : now, they work only for integer values,
  • avoid using deprecated function (see LDAP_DEPRECATED flag and "// DEPRECATED" comments in *.go sources),
  • write some tests,
  • verify memory leaks (Valgrind),
  • support LDIF format (in, out),
  • add support for external commands (ldapadd, ldapdelete)
  • create an LDAP CLI (command line interface), like lftp, with commands like shell,
  • a nice GUI with GTK,
  • proxy, server,
  • what else ?

Licence :

Copyright (C) 2012 - Marc Quinton.

Use of this source code is governed by the MIT Licence : http://opensource.org/licenses/mit-license.php

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	LDAP_VERSION1 = 1
	LDAP_VERSION2 = 2
	LDAP_VERSION3 = 3
)
View Source
const (
	LDAP_VERSION_MIN = LDAP_VERSION2
	LDAP_VERSION     = LDAP_VERSION2
	LDAP_VERSION_MAX = LDAP_VERSION3
)
View Source
const (
	LDAP_API_VERSION = 3001
	LDAP_VENDOR_NAME = "OpenLDAP"
)
View Source
const (
	LDAP_PORT  = 389
	LDAPS_PORT = 636
)
View Source
const (
	LDAP_OPT_SUCCESS = 0
	LDAP_OPT_ERROR   = -1
)
View Source
const (
	LDAP_SCOPE_BASE        = 0x0000
	LDAP_SCOPE_ONELEVEL    = 0x0001
	LDAP_SCOPE_SUBTREE     = 0x0002
	LDAP_SCOPE_SUBORDINATE = 0x0003 // OpenLDAP extension
	LDAP_SCOPE_DEFAULT     = -1     // OpenLDAP extension
)

search scopes

View Source
const (
	LDAP_SCOPE_BASEOBJECT = LDAP_SCOPE_BASE
	LDAP_SCOPE_ONE        = LDAP_SCOPE_ONELEVEL
	LDAP_SCOPE_SUB        = LDAP_SCOPE_SUBTREE
	LDAP_SCOPE_CHILDREN   = LDAP_SCOPE_SUBORDINATE
)
View Source
const (
	LDAP_RES_ANY         = -1
	LDAP_RES_UNSOLICITED = 0
)
View Source
const (
	LDAP_SUCCESS                   = 0x00
	LDAP_OPERATIONS_ERROR          = 0x01
	LDAP_PROTOCOL_ERROR            = 0x02
	LDAP_TIMELIMIT_EXCEEDED        = 0x03
	LDAP_SIZELIMIT_EXCEEDED        = 0x04
	LDAP_COMPARE_FALSE             = 0x05
	LDAP_COMPARE_TRUE              = 0x06
	LDAP_AUTH_METHOD_NOT_SUPPORTED = 0x07
	LDAP_STRONG_AUTH_REQUIRED      = 0x08
	// Not used in LDAPv3
	LDAP_PARTIAL_RESULTS = 0x09

	// Next 5 new in LDAPv3
	LDAP_REFERRAL                       = 0x0a
	LDAP_ADMINLIMIT_EXCEEDED            = 0x0b
	LDAP_UNAVAILABLE_CRITICAL_EXTENSION = 0x0c
	LDAP_CONFIDENTIALITY_REQUIRED       = 0x0d
	LDAP_SASL_BIND_INPROGRESS           = 0x0e

	LDAP_NO_SUCH_ATTRIBUTE      = 0x10
	LDAP_UNDEFINED_TYPE         = 0x11
	LDAP_INAPPROPRIATE_MATCHING = 0x12
	LDAP_CONSTRAINT_VIOLATION   = 0x13
	LDAP_TYPE_OR_VALUE_EXISTS   = 0x14
	LDAP_INVALID_SYNTAX         = 0x15

	LDAP_NO_SUCH_OBJECT    = 0x20 /* 32 */
	LDAP_ALIAS_PROBLEM     = 0x21
	LDAP_INVALID_DN_SYNTAX = 0x22
	// Next two not used in LDAPv3
	LDAP_IS_LEAF             = 0x23
	LDAP_ALIAS_DEREF_PROBLEM = 0x24

	LDAP_INAPPROPRIATE_AUTH   = 0x30 /* 48 */
	LDAP_INVALID_CREDENTIALS  = 0x31 /* 49 */
	LDAP_INSUFFICIENT_ACCESS  = 0x32
	LDAP_BUSY                 = 0x33
	LDAP_UNAVAILABLE          = 0x34
	LDAP_UNWILLING_TO_PERFORM = 0x35
	LDAP_LOOP_DETECT          = 0x36

	LDAP_SORT_CONTROL_MISSING = 0x3C /* 60 */
	LDAP_INDEX_RANGE_ERROR    = 0x3D /* 61 */

	LDAP_NAMING_VIOLATION       = 0x40
	LDAP_OBJECT_CLASS_VIOLATION = 0x41
	LDAP_NOT_ALLOWED_ON_NONLEAF = 0x42
	LDAP_NOT_ALLOWED_ON_RDN     = 0x43
	LDAP_ALREADY_EXISTS         = 0x44 /* 68 */
	LDAP_NO_OBJECT_CLASS_MODS   = 0x45
	LDAP_RESULTS_TOO_LARGE      = 0x46
	// Next two for LDAPv3
	LDAP_AFFECTS_MULTIPLE_DSAS = 0x47
	LDAP_OTHER                 = 0x50

	// Used by some APIs
	LDAP_SERVER_DOWN    = 0x51
	LDAP_LOCAL_ERROR    = 0x52
	LDAP_ENCODING_ERROR = 0x53
	LDAP_DECODING_ERROR = 0x54
	LDAP_TIMEOUT        = 0x55
	LDAP_AUTH_UNKNOWN   = 0x56
	LDAP_FILTER_ERROR   = 0x57 /* 87 */
	LDAP_USER_CANCELLED = 0x58
	LDAP_PARAM_ERROR    = 0x59
	LDAP_NO_MEMORY      = 0x5a

	// Preliminary LDAPv3 codes
	LDAP_CONNECT_ERROR           = 0x5b
	LDAP_NOT_SUPPORTED           = 0x5c
	LDAP_CONTROL_NOT_FOUND       = 0x5d
	LDAP_NO_RESULTS_RETURNED     = 0x5e
	LDAP_MORE_RESULTS_TO_RETURN  = 0x5f
	LDAP_CLIENT_LOOP             = 0x60
	LDAP_REFERRAL_LIMIT_EXCEEDED = 0x61
)
View Source
const (
	LDAP_DEREF_NEVER     = 0
	LDAP_DEREF_SEARCHING = 1
	LDAP_DEREF_FINDING   = 2
	LDAP_DEREF_ALWAYS    = 3
)
View Source
const (
	LDAP_MSG_ONE      = 0
	LDAP_MSG_ALL      = 1
	LDAP_MSG_RECEIVED = 2
)
View Source
const (
	LDAP_OPT_API_INFO  = 0x0000
	LDAP_OPT_DESC      = 0x0001 // historic
	LDAP_OPT_DEREF     = 0x0002
	LDAP_OPT_SIZELIMIT = 0x0003
	LDAP_OPT_TIMELIMIT = 0x0004

	LDAP_OPT_REFERRALS = 0x0008
	LDAP_OPT_RESTART   = 0x0009

	LDAP_OPT_PROTOCOL_VERSION = 0x0011
	LDAP_OPT_SERVER_CONTROLS  = 0x0012
	LDAP_OPT_CLIENT_CONTROLS  = 0x0013

	LDAP_OPT_API_FEATURE_INFO = 0x0015

	LDAP_OPT_HOST_NAME          = 0x0030
	LDAP_OPT_RESULT_CODE        = 0x0031
	LDAP_OPT_ERROR_NUMBER       = LDAP_OPT_RESULT_CODE
	LDAP_OPT_DIAGNOSTIC_MESSAGE = 0x0032
	LDAP_OPT_ERROR_STRING       = LDAP_OPT_DIAGNOSTIC_MESSAGE
	LDAP_OPT_MATCHED_DN         = 0x0033

	LDAP_OPT_SSPI_FLAGS = 0x0092

	LDAP_OPT_SIGN        = 0x0095
	LDAP_OPT_ENCRYPT     = 0x0096
	LDAP_OPT_SASL_METHOD = 0x0097

	LDAP_OPT_SECURITY_CONTEXT = 0x0099
)
View Source
const (
	LDAP_OPT_DEBUG_LEVEL     = 0x5001 // debug level
	LDAP_OPT_TIMEOUT         = 0x5002 // default timeout
	LDAP_OPT_REFHOPLIMIT     = 0x5003 // ref hop limit
	LDAP_OPT_NETWORK_TIMEOUT = 0x5005 // socket level timeout
	LDAP_OPT_URI             = 0x5006
	LDAP_OPT_REFERRAL_URLS   = 0x5007 // Referral URLs
	LDAP_OPT_SOCKBUF         = 0x5008 // sockbuf
	LDAP_OPT_DEFBASE         = 0x5009 // searchbase
	LDAP_OPT_CONNECT_ASYNC   = 0x5010 // create connections asynchronously
	LDAP_OPT_CONNECT_CB      = 0x5011 // connection callbacks
	LDAP_OPT_SESSION_REFCNT  = 0x5012 // session reference count
)
View Source
const (
	LDAP_OPT_X_TLS              = 0x6000
	LDAP_OPT_X_TLS_CTX          = 0x6001 // OpenSSL CTX*
	LDAP_OPT_X_TLS_CACERTFILE   = 0x6002
	LDAP_OPT_X_TLS_CACERTDIR    = 0x6003
	LDAP_OPT_X_TLS_CERTFILE     = 0x6004
	LDAP_OPT_X_TLS_KEYFILE      = 0x6005
	LDAP_OPT_X_TLS_REQUIRE_CERT = 0x6006
	LDAP_OPT_X_TLS_PROTOCOL_MIN = 0x6007
	LDAP_OPT_X_TLS_CIPHER_SUITE = 0x6008
	LDAP_OPT_X_TLS_RANDOM_FILE  = 0x6009
	LDAP_OPT_X_TLS_SSL_CTX      = 0x600a // OpenSSL SSL*
	LDAP_OPT_X_TLS_CRLCHECK     = 0x600b
	LDAP_OPT_X_TLS_CONNECT_CB   = 0x600c
	LDAP_OPT_X_TLS_CONNECT_ARG  = 0x600d
	LDAP_OPT_X_TLS_DHFILE       = 0x600e
	LDAP_OPT_X_TLS_NEWCTX       = 0x600f
	LDAP_OPT_X_TLS_CRLFILE      = 0x6010 // GNUtls only
	LDAP_OPT_X_TLS_PACKAGE      = 0x6011
)
View Source
const (
	LDAP_OPT_X_TLS_NEVER  = 0
	LDAP_OPT_X_TLS_HARD   = 1
	LDAP_OPT_X_TLS_DEMAND = 2
	LDAP_OPT_X_TLS_ALLOW  = 3
	LDAP_OPT_X_TLS_TRY    = 4
)
View Source
const (
	LDAP_OPT_X_TLS_CRL_NONE = 0
	LDAP_OPT_X_TLS_CRL_PEER = 1
	LDAP_OPT_X_TLS_CRL_ALL  = 2
)
View Source
const (
	LDAP_OPT_X_SASL_MECH         = 0x6100
	LDAP_OPT_X_SASL_REALM        = 0x6101
	LDAP_OPT_X_SASL_AUTHCID      = 0x6102
	LDAP_OPT_X_SASL_AUTHZID      = 0x6103
	LDAP_OPT_X_SASL_SSF          = 0x6104 // read-only
	LDAP_OPT_X_SASL_SSF_EXTERNAL = 0x6105 // write-only
	LDAP_OPT_X_SASL_SECPROPS     = 0x6106 // write-only
	LDAP_OPT_X_SASL_SSF_MIN      = 0x6107
	LDAP_OPT_X_SASL_SSF_MAX      = 0x6108
	LDAP_OPT_X_SASL_MAXBUFSIZE   = 0x6109
	LDAP_OPT_X_SASL_MECHLIST     = 0x610a // read-only
	LDAP_OPT_X_SASL_NOCANON      = 0x610b
	LDAP_OPT_X_SASL_USERNAME     = 0x610c // read-only
	LDAP_OPT_X_SASL_GSS_CREDS    = 0x610d
)
View Source
const (
	LDAP_OPT_X_GSSAPI_DO_NOT_FREE_CONTEXT    = 0x6200
	LDAP_OPT_X_GSSAPI_ALLOW_REMOTE_PRINCIPAL = 0x6201
)
View Source
const (
	LDAP_OPT_X_KEEPALIVE_IDLE     = 0x6300
	LDAP_OPT_X_KEEPALIVE_PROBES   = 0x6301
	LDAP_OPT_X_KEEPALIVE_INTERVAL = 0x6302
)

OpenLDAP per connection tcp-keepalive settings (Linux only, ignored where unsupported)

View Source
const (
	LDAP_AUTH_NONE   = 0x00 // no authentication
	LDAP_AUTH_SIMPLE = 0x80 // context specific + primitive
	LDAP_AUTH_SASL   = 0xa3 // context specific + constructed
	LDAP_AUTH_KRBV4  = 0xff // means do both of the following
	LDAP_AUTH_KRBV41 = 0x81 // context specific + primitive
	LDAP_AUTH_KRBV42 = 0x82 // context specific + primitive
)

authentication methods available

View Source
const (
	LDAP_NO_LIMIT = 0
)
View Source
const LDAP_OPT_API_EXTENSION_BASE = 0x4000 // API extensions
View Source
const (
	// first version for this GO API binding
	OPENLDAP_API_BINDING_VERSION = "0.2"
)

Variables

This section is empty.

Functions

func ErrorToString

func ErrorToString(err int) string

Types

type Ldap

type Ldap struct {
	// contains filtered or unexported fields
}

func Initialize

func Initialize(url string) (*Ldap, error)

Intialize() open an LDAP connexion ; supported url formats : * * ldap://host:389/ * ldaps://secure-host:636/ * * return values : * - on success : LDAP object, nil * - on error : nil and error with error description.

func (*Ldap) Add

func (self *Ldap) Add(dn string, attrs map[string][]string) error

func (*Ldap) Bind

func (self *Ldap) Bind(who, cred string) error

* Bind() is used for LDAP authentifications * * if who is empty this is an anonymous bind * else this is an authentificated bind * * return value : * - nil on succes, * - error with error description on error. *

func (*Ldap) Close

func (self *Ldap) Close() error

* close LDAP connexion * * return value : * - nil on succes, * - error with error description on error. *

func (*Ldap) Delete

func (self *Ldap) Delete(dn string) error

func (*Ldap) Errno

func (self *Ldap) Errno() int

func (*Ldap) GetOption

func (self *Ldap) GetOption(opt int) (val int, err error)

FIXME : support all kind of option (int, int*, ...) should take care of all return type for ldap_get_option

func (*Ldap) IsThreadSafe

func (self *Ldap) IsThreadSafe() bool

func (*Ldap) Modify

func (self *Ldap) Modify(dn string, attrs map[string][]string) error

func (*Ldap) ModifyAdd

func (self *Ldap) ModifyAdd(dn string, attrs map[string][]string) error

func (*Ldap) ModifyDel

func (self *Ldap) ModifyDel(dn string, attrs map[string][]string) error

func (*Ldap) Rename

func (self *Ldap) Rename(dn string, newrdn string, newSuperior string, deleteOld bool) error

Rename() to rename LDAP entries.

These routines are used to perform a LDAP rename operation. The function changes the leaf compo- nent of an entry's distinguished name and optionally moves the entry to a new parent container. The ldap_rename_s performs a rename operation synchronously. The method takes dn, which points to the distinguished name of the entry whose attribute is being compared, newparent,the distinguished name of the entry's new parent. If this parameter is NULL, only the RDN is changed. The root DN is specified by passing a zero length string, "". deleteoldrdn specifies whether the old RDN should be retained or deleted. Zero indicates that the old RDN should be retained. If you choose this option, the attribute will contain both names (the old and the new). Non-zero indicates that the old RDN should be deleted. serverctrls points to an array of LDAPControl structures that list the client controls to use with this extended operation. Use NULL to specify no client controls. clientctrls points to an array of LDAPControl structures that list the client controls to use with the search. FIXME: support NULL and "" values for newSuperior parameter.

func (*Ldap) Result

func (self *Ldap) Result() (*LdapMessage, error)

Result() take care to free LdapMessage result with MsgFree()

func (*Ldap) Search

func (self *Ldap) Search(base string, scope int, filter string, attributes []string) (*LdapMessage, error)
 Search() is used to search LDAP server
  - base is where search is starting
  - scope allows local or deep search. Supported values :
     - LDAP_SCOPE_BASE
	   - LDAP_SCOPE_ONELEVEL
     - LDAP_SCOPE_SUBTREE
  - filter is an LDAP search expression,
  - attributes is an array of string telling with LDAP attribute to get from this request

func (*Ldap) SearchAll

func (self *Ldap) SearchAll(base string, scope int, filter string, attributes []string) (*LdapSearchResult, error)

SearchAll() : a quick way to make search. This method returns an LdapSearchResult with all necessary methods to access data. Result is a collection (tree) of []LdapEntry / []LdapAttribute.

func (*Ldap) SetOption

func (self *Ldap) SetOption(opt int, val int) error

FIXME : support all kind of option (int, int*, ...)

func (*Ldap) StartTLS

func (self *Ldap) StartTLS() error

* StartTLS() is used for regular LDAP (not * LDAPS) connections to establish encryption * after the session is running. * * return value : * - nil on success, * - error with error description on error.

func (*Ldap) Unbind

func (self *Ldap) Unbind() error

* Unbind() close LDAP connexion * * an alias to Ldap::Close() *

type LdapAttribute

type LdapAttribute struct {
	// contains filtered or unexported fields
}

func LdapAttributeNew

func LdapAttributeNew(name string, values []string) *LdapAttribute

Create a new LdapAttribute entry with name and values.

func (*LdapAttribute) IsPrint

func (self *LdapAttribute) IsPrint() bool

IsPrint() returns true is self LdapAttribute is printable.

func (*LdapAttribute) Name

func (self *LdapAttribute) Name() string

Name() return attribute name

func (*LdapAttribute) String

func (self *LdapAttribute) String() string

String() is used for fmt.Println(self)

func (*LdapAttribute) ToText

func (self *LdapAttribute) ToText() string

ToText() returns a text string representation of LdapAttribute avoiding displaying binary data.

func (*LdapAttribute) Values

func (self *LdapAttribute) Values() []string

Values() returns array values for self LdapAttribute

type LdapEntry

type LdapEntry struct {
	// contains filtered or unexported fields
}

func (*LdapEntry) Append

func (self *LdapEntry) Append(a LdapAttribute)

Append() adds an LdapAttribute to self LdapEntry

func (*LdapEntry) Attributes

func (self *LdapEntry) Attributes() []LdapAttribute

Attributes() returns an array of LdapAttribute

func (*LdapEntry) CountEntries

func (self *LdapEntry) CountEntries() int

an alias to ldap_count_message() ?

func (*LdapEntry) Dn

func (self *LdapEntry) Dn() string

Dn() returns DN (Distinguish Name) for self LdapEntry

func (*LdapEntry) FirstAttribute

func (self *LdapEntry) FirstAttribute() (string, error)

func (*LdapEntry) GetDn

func (self *LdapEntry) GetDn() string

GetDn() return the DN (Distinguish Name) for self LdapEntry

func (*LdapEntry) GetOneValueByName

func (self *LdapEntry) GetOneValueByName(attrib string) (string, error)

GetOneValueByName() ; a quick way to get a single attribute value

func (*LdapEntry) GetValues

func (self *LdapEntry) GetValues(attr string) []string

GetValues() return an array of string containing values for LDAP attribute "attr". Binary data are supported.

func (*LdapEntry) GetValuesByName

func (self *LdapEntry) GetValuesByName(attrib string) []string

GetValuesByName() get a list of values for self LdapEntry, using "name" attribute

func (*LdapEntry) NextAttribute

func (self *LdapEntry) NextAttribute() (string, error)

func (*LdapEntry) NextEntry

func (self *LdapEntry) NextEntry() *LdapEntry

func (*LdapEntry) String

func (self *LdapEntry) String() string

Print() allow printing self LdapEntry with fmt.Println()

func (*LdapEntry) ToText

func (self *LdapEntry) ToText() string

ToText() return a string representating self LdapEntry

type LdapMessage

type LdapMessage struct {
	// contains filtered or unexported fields
}

func (*LdapMessage) Count

func (self *LdapMessage) Count() int

func (*LdapMessage) FirstEntry

func (self *LdapMessage) FirstEntry() *LdapEntry

func (*LdapMessage) FirstMessage

func (self *LdapMessage) FirstMessage() *LdapMessage

func (*LdapMessage) MsgFree

func (self *LdapMessage) MsgFree() int

MsgFree() is used to free LDAP::Result() allocated data

returns -1 on error.

func (*LdapMessage) NextMessage

func (self *LdapMessage) NextMessage() *LdapMessage

type LdapSearchResult

type LdapSearchResult struct {
	// contains filtered or unexported fields
}

func (*LdapSearchResult) Append

func (self *LdapSearchResult) Append(e LdapEntry)

Append() add e to LdapSearchResult array

func (*LdapSearchResult) Attributes

func (self *LdapSearchResult) Attributes() []string

Filter() : returns an array of attributes used for this actual search

func (*LdapSearchResult) Base

func (self *LdapSearchResult) Base() string

Filter() : returns base DN for self search

func (*LdapSearchResult) Count

func (self *LdapSearchResult) Count() int

Count() : returns number of results for self search.

func (*LdapSearchResult) Entries

func (self *LdapSearchResult) Entries() []LdapEntry

Entries() : returns an array of LdapEntry for self

func (*LdapSearchResult) Filter

func (self *LdapSearchResult) Filter() string

Filter() : returns filter for self search

func (*LdapSearchResult) Scope

func (self *LdapSearchResult) Scope() int

Filter() : returns scope for self search

func (*LdapSearchResult) String

func (self *LdapSearchResult) String() string

String() : used for fmt.Println(self)

func (*LdapSearchResult) ToText

func (self *LdapSearchResult) ToText() string

ToText() : a quick way to print an LdapSearchResult

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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