From 36b0f5899329a39e6e75204e91e08d26aa22be99 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 19 Jan 2023 11:15:02 +0100 Subject: [PATCH] rewrite list_shells --- src/user.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/user.py b/src/user.py index 61060a9ef..b3a2a22e6 100644 --- a/src/user.py +++ b/src/user.py @@ -122,21 +122,17 @@ def user_list(fields=None): return {"users": users} -def list_shells(): - import ctypes - import ctypes.util - """List the shells from /etc/shells.""" - libc = ctypes.CDLL(ctypes.util.find_library("c")) - getusershell = libc.getusershell - getusershell.restype = ctypes.c_char_p - libc.setusershell() - while True: - shell = getusershell() - if not shell: - break - yield shell.decode() - libc.endusershell() +def list_shells(): + with open("/etc/shells", "r") as f: + content = f.readlines() + + shells = [] + for line in content: + if line.startswith("/"): + shells.append(line.replace("\n","")) + return shells + def shellexists(shell):