ソースを参照

Allow configuring relay

tags/v2.4.0-rc1
Daniel Oaks 4年前
コミット
4ecd7fdf43
7個のファイルの変更95行の追加28行の削除
  1. 13
    0
      conventional.yaml
  2. 7
    2
      irc/client_lookup_set.go
  3. 23
    10
      irc/config.go
  4. 24
    7
      irc/handlers.go
  5. 4
    0
      irc/server.go
  6. 11
    9
      irc/strings.go
  7. 13
    0
      oragono.yaml

+ 13
- 0
conventional.yaml ファイルの表示

@@ -134,6 +134,19 @@ server:
134 134
     # if this is true, the motd is escaped using formatting codes like $c, $b, and $i
135 135
     motd-formatting: true
136 136
 
137
+    # relaying using the RELAYMSG command
138
+    relaying:
139
+        # is relaying enabled at all?
140
+        enabled: true
141
+
142
+        # which character(s) are reserved for relayed nicks?
143
+        separators: "/"
144
+
145
+        # can channel operators use RELAYMSG in their channels?
146
+        # our implementation of RELAYMSG makes it safe for chanops to use without the
147
+        # possibility of real users being silently spoofed
148
+        available-to-chanops: true
149
+
137 150
     # addresses/CIDRs the PROXY command can be used from
138 151
     # this should be restricted to localhost (127.0.0.1/8, ::1/128, and unix sockets),
139 152
     # unless you have a good reason. you should also add these addresses to the

+ 7
- 2
irc/client_lookup_set.go ファイルの表示

@@ -173,8 +173,13 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
173 173
 			return "", errNicknameInvalid, false
174 174
 		}
175 175
 
176
-		if strings.Contains(newCfNick, "/") {
177
-			return "", errNicknameInvalid, false
176
+		config := client.server.Config()
177
+		if config.Server.Relaying.Enabled {
178
+			for _, char := range config.Server.Relaying.Separators {
179
+				if strings.ContainsRune(newCfNick, char) {
180
+					return "", errNicknameInvalid, false
181
+				}
182
+			}
178 183
 		}
179 184
 
180 185
 		if restrictedCasefoldedNicks[newCfNick] || restrictedSkeletons[newSkeleton] {

+ 23
- 10
irc/config.go ファイルの表示

@@ -499,14 +499,19 @@ type Config struct {
499 499
 		CheckIdent              bool `yaml:"check-ident"`
500 500
 		MOTD                    string
501 501
 		motdLines               []string
502
-		MOTDFormatting          bool     `yaml:"motd-formatting"`
503
-		ProxyAllowedFrom        []string `yaml:"proxy-allowed-from"`
504
-		proxyAllowedFromNets    []net.IPNet
505
-		WebIRC                  []webircConfig `yaml:"webirc"`
506
-		MaxSendQString          string         `yaml:"max-sendq"`
507
-		MaxSendQBytes           int
508
-		AllowPlaintextResume    bool `yaml:"allow-plaintext-resume"`
509
-		Compatibility           struct {
502
+		MOTDFormatting          bool `yaml:"motd-formatting"`
503
+		Relaying                struct {
504
+			Enabled            bool
505
+			Separators         string
506
+			AvailableToChanops bool `yaml:"available-to-chanops"`
507
+		}
508
+		ProxyAllowedFrom     []string `yaml:"proxy-allowed-from"`
509
+		proxyAllowedFromNets []net.IPNet
510
+		WebIRC               []webircConfig `yaml:"webirc"`
511
+		MaxSendQString       string         `yaml:"max-sendq"`
512
+		MaxSendQBytes        int
513
+		AllowPlaintextResume bool `yaml:"allow-plaintext-resume"`
514
+		Compatibility        struct {
510 515
 			ForceTrailing      *bool `yaml:"force-trailing"`
511 516
 			forceTrailing      bool
512 517
 			SendUnprefixedSasl bool `yaml:"send-unprefixed-sasl"`
@@ -1068,8 +1073,16 @@ func LoadConfig(filename string) (config *Config, err error) {
1068 1073
 	}
1069 1074
 	config.Server.capValues[caps.Languages] = config.languageManager.CapValue()
1070 1075
 
1071
-	// intentionally not configurable
1072
-	config.Server.capValues[caps.Relaymsg] = "/"
1076
+	if config.Server.Relaying.Enabled {
1077
+		for _, char := range protocolBreakingNameCharacters {
1078
+			if strings.ContainsRune(config.Server.Relaying.Separators, char) {
1079
+				return nil, fmt.Errorf("Relaying separators cannot include the characters %s", protocolBreakingNameCharacters)
1080
+			}
1081
+		}
1082
+		config.Server.capValues[caps.Relaymsg] = config.Server.Relaying.Separators
1083
+	} else {
1084
+		config.Server.supportedCaps.Disable(caps.Relaymsg)
1085
+	}
1073 1086
 
1074 1087
 	config.Debug.recoverFromErrors = utils.BoolDefaultTrue(config.Debug.RecoverFromErrors)
1075 1088
 

+ 24
- 7
irc/handlers.go ファイルの表示

@@ -1888,12 +1888,22 @@ func messageHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
1888 1888
 			break
1889 1889
 		}
1890 1890
 
1891
-		if strings.Contains(targetString, "/") {
1892
-			if histType == history.Privmsg {
1893
-				rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), targetString, client.t("Relayed users cannot be sent private messages"))
1891
+		config := server.Config()
1892
+		if config.Server.Relaying.Enabled {
1893
+			var isForRelayClient bool
1894
+			for _, char := range config.Server.Relaying.Separators {
1895
+				if strings.ContainsRune(targetString, char) {
1896
+					isForRelayClient = true
1897
+					break
1898
+				}
1899
+			}
1900
+			if isForRelayClient {
1901
+				if histType == history.Privmsg {
1902
+					rb.Add(nil, server.name, ERR_NOSUCHNICK, client.Nick(), targetString, client.t("Relayed users cannot be sent private messages"))
1903
+				}
1904
+				// TAGMSG/NOTICEs are intentionally silently dropped
1905
+				continue
1894 1906
 			}
1895
-			// TAGMSG/NOTICEs are intentionally silently dropped
1896
-			continue
1897 1907
 		}
1898 1908
 
1899 1909
 		// each target gets distinct msgids
@@ -2281,14 +2291,21 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2281 2291
 
2282 2292
 // RELAYMSG <channel> <spoofed nick> :<message>
2283 2293
 func relaymsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) (result bool) {
2294
+	config := server.Config()
2295
+	if !config.Server.Relaying.Enabled {
2296
+		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_ENABLED", client.t("Relaying has been disabled"))
2297
+		return false
2298
+	}
2299
+
2284 2300
 	channel := server.channels.Get(msg.Params[0])
2285 2301
 	if channel == nil {
2286 2302
 		rb.Add(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), utils.SafeErrorParam(msg.Params[0]), client.t("No such channel"))
2287 2303
 		return false
2288 2304
 	}
2289 2305
 
2290
-	if !(channel.ClientIsAtLeast(client, modes.ChannelOperator) || client.HasRoleCapabs("relaymsg-anywhere")) {
2291
-		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_PRIVED", client.t("Only channel operators or ircops with the 'relaymsg-anywhere' role can relay messages"))
2306
+	allowedToRelay := client.HasRoleCapabs("relaymsg-anywhere") || (config.Server.Relaying.AvailableToChanops && channel.ClientIsAtLeast(client, modes.ChannelOperator))
2307
+	if !allowedToRelay {
2308
+		rb.Add(nil, server.name, "FAIL", "RELAYMSG", "NOT_PRIVED", client.t("You cannot relay messages to this channel"))
2292 2309
 		return false
2293 2310
 	}
2294 2311
 

+ 4
- 0
irc/server.go ファイルの表示

@@ -497,6 +497,10 @@ func (server *Server) applyConfig(config *Config) (err error) {
497 497
 			return fmt.Errorf("Casemapping cannot be changed after launching the server, rehash aborted")
498 498
 		} else if oldConfig.Accounts.Multiclient.AlwaysOn != config.Accounts.Multiclient.AlwaysOn {
499 499
 			return fmt.Errorf("Default always-on setting cannot be changed after launching the server, rehash aborted")
500
+		} else if oldConfig.Server.Relaying.Enabled != config.Server.Relaying.Enabled {
501
+			return fmt.Errorf("Cannot enable or disable relaying after launching the server, rehash aborted")
502
+		} else if oldConfig.Server.Relaying.Separators != config.Server.Relaying.Separators {
503
+			return fmt.Errorf("Cannot change relaying separators after launching the server, rehash aborted")
500 504
 		}
501 505
 	}
502 506
 

+ 11
- 9
irc/strings.go ファイルの表示

@@ -19,6 +19,16 @@ import (
19 19
 
20 20
 const (
21 21
 	precisUTF8MappingToken = "rfc8265"
22
+
23
+	// space can't be used
24
+	// , is used as a separator
25
+	// * is used in mask matching
26
+	// ? is used in mask matching
27
+	// . denotes a server name
28
+	// ! separates nickname from username
29
+	// @ separates username from hostname
30
+	// : means trailing
31
+	protocolBreakingNameCharacters = " ,*?.!@:"
22 32
 )
23 33
 
24 34
 var (
@@ -132,18 +142,10 @@ func CasefoldName(name string) (string, error) {
132 142
 		return "", errStringIsEmpty
133 143
 	}
134 144
 
135
-	// space can't be used
136
-	// , is used as a separator
137
-	// * is used in mask matching
138
-	// ? is used in mask matching
139
-	// . denotes a server name
140
-	// ! separates nickname from username
141
-	// @ separates username from hostname
142
-	// : means trailing
143 145
 	// # is a channel prefix
144 146
 	// ~&@%+ are channel membership prefixes
145 147
 	// - I feel like disallowing
146
-	if strings.ContainsAny(lowered, " ,*?.!@:") || strings.ContainsAny(string(lowered[0]), "#~&@%+-") {
148
+	if strings.ContainsAny(lowered, protocolBreakingNameCharacters) || strings.ContainsAny(string(lowered[0]), "#~&@%+-") {
147 149
 		return "", errInvalidCharacter
148 150
 	}
149 151
 

+ 13
- 0
oragono.yaml ファイルの表示

@@ -160,6 +160,19 @@ server:
160 160
     # if this is true, the motd is escaped using formatting codes like $c, $b, and $i
161 161
     motd-formatting: true
162 162
 
163
+    # relaying using the RELAYMSG command
164
+    relaying:
165
+        # is relaying enabled at all?
166
+        enabled: true
167
+
168
+        # which character(s) are reserved for relayed nicks?
169
+        separators: "/"
170
+
171
+        # can channel operators use RELAYMSG in their channels?
172
+        # our implementation of RELAYMSG makes it safe for chanops to use without the
173
+        # possibility of real users being silently spoofed
174
+        available-to-chanops: true
175
+
163 176
     # addresses/CIDRs the PROXY command can be used from
164 177
     # this should be restricted to localhost (127.0.0.1/8, ::1/128, and unix sockets),
165 178
     # unless you have a good reason. you should also add these addresses to the

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