MCPcopy Create free account
hub / github.com/saltstack/salt / _is_valid_shell

Function _is_valid_shell

salt/modules/cmdmod.py:3838–3867  ·  view source on GitHub ↗

Attempts to search for valid shells on a system and see if a given shell is in the list

(shell)

Source from the content-addressed store, hash-verified

3836
3837
3838def _is_valid_shell(shell):
3839 """
3840 Attempts to search for valid shells on a system and
3841 see if a given shell is in the list
3842 """
3843 if salt.utils.platform.is_windows():
3844 return True # Don't even try this for Windows
3845 shells = "/etc/shells"
3846 available_shells = []
3847 if os.path.exists(shells):
3848 try:
3849 with salt.utils.files.fopen(shells, "r") as shell_fp:
3850 lines = [
3851 salt.utils.stringutils.to_unicode(x)
3852 for x in shell_fp.read().splitlines()
3853 ]
3854 for line in lines:
3855 if line.startswith("#"):
3856 continue
3857 else:
3858 available_shells.append(line)
3859 except OSError:
3860 return True
3861 else:
3862 # No known method of determining available shells
3863 return None
3864 if shell in available_shells:
3865 return True
3866 else:
3867 return False
3868
3869
3870def shells():

Callers 1

_runFunction · 0.85

Calls 3

existsMethod · 0.45
readMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected