ldap

package
v0.0.0-...-1a8d2dc Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 License: GPL-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SEARCH   = "SearchRequest"
	BIND     = "BindRequest"
	COMPARE  = "CompareRequest"
	ADD      = "AddRequest"
	MODIFY   = "ModifyRequest"
	DELETE   = "DelRequest"
	EXTENDED = "ExtendedRequest"
	ABANDON  = "AbandonRequest"
)

Constant to LDAP Request protocol Type names

Variables

View Source
var (
	// ServerContextKey is a context key. It can be used in HTTP
	// handlers with Context.Value to access the server that
	// started the handler. The associated value will be of
	// type *Server.
	ServerContextKey = &contextKey{"ldap-server"}

	// LocalAddrContextKey is a context key. It can be used in
	// HTTP handlers with Context.Value to access the local
	// address the connection arrived on.
	// The associated value will be of type net.Addr.
	LocalAddrContextKey = &contextKey{"local-addr"}
)
View Source
var ErrServerClosed = errors.New("ldap: Server closed")

ErrServerClosed is returned by the Server's Serve, (TODO ServeTLS,) ListenAndServe, and ListenAndServeTLS methods after a call to Shutdown or Close.

Functions

func NewAddResponse

func NewAddResponse(resultCode int) message.AddResponse

func NewBindResponse

func NewBindResponse(resultCode int) message.BindResponse

func NewCompareResponse

func NewCompareResponse(resultCode int) message.CompareResponse

func NewDeleteResponse

func NewDeleteResponse(resultCode int) message.DelResponse

func NewExtendedResponse

func NewExtendedResponse(resultCode int) message.ExtendedResponse

func NewModifyResponse

func NewModifyResponse(resultCode int) message.ModifyResponse

func NewResponse

func NewResponse(resultCode int) message.LDAPResult

func NewSearchResultDoneResponse

func NewSearchResultDoneResponse(resultCode int) message.SearchResultDone

func NewSearchResultEntry

func NewSearchResultEntry(objectname string) message.SearchResultEntry

Types

type ConnState

type ConnState int

A ConnState represents the state of a client connection to a server. It's used by the optional Server.ConnState hook.

const (
	// StateNew represents a new connection that is expected to
	// send a request immediately. Connections begin at this
	// state and then transition to either StateActive or
	// StateClosed.
	StateNew ConnState = iota

	// StateActive represents a connection that has read 1 or more
	// bytes of a request. The Server.ConnState hook for
	// StateActive fires before the request has entered a handler
	// and doesn't fire again until the request has been
	// handled. After the request is handled, the state
	// transitions to StateClosed or StateIdle.
	// StateActive fires on the transition from zero
	// to one active request, and only transitions away once all
	// active requests are complete. That means that ConnState
	// cannot be used to do per-request work; ConnState only notes
	// the overall state of the connection.
	StateActive

	// StateIdle represents a connection that has finished
	// handling a request and is waiting
	// for a new request. Connections transition from StateIdle
	// to either StateActive or StateClosed.
	StateIdle

	// StateClosed represents a closed connection.
	// This is a terminal state.
	StateClosed
)

func (ConnState) String

func (c ConnState) String() string

type E

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

func (E) Error

func (e E) Error() string

type Handler

type Handler interface {
	ServeLDAP(w ResponseWriter, r *Request)
}

Handler interface used to serve a LDAP Request message

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)

HandlerFunc type is an adapter to allow the use of ordinary functions as LDAP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.

type Option

type Option func(o *Options)

func Addr

func Addr(val string) Option

func Listener

func Listener(val net.Listener) Option

func Logger

func Logger(val logr.Logger) Option

func TLSConfig

func TLSConfig(val *tls.Config) Option

type Options

type Options struct {
	Addr      string
	Logger    logr.Logger
	Listener  net.Listener
	TLSConfig *tls.Config
}

type Request

type Request struct {
	// TODO add reference to map of messages, needed for abandon
	*message.LDAPMessage
	Done chan bool
	Conn *conn
}

func (*Request) Abandon

func (r *Request) Abandon()

Abandon close the Done channel, to notify handler's user function to stop any running process

func (*Request) GetAbandonRequest

func (r *Request) GetAbandonRequest() message.AbandonRequest

func (*Request) GetAddRequest

func (r *Request) GetAddRequest() message.AddRequest

func (*Request) GetBindRequest

func (r *Request) GetBindRequest() message.BindRequest

func (*Request) GetCompareRequest

func (r *Request) GetCompareRequest() message.CompareRequest

func (*Request) GetDeleteRequest

func (r *Request) GetDeleteRequest() message.DelRequest

func (*Request) GetExtendedRequest

func (r *Request) GetExtendedRequest() message.ExtendedRequest

func (*Request) GetModifyRequest

func (r *Request) GetModifyRequest() message.ModifyRequest

func (*Request) GetSearchRequest

func (r *Request) GetSearchRequest() message.SearchRequest

func (*Request) String

func (r *Request) String() string

type ResponseWriter

type ResponseWriter interface {
	// Write writes the LDAPResponse to the connection as part of an LDAP reply.
	Write(po message.ProtocolOp)
}

ResponseWriter interface is used by an LDAP handler to construct an LDAP response.

type RouteMux

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

RouteMux manages all routes

func NewRouteMux

