From 6b11f0bfe47f76f62beadc76ad5015b9c69532e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sw=C3=A4rd?= Date: Tue, 14 Mar 2023 13:23:31 +0100 Subject: [PATCH] graph: Fix problem with unescaped semicolon and such causing problems. --- ocis-pkg/ldap/ldap.go | 32 ------------------- ocis-pkg/ldap/ldap_test.go | 25 --------------- services/graph/pkg/identity/ldap.go | 21 ++++++++---- .../pkg/identity/ldap_education_class.go | 7 ++-- .../pkg/identity/ldap_education_school.go | 22 +++++++------ services/graph/pkg/identity/ldap_group.go | 7 ++-- 6 files changed, 36 insertions(+), 78 deletions(-) delete mode 100644 ocis-pkg/ldap/ldap_test.go diff --git a/ocis-pkg/ldap/ldap.go b/ocis-pkg/ldap/ldap.go index 194ddb42ed..f9b5786b79 100644 --- a/ocis-pkg/ldap/ldap.go +++ b/ocis-pkg/ldap/ldap.go @@ -4,7 +4,6 @@ import ( "crypto/x509" "errors" "os" - "strings" "time" "github.com/owncloud/ocis/v2/ocis-pkg/log" @@ -15,20 +14,6 @@ const ( caCheckSleep = 2 ) -var ( - dnEscaper = strings.NewReplacer( - "\\", "\\\\", - ",", "\\,", - "+", "\\+", - `"`, `\\"`, - "<", "\\<", - ">", "\\>", - ";", "\\;", - "=", "\\=", - "\000", "\\00", - ) -) - func WaitForCA(log log.Logger, insecure bool, caCert string) error { if !insecure && caCert != "" { for i := 0; i < caCheckRetries; i++ { @@ -52,20 +37,3 @@ func WaitForCA(log log.Logger, insecure bool, caCert string) error { } return nil } - -// EscapeDNAttributeValue escapes special characters in an attribute value as [described in RFC4514](https://datatracker.ietf.org/doc/html/rfc4514). -func EscapeDNAttributeValue(v string) string { - if v == "" { - return v - } - - v = dnEscaper.Replace(v) - - if strings.HasSuffix(v, " ") { - v = v[:len(v)-1] + "\\ " - } - if strings.HasPrefix(v, "#") || strings.HasPrefix(v, " ") { - v = "\\" + v - } - return v -} diff --git a/ocis-pkg/ldap/ldap_test.go b/ocis-pkg/ldap/ldap_test.go deleted file mode 100644 index d3ee3152cf..0000000000 --- a/ocis-pkg/ldap/ldap_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package ldap_test - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/owncloud/ocis/v2/ocis-pkg/ldap" -) - -var _ = Describe("ldap", func() { - DescribeTable("EscapeDNAttributeValue should escape special characters", - func(input, expected string) { - escaped := ldap.EscapeDNAttributeValue(input) - Expect(escaped).To(Equal(expected)) - }, - Entry("normal dn", "foobar", "foobar"), - Entry("including comma", "foo,bar", "foo\\,bar"), - Entry("including equals", "foo=bar", "foo\\=bar"), - Entry("beginning with number sign", "#foobar", "\\#foobar"), - Entry("beginning with space", " foobar", "\\ foobar"), - Entry("only one space", " ", "\\ "), - Entry("two spaces", " ", "\\ \\ "), - Entry("ending with space", "foobar ", "foobar\\ "), - Entry("containing multiple special chars", "f+o>o,bo\,b\