Przeglądaj źródła

opers: Enforce oper class permissions

tags/v0.4.0
Daniel Oaks 7 lat temu
rodzic
commit
8e2a8cb1b3
2 zmienionych plików z 22 dodań i 0 usunięć
  1. 15
    0
      irc/client.go
  2. 7
    0
      irc/commands.go

+ 15
- 0
irc/client.go Wyświetl plik

247
 	return client.username != "" && client.username != "*"
247
 	return client.username != "" && client.username != "*"
248
 }
248
 }
249
 
249
 
250
+// HasCapabs returns true if client has the given (role) capabilities.
251
+func (client *Client) HasCapabs(capabs ...string) bool {
252
+	if client.class == nil {
253
+		return false
254
+	}
255
+
256
+	for _, capab := range capabs {
257
+		if !client.class.Capabilities[capab] {
258
+			return false
259
+		}
260
+	}
261
+
262
+	return true
263
+}
264
+
250
 // <mode>
265
 // <mode>
251
 func (c *Client) ModeString() (str string) {
266
 func (c *Client) ModeString() (str string) {
252
 	str = "+"
267
 	str = "+"

+ 7
- 0
irc/commands.go Wyświetl plik

15
 	leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
15
 	leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
16
 	leaveClientIdle   bool
16
 	leaveClientIdle   bool
17
 	minParams         int
17
 	minParams         int
18
+	capabs            []string
18
 }
19
 }
19
 
20
 
20
 // Run runs this command with the given client/message.
21
 // Run runs this command with the given client/message.
27
 		client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied - You're not an IRC operator")
28
 		client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied - You're not an IRC operator")
28
 		return false
29
 		return false
29
 	}
30
 	}
31
+	if len(cmd.capabs) > 0 && !client.HasCapabs(cmd.capabs...) {
32
+		client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied")
33
+		return false
34
+	}
30
 	if len(msg.Params) < cmd.minParams {
35
 	if len(msg.Params) < cmd.minParams {
31
 		client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters")
36
 		client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters")
32
 		return false
37
 		return false
91
 		handler:   killHandler,
96
 		handler:   killHandler,
92
 		minParams: 1,
97
 		minParams: 1,
93
 		oper:      true,
98
 		oper:      true,
99
+		capabs:    []string{"oper:local_kill"}, //TODO(dan): when we have S2S, this will be checked in the command handler itself
94
 	},
100
 	},
95
 	"LIST": {
101
 	"LIST": {
96
 		handler:   listHandler,
102
 		handler:   listHandler,
168
 		handler:   rehashHandler,
174
 		handler:   rehashHandler,
169
 		minParams: 0,
175
 		minParams: 0,
170
 		oper:      true,
176
 		oper:      true,
177
+		capabs:    []string{"oper:rehash"},
171
 	},
178
 	},
172
 	"TIME": {
179
 	"TIME": {
173
 		handler:   timeHandler,
180
 		handler:   timeHandler,

Ładowanie…
Anuluj
Zapisz