From e730579b14b23fbb5bf328c8c79c0cc38adb5731 Mon Sep 17 00:00:00 2001 From: Markus Stoll Date: Sat, 12 Jun 2021 15:10:32 +0200 Subject: [PATCH 1/3] Implementation for anonymous bind --- gitea-group-sync.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gitea-group-sync.go b/gitea-group-sync.go index 1fb2e2b..2e5f1e1 100644 --- a/gitea-group-sync.go +++ b/gitea-group-sync.go @@ -165,11 +165,8 @@ func (c Config) checkConfig() { } else { log.Printf("DialTLS:=%v:%d", c.LdapURL, c.LdapPort) } - if len(c.LdapBindDN) == 0 { - log.Println("BIND_DN is empty") - } - if len(c.LdapBindPassword) == 0 { - log.Println("BIND_PASSWORD is empty") + if (len(c.LdapBindDN) > 0 && len(c.LdapBindPassword) == 0) { + log.Println("BIND_DN supplied, but BIND_PASSWORD is empty") } if len(c.LdapFilter) == 0 { log.Println("LDAP_FILTER is empty") @@ -222,10 +219,16 @@ func mainJob() { } defer l.Close() - err = l.Bind(cfg.LdapBindDN, cfg.LdapBindPassword) + if len(cfg.LdapBindDN) == 0 { + err = l.UnauthenticatedBind("") + } else { + err = l.Bind(cfg.LdapBindDN, cfg.LdapBindPassword) + } + if err != nil { log.Fatal(err) } + page := 1 cfg.ApiKeys.BruteforceTokenKey = 0 cfg.ApiKeys.Command = "/api/v1/admin/orgs?page=" + fmt.Sprintf("%d", page) + "&limit=20&access_token=" // List all organizations From 0801c2993e700db70ad0eebc61690863421b3bcd Mon Sep 17 00:00:00 2001 From: Markus Stoll Date: Sat, 12 Jun 2021 15:13:18 +0200 Subject: [PATCH 2/3] Add comment in config file --- config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/config.yaml b/config.yaml index 4773612..42f1451 100644 --- a/config.yaml +++ b/config.yaml @@ -9,6 +9,7 @@ ApiKeys: LdapURL: "localhost" LdapPort: 639 LdapTLS: false +# LdapBindDN is optional, if unset we will do an anonymous bind LdapBindDN: "cn=admin,dc=planetexpress,dc=com" LdapBindPassword: "GoodNewsEveryone" LdapFilter: '(&(objectClass=person)(memberOf=cn=%s,ou=people,dc=planetexpress,dc=com))' From 44a7868ce07c82b2797972d9b82917cea0ad838f Mon Sep 17 00:00:00 2001 From: Markus Stoll Date: Sun, 13 Jun 2021 14:05:04 +0200 Subject: [PATCH 3/3] Fix code indentation --- gitea-group-sync.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitea-group-sync.go b/gitea-group-sync.go index 2e5f1e1..f8698db 100644 --- a/gitea-group-sync.go +++ b/gitea-group-sync.go @@ -165,7 +165,7 @@ func (c Config) checkConfig() { } else { log.Printf("DialTLS:=%v:%d", c.LdapURL, c.LdapPort) } - if (len(c.LdapBindDN) > 0 && len(c.LdapBindPassword) == 0) { + if len(c.LdapBindDN) > 0 && len(c.LdapBindPassword) == 0 { log.Println("BIND_DN supplied, but BIND_PASSWORD is empty") } if len(c.LdapFilter) == 0 { @@ -219,12 +219,12 @@ func mainJob() { } defer l.Close() - if len(cfg.LdapBindDN) == 0 { - err = l.UnauthenticatedBind("") + if len(cfg.LdapBindDN) == 0 { + err = l.UnauthenticatedBind("") } else { - err = l.Bind(cfg.LdapBindDN, cfg.LdapBindPassword) + err = l.Bind(cfg.LdapBindDN, cfg.LdapBindPassword) } - + if err != nil { log.Fatal(err) } @@ -236,7 +236,7 @@ func mainJob() { log.Printf("%d organizations were found on the server: %s", len(organizationList), cfg.ApiKeys.BaseUrl) - for 1 < len(organizationList) { + for 0 < len(organizationList) { for i := 0; i < len(organizationList); i++ {