diff options
Diffstat (limited to 'read.go')
-rw-r--r-- | read.go | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -9,6 +9,46 @@ import ( message "github.com/lor00x/goldap/message" ) +// Generic read utility functions ---------- + +func (server *Server) getAttribute(dn string, attr string) ([]string, error) { + path, err := dnToConsul(dn) + if err != nil { + return nil, err + } + + pairs, _, err := server.kv.List(path+"/attribute=", &server.readOpts) + if err != nil { + return nil, err + } + + values := []string{} + for _, pair := range pairs { + if strings.EqualFold(pair.Key, path+"/attribute="+attr) { + newVals, err := parseValue(pair.Value) + if err != nil { + return nil, err + } + values = append(values, newVals...) + } + } + + return values, nil +} + +func (server *Server) objectExists(dn string) (bool, error) { + prefix, err := dnToConsul(dn) + if err != nil { + return false, err + } + + data, _, err := server.kv.List(prefix+"/attribute=", &server.readOpts) + if err != nil { + return false, err + } + return len(data) > 0, nil +} + // Compare request ------------------------- func (server *Server) handleCompare(s ldap.UserState, w ldap.ResponseWriter, m *ldap.Message) { |