work on #986 and fix a LDAP crash
This commit is contained in:
parent
71fd10dd37
commit
6235bd1fe9
4 changed files with 116 additions and 66 deletions
|
@ -42,7 +42,7 @@ func (ls Ldapsource) FindUserDN(name string) (string, bool) {
|
|||
if ls.BindDN != "" && ls.BindPassword != "" {
|
||||
err = l.Bind(ls.BindDN, ls.BindPassword)
|
||||
if err != nil {
|
||||
log.Debug("Failed to bind as BindDN: %s, %s", ls.BindDN, err.Error())
|
||||
log.Debug("Failed to bind as BindDN[%s]: %v", ls.BindDN, err)
|
||||
return "", false
|
||||
}
|
||||
log.Trace("Bound as BindDN %s", ls.BindDN)
|
||||
|
@ -60,7 +60,7 @@ func (ls Ldapsource) FindUserDN(name string) (string, bool) {
|
|||
// Ensure we found a user
|
||||
sr, err := l.Search(search)
|
||||
if err != nil || len(sr.Entries) < 1 {
|
||||
log.Debug("Failed search using filter %s: %s", userFilter, err.Error())
|
||||
log.Debug("Failed search using filter[%s]: %v", userFilter, err)
|
||||
return "", false
|
||||
} else if len(sr.Entries) > 1 {
|
||||
log.Debug("Filter '%s' returned more than one user.", userFilter)
|
||||
|
@ -95,7 +95,7 @@ func (ls Ldapsource) SearchEntry(name, passwd string) (string, string, string, b
|
|||
log.Trace("Binding with userDN: %s", userDN)
|
||||
err = l.Bind(userDN, passwd)
|
||||
if err != nil {
|
||||
log.Debug("LDAP auth. failed for %s, reason: %s", userDN, err.Error())
|
||||
log.Debug("LDAP auth. failed for %s, reason: %v", userDN, err)
|
||||
return "", "", "", false
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ func (ls Ldapsource) SearchEntry(name, passwd string) (string, string, string, b
|
|||
|
||||
sr, err := l.Search(search)
|
||||
if err != nil {
|
||||
log.Error(4, "LDAP Search failed unexpectedly! (%s)", err.Error())
|
||||
log.Error(4, "LDAP Search failed unexpectedly! (%v)", err)
|
||||
return "", "", "", false
|
||||
} else if len(sr.Entries) < 1 {
|
||||
log.Error(4, "LDAP Search failed unexpectedly! (0 entries)")
|
||||
|
|
|
@ -91,34 +91,33 @@ type FuncJob func()
|
|||
func (f FuncJob) Run() { f() }
|
||||
|
||||
// AddFunc adds a func to the Cron to be run on the given schedule.
|
||||
func (c *Cron) AddFunc(desc, spec string, cmd func()) error {
|
||||
func (c *Cron) AddFunc(desc, spec string, cmd func()) (*Entry, error) {
|
||||
return c.AddJob(desc, spec, FuncJob(cmd))
|
||||
}
|
||||
|
||||
// AddFunc adds a Job to the Cron to be run on the given schedule.
|
||||
func (c *Cron) AddJob(desc, spec string, cmd Job) error {
|
||||
func (c *Cron) AddJob(desc, spec string, cmd Job) (*Entry, error) {
|
||||
schedule, err := Parse(spec)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
c.Schedule(desc, spec, schedule, cmd)
|
||||
return nil
|
||||
return c.Schedule(desc, spec, schedule, cmd), nil
|
||||
}
|
||||
|
||||
// Schedule adds a Job to the Cron to be run on the given schedule.
|
||||
func (c *Cron) Schedule(desc, spec string, schedule Schedule, cmd Job) {
|
||||
func (c *Cron) Schedule(desc, spec string, schedule Schedule, cmd Job) *Entry {
|
||||
entry := &Entry{
|
||||
Description: desc,
|
||||
Spec: spec,
|
||||
Schedule: schedule,
|
||||
Job: cmd,
|
||||
}
|
||||
if !c.running {
|
||||
if c.running {
|
||||
c.add <- entry
|
||||
} else {
|
||||
c.entries = append(c.entries, entry)
|
||||
return
|
||||
}
|
||||
|
||||
c.add <- entry
|
||||
return entry
|
||||
}
|
||||
|
||||
// Entries returns a snapshot of the cron entries.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue