From 069230e0bef44eb18252254713627a452306f23a Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Thu, 30 Dec 2021 01:15:19 +0530 Subject: [PATCH] Fixed running swhkd as sudo and added exception for no input group --- src/swhkd.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/swhkd.py b/src/swhkd.py index 2a4a77d..fcead0a 100755 --- a/src/swhkd.py +++ b/src/swhkd.py @@ -26,14 +26,17 @@ class SWHKD: sys.exit(0) async def run_swhkd(self): + if os.getuid() == 0: + await self.log_util.log_error('Refusing to run SWHKD as root.') + sys.exit(1) + # Permission check groups = [g.gr_name for g in grp.getgrall() if self.user in g.gr_mem] gid = pwd.getpwnam(self.user).pw_gid groups.append(grp.getgrgid(gid).gr_name) - for group in groups: - if group.lower() == "input": - await self.log_util.log_warn("User is in input group, proceeding.") - break; + if "input" not in groups: + await self.log_util.log_error("User is in not in input group, exiting.") + sys.exit(1) # Config parsing try: