isValidShell

This commit is contained in:
chrys 2018-03-26 07:40:04 +02:00
parent 71bc7c6042
commit 8c114ea318

View File

@ -39,16 +39,29 @@ def createScreenEventData(content):
def hasMore(fd, timetout=0.2): def hasMore(fd, timetout=0.2):
r, _, _ = select.select([fd], [], [], timetout) r, _, _ = select.select([fd], [], [], timetout)
return (fd in r) 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(): def getShell():
try: try:
shell = os.environ["FENRIRSHELL"] shell = os.environ["FENRIRSHELL"]
if os.path.isfile(shell): if isValidShell(shell):
return shell return shell
except: except:
pass pass
try: try:
shell = os.environ["SHELL"] shell = os.environ["SHELL"]
if os.path.isfile(shell): if isValidShell(shell):
return shell return shell
except: except:
pass pass
@ -60,17 +73,12 @@ def getShell():
(username, encrypwd, uid, gid, gecos, homedir, shell) = user.split(':') (username, encrypwd, uid, gid, gecos, homedir, shell) = user.split(':')
shell = shell.replace('\n','') shell = shell.replace('\n','')
if username == getpass.getuser(): if username == getpass.getuser():
if shell != '': if isValidShell(shell):
if os.path.isfile(shell):
return shell
except:
pass
try:
if os.path.isfile('/bin/bash'):
shell = '/bin/bash'
return shell return shell
except: except:
pass pass
if isValidShell('/bin/bash'):
return '/bin/bash'
return '/bin/sh' return '/bin/sh'
def trackHighlights(oldAttr, newAttr, text, lenght): def trackHighlights(oldAttr, newAttr, text, lenght):
result = '' result = ''