How to change the effective user ID of a running program?

I am writing a simple package manager and I would like to try sudo automatically if the program does not start as root. I found a function called seteuid that looks the way I need it, but I don’t have permission to run it. For now, all I can think of is a bash script to check before they get into the actual binary, but I would like to do it all like C ++, if possible.

Is there any method to change the euid process after it starts? Or a way to call sudo?

+3
source share
2 answers

As bmargulies says in his answer , you can do this if the binary belongs to root and the setuid bit is set, but then you will need to implement the authentication part (checking that the user is really allowed to root) too.

Essentially, you are rewriting sudoin your application - the best way to handle this is to do what you have proposed and install the application using a script wrapper that uses /usr/bin/idroot to check, and if not, call sudo(or su).

+2
source

Here's how these features work.

setuid, . , seteuid , . Ditty setgid.

. , , . , setuid, , , , .

sudo (, , fork/exec). , sudo, ​​setuid, , .

+3

Source: https://habr.com/ru/post/1738426/


All Articles