简体   繁体   中英

python | start new thread that will impersonate another uid without affecting main thread

I with to create a new thread which will impersonate to another uid, execute a task and finish, while my main thread will keep is original uid all the time.

impersonation can easily be achieved by using

os.setuid(self.impersonation_uid)

but how can I make sure that it won't change my original uid from the main thread?

Thank you

Threads cannot have separate user ids; only processes can. The data structure the kernel uses for process has a user id field, but the thread one doesn't - so, this is an architectural limitation.

Processes are defined by task_struct , which has a cred field, pointing to a cred structure, including uid, gid etc.

Threads are defined by thread_info , which doesn't have anything point to user credentials.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM