Browse Source

Allow looking up usernames with ident on connection

tags/v0.1.0
Daniel Oaks 8 years ago
parent
commit
19c2bb69fc
5 changed files with 38 additions and 0 deletions
  1. 1
    0
      CHANGELOG.md
  2. 31
    0
      irc/client.go
  3. 1
    0
      irc/config.go
  4. 2
    0
      irc/server.go
  5. 3
    0
      oragono.yaml

+ 1
- 0
CHANGELOG.md View File

@@ -16,6 +16,7 @@ Initial release of Oragono!
16 16
 * Added YAML config file format.
17 17
 * Added native SSL/TLS support (thanks to @edmand).
18 18
 * Added ability to generate certificates from the command line.
19
+* Can now lookup usernames with ident on client connection.
19 20
 * We now advertise the [`RPL_ISUPPORT`](http://modern.ircdocs.horse/#rplisupport-005) numeric.
20 21
 * Parse new mode change syntax commonly used these days (i.e. `+h-ov dan dan dan`).
21 22
 * User mode for clients connected via TLS (`+Z`).

+ 31
- 0
irc/client.go View File

@@ -7,11 +7,13 @@ package irc
7 7
 
8 8
 import (
9 9
 	"fmt"
10
+	"log"
10 11
 	"net"
11 12
 	"strconv"
12 13
 	"time"
13 14
 
14 15
 	"github.com/DanielOaks/girc-go/ircmsg"
16
+	"github.com/DanielOaks/go-ident"
15 17
 )
16 18
 
17 19
 const (
@@ -67,6 +69,35 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
67 69
 	if isTLS {
68 70
 		client.flags[TLS] = true
69 71
 	}
72
+	if server.checkIdent {
73
+		_, serverPortString, err := net.SplitHostPort(conn.LocalAddr().String())
74
+		serverPort, _ := strconv.Atoi(serverPortString)
75
+		if err != nil {
76
+			log.Fatal(err)
77
+		}
78
+		clientHost, clientPortString, err := net.SplitHostPort(conn.RemoteAddr().String())
79
+		clientPort, _ := strconv.Atoi(clientPortString)
80
+		if err != nil {
81
+			log.Fatal(err)
82
+		}
83
+
84
+		client.Notice("*** Looking up your username")
85
+		resp, err := ident.Query(clientHost, serverPort, clientPort)
86
+		if err == nil {
87
+			username := resp.Identifier
88
+			//TODO(dan): replace this with IsUsername/IsIRCName?
89
+			if Name(username).IsNickname() {
90
+				client.Notice("*** Found your username")
91
+				//TODO(dan): we do a bunch of user replacing in server.go userHandler, do we need that here?
92
+				client.username = Name(username)
93
+				// we don't need to updateNickMask here since nickMask is not used for anything yet
94
+			} else {
95
+				client.Notice("*** Got a malformed username, ignoring")
96
+			}
97
+		} else {
98
+			client.Notice("*** Could not find your username")
99
+		}
100
+	}
70 101
 	client.Touch()
71 102
 	go client.run()
72 103
 

+ 1
- 0
irc/config.go View File

@@ -57,6 +57,7 @@ type Config struct {
57 57
 		Listen           []string
58 58
 		Wslisten         string                      `yaml:"ws-listen"`
59 59
 		TLSListeners     map[string]*TLSListenConfig `yaml:"tls-listeners"`
60
+		CheckIdent       bool                        `yaml:"check-ident"`
60 61
 		Log              string
61 62
 		MOTD             string
62 63
 		ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`

+ 2
- 0
irc/server.go View File

@@ -41,6 +41,7 @@ type Server struct {
41 41
 	whoWas           *WhoWasList
42 42
 	theaters         map[Name][]byte
43 43
 	isupport         *ISupportList
44
+	checkIdent       bool
44 45
 }
45 46
 
46 47
 var (
@@ -69,6 +70,7 @@ func NewServer(config *Config) *Server {
69 70
 		proxyAllowedFrom: config.Server.ProxyAllowedFrom,
70 71
 		whoWas:           NewWhoWasList(100),
71 72
 		theaters:         config.Theaters(),
73
+		checkIdent:       config.Server.CheckIdent,
72 74
 	}
73 75
 
74 76
 	if config.Server.MOTD != "" {

+ 3
- 0
oragono.yaml View File

@@ -30,6 +30,9 @@ server:
30 30
             key: tls.key
31 31
             cert: tls.crt
32 32
 
33
+    # use ident protocol to get usernames
34
+    check-ident: true
35
+
33 36
     # password to login to the server
34 37
     # generated using  "oragono genpasswd"
35 38
     #password: ""

Loading…
Cancel
Save