|
@@ -55,26 +55,39 @@ func (server *Server) receiveCommands(commands <-chan Command) {
|
55
|
55
|
log.Printf("%s → %s %s", command.Client(), server, command)
|
56
|
56
|
}
|
57
|
57
|
client := command.Client()
|
58
|
|
- client.Touch()
|
59
|
58
|
|
60
|
|
- if !client.serverPass {
|
61
|
|
- if server.password == "" {
|
62
|
|
- client.serverPass = true
|
63
|
|
-
|
64
|
|
- } else {
|
65
|
|
- switch command.(type) {
|
66
|
|
- case *PassCommand, *CapCommand, *ProxyCommand:
|
67
|
|
- // no-op
|
68
|
|
- default:
|
69
|
|
- client.Reply(ErrPasswdMismatch(server))
|
70
|
|
- server.clients.Remove(client)
|
71
|
|
- client.Destroy()
|
72
|
|
- return
|
73
|
|
- }
|
74
|
|
- }
|
|
59
|
+ if !server.Authorize(client, command) {
|
|
60
|
+ client.Destroy()
|
|
61
|
+ return
|
75
|
62
|
}
|
|
63
|
+
|
|
64
|
+ client.Touch()
|
76
|
65
|
command.HandleServer(server)
|
|
66
|
+
|
|
67
|
+ if DEBUG_SERVER {
|
|
68
|
+ log.Printf("%s → %s %s processed", command.Client(), server, command)
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+}
|
|
72
|
+
|
|
73
|
+func (server *Server) Authorize(client *Client, command Command) bool {
|
|
74
|
+ if client.authorized {
|
|
75
|
+ return true
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ if server.password == "" {
|
|
79
|
+ client.authorized = true
|
|
80
|
+ return true
|
77
|
81
|
}
|
|
82
|
+
|
|
83
|
+ switch command.(type) {
|
|
84
|
+ case *PassCommand, *CapCommand, *ProxyCommand:
|
|
85
|
+ // no-op
|
|
86
|
+ default:
|
|
87
|
+ return false
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ return true
|
78
|
91
|
}
|
79
|
92
|
|
80
|
93
|
func newListener(config ListenerConfig) (net.Listener, error) {
|
|
@@ -222,14 +235,20 @@ func (m *PongCommand) HandleServer(s *Server) {
|
222
|
235
|
}
|
223
|
236
|
|
224
|
237
|
func (m *PassCommand) HandleServer(s *Server) {
|
|
238
|
+ client := m.Client()
|
|
239
|
+
|
|
240
|
+ if client.registered || client.authorized {
|
|
241
|
+ client.Reply(ErrAlreadyRegistered(s))
|
|
242
|
+ return
|
|
243
|
+ }
|
|
244
|
+
|
225
|
245
|
if s.password != m.password {
|
226
|
|
- m.Client().Reply(ErrPasswdMismatch(s))
|
227
|
|
- m.Client().Destroy()
|
|
246
|
+ client.Reply(ErrPasswdMismatch(s))
|
|
247
|
+ client.Destroy()
|
228
|
248
|
return
|
229
|
249
|
}
|
230
|
250
|
|
231
|
|
- m.Client().serverPass = true
|
232
|
|
- // no reply?
|
|
251
|
+ client.authorized = true
|
233
|
252
|
}
|
234
|
253
|
|
235
|
254
|
func (m *NickCommand) HandleServer(s *Server) {
|
|
@@ -449,9 +468,7 @@ func (msg *CapCommand) HandleServer(server *Server) {
|
449
|
468
|
}
|
450
|
469
|
|
451
|
470
|
func (msg *ProxyCommand) HandleServer(server *Server) {
|
452
|
|
- go func() {
|
453
|
|
- msg.Client().hostname = LookupHostname(msg.sourceIP)
|
454
|
|
- }()
|
|
471
|
+ msg.Client().hostname = LookupHostname(msg.sourceIP)
|
455
|
472
|
}
|
456
|
473
|
|
457
|
474
|
func (msg *AwayCommand) HandleServer(server *Server) {
|