From: Frank Brehm Date: Wed, 9 Aug 2017 15:10:52 +0000 (+0200) Subject: Checking group membership in simulation mode X-Git-Tag: 0.1.2~131 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=c5c06f3ec9f8a741e289a36dfc3100496eae5c9b;p=pixelpark%2Fadmin-tools.git Checking group membership in simulation mode --- diff --git a/pp_lib/config_named_app.py b/pp_lib/config_named_app.py index 42812ce..2cba079 100644 --- a/pp_lib/config_named_app.py +++ b/pp_lib/config_named_app.py @@ -39,7 +39,7 @@ from .cfg_app import PpCfgAppError, PpConfigApplication from .pidfile import PidFileError, InvalidPidFileError, PidFileInUseError, PidFile -__version__ = '0.6.2' +__version__ = '0.6.3' LOG = logging.getLogger(__name__) @@ -786,10 +786,28 @@ class PpConfigNamedApp(PpConfigApplication): # ------------------------------------------------------------------------- def _run(self): - if os.geteuid(): + my_uid = os.geteuid() + if my_uid: if self.simulate: LOG.warn("You must be root to execute this script.") - LOG.warn("But hey - this is simulation mode ...") + group_ids = {} + for group in grp.getgrall(): + for g_username in group.gr_mem: + g_uid = pwd.getpwnam(g_username).pw_uid + if g_uid == my_uid: + group_ids[group.gr_name] = group.gr_gid + if self.verbose > 2: + LOG.debug("You are a member of the groups:\n{}".format(group_ids)) + if self.named_group in group_ids: + LOG.warn(( + "But hey - this is simulation mode, " + "and you are a member of group {!r} ...").format( + self.named_group)) + else: + LOG.error(( + "But also in simulation mode you has to be a member " + "of group {!r}!").format(self.named_group)) + self.exit(1) time.sleep(1) else: LOG.error("You must be root to execute this script.")