ソースを参照

dline: Prevent opers from banning themselves

tags/v0.5.0
Daniel Oaks 7年前
コミット
f1e2c54fca
2個のファイルの変更23行の追加2行の削除
  1. 17
    1
      irc/dline.go
  2. 6
    1
      irc/help.go

+ 17
- 1
irc/dline.go ファイルの表示

@@ -168,7 +168,7 @@ func (dm *DLineManager) CheckIP(addr net.IP) (isBanned bool, info *IPBanInfo) {
168 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 172
 func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
173 173
 	// check oper permissions
174 174
 	if !client.class.Capabilities["oper:local_ban"] {
@@ -178,6 +178,14 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
178 178
 
179 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 189
 	// duration
182 190
 	duration, err := time.ParseDuration(msg.Params[currentArg])
183 191
 	durationIsUsed := err == nil
@@ -209,8 +217,16 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
209 217
 
210 218
 	if hostNet == nil {
211 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 224
 	} else {
213 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 232
 	// check remote

+ 6
- 1
irc/help.go ファイルの表示

@@ -99,7 +99,7 @@ Prints debug information about the IRCd. <option> can be one of:
99 99
 	},
100 100
 	"dline": {
101 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 104
 Bans an IP address or network from connecting to the server. If the duration is
105 105
 given then only for that long. The reason is shown to the user themselves, but
@@ -108,6 +108,9 @@ operators getting info about the DLINEs that exist.
108 108
 
109 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 114
 [duration] can be of the following forms:
112 115
 	10h 8m 13s
113 116
 
@@ -115,6 +118,8 @@ Bans are saved across subsequent launches of the server.
115 118
 	127.0.0.1/8
116 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 123
 [reason] and [oper reason], if they exist, are separated by a vertical bar (|).`,
119 124
 	},
120 125
 	"help": {

読み込み中…
キャンセル
保存