mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 20:29:22 -05:00
Fix auth to correctly handle initial creation of rooms
This commit is contained in:
parent
ae9c2ab165
commit
95614e5220
@ -21,7 +21,7 @@ from synapse.api.constants import Membership, JoinRules
|
|||||||
from synapse.api.errors import AuthError, StoreError, Codes, SynapseError
|
from synapse.api.errors import AuthError, StoreError, Codes, SynapseError
|
||||||
from synapse.api.events.room import (
|
from synapse.api.events.room import (
|
||||||
RoomMemberEvent, RoomPowerLevelsEvent, RoomRedactionEvent,
|
RoomMemberEvent, RoomPowerLevelsEvent, RoomRedactionEvent,
|
||||||
RoomJoinRulesEvent, RoomCreateEvent,
|
RoomJoinRulesEvent, RoomCreateEvent, RoomAliasesEvent,
|
||||||
)
|
)
|
||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
from syutil.base64util import encode_base64
|
from syutil.base64util import encode_base64
|
||||||
@ -63,6 +63,10 @@ class Auth(object):
|
|||||||
# FIXME
|
# FIXME
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# FIXME: Temp hack
|
||||||
|
if event.type == RoomAliasesEvent.TYPE:
|
||||||
|
return True
|
||||||
|
|
||||||
if event.type == RoomMemberEvent.TYPE:
|
if event.type == RoomMemberEvent.TYPE:
|
||||||
allowed = self.is_membership_change_allowed(event)
|
allowed = self.is_membership_change_allowed(event)
|
||||||
if allowed:
|
if allowed:
|
||||||
@ -144,6 +148,17 @@ class Auth(object):
|
|||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
def is_membership_change_allowed(self, event):
|
def is_membership_change_allowed(self, event):
|
||||||
|
membership = event.content["membership"]
|
||||||
|
|
||||||
|
# Check if this is the room creator joining:
|
||||||
|
if len(event.prev_events) == 1 and Membership.JOIN == membership:
|
||||||
|
# Get room creation event:
|
||||||
|
key = (RoomCreateEvent.TYPE, "", )
|
||||||
|
create = event.old_state_events.get(key)
|
||||||
|
if event.prev_events[0][0] == create.event_id:
|
||||||
|
if create.content["creator"] == event.state_key:
|
||||||
|
return True
|
||||||
|
|
||||||
target_user_id = event.state_key
|
target_user_id = event.state_key
|
||||||
|
|
||||||
# get info about the caller
|
# get info about the caller
|
||||||
@ -159,8 +174,6 @@ class Auth(object):
|
|||||||
|
|
||||||
target_in_room = target and target.membership == Membership.JOIN
|
target_in_room = target and target.membership == Membership.JOIN
|
||||||
|
|
||||||
membership = event.content["membership"]
|
|
||||||
|
|
||||||
key = (RoomJoinRulesEvent.TYPE, "", )
|
key = (RoomJoinRulesEvent.TYPE, "", )
|
||||||
join_rule_event = event.old_state_events.get(key)
|
join_rule_event = event.old_state_events.get(key)
|
||||||
if join_rule_event:
|
if join_rule_event:
|
||||||
@ -255,6 +268,11 @@ class Auth(object):
|
|||||||
level = power_level_event.content.get("users", {}).get(user_id)
|
level = power_level_event.content.get("users", {}).get(user_id)
|
||||||
if not level:
|
if not level:
|
||||||
level = power_level_event.content.get("users_default", 0)
|
level = power_level_event.content.get("users_default", 0)
|
||||||
|
else:
|
||||||
|
key = (RoomCreateEvent.TYPE, "", )
|
||||||
|
create_event = event.old_state_events.get(key)
|
||||||
|
if create_event.content["creator"] == user_id:
|
||||||
|
return 100
|
||||||
|
|
||||||
return level
|
return level
|
||||||
|
|
||||||
|
@ -184,15 +184,7 @@ class SynapseHomeServer(HomeServer):
|
|||||||
logger.info("Synapse now listening on port %d", unsecure_port)
|
logger.info("Synapse now listening on port %d", unsecure_port)
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup(config, run_http=True):
|
||||||
config = HomeServerConfig.load_config(
|
|
||||||
"Synapse Homeserver",
|
|
||||||
sys.argv[1:],
|
|
||||||
generate_section="Homeserver"
|
|
||||||
)
|
|
||||||
|
|
||||||
config.setup_logging()
|
|
||||||
|
|
||||||
logger.info("Server hostname: %s", config.server_name)
|
logger.info("Server hostname: %s", config.server_name)
|
||||||
|
|
||||||
if re.search(":[0-9]+$", config.server_name):
|
if re.search(":[0-9]+$", config.server_name):
|
||||||
@ -212,6 +204,7 @@ def setup():
|
|||||||
content_addr=config.content_addr,
|
content_addr=config.content_addr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if run_http:
|
||||||
hs.register_servlets()
|
hs.register_servlets()
|
||||||
|
|
||||||
hs.create_resource_tree(
|
hs.create_resource_tree(
|
||||||
@ -237,11 +230,18 @@ def setup():
|
|||||||
f.namespace['hs'] = hs
|
f.namespace['hs'] = hs
|
||||||
reactor.listenTCP(config.manhole, f, interface='127.0.0.1')
|
reactor.listenTCP(config.manhole, f, interface='127.0.0.1')
|
||||||
|
|
||||||
|
if run_http:
|
||||||
bind_port = config.bind_port
|
bind_port = config.bind_port
|
||||||
if config.no_tls:
|
if config.no_tls:
|
||||||
bind_port = None
|
bind_port = None
|
||||||
hs.start_listening(bind_port, config.unsecure_port)
|
hs.start_listening(bind_port, config.unsecure_port)
|
||||||
|
|
||||||
|
hs.config = config
|
||||||
|
|
||||||
|
return hs
|
||||||
|
|
||||||
|
|
||||||
|
def run(config):
|
||||||
if config.daemonize:
|
if config.daemonize:
|
||||||
print config.pid_file
|
print config.pid_file
|
||||||
daemon = Daemonize(
|
daemon = Daemonize(
|
||||||
@ -257,13 +257,26 @@ def setup():
|
|||||||
else:
|
else:
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
def run():
|
|
||||||
with LoggingContext("run"):
|
|
||||||
reactor.run()
|
|
||||||
|
|
||||||
def main():
|
def main(args, run_http=True):
|
||||||
with LoggingContext("main"):
|
with LoggingContext("main"):
|
||||||
setup()
|
config = HomeServerConfig.load_config(
|
||||||
|
"Synapse Homeserver",
|
||||||
|
args,
|
||||||
|
generate_section="Homeserver"
|
||||||
|
)
|
||||||
|
|
||||||
|
config.setup_logging()
|
||||||
|
|
||||||
|
hs = setup(config, run_http=run_http)
|
||||||
|
|
||||||
|
def r():
|
||||||
|
run(config)
|
||||||
|
hs.run = r
|
||||||
|
|
||||||
|
return hs
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
hs = main(sys.argv[1:])
|
||||||
|
hs.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user