Attempts to search for valid shells on a system and see if a given shell is in the list
(shell)
| 3836 | |
| 3837 | |
| 3838 | def _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 | |
| 3870 | def shells(): |