mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
rewrite list_shells
This commit is contained in:
parent
21c72ad1c5
commit
36b0f58993
1 changed files with 10 additions and 14 deletions
24
src/user.py
24
src/user.py
|
@ -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):
|
||||||
|
|
Loading…
Add table
Reference in a new issue