Bind identd to config address, set read/write deadlines in ident.Server, only reply to ident queries where the remote hosts match

This commit is contained in:
Ken-Håvard Lieng 2020-06-17 03:19:20 +02:00
parent 15ee5ce1c9
commit 04e6e8c7a2
4 changed files with 92 additions and 28 deletions

View file

@ -3,6 +3,7 @@ package server
import (
"fmt"
"log"
"net"
"os"
"strconv"
"strings"
@ -46,7 +47,8 @@ func newIRCHandler(client *irc.Client, state *State) *ircHandler {
func (i *ircHandler) run() {
var lastConnErr error
var localPort string
var localAddr net.Addr
var remoteAddr net.Addr
for {
select {
@ -61,11 +63,10 @@ func (i *ircHandler) run() {
case state := <-i.client.ConnectionChanged:
if identd := i.state.srv.identd; identd != nil {
if state.Connected {
if localPort = i.client.LocalPort(); localPort != "" {
identd.Add(localPort, i.client.Config.Port, i.client.Config.Username)
}
localAddr, remoteAddr = i.client.LocalAddr(), i.client.RemoteAddr()
identd.Add(localAddr, remoteAddr, i.client.Config.Username)
} else {
identd.Remove(localPort, i.client.Config.Port)
identd.Remove(localAddr, remoteAddr)
}
}
@ -310,9 +311,7 @@ func (i *ircHandler) info(msg *irc.Message) {
}
if identd := i.state.srv.identd; identd != nil {
if localPort := i.client.LocalPort(); localPort != "" {
identd.Remove(localPort, i.client.Config.Port)
}
identd.Remove(i.client.LocalAddr(), i.client.RemoteAddr())
}
if network, ok := i.state.network(i.client.Host()); ok {

View file

@ -2,6 +2,7 @@ package server
import (
"log"
"net"
"net/http"
"os"
"strconv"
@ -64,6 +65,7 @@ func (d *Dispatch) Run() {
if cfg.Identd {
d.identd = ident.NewServer()
d.identd.Addr = net.JoinHostPort(cfg.Address, "113")
go d.identd.Listen()
}
@ -74,7 +76,7 @@ func (d *Dispatch) Run() {
d.loadUsers()
d.initFileServer()
d.startHTTP()
d.serveHTTP()
}
func (d *Dispatch) loadUsers() {
@ -119,12 +121,12 @@ func (d *Dispatch) loadUser(user *storage.User) {
}
}
func (d *Dispatch) startHTTP() {
func (d *Dispatch) serveHTTP() {
cfg := d.Config()
port := cfg.Port
if cfg.Dev {
// The node dev network will proxy index page requests and
// The node dev server will proxy index page requests and
// websocket connections to this port
port = "1337"
}