From 8c114ea318ac0b6d0942ba85e66e147df4b28270 Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 26 Mar 2018 07:40:04 +0200 Subject: [PATCH] isValidShell --- src/fenrirscreenreader/utils/screen_utils.py | 30 +++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/fenrirscreenreader/utils/screen_utils.py b/src/fenrirscreenreader/utils/screen_utils.py index e8b32731..90785299 100644 --- a/src/fenrirscreenreader/utils/screen_utils.py +++ b/src/fenrirscreenreader/utils/screen_utils.py @@ -39,16 +39,29 @@ def createScreenEventData(content): def hasMore(fd, timetout=0.2): r, _, _ = select.select([fd], [], [], timetout) return (fd in r) +def isValidShell(shell = ''): + if not isinstance(shell, str): + return False + if shell == '': + return False + try: + if not os.path.isfile(shell): + return False + if not os.access(shell,os.X_OK) + return False + except: + return False + return True def getShell(): try: shell = os.environ["FENRIRSHELL"] - if os.path.isfile(shell): + if isValidShell(shell): return shell except: pass try: shell = os.environ["SHELL"] - if os.path.isfile(shell): + if isValidShell(shell): return shell except: pass @@ -60,17 +73,12 @@ def getShell(): (username, encrypwd, uid, gid, gecos, homedir, shell) = user.split(':') shell = shell.replace('\n','') if username == getpass.getuser(): - if shell != '': - if os.path.isfile(shell): - return shell - except: - pass - try: - if os.path.isfile('/bin/bash'): - shell = '/bin/bash' - return shell + if isValidShell(shell): + return shell except: pass + if isValidShell('/bin/bash'): + return '/bin/bash' return '/bin/sh' def trackHighlights(oldAttr, newAttr, text, lenght): result = ''