-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
52 lines (44 loc) · 1.06 KB
/
auth.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
package main
// NOOP authentication, which is not completely correct as clients are stalling at this point
func doAuthNone(data []byte, conn *serverConnection) {
log.Debug("NOOP auth - pass through")
conn.status = stsWrCmd
}
// Username Password authentication
func doAuthPass(data []byte, conn *serverConnection) {
var hIdx int
var version = -1
var lenUname = -1
var lenPassw = -1
var username = ""
var password = ""
if len(data) >= hIdx+1 {
version = int(data[hIdx])
hIdx++
}
if len(data) >= hIdx+1 {
lenUname = int(data[hIdx])
hIdx++
}
if len(data) >= (lenUname + hIdx) {
username = string(data[hIdx : hIdx+lenUname])
hIdx += lenUname
}
if len(data) >= hIdx+1 {
lenPassw = int(data[hIdx])
hIdx++
}
if len(data) >= (lenPassw + hIdx) {
password = string(data[hIdx : hIdx+lenPassw])
hIdx += lenPassw
}
if len(data) >= hIdx {
if version == 1 && username == "james" && password == "james" {
log.Info("User authenticated")
conn.status = stsWrCmd
} else {
log.Info("User failed authentication")
conn.status = stsWrAuthErr
}
}
}