add a perimitive nobody switch user call

This commit is contained in:
randomuser 2021-07-20 03:18:48 -05:00
parent 4585792396
commit 7d8b259a2f
1 changed files with 7 additions and 1 deletions

View File

@ -2,6 +2,8 @@ import socketserver
import subprocess import subprocess
import os import os
import time import time
import pwd
import grp
class GopherError(BaseException): pass class GopherError(BaseException): pass
class RequestError(GopherError): pass class RequestError(GopherError): pass
@ -185,8 +187,12 @@ class GopherHandler(socketserver.BaseRequestHandler, GopherServerLogic):
log = Logger() log = Logger()
host = "localhost" host = "localhost"
port = 77 port = 70
if __name__ == "__main__": if __name__ == "__main__":
switchgrp = grp.getgrnam("nobody").gr_gid
switchusr = pwd.getpwnam("nobody").pw_uid
with socketserver.TCPServer((host, port), GopherHandler) as server: with socketserver.TCPServer((host, port), GopherHandler) as server:
os.setgid(switchgrp)
os.seteuid(switchusr)
server.serve_forever() server.serve_forever()