summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-04-24 18:11:21 +0100
committerDavid Baker <dave@matrix.org>2015-04-24 18:11:21 +0100
commita7b51f4539af90460d47efe0bae2692de285cd26 (patch)
tree9e5413523390c24e13f35795dae62fff0c627427 /synapse
parentAdd note about updating your signing keys (ie. "the auto thing") (diff)
downloadsynapse-a7b51f4539af90460d47efe0bae2692de285cd26.tar.xz
Check users in our table aren't on a different domain to the one we're configured with to try & fix SYN-266
Diffstat (limited to 'synapse')
-rwxr-xr-xsynapse/app/homeserver.py19
-rw-r--r--synapse/storage/registration.py18
2 files changed, 37 insertions, 0 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 27e53a9e56..5f6cf4deeb 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -26,6 +26,7 @@ from synapse.server import HomeServer
 from synapse.python_dependencies import check_requirements
 
 from twisted.internet import reactor
+from twisted.internet import defer
 from twisted.application import service
 from twisted.enterprise import adbapi
 from twisted.web.resource import Resource
@@ -241,6 +242,22 @@ class SynapseHomeServer(HomeServer):
             )
             logger.info("Metrics now running on 127.0.0.1 port %d", config.metrics_port)
 
+    @defer.inlineCallbacks
+    def post_startup_check(self):
+        all_users_native = yield self.get_datastore().all_users_on_domain(
+            self.hostname
+        )
+        if not all_users_native:
+            sys.stderr.write(
+                "\n"
+                "******************************************************\n"
+                "Found users in database not native to %s!\n"
+                "You cannot changed a synapse server_name after it's been configured\n"
+                "******************************************************\n"
+                "\n"
+            )
+            reactor.stop()
+
 
 def get_version_string():
     try:
@@ -399,6 +416,8 @@ def setup(config_options):
     hs.get_datastore().start_profiling()
     hs.get_replication_layer().start_get_pdu_cache()
 
+    reactor.callWhenRunning(hs.post_startup_check)
+
     return hs
 
 
diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py
index f24154f146..c2efc3fd32 100644
--- a/synapse/storage/registration.py
+++ b/synapse/storage/registration.py
@@ -144,3 +144,21 @@ class RegistrationStore(SQLBaseStore):
             return rows[0]
 
         raise StoreError(404, "Token not found.")
+
+    @defer.inlineCallbacks
+    def all_users_on_domain(self, domain):
+        res = yield self.runInteraction(
+            "all_users_on_domain",
+            self._all_users_on_domain_txn,
+            domain
+        )
+        defer.returnValue(res)
+
+    def _all_users_on_domain_txn(self, txn, domain):
+        sql = "SELECT COUNT(*) FROM users WHERE name NOT LIKE ?"
+        pat = "%:"+domain
+        cursor = txn.execute(sql, (pat,))
+        num_not_matching = cursor.fetchall()[0][0]
+        if num_not_matching == 0:
+            return True
+        return False
\ No newline at end of file