forked from fclairamb/ftpserverlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_auth.go
62 lines (49 loc) · 1.38 KB
/
handle_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
53
54
55
56
57
58
59
60
61
62
package ftpserver // nolint
import (
"crypto/tls"
"fmt"
)
// Handle the "USER" command
func (c *clientHandler) handleUSER(param string) error {
if c.server.settings.TLSRequired == MandatoryEncryption && !c.HasTLSForControl() {
c.writeMessage(StatusServiceNotAvailable, "TLS is required")
return nil
}
if c.HasTLSForControl() {
if verifier, ok := c.server.driver.(MainDriverExtensionTLSVerifier); ok {
if tlsConn, ok := c.conn.(*tls.Conn); ok {
driver, err := verifier.VerifyConnection(c, param, tlsConn)
if err != nil {
c.writeMessage(StatusNotLoggedIn, fmt.Sprintf("TLS verification failed: %v", err))
c.disconnect()
return nil
}
if driver != nil {
c.user = param
c.driver = driver
c.writeMessage(StatusUserLoggedIn, "TLS certificate ok, continue")
return nil
}
}
}
}
c.user = param
c.writeMessage(StatusUserOK, "OK")
return nil
}
// Handle the "PASS" command
func (c *clientHandler) handlePASS(param string) error {
var err error
c.driver, err = c.server.driver.AuthUser(c, c.user, param)
switch {
case err == nil:
c.writeMessage(StatusUserLoggedIn, "Password ok, continue")
case err != nil:
c.writeMessage(StatusNotLoggedIn, fmt.Sprintf("Authentication problem: %v", err))
c.disconnect()
default:
c.writeMessage(StatusNotLoggedIn, "I can't deal with you (nil driver)")
c.disconnect()
}
return nil
}