identd support

This commit is contained in:
raylu 2011-03-09 23:47:07 -06:00
parent 420f9ed131
commit c7fce11e01
2 changed files with 41 additions and 0 deletions

View File

@ -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

38
rbot.go
View File

@ -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()
}
}