func NewRouteMux(opts ...Option) *RouteMux

NewRouteMux returns a new *RouteMux RouteMux implements ldapserver.Handler

func (*RouteMux) Abandon

func (h *RouteMux) Abandon(handler HandlerFunc) *route

func (*RouteMux) Add

func (h *RouteMux) Add(handler HandlerFunc) *route

func (*RouteMux) Bind

func (h *RouteMux) Bind(handler HandlerFunc) *route

func (*RouteMux) Compare

func (h *RouteMux) Compare(handler HandlerFunc) *route

func (*RouteMux) Delete

func (h *RouteMux) Delete(handler HandlerFunc) *route

func (*RouteMux) Extended

func (h *RouteMux) Extended(handler HandlerFunc) *route

func (*RouteMux) Modify

func (h *RouteMux) Modify(handler HandlerFunc) *route

func (*RouteMux) NotFound

func (h *RouteMux) NotFound(handler HandlerFunc) *route

func (*RouteMux) Search

func (h *RouteMux) Search(handler HandlerFunc) *route

func (*RouteMux) ServeLDAP

func (h *RouteMux) ServeLDAP(w ResponseWriter, r *Request)

ServeLDAP dispatches the request to the handler whose pattern most closely matches the request request Message.

type Server

type Server struct {
	Addr string // TCP address to listen on, ":389" if empty
	// Handler handles ldap message received from client
	// it SHOULD "implement" RequestHandler interface
	Handler Handler

	// TLSConfig optionally provides a TLS configuration for use
	// by ServeTLS and ListenAndServeTLS. Note that this value is
	// cloned by ServeTLS and ListenAndServeTLS, so it's not
	// possible to modify the configuration with methods like
	// tls.Config.SetSessionTicketKeys. To use
	// SetSessionTicketKeys, use Server.Serve with a TLS Listener
	// instead.
	TLSConfig *tls.Config

	// ReadTimeout is the maximum duration for reading the entire
	// request.
	ReadTimeout time.Duration

	// WriteTimeout is the maximum duration before timing out
	// writes of the response. It is reset whenever a new
	// request is read. Like ReadTimeout, it does not
	// let Handlers make decisions on a per-request basis.
	WriteTimeout time.Duration

	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled. If IdleTimeout
	// is zero, the value of ReadTimeout is used. If both are
	// zero, there is no timeout.
	IdleTimeout time.Duration

	// ConnState specifies an optional callback function that is
	// called when a client connection changes state. See the
	// ConnState type and associated constants for details.
	ConnState func(net.Conn, ConnState)

	// Logger specifies an optional logger
	// If nil, logging is done via the github.com/go-logr/stdr package's logger.
	Logger logr.Logger

	// BaseContext optionally specifies a function that returns
	// the base context for incoming requests on this server.
	// The provided Listener is the specific Listener that's
	// about to start accepting requests.
	// If BaseContext is nil, the default is context.Background().
	// If non-nil, it must return a non-nil context.
	BaseContext func(net.Listener) context.Context

	// ConnContext optionally specifies a function that modifies
	// the context used for a new connection c. The provided ctx
	// is derived from the base context and has a ServerContextKey
	// value.
	ConnContext func(ctx context.Context, c net.Conn) context.Context
	// contains filtered or unexported fields
}

Server is an LDAP server.

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) Close

func (srv *Server) Close() error

Close immediately closes all active net.Listeners and any connections in state StateNew, StateActive, or StateIdle. For a graceful shutdown, use Shutdown.

Close returns any error returned from closing the Server's underlying Listener(s).

func (*Server) Handle

func (srv *Server) Handle(h Handler)

Handle registers the handler for the server. If a handler already exists for pattern, Handle panics

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address s.Addr and then calls Serve to handle requests on incoming connections. If s.Addr is blank, ":389" is used.

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS() error

ListenAndServeTLS listens on the TCP network address s.Addr and then calls ServeLTS to handle requests on incoming connections. If s.Addr is blank, ":636" is used.

func (*Server) RegisterOnShutdown

func (srv *Server) RegisterOnShutdown(f func())

RegisterOnShutdown registers a function to call on Shutdown. This can be used to gracefully shutdown connections that have undergone NPN/ALPN protocol upgrade or that have been hijacked. This function should start protocol-specific graceful shutdown, but should not wait for shutdown to complete.

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them.

Serve always returns a non-nil error and closes l. After Shutdown or Close, the returned error is ErrServerClosed.

func (*Server) ServeTLS

func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error

ServeTLS accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines perform TLS setup and then read requests, calling srv.Handler to reply to them.

Files containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

ServeTLS always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.

func (*Server) Shutdown

func (srv *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down. If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Server's underlying Listener(s).

When Shutdown is called, Serve, ListenAndServe, and ListenAndServeTLS immediately return ErrServerClosed. Make sure the program doesn't exit and waits instead for Shutdown to return.

Shutdown does not attempt to close nor wait for hijacked connections such as WebSockets. The caller of Shutdown should separately notify such long-lived connections of shutdown and wait for them to close, if desired. See RegisterOnShutdown for a way to register shutdown notification functions.

Once Shutdown has been called on a server, it may not be reused; future calls to methods such as Serve will return ErrServerClosed.

Jump to

Keyboard shortcuts

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