From bbdf2e0896cb8ffb43c4e544f384b7c409dfd22f Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 11 Mar 2013 20:01:03 +0100 Subject: [PATCH] Fixed a bug that caused superuser status to be cached only once for characters, even if the player was not yet connected. --- src/commands/default/system.py | 2 +- src/locks/lockhandler.py | 26 ++++++++++++-------------- src/objects/models.py | 4 ++++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/commands/default/system.py b/src/commands/default/system.py index 323652fb5f..c3f6e84b8d 100644 --- a/src/commands/default/system.py +++ b/src/commands/default/system.py @@ -136,7 +136,7 @@ class CmdPy(MuxCommand): """ key = "@py" aliases = ["!"] - locks = "cmd:perm(py) or perm(Immortals)" + locks = "cmd:all()"#"cmd:perm(py) or perm(Immortals)" help_category = "System" def func(self): diff --git a/src/locks/lockhandler.py b/src/locks/lockhandler.py index 949bccd489..3451203ce9 100644 --- a/src/locks/lockhandler.py +++ b/src/locks/lockhandler.py @@ -170,20 +170,7 @@ class LockHandler(object): self.log_obj = None self.reset_flag = False self._cache_locks(self.obj.lock_storage) - # we handle bypass checks already here for efficiency. We need to grant access to superusers. - # We need to check both directly on the object (players), through obj.player and using the - # get_player method (this sits on serversessions, in some rare cases where a check is done - # before the login process has yet been fully finalized) - self.lock_bypass = ((hasattr(obj, "is_superuser") and obj.is_superuser) - or (hasattr(obj, "player") and hasattr(obj.player, "is_superuser") and obj.player.is_superuser) - or (hasattr(obj, "get_player") and (not obj.get_player() or obj.get_player().is_superuser))) - if obj.key == "Griatch": - print "SETTING lock_bypass:", obj, self.lock_bypass, "<-", - print (hasattr(obj, "is_superuser") and obj.is_superuser), - print (hasattr(obj, "player") and hasattr(obj.player, "is_superuser") and obj.player.is_superuser), - print (hasattr(obj, "get_player") and (not obj.get_player() or obj.get_player().is_superuser)), - if hasattr(obj, "player"): - print obj.player and obj.player.is_superuser + self.cache_lock_bypass(obj) def __str__(self): return ";".join(self.locks[key][2] for key in sorted(self.locks)) @@ -265,6 +252,17 @@ class LockHandler(object): "Store locks to obj" self.obj.lock_storage = ";".join([tup[2] for tup in self.locks.values()]) + def cache_lock_bypass(self, obj): + """ + We cache superuser bypass checks here for efficiency. This needs to be re-run when a player is assigned to a character. + We need to grant access to superusers. We need to check both directly on the object (players), through obj.player and using the + get_player method (this sits on serversessions, in some rare cases where a check is done + before the login process has yet been fully finalized) + """ + self.lock_bypass = ((hasattr(obj, "is_superuser") and obj.is_superuser) + or (hasattr(obj, "player") and hasattr(obj.player, "is_superuser") and obj.player.is_superuser) + or (hasattr(obj, "get_player") and (not obj.get_player() or obj.get_player().is_superuser))) + def add(self, lockstring, log_obj=None): """ Add a new lockstring on the form ':'. Multiple diff --git a/src/objects/models.py b/src/objects/models.py index 61ddc38139..c26a8d7ddd 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -256,6 +256,10 @@ class ObjectDB(TypedObject): if inherits_from(player, TypeClass): player = player.dbobj set_field_cache(self, "player", player) + # we must set this here or superusers won't be able to + # bypass lockchecks unless they start the game connected + # to the character in question. + self.locks.cache_lock_bypass(self) #@player.deleter def __player_del(self): "Deleter. Allows for del self.player"