Skip to content

Commit b6b1560

Browse files
davidsvantessonsapk
authored andcommitted
Abort syncrhonization from LDAP source if there is some error. (#7965)
Signed-off-by: David Svantesson <[email protected]> (cherry picked from commit b2d23a1)
1 parent 30dbddc commit b6b1560

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

models/user.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,12 @@ func SyncExternalUsers() {
16451645
return
16461646
}
16471647

1648-
sr := s.LDAP().SearchEntries()
1648+
sr, err := s.LDAP().SearchEntries()
1649+
if err != nil {
1650+
log.Error("SyncExternalUsers LDAP source failure [%s], skipped", s.Name)
1651+
continue
1652+
}
1653+
16491654
for _, su := range sr {
16501655
if len(su.Username) == 0 {
16511656
continue

modules/auth/ldap/ldap.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,20 @@ func (ls *Source) UsePagedSearch() bool {
308308
}
309309

310310
// SearchEntries : search an LDAP source for all users matching userFilter
311-
func (ls *Source) SearchEntries() []*SearchResult {
311+
func (ls *Source) SearchEntries() ([]*SearchResult, error) {
312312
l, err := dial(ls)
313313
if err != nil {
314314
log.Error("LDAP Connect error, %s:%v", ls.Host, err)
315315
ls.Enabled = false
316-
return nil
316+
return nil, err
317317
}
318318
defer l.Close()
319319

320320
if ls.BindDN != "" && ls.BindPassword != "" {
321321
err := l.Bind(ls.BindDN, ls.BindPassword)
322322
if err != nil {
323323
log.Debug("Failed to bind as BindDN[%s]: %v", ls.BindDN, err)
324-
return nil
324+
return nil, err
325325
}
326326
log.Trace("Bound as BindDN %s", ls.BindDN)
327327
} else {
@@ -350,7 +350,7 @@ func (ls *Source) SearchEntries() []*SearchResult {
350350
}
351351
if err != nil {
352352
log.Error("LDAP Search failed unexpectedly! (%v)", err)
353-
return nil
353+
return nil, err
354354
}
355355

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

371-
return result
371+
return result, nil
372372
}

0 commit comments

Comments
 (0)