forked from External/ergo
many changes
- load config sub files relative to config file dir - load config file by name - expect bcrypt for passwords - -genpasswd for generating config-file-safe passwords - block client thread while checking passwords (PASS and OPER)
This commit is contained in:
parent
be089e7f5f
commit
72726a39b8
5 changed files with 77 additions and 107 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package irc
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.crypto/bcrypt"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
|
@ -14,6 +15,11 @@ type editableCommand interface {
|
|||
SetClient(*Client)
|
||||
}
|
||||
|
||||
type checkPasswordCommand interface {
|
||||
LoadPassword(*Server)
|
||||
CheckPassword()
|
||||
}
|
||||
|
||||
type parseCommandFunc func([]string) (editableCommand, error)
|
||||
|
||||
var (
|
||||
|
|
@ -188,19 +194,34 @@ func NewPongCommand(args []string) (editableCommand, error) {
|
|||
|
||||
type PassCommand struct {
|
||||
BaseCommand
|
||||
password string
|
||||
hash []byte
|
||||
password []byte
|
||||
err error
|
||||
}
|
||||
|
||||
var ErrCannotCheck = errors.New("cannot check password")
|
||||
|
||||
func (cmd *PassCommand) String() string {
|
||||
return fmt.Sprintf("PASS(password=%s)", cmd.password)
|
||||
}
|
||||
|
||||
func (cmd *PassCommand) LoadPassword(server *Server) {
|
||||
cmd.hash = server.password
|
||||
}
|
||||
|
||||
func (cmd *PassCommand) CheckPassword() {
|
||||
if cmd.hash == nil {
|
||||
return
|
||||
}
|
||||
cmd.err = bcrypt.CompareHashAndPassword(cmd.hash, cmd.password)
|
||||
}
|
||||
|
||||
func NewPassCommand(args []string) (editableCommand, error) {
|
||||
if len(args) < 1 {
|
||||
return nil, NotEnoughArgsError
|
||||
}
|
||||
return &PassCommand{
|
||||
password: args[0],
|
||||
password: []byte(args[0]),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -652,25 +673,29 @@ func (msg *WhoCommand) String() string {
|
|||
}
|
||||
|
||||
type OperCommand struct {
|
||||
BaseCommand
|
||||
name string
|
||||
password string
|
||||
PassCommand
|
||||
name string
|
||||
}
|
||||
|
||||
func (msg *OperCommand) String() string {
|
||||
return fmt.Sprintf("OPER(name=%s, password=%s)", msg.name, msg.password)
|
||||
}
|
||||
|
||||
func (msg *OperCommand) LoadPassword(server *Server) {
|
||||
msg.hash = server.operators[msg.name]
|
||||
}
|
||||
|
||||
// OPER <name> <password>
|
||||
func NewOperCommand(args []string) (editableCommand, error) {
|
||||
if len(args) < 2 {
|
||||
return nil, NotEnoughArgsError
|
||||
}
|
||||
|
||||
return &OperCommand{
|
||||
name: args[0],
|
||||
password: args[1],
|
||||
}, nil
|
||||
cmd := &OperCommand{
|
||||
name: args[0],
|
||||
}
|
||||
cmd.password = []byte(args[1])
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue