forked from hamano/lb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind.go
67 lines (60 loc) · 1.03 KB
/
bind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"log"
"fmt"
"strings"
"reflect"
"math/rand"
"github.com/urfave/cli"
)
type BindJob struct {
BaseJob
dn string
password string
first int
last int
idRange int
}
var bindFlags = []cli.Flag {
cli.IntFlag {
Name: "first",
Value: 1,
Usage: "first id",
},
cli.IntFlag {
Name: "last",
Value: 0,
Usage: "last id",
},
}
func Bind(c *cli.Context) error {
runBenchmark(c, reflect.TypeOf(BindJob{}))
return nil
}
func (job *BindJob) Prep(c *cli.Context) bool {
if job.GetVerbose() >= 2 {
log.Printf("worker[%d]: prepare\n", job.wid)
}
job.dn = c.String("D")
job.password = c.String("w")
job.first = c.Int("first")
job.last = c.Int("last")
if strings.Contains(job.dn, "%") {
job.idRange = job.last - job.first + 1
}
return true
}
func (job *BindJob) Request() bool {
var dn string
if job.idRange > 0 {
id := rand.Intn(job.idRange) + job.first
dn = fmt.Sprintf(job.dn, id)
} else {
dn = job.dn
}
err := job.ldap.Bind(dn, job.password)
if err != nil {
return false
}
return true
}