From c7fce11e01d68862e9a1ca2601747c92d4743e89 Mon Sep 17 00:00:00 2001 From: raylu Date: Wed, 9 Mar 2011 23:47:07 -0600 Subject: [PATCH] identd support --- rbot.conf.example | 3 +++ rbot.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/rbot.conf.example b/rbot.conf.example index 5dcea71..50d8988 100644 --- a/rbot.conf.example +++ b/rbot.conf.example @@ -1,5 +1,8 @@ [DEFAULT] trigger: ! +# 0 means don't run an identd. ircds expect 113, but on Linux that requires root +# most users should be able to set it to 1130 and port forward 113->1130 +identdport: 0 [Rizon] server: irc.rizon.net diff --git a/rbot.go b/rbot.go index 82d1911..9ee852f 100644 --- a/rbot.go +++ b/rbot.go @@ -6,6 +6,8 @@ import ( "os" "strings" "time" + "net" + "bufio" "crypto/tls" "crypto/rand" "goconfig" @@ -21,6 +23,11 @@ func main() { trigger = readConfString("DEFAULT", "trigger") readAuth() + identdport, _ := conf.String("DEFAULT", "identdport") + if identdport != "" && identdport != "0" { + go identd(identdport) + } + sections = conf.Sections() for _, s := range sections { if strings.Index(s, " ") == -1 && s != "DEFAULT" { @@ -123,3 +130,34 @@ func updateConf(section, option, value string) { // config.WriteFile destroys the config, so readConf() } + +func identd(port string) { + identd, err := net.Listen("tcp", "0.0.0.0:" + port) + if err != nil { + fmt.Println("Failed to start identd on port", port) + return + } + defer identd.Close() + fmt.Println("Started identd on port", port) + + for { + conn, err := identd.Accept() + if err != nil { + fmt.Println("Failed to accept identd connection") + continue + } + + io := bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn)) + line, err := io.Reader.ReadString('\n') + if err != nil || len(line) < 2 { + conn.Close() + fmt.Println("Failed to read identd request") + continue + } + line = line[:len(line) - 2] + line = fmt.Sprintf("%s : ERROR : NO-USER\r\n", line) + io.Writer.WriteString(line) + time.Sleep(1000000000) // 1 second + conn.Close() + } +}