aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-15 12:04:06 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-15 12:07:31 +0100
commit825aa770893850fb2626def316c4b0f060ef776f (patch)
treeec09d3475f50886c001af29f4b593a9167be084a /util.go
parent0c4d55895cfda3632af8ada1cebd3e14addb6033 (diff)
downloadbottin-825aa770893850fb2626def316c4b0f060ef776f.tar.gz
bottin-825aa770893850fb2626def316c4b0f060ef776f.zip
Hopefully, fix most case-sensitivity issues
- DNs are always used in canonical form: lowercase, no spaces. This is how they are internally handled and stored in paths and fields such as member and memberof - Attribute names now can have any combination of lower/uppercase and stuff should work - When modifying an attribute with a name that hase a different lower/upper combination than the previously stored value, keep the previous attribute name - Trim spaces from values and do not store empty values
Diffstat (limited to 'util.go')
-rw-r--r--util.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/util.go b/util.go
index 96bb00b..95ad102 100644
--- a/util.go
+++ b/util.go
@@ -98,19 +98,14 @@ func parseDN(dn string) ([]DNComponent, error) {
return nil, fmt.Errorf("Wrong DN component: %s (expected type=value)", rdn)
}
ret = append(ret, DNComponent{
- Type: strings.TrimSpace(splits[0]),
- Value: strings.TrimSpace(splits[1]),
+ Type: strings.ToLower(strings.TrimSpace(splits[0])),
+ Value: strings.ToLower(strings.TrimSpace(splits[1])),
})
}
return ret, nil
}
-func canonicalDN(dn string) (string, error) {
- path, err := parseDN(dn)
- if err != nil {
- return "", err
- }
-
+func unparseDN(path []DNComponent) string {
ret := ""
for _, c := range path {
if ret != "" {
@@ -118,7 +113,16 @@ func canonicalDN(dn string) (string, error) {
}
ret = ret + c.Type + "=" + c.Value
}
- return ret, nil
+ return ret
+}
+
+func canonicalDN(dn string) (string, error) {
+ path, err := parseDN(dn)
+ if err != nil {
+ return "", err
+ }
+
+ return unparseDN(path), nil
}
func checkRestrictedAttr(attr string) error {
@@ -162,3 +166,12 @@ func valueMatch(attr, val1, val2 string) bool {
return strings.EqualFold(val1, val2)
}
}
+
+func listContains(list []string, key string) bool {
+ for _, v := range list {
+ if key == v {
+ return true
+ }
+ }
+ return false
+}