3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

opers: Enforce oper class permissions

This commit is contained in:
Daniel Oaks 2016-10-23 11:13:08 +10:00
parent f3459830e7
commit 8e2a8cb1b3
2 changed files with 22 additions and 0 deletions

View File

@ -247,6 +247,21 @@ func (client *Client) HasUsername() bool {
return client.username != "" && client.username != "*"
}
// HasCapabs returns true if client has the given (role) capabilities.
func (client *Client) HasCapabs(capabs ...string) bool {
if client.class == nil {
return false
}
for _, capab := range capabs {
if !client.class.Capabilities[capab] {
return false
}
}
return true
}
// <mode>
func (c *Client) ModeString() (str string) {
str = "+"

View File

@ -15,6 +15,7 @@ type Command struct {
leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True
leaveClientIdle bool
minParams int
capabs []string
}
// Run runs this command with the given client/message.
@ -27,6 +28,10 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied - You're not an IRC operator")
return false
}
if len(cmd.capabs) > 0 && !client.HasCapabs(cmd.capabs...) {
client.Send(nil, server.name, ERR_NOPRIVILEGES, client.nick, "Permission Denied")
return false
}
if len(msg.Params) < cmd.minParams {
client.Send(nil, server.name, ERR_NEEDMOREPARAMS, client.nick, msg.Command, "Not enough parameters")
return false
@ -91,6 +96,7 @@ var Commands = map[string]Command{
handler: killHandler,
minParams: 1,
oper: true,
capabs: []string{"oper:local_kill"}, //TODO(dan): when we have S2S, this will be checked in the command handler itself
},
"LIST": {
handler: listHandler,
@ -168,6 +174,7 @@ var Commands = map[string]Command{
handler: rehashHandler,
minParams: 0,
oper: true,
capabs: []string{"oper:rehash"},
},
"TIME": {
handler: timeHandler,