File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import grp
2+ import os
3+ import pwd
4+
15import uinput
26
37def drop_privileges (uid_name = 'nobody' , gid_name = 'nogroup' ):
4- #https://stackoverflow.com/questions/2699907/dropping-root-permissions-in-python
5- import os , pwd , grp
8+ # https://stackoverflow.com/questions/2699907/dropping-root-permissions-in-python
9+
610 if os .getuid () != 0 :
711 return
12+
813 running_uid = pwd .getpwnam (uid_name ).pw_uid
914 running_gid = grp .getgrnam (gid_name ).gr_gid
15+
1016 os .setgroups ([])
1117 os .setgid (running_gid )
1218 os .setuid (running_uid )
1319 old_umask = os .umask (077 )
1420
15-
1621def main ():
17- uinput_fd = uinput .Device . create_uinput_fd ()
18- drop_privileges () #no need to be root beyond this line
22+ uinput_fd = uinput .fdopen ()
23+ drop_privileges () # No need to be root beyond this line.
1924
2025 events = (uinput .KEY_A ,)
2126 with uinput .Device (events , fd = uinput_fd ) as device :
You can’t perform that action at this time.
0 commit comments