More logs

This commit is contained in:
Alex 2020-01-28 00:52:30 +01:00
parent 3edaad9317
commit e1f5c31402
5 changed files with 15 additions and 9 deletions

View File

@ -12,10 +12,10 @@ job "directory" {
task "server" { task "server" {
driver = "docker" driver = "docker"
config { config {
image = "lxpz/gobottin_amd64:5" image = "lxpz/gobottin_amd64:12"
readonly_rootfs = true readonly_rootfs = true
port_map { port_map {
ldap_port = 1389 ldap_port = 389
} }
volumes = [ volumes = [
"secrets/config.json:/config.json" "secrets/config.json:/config.json"

View File

@ -134,8 +134,9 @@ func (c *client) serve() {
Logger.Printf("Error reading Message : %s\n\t%x", err.Error(), messagePacket.bytes) Logger.Printf("Error reading Message : %s\n\t%x", err.Error(), messagePacket.bytes)
continue continue
} }
if DEBUG { if TRACE {
Logger.Printf("<<< %d - %s - hex=%x", c.Numero, message.ProtocolOpName(), messagePacket) //Logger.Printf("<<< %d - %s - hex=%x", c.Numero, message.ProtocolOpName(), messagePacket)
Logger.Printf("<<< %d - %#v", c.Numero, message)
} }
// TODO: Use a implementation to limit runnuning request by client // TODO: Use a implementation to limit runnuning request by client
@ -211,8 +212,9 @@ func (c *client) close() {
func (c *client) writeMessage(m *ldap.LDAPMessage) { func (c *client) writeMessage(m *ldap.LDAPMessage) {
data, _ := m.Write() data, _ := m.Write()
if DEBUG { if TRACE {
Logger.Printf(">>> %d - %s - hex=%x", c.Numero, m.ProtocolOpName(), data.Bytes()) //Logger.Printf(">>> %d - %s - hex=%x", c.Numero, m.ProtocolOpName(), data.Bytes())
Logger.Printf(">>> %d - %#v", c.Numero, m)
} }
c.bw.Write(data.Bytes()) c.bw.Write(data.Bytes())
c.bw.Flush() c.bw.Flush()

View File

@ -9,6 +9,7 @@ import (
var Logger logger var Logger logger
const DEBUG = false const DEBUG = false
const TRACE = false
// Logger represents log.Logger functions from the standard library // Logger represents log.Logger functions from the standard library
type logger interface { type logger interface {

View File

@ -413,7 +413,7 @@ func (server *Server) handleBind(s ldap.UserState, w ldap.ResponseWriter, m *lda
func (server *Server) handleBindInternal(state *State, r *message.BindRequest) (int, error) { func (server *Server) handleBindInternal(state *State, r *message.BindRequest) (int, error) {
// Check permissions // Check permissions
if !server.config.Acl.Check(&state.login, "bind", string(r.Name()), []string{}) { if !server.config.Acl.Check(&state.login, "bind", string(r.Name()), []string{}) {
return ldap.LDAPResultInsufficientAccessRights, nil return ldap.LDAPResultInsufficientAccessRights, fmt.Errorf("Insufficient access rights for %#v", state.login)
} }
// Try to retrieve password and check for match // Try to retrieve password and check for match
@ -422,7 +422,7 @@ func (server *Server) handleBindInternal(state *State, r *message.BindRequest) (
return ldap.LDAPResultOperationsError, err return ldap.LDAPResultOperationsError, err
} }
if passwd == nil { if passwd == nil {
return ldap.LDAPResultNoSuchObject, nil return ldap.LDAPResultNoSuchObject, fmt.Errorf("%s has no password", string(r.Name()))
} }
for _, hash := range passwd { for _, hash := range passwd {
@ -439,5 +439,5 @@ func (server *Server) handleBindInternal(state *State, r *message.BindRequest) (
return ldap.LDAPResultSuccess, nil return ldap.LDAPResultSuccess, nil
} }
} }
return ldap.LDAPResultInvalidCredentials, nil return ldap.LDAPResultInvalidCredentials, fmt.Errorf("No password match")
} }

View File

@ -73,6 +73,9 @@ func (server *Server) handleSearch(s ldap.UserState, w ldap.ResponseWriter, m *l
if err != nil { if err != nil {
res.SetDiagnosticMessage(err.Error()) res.SetDiagnosticMessage(err.Error())
} }
if code != ldap.LDAPResultSuccess {
server.logger.Printf("Failed to do search %#v (%s)", r, err)
}
w.Write(message.SearchResultDone(res)) w.Write(message.SearchResultDone(res))
} }