shells.py (nss-pam-ldapd-0.9.11) | : | shells.py (nss-pam-ldapd-0.9.12) | ||
---|---|---|---|---|
skipping to change at line 37 | skipping to change at line 37 | |||
def list_shells(): | def list_shells(): | |||
"""List the shells from /etc/shells.""" | """List the shells from /etc/shells.""" | |||
libc = ctypes.CDLL(ctypes.util.find_library("c")) | libc = ctypes.CDLL(ctypes.util.find_library("c")) | |||
getusershell = libc.getusershell | getusershell = libc.getusershell | |||
getusershell.restype = ctypes.c_char_p | getusershell.restype = ctypes.c_char_p | |||
libc.setusershell() | libc.setusershell() | |||
while True: | while True: | |||
shell = getusershell() | shell = getusershell() | |||
if not shell: | if not shell: | |||
break | break | |||
yield shell | yield shell.decode('utf-8') | |||
libc.endusershell() | libc.endusershell() | |||
def shellexists(shell): | def shellexists(shell): | |||
"""Check if the provided shell exists and is executable.""" | """Check if the provided shell exists and is executable.""" | |||
return os.path.isfile(shell) and os.access(shell, os.X_OK) | return os.path.isfile(shell) and os.access(shell, os.X_OK) | |||
def check(shell, asroot=False): | def check(shell, asroot=False): | |||
"""Check if the specified shell is valid and exit if it isn't.""" | """Check if the specified shell is valid and exit if it isn't.""" | |||
# if the shell is listed in /etc/shells, everything should be OK | # if the shell is listed in /etc/shells, everything should be OK | |||
if shell in list_shells(): | if shell in list_shells(): | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 1 lines changed or added |