forked from micropython/micropython-lib
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwd.py
25 lines (17 loc) · 594 Bytes
/
pwd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
importffilib
importuctypes
importstruct
fromcollectionsimportnamedtuple
libc=ffilib.libc()
getpwnam_=libc.func("P", "getpwnam", "s")
struct_passwd=namedtuple(
"struct_passwd", ["pw_name", "pw_passwd", "pw_uid", "pw_gid", "pw_gecos", "pw_dir", "pw_shell"]
)
defgetpwnam(user):
passwd=getpwnam_(user)
ifnotpasswd:
raiseKeyError("getpwnam(): name not found: {}".format(user))
passwd_fmt="SSIISSS"
passwd=uctypes.bytes_at(passwd, struct.calcsize(passwd_fmt))
passwd=struct.unpack(passwd_fmt, passwd)
returnstruct_passwd(*passwd)