-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldap.go
51 lines (41 loc) · 835 Bytes
/
ldap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"crypto/tls"
"fmt"
"github.com/go-ldap/ldap/v3"
)
func LDAPConnect() (*ldap.Conn, error) {
l, err := ldap.DialURL(c.Server)
if err != nil {
return nil, err
}
err = l.StartTLS(&tls.Config{InsecureSkipVerify: true})
if err != nil {
return nil, err
}
return l, nil
}
func LDAPSearch(l *ldap.Conn, base string, attr []string) (*ldap.SearchResult, error) {
l.Bind(c.Binddn, c.Password)
searchReq := ldap.NewSearchRequest(
base,
ldap.ScopeWholeSubtree,
ldap.NeverDerefAliases,
0,
0,
false,
"(objectClass=configFile)",
attr,
nil,
)
result, err := l.Search(searchReq)
if err != nil {
return nil, fmt.Errorf("Search Error: %s", err)
}
if len(result.Entries) > 0 {
return result, nil
} else {
return nil, fmt.Errorf("Couldn't fetch search entries")
}
}
// LDAPWrite