Add support for PASS to downstream
This commit is contained in:
parent
a572b24702
commit
f3656028f6
2
db.go
2
db.go
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string // hashed
|
||||||
}
|
}
|
||||||
|
|
||||||
type Network struct {
|
type Network struct {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
"gopkg.in/irc.v3"
|
"gopkg.in/irc.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,6 +14,10 @@ type ircError struct {
|
|||||||
Message *irc.Message
|
Message *irc.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (err ircError) Error() string {
|
||||||
|
return err.Message.String()
|
||||||
|
}
|
||||||
|
|
||||||
func newUnknownCommandError(cmd string) ircError {
|
func newUnknownCommandError(cmd string) ircError {
|
||||||
return ircError{&irc.Message{
|
return ircError{&irc.Message{
|
||||||
Command: irc.ERR_UNKNOWNCOMMAND,
|
Command: irc.ERR_UNKNOWNCOMMAND,
|
||||||
@ -35,9 +40,10 @@ func newNeedMoreParamsError(cmd string) ircError {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err ircError) Error() string {
|
var errAuthFailed = ircError{&irc.Message{
|
||||||
return err.Message.String()
|
Command: irc.ERR_PASSWDMISMATCH,
|
||||||
}
|
Params: []string{"*", "Invalid username or password"},
|
||||||
|
}}
|
||||||
|
|
||||||
type consumption struct {
|
type consumption struct {
|
||||||
consumer *RingConsumer
|
consumer *RingConsumer
|
||||||
@ -58,6 +64,7 @@ type downstreamConn struct {
|
|||||||
nick string
|
nick string
|
||||||
username string
|
username string
|
||||||
realname string
|
realname string
|
||||||
|
password string // empty after authentication
|
||||||
network *network // can be nil
|
network *network // can be nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,6 +296,10 @@ func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dc.username = "~" + username
|
dc.username = "~" + username
|
||||||
|
case "PASS":
|
||||||
|
if err := parseMessageParams(msg, &dc.password); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
dc.logger.Printf("unhandled message: %v", msg)
|
dc.logger.Printf("unhandled message: %v", msg)
|
||||||
return newUnknownCommandError(msg.Command)
|
return newUnknownCommandError(msg.Command)
|
||||||
@ -309,15 +320,19 @@ func (dc *downstreamConn) register() error {
|
|||||||
username = username[:i]
|
username = username[:i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
password := dc.password
|
||||||
|
dc.password = ""
|
||||||
|
|
||||||
u := dc.srv.getUser(username)
|
u := dc.srv.getUser(username)
|
||||||
if u == nil {
|
if u == nil {
|
||||||
dc.logger.Printf("failed authentication: unknown username %q", username)
|
dc.logger.Printf("failed authentication for %q: unknown username", username)
|
||||||
dc.SendMessage(&irc.Message{
|
return errAuthFailed
|
||||||
Prefix: dc.srv.prefix(),
|
}
|
||||||
Command: irc.ERR_PASSWDMISMATCH,
|
|
||||||
Params: []string{"*", "Invalid username or password"},
|
err := bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
|
||||||
})
|
if err != nil {
|
||||||
return nil
|
dc.logger.Printf("failed authentication for %q: %v", username, err)
|
||||||
|
return errAuthFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
if networkName != "" {
|
if networkName != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user