aboutsummaryrefslogtreecommitdiff
path: root/read.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-03-09 18:30:59 +0100
committerAlex Auvolat <alex@adnab.me>2021-03-09 18:30:59 +0100
commit1a20a64eff34336789c0e3b41db1de727e3fe998 (patch)
tree27e32e575eeace4260f21f76969f6e1ab5c8b5c2 /read.go
parentdc3fd4df659bb35d7858714a429fc797bf5f1222 (diff)
downloadbottin-1a20a64eff34336789c0e3b41db1de727e3fe998.tar.gz
bottin-1a20a64eff34336789c0e3b41db1de727e3fe998.zip
Refactoring
Diffstat (limited to 'read.go')
-rw-r--r--read.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/read.go b/read.go
index b139175..b36b966 100644
--- a/read.go
+++ b/read.go
@@ -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) {