Browse Source

dline: Prevent opers from banning themselves

tags/v0.5.0
Daniel Oaks 7 years ago
parent
commit
f1e2c54fca
2 changed files with 23 additions and 2 deletions
  1. 17
    1
      irc/dline.go
  2. 6
    1
      irc/help.go

+ 17
- 1
irc/dline.go View File

168
 	return false, nil
168
 	return false, nil
169
 }
169
 }
170
 
170
 
171
-// DLINE [duration] <ip>/<net> [ON <server>] [reason [| oper reason]]
171
+// DLINE [MYSELF] [duration] <ip>/<net> [ON <server>] [reason [| oper reason]]
172
 func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
172
 func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
173
 	// check oper permissions
173
 	// check oper permissions
174
 	if !client.class.Capabilities["oper:local_ban"] {
174
 	if !client.class.Capabilities["oper:local_ban"] {
178
 
178
 
179
 	currentArg := 0
179
 	currentArg := 0
180
 
180
 
181
+	// when setting a ban that covers the oper's current connection, we require them to say
182
+	// "DLINE MYSELF" so that we're sure they really mean it.
183
+	var dlineMyself bool
184
+	if len(msg.Params) > currentArg+1 && strings.ToLower(msg.Params[currentArg]) == "myself" {
185
+		dlineMyself = true
186
+		currentArg++
187
+	}
188
+
181
 	// duration
189
 	// duration
182
 	duration, err := time.ParseDuration(msg.Params[currentArg])
190
 	duration, err := time.ParseDuration(msg.Params[currentArg])
183
 	durationIsUsed := err == nil
191
 	durationIsUsed := err == nil
209
 
217
 
210
 	if hostNet == nil {
218
 	if hostNet == nil {
211
 		hostString = hostAddr.String()
219
 		hostString = hostAddr.String()
220
+		if !dlineMyself && hostAddr.Equal(net.ParseIP(IPString(client.socket.conn.RemoteAddr()))) {
221
+			client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, msg.Command, "This ban matches you. To DLINE yourself, you must pass use the command:  /DLINE MYSELF <arguments>")
222
+			return false
223
+		}
212
 	} else {
224
 	} else {
213
 		hostString = hostNet.String()
225
 		hostString = hostNet.String()
226
+		if !dlineMyself && hostNet.Contains(net.ParseIP(IPString(client.socket.conn.RemoteAddr()))) {
227
+			client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, msg.Command, "This ban matches you. To DLINE yourself, you must pass use the command:  /DLINE MYSELF <arguments>")
228
+			return false
229
+		}
214
 	}
230
 	}
215
 
231
 
216
 	// check remote
232
 	// check remote

+ 6
- 1
irc/help.go View File

99
 	},
99
 	},
100
 	"dline": {
100
 	"dline": {
101
 		oper: true,
101
 		oper: true,
102
-		text: `DLINE [duration] <ip>/<net> [ON <server>] [reason [| oper reason]]
102
+		text: `DLINE [MYSELF] [duration] <ip>/<net> [ON <server>] [reason [| oper reason]]
103
 
103
 
104
 Bans an IP address or network from connecting to the server. If the duration is
104
 Bans an IP address or network from connecting to the server. If the duration is
105
 given then only for that long. The reason is shown to the user themselves, but
105
 given then only for that long. The reason is shown to the user themselves, but
108
 
108
 
109
 Bans are saved across subsequent launches of the server.
109
 Bans are saved across subsequent launches of the server.
110
 
110
 
111
+"MYSELF" is required when the DLINE matches the address the person applying it is connected
112
+from. If "MYSELF" is not given, trying to DLINE yourself will result in an error.
113
+
111
 [duration] can be of the following forms:
114
 [duration] can be of the following forms:
112
 	10h 8m 13s
115
 	10h 8m 13s
113
 
116
 
115
 	127.0.0.1/8
118
 	127.0.0.1/8
116
 	8.8.8.8/24
119
 	8.8.8.8/24
117
 
120
 
121
+ON <server> specifies that the ban is to be set on that specific server.
122
+
118
 [reason] and [oper reason], if they exist, are separated by a vertical bar (|).`,
123
 [reason] and [oper reason], if they exist, are separated by a vertical bar (|).`,
119
 	},
124
 	},
120
 	"help": {
125
 	"help": {

Loading…
Cancel
Save