diff --git a/configbackend.go b/configbackend.go index d3d4e4e..ee84848 100644 --- a/configbackend.go +++ b/configbackend.go @@ -21,7 +21,7 @@ func newConfigHandler(cfg *config) Backend { } // -func (h configHandler) Bind(bindDN, bindSimplePw string, conn net.Conn) (resultCode uint64, err error) { +func (h configHandler) Bind(bindDN, bindSimplePw string, conn net.Conn) (resultCode ldap.LDAPResultCode, err error) { bindDN = strings.ToLower(bindDN) baseDN := strings.ToLower("," + h.cfg.Backend.BaseDN) log.Debug("Bind request as %s from %s", bindDN, conn.RemoteAddr().String()) @@ -108,13 +108,13 @@ func (h configHandler) Search(bindDN string, searchReq ldap.SearchRequest, conn } // return all users in the config file - the LDAP library will filter results for us entries := []*ldap.Entry{} - filterType, err := ldap.GetFilterType(searchReq.Filter) + filterEntity, err := ldap.GetFilterObjectClass(searchReq.Filter) if err != nil { return ldap.ServerSearchResult{ResultCode: ldap.LDAPResultOperationsError}, fmt.Errorf("Search Error: error parsing filter: %s", searchReq.Filter) } - switch filterType { + switch filterEntity { default: - return ldap.ServerSearchResult{ResultCode: ldap.LDAPResultOperationsError}, fmt.Errorf("Search Error: unhandled filter type: %s [%s]", filterType, searchReq.Filter) + return ldap.ServerSearchResult{ResultCode: ldap.LDAPResultOperationsError}, fmt.Errorf("Search Error: unhandled filter type: %s [%s]", filterEntity, searchReq.Filter) case "posixgroup": for _, g := range h.cfg.Groups { attrs := []*ldap.EntryAttribute{} @@ -155,7 +155,7 @@ func (h configHandler) Search(bindDN string, searchReq ldap.SearchRequest, conn } // -func (h configHandler) Close(conn net.Conn) error { +func (h configHandler) Close(boundDn string, conn net.Conn) error { stats_frontend.Add("closes", 1) return nil } diff --git a/glauth.go b/glauth.go index 8734323..ea4282f 100644 --- a/glauth.go +++ b/glauth.go @@ -4,8 +4,8 @@ import ( "expvar" "fmt" "github.com/BurntSushi/toml" - "github.com/nmcclain/ldap" "github.com/docopt/docopt-go" + "github.com/nmcclain/ldap" "github.com/op/go-logging" "launchpad.net/goamz/aws" "launchpad.net/goamz/s3" @@ -13,9 +13,6 @@ import ( "strings" ) -//import "github.com/kr/pretty" -//log.Critical(": %# v", pretty.Formatter(string(tomlData))) - var version = "0.1" const programName = "glauth" @@ -36,8 +33,6 @@ Options: --version Show version. ` -// ldapsearch -LLL -H ldaps://localhost:3389 -D cn=ned,ou=seals,o=ate,c=opsbot -w mysecret -x -b 'o=ate,c=opsbot' 'cn=ned' cn - // exposed expvar variables var stats_frontend = expvar.NewMap("proxy_frontend") var stats_backend = expvar.NewMap("proxy_backend") diff --git a/ldapbackend.go b/ldapbackend.go index f8bd814..a289a23 100644 --- a/ldapbackend.go +++ b/ldapbackend.go @@ -5,8 +5,8 @@ import ( "crypto/tls" "encoding/json" "fmt" - "github.com/nmcclain/ldap" "github.com/kr/pretty" + "github.com/nmcclain/ldap" "net" "net/url" "strconv" @@ -65,7 +65,7 @@ func newLdapHandler(cfg *config) Backend { } // -func (h ldapHandler) Bind(bindDN, bindSimplePw string, conn net.Conn) (resultCode uint64, err error) { +func (h ldapHandler) Bind(bindDN, bindSimplePw string, conn net.Conn) (resultCode ldap.LDAPResultCode, err error) { log.Debug("Bind request as %s from %s", bindDN, conn.RemoteAddr().String()) stats_frontend.Add("bind_reqs", 1) s, err := h.getSession(conn) @@ -118,14 +118,14 @@ func (h ldapHandler) Search(boundDN string, searchReq ldap.SearchRequest, conn n e := err.(*ldap.Error) log.Debug("Search Err: %# v", pretty.Formatter(err)) stats_frontend.Add("search_errors", 1) - ssr.ResultCode = uint64(e.ResultCode) + ssr.ResultCode = ldap.LDAPResultCode(e.ResultCode) return ssr, err } stats_frontend.Add("search_successes", 1) log.Debug("AP: Search OK: %s -> num of entries = %d\n", search.Filter, len(ssr.Entries)) return ssr, nil } -func (h ldapHandler) Close(conn net.Conn) error { +func (h ldapHandler) Close(boundDn string, conn net.Conn) error { conn.Close() // close connection to the server when then client is closed h.lock.Lock() defer h.lock.Unlock()