3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

relay: move ban-style and whitelist checks to earlier in get_supported_cmodes

This commit is contained in:
James Lu 2017-08-05 22:02:12 -07:00
parent ffde2c6b32
commit b456966dd3

View File

@ -779,6 +779,18 @@ def get_supported_cmodes(irc, remoteirc, channel, modes):
continue continue
if modechar == m: if modechar == m:
if name not in whitelist:
log.debug("(%s) relay.get_supported_cmodes: skipping mode (%r, %r) because "
"it isn't a whitelisted (safe) mode for relay.",
irc.name, modechar, arg)
break
elif name in ('ban', 'banexception', 'invex', 'quiet') and not utils.isHostmask(arg):
# Don't add bans that don't match n!u@h syntax!
log.debug("(%s) relay.get_supported_cmodes: skipping mode (%r, %r) because it doesn't match nick!user@host syntax.",
irc.name, modechar, arg)
break
supported_char = remoteirc.cmodes.get(name) supported_char = remoteirc.cmodes.get(name)
# The mode we requested is an extban. # The mode we requested is an extban.
@ -792,12 +804,6 @@ def get_supported_cmodes(irc, remoteirc, channel, modes):
elif supported_char is None: elif supported_char is None:
continue continue
if name not in whitelist:
log.debug("(%s) relay.get_supported_cmodes: skipping mode (%r, %r) because "
"it isn't a whitelisted (safe) mode for relay.",
irc.name, modechar, arg)
break
if modechar in irc.prefixmodes: if modechar in irc.prefixmodes:
# This is a prefix mode (e.g. +o). We must coerse the argument # This is a prefix mode (e.g. +o). We must coerse the argument
# so that the target exists on the remote relay network. # so that the target exists on the remote relay network.
@ -836,7 +842,7 @@ def get_supported_cmodes(irc, remoteirc, channel, modes):
# Expand extbans known on the local IRCd to modes on the remote, if any exist. # Expand extbans known on the local IRCd to modes on the remote, if any exist.
for extban_name, extban_prefix in irc.extbans_acting.items(): for extban_name, extban_prefix in irc.extbans_acting.items():
log.debug('(%s) relay.get_supported_cmodes: checking for extban that needs expansion' log.debug('(%s) relay.get_supported_cmodes: checking for extban that needs expansion: '
'name=%s, extban_name=%s, arg=%s, extban_prefix=%s', irc.name, name, extban_name, arg, 'name=%s, extban_name=%s, arg=%s, extban_prefix=%s', irc.name, name, extban_name, arg,
extban_prefix) extban_prefix)
if name == 'ban' and arg.startswith(extban_prefix): if name == 'ban' and arg.startswith(extban_prefix):
@ -863,11 +869,6 @@ def get_supported_cmodes(irc, remoteirc, channel, modes):
if mode_parse_aborted: if mode_parse_aborted:
break break
final_modepair = (prefix+supported_char, arg) final_modepair = (prefix+supported_char, arg)
if name in ('ban', 'banexception', 'invex', 'quiet') and not utils.isHostmask(arg):
# Don't add bans that don't match n!u@h syntax!
log.debug("(%s) relay.get_supported_cmodes: skipping mode (%r, %r) because it doesn't match nick!user@host syntax.",
irc.name, modechar, arg)
break
# Don't set modes that are already set, to prevent floods on TS6 # Don't set modes that are already set, to prevent floods on TS6
# where the same mode can be set infinite times. # where the same mode can be set infinite times.