rewrite list_shells

This commit is contained in:
Kay0u 2023-01-19 11:15:02 +01:00
parent 21c72ad1c5
commit 36b0f58993
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D

View file

@ -122,21 +122,17 @@ def user_list(fields=None):
return {"users": users} return {"users": users}
def list_shells():
import ctypes
import ctypes.util
"""List the shells from /etc/shells.""" def list_shells():
libc = ctypes.CDLL(ctypes.util.find_library("c")) with open("/etc/shells", "r") as f:
getusershell = libc.getusershell content = f.readlines()
getusershell.restype = ctypes.c_char_p
libc.setusershell() shells = []
while True: for line in content:
shell = getusershell() if line.startswith("/"):
if not shell: shells.append(line.replace("\n",""))
break return shells
yield shell.decode()
libc.endusershell()
def shellexists(shell): def shellexists(shell):