Make getAttribute return an empty array instead of nil when key not found

This commit is contained in:
Alex 2020-02-13 13:53:35 +01:00
parent 851573e28f
commit 6f893138a3
2 changed files with 1 additions and 13 deletions

View file

@ -359,7 +359,7 @@ func (server *Server) getAttribute(dn string, attr string) ([]string, error) {
} }
if pair == nil { if pair == nil {
return nil, nil return []string{}, nil
} }
return parseValue(pair.Value) return parseValue(pair.Value)
@ -448,9 +448,6 @@ func (server *Server) handleBindInternal(state *State, r *message.BindRequest) (
if err != nil { if err != nil {
return ldap.LDAPResultOperationsError, err return ldap.LDAPResultOperationsError, err
} }
if passwd == nil {
return ldap.LDAPResultNoSuchObject, fmt.Errorf("%s has no password", string(r.Name()))
}
for _, hash := range passwd { for _, hash := range passwd {
valid := SSHAMatches(hash, []byte(r.AuthenticationSimple())) valid := SSHAMatches(hash, []byte(r.AuthenticationSimple()))

View file

@ -118,9 +118,6 @@ func (server *Server) handleAddInternal(state *State, r *message.AddRequest) (in
server.logger.Warnf("Could not add %s to memberOf of %s: %s", dn, member, err) server.logger.Warnf("Could not add %s to memberOf of %s: %s", dn, member, err)
continue continue
} }
if memberGroups == nil {
memberGroups = []string{}
}
alreadyMember := false alreadyMember := false
for _, mb := range memberGroups { for _, mb := range memberGroups {
@ -473,9 +470,6 @@ func (server *Server) handleModifyInternal(state *State, r *message.ModifyReques
server.logger.Warnf("Could not add %s to memberOf of %s: %s", dn, addMem, err) server.logger.Warnf("Could not add %s to memberOf of %s: %s", dn, addMem, err)
continue continue
} }
if memberOf == nil {
memberOf = []string{}
}
alreadyMember := false alreadyMember := false
for _, mb := range memberOf { for _, mb := range memberOf {
@ -501,9 +495,6 @@ func (server *Server) handleModifyInternal(state *State, r *message.ModifyReques
server.logger.Warnf("Could not remove %s from memberOf of %s: %s", dn, delMem, err) server.logger.Warnf("Could not remove %s from memberOf of %s: %s", dn, delMem, err)
continue continue
} }
if memberOf == nil {
memberOf = []string{}
}
newMemberOf := []string{} newMemberOf := []string{}
for _, g := range memberOf { for _, g := range memberOf {
if g != dn { if g != dn {