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

Move U:line checking into core as PyLinkNCWUtils.is_privileged_server()

Closes #604.
This commit is contained in:
James Lu 2018-05-26 00:14:04 -07:00
parent 9e936f1612
commit ec3a94c4ca
2 changed files with 19 additions and 9 deletions

View File

@ -1186,6 +1186,19 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
else: else:
raise KeyError("Unknown UID/SID %s" % entityid) raise KeyError("Unknown UID/SID %s" % entityid)
def is_privileged_service(self, entityid):
"""
Returns whether the given UID and SID belongs to a privileged service (IRC U:line).
"""
ulines = self.serverdata.get('ulines', [])
if entityid in self.users:
sid = self.get_server(entityid)
else:
sid = entityid
return self.get_friendly_name(sid) in ulines
def is_oper(self, uid, allowAuthed=True, allowOper=True): def is_oper(self, uid, allowAuthed=True, allowOper=True):
""" """
Returns whether the given user has operator status on PyLink. This can be achieved Returns whether the given user has operator status on PyLink. This can be achieved

View File

@ -598,7 +598,7 @@ def check_claim(irc, channel, sender, chanobj=None):
return (not relay) or irc.name == relay[0] or not db[relay]['claim'] or \ return (not relay) or irc.name == relay[0] or not db[relay]['claim'] or \
irc.name in db[relay]['claim'] or \ irc.name in db[relay]['claim'] or \
(any([mode in sender_modes for mode in ('y', 'q', 'a', 'o', 'h')]) (any([mode in sender_modes for mode in ('y', 'q', 'a', 'o', 'h')])
and not _is_uline(irc, sender)) \ and not irc.is_privileged_service(sender)) \
or irc.is_internal_client(sender) or \ or irc.is_internal_client(sender) or \
irc.is_internal_server(sender) irc.is_internal_server(sender)
@ -1246,7 +1246,7 @@ def handle_join(irc, numeric, command, args):
modechar = irc.cmodes.get(modename) modechar = irc.cmodes.get(modename)
# Special case for U-lined servers: allow them to join with ops, # Special case for U-lined servers: allow them to join with ops,
# but don't forward this mode change on. # but don't forward this mode change on.
if modechar and not _is_uline(irc, numeric): if modechar and not irc.is_privileged_service(numeric):
modes.append(('-%s' % modechar, user)) modes.append(('-%s' % modechar, user))
if modes: if modes:
@ -1514,7 +1514,7 @@ def handle_messages(irc, numeric, command, args):
# Note: don't spam ulined senders (e.g. services announcers) with # Note: don't spam ulined senders (e.g. services announcers) with
# these notices. # these notices.
if homenet not in remoteusers.keys(): if homenet not in remoteusers.keys():
if not _is_uline(irc, numeric): if not irc.is_privileged_service(numeric):
irc.msg(numeric, 'You must be in a common channel ' irc.msg(numeric, 'You must be in a common channel '
'with %r in order to send messages.' % \ 'with %r in order to send messages.' % \
irc.users[target].nick, notice=True) irc.users[target].nick, notice=True)
@ -1522,7 +1522,7 @@ def handle_messages(irc, numeric, command, args):
remoteirc = world.networkobjects[homenet] remoteirc = world.networkobjects[homenet]
if (not remoteirc.has_cap('can-spawn-clients')) and not conf.conf.get('relay', {}).get('allow_clientbot_pms'): if (not remoteirc.has_cap('can-spawn-clients')) and not conf.conf.get('relay', {}).get('allow_clientbot_pms'):
if not _is_uline(irc, numeric): if not irc.is_privileged_service(numeric):
irc.msg(numeric, 'Private messages to users connected via Clientbot have ' irc.msg(numeric, 'Private messages to users connected via Clientbot have '
'been administratively disabled.', notice=True) 'been administratively disabled.', notice=True)
return return
@ -1691,9 +1691,6 @@ def handle_chgclient(irc, source, command, args):
for c in ('CHGHOST', 'CHGNAME', 'CHGIDENT'): for c in ('CHGHOST', 'CHGNAME', 'CHGIDENT'):
utils.add_hook(handle_chgclient, c) utils.add_hook(handle_chgclient, c)
def _is_uline(irc, client):
return irc.get_friendly_name(irc.get_server(client)) in irc.serverdata.get('ulines', [])
def handle_mode(irc, numeric, command, args): def handle_mode(irc, numeric, command, args):
target = args['target'] target = args['target']
modes = args['modes'] modes = args['modes']
@ -1772,7 +1769,7 @@ def handle_mode(irc, numeric, command, args):
# Mode change blocked by CLAIM. # Mode change blocked by CLAIM.
reversed_modes = irc.reverse_modes(target, modes, oldobj=oldchan) reversed_modes = irc.reverse_modes(target, modes, oldobj=oldchan)
if _is_uline(irc, numeric): if irc.is_privileged_service(numeric):
# Special hack for "U-lined" servers - ignore changes to SIMPLE modes and # Special hack for "U-lined" servers - ignore changes to SIMPLE modes and
# attempts to op u-lined clients (trying to change status for others # attempts to op u-lined clients (trying to change status for others
# SHOULD be reverted). # SHOULD be reverted).
@ -1781,7 +1778,7 @@ def handle_mode(irc, numeric, command, args):
reversed_modes = [modepair for modepair in reversed_modes if reversed_modes = [modepair for modepair in reversed_modes if
# Mode is a prefix mode but target isn't ulined, revert # Mode is a prefix mode but target isn't ulined, revert
((modepair[0][-1] in irc.prefixmodes and not ((modepair[0][-1] in irc.prefixmodes and not
_is_uline(irc, modepair[1])) irc.is_privileged_service(modepair[1]))
# Tried to set a list mode, revert # Tried to set a list mode, revert
or modepair[0][-1] in irc.cmodes['*A']) or modepair[0][-1] in irc.cmodes['*A'])
] ]