From 2c533eb48672110a04d6c4850d3e103d6294ee8d Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Sat, 3 Oct 2020 18:09:10 +0000 Subject: [PATCH] Add restricted debug mode Create a new configuration flag, .mudpy.limit.debug, which indicates unsafe debugging options will be available in the running engine. This is unused, but lays the groundwork for future unsafe commands to be toggled at start in base configuration. --- doc/source/configuration.rst | 14 +++++++++++++- etc/mudpy.yaml | 3 ++- mudpy/misc.py | 11 ++++++++++- mudpy/tests/fixtures/test_daemon.yaml | 3 ++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index d0f8093..d0001fc 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -2,7 +2,7 @@ configuration =============== -.. Copyright (c) 2004-2019 mudpy authors. Permission to use, copy, +.. Copyright (c) 2004-2020 mudpy authors. Permission to use, copy, modify, and distribute this software is granted under terms provided in the LICENSE file distributed with this software. @@ -167,6 +167,18 @@ Example:: .mudpy.limit.backups: 10 +.mudpy.limit.debug +~~~~~~~~~~~~~~~~~~ + +bool, optional + +Whether unsafe debugging functionality is enabled. If unspecified or +set to false, unsafe debugging functions will be disabled. + +Example:: + + .mudpy.limit.debug: true + .mudpy.limit.password_tries ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/etc/mudpy.yaml b/etc/mudpy.yaml index 8eccba3..8c413a3 100644 --- a/etc/mudpy.yaml +++ b/etc/mudpy.yaml @@ -1,5 +1,5 @@ --- -_copy: Copyright (c) 2004-2019 mudpy authors. Permission to use, copy, +_copy: Copyright (c) 2004-2020 mudpy authors. Permission to use, copy, modify, and distribute this software is granted under terms provided in the LICENSE file distributed with this software. @@ -48,6 +48,7 @@ _lock: true - admin .mudpy.limit.avatars: 7 # .mudpy.limit.backups: 10 +# .mudpy.limit.debug: true .mudpy.limit.password_tries: 3 # .mudpy.log.file: var/mudpy.log diff --git a/mudpy/misc.py b/mudpy/misc.py index babd42f..3968039 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -186,7 +186,8 @@ class Element: def is_restricted(self): """Boolean check whether command is administrative or debugging.""" - return(self.get("administrative", False)) + return( + self.get("administrative", False) or self.get("debugging", False)) def is_admin(self): """Boolean check whether an actor is controlled by an admin owner.""" @@ -199,6 +200,10 @@ class Element: if command not in self.universe.groups["command"].values(): return(False) + # debugging commands are not allowed outside debug mode + if command.get("debugging") and not self.universe.debug_mode(): + return(False) + # avatars of administrators can run any command if self.is_admin(): return(True) @@ -481,6 +486,10 @@ class Universe: if fallback not in self.files: mudpy.data.Data(fallback, self, flags=flags) + def debug_mode(self): + """Boolean method to indicate whether unsafe debugging is enabled.""" + return self.groups["mudpy"]["limit"].get("debug", False) + class User: diff --git a/mudpy/tests/fixtures/test_daemon.yaml b/mudpy/tests/fixtures/test_daemon.yaml index 9052a6c..3a7f8e1 100644 --- a/mudpy/tests/fixtures/test_daemon.yaml +++ b/mudpy/tests/fixtures/test_daemon.yaml @@ -1,5 +1,5 @@ --- -_copy: Copyright (c) 2004-2019 mudpy authors. Permission to use, copy, +_copy: Copyright (c) 2004-2020 mudpy authors. Permission to use, copy, modify, and distribute this software is granted under terms provided in the LICENSE file distributed with this software. @@ -49,6 +49,7 @@ _lock: true - admin .mudpy.limit.avatars: 7 .mudpy.limit.backups: 3 +# .mudpy.limit.debug: true .mudpy.limit.password_tries: 3 .mudpy.log.file: var/mudpy.log -- 2.11.0