Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort synchronization from LDAP source if there is some error. #7960

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,12 @@ func SyncExternalUsers() {
return
}

sr := s.LDAP().SearchEntries()
sr, err := s.LDAP().SearchEntries()
if err != nil {
log.Error("SyncExternalUsers LDAP source failure [%s], skipped", s.Name)
continue
}

for _, su := range sr {
if len(su.Username) == 0 {
continue
Expand Down
10 changes: 5 additions & 5 deletions modules/auth/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,20 @@ func (ls *Source) UsePagedSearch() bool {
}

// SearchEntries : search an LDAP source for all users matching userFilter
func (ls *Source) SearchEntries() []*SearchResult {
func (ls *Source) SearchEntries() ([]*SearchResult, error) {
l, err := dial(ls)
if err != nil {
log.Error("LDAP Connect error, %s:%v", ls.Host, err)
ls.Enabled = false
return nil
return nil, err
}
defer l.Close()

if ls.BindDN != "" && ls.BindPassword != "" {
err := l.Bind(ls.BindDN, ls.BindPassword)
if err != nil {
log.Debug("Failed to bind as BindDN[%s]: %v", ls.BindDN, err)
return nil
return nil, err
}
log.Trace("Bound as BindDN %s", ls.BindDN)
} else {
Expand Down Expand Up @@ -350,7 +350,7 @@ func (ls *Source) SearchEntries() []*SearchResult {
}
if err != nil {
log.Error("LDAP Search failed unexpectedly! (%v)", err)
return nil
return nil, err
}

result := make([]*SearchResult, len(sr.Entries))
Expand All @@ -368,5 +368,5 @@ func (ls *Source) SearchEntries() []*SearchResult {
}
}

return result
return result, nil
}