-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldap.go
89 lines (76 loc) · 3.04 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package ldap-format
import (
"fmt"
"strings"
)
func FormatLDAP( whitelist []string) {
for _, value := range whitelist {
// Split the string into slices separated by comma
splitValue := strings.Split(value, ",")
// Send each attribute through the necessary checks
for _, singleAttribute := range splitValue {
err := CheckPrefix(singleAttribute)
if err != nil {
fmt.Printf("Attribute formatting error: %s\n", singleAttribute)
}
if strings.HasPrefix(singleAttribute, "CN=") {
err := CheckCN(singleAttribute)
if err != nil {
fmt.Printf("Common name contains invalid character: %s\n", singleAttribute)
}
}
if strings.HasPrefix(singleAttribute, "OU=") {
err := CheckOU(singleAttribute)
if err != nil {
fmt.Printf("OU name error: %s\n", singleAttribute)
}
}
if strings.HasPrefix(singleAttribute, "DC=") {
err := CheckDC(singleAttribute)
if err != nil {
fmt.Printf("Domain component error: %s\n", singleAttribute)
}
}
}
}
}
// CheckPrefixis a function that checks if the query contains only CN, OU, and DC, err if not
func CheckPrefix(whitelist_query string) error {
attribute := strings.HasPrefix(whitelist_query, "CN=") || strings.HasPrefix(whitelist_query, "DC=") || strings.HasPrefix(whitelist_query, "OU=")
switch attribute {
case true:
return nil
default:
return fmt.Errorf("Incorrect attribute naming convention")
}
}
func CheckCN(common_name string) error {
cn_name := strings.ContainsAny(common_name, "+)(*&^%$#@!")
switch cn_name {
case true:
return fmt.Errorf("Incorrect naming convention for common name")
default:
return nil
}
}
// CheckOU is a function that checks if the query contains the right organization unit options, err if not
func CheckOU(organizational_unit string) error {
ou_name := strings.HasSuffix(organizational_unit,"=DOCET") || strings.HasSuffix(organizational_unit,"=Admin Groups") || strings.HasSuffix(organizational_unit,"=Admin") ||
strings.HasSuffix(organizational_unit,"=Infrastructure") || strings.HasSuffix(organizational_unit,"=Security Groups") || strings.HasSuffix(organizational_unit,"=Worldpay")
switch ou_name {
case true:
return nil
default:
return fmt.Errorf("Organizational Unit not currently supported")
}
}
// Check DC checks to ensure the domain component follows the path of worldpay -> local (will add other domain components)
func CheckDC(domain_component string) error {
dc_name := strings.HasSuffix(domain_component,"=worldpay") || strings.HasSuffix(domain_component,"=local")
switch dc_name {
case true:
return nil
default:
return fmt.Errorf("Domain Component not currently supported")
}
}