Allow looking up usernames with ident on connection

This commit is contained in:
Daniel Oaks
2016-06-30 19:28:34 +10:00
parent 1d51bb450a
commit 19c2bb69fc
5 changed files with 38 additions and 0 deletions
+31
View File
@@ -7,11 +7,13 @@ package irc
import (
"fmt"
"log"
"net"
"strconv"
"time"
"github.com/DanielOaks/girc-go/ircmsg"
"github.com/DanielOaks/go-ident"
)
const (
@@ -67,6 +69,35 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
if isTLS {
client.flags[TLS] = true
}
if server.checkIdent {
_, serverPortString, err := net.SplitHostPort(conn.LocalAddr().String())
serverPort, _ := strconv.Atoi(serverPortString)
if err != nil {
log.Fatal(err)
}
clientHost, clientPortString, err := net.SplitHostPort(conn.RemoteAddr().String())
clientPort, _ := strconv.Atoi(clientPortString)
if err != nil {
log.Fatal(err)
}
client.Notice("*** Looking up your username")
resp, err := ident.Query(clientHost, serverPort, clientPort)
if err == nil {
username := resp.Identifier
//TODO(dan): replace this with IsUsername/IsIRCName?
if Name(username).IsNickname() {
client.Notice("*** Found your username")
//TODO(dan): we do a bunch of user replacing in server.go userHandler, do we need that here?
client.username = Name(username)
// we don't need to updateNickMask here since nickMask is not used for anything yet
} else {
client.Notice("*** Got a malformed username, ignoring")
}
} else {
client.Notice("*** Could not find your username")
}
}
client.Touch()
go client.run()
+1
View File
@@ -57,6 +57,7 @@ type Config struct {
Listen []string
Wslisten string `yaml:"ws-listen"`
TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
CheckIdent bool `yaml:"check-ident"`
Log string
MOTD string
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
+2
View File
@@ -41,6 +41,7 @@ type Server struct {
whoWas *WhoWasList
theaters map[Name][]byte
isupport *ISupportList
checkIdent bool
}
var (
@@ -69,6 +70,7 @@ func NewServer(config *Config) *Server {
proxyAllowedFrom: config.Server.ProxyAllowedFrom,
whoWas: NewWhoWasList(100),
theaters: config.Theaters(),
checkIdent: config.Server.CheckIdent,
}
if config.Server.MOTD != "" {