"Denying" sudo privilages mid-program

So I'm writing a package manager that is approaching initial release. Consider the following flow of code:

# Some code that needs root privalages. Database syncing, etc.
# Building packages. *Does not require root.* 
# In fact, this is a call to a child process through the shell and it will complain if called by root.
# Copying built packages to root-owned locations. Needs root.
# Installing packages. Needs root.

I'd like to be able to run the program with sudo initially, as the copying part above is done in native code and will fail if the entire program wasn't run with root privileges to begin with. The building process however needs to no be done as root. My question is in essence, would there be a way "deny" or "halt" the root privileges before calling the child process that does the building? It would need to be in such a way that when control returns to the parent the root-state would still be in effect for the actual installation to take place unhindered.

Por favor y gracias de antemano.

También, trabaja para here is the repo is anyone is interested.

preguntado el 12 de junio de 12 a las 13:06

1 Respuestas

So it seems that when a program is run with sudo, the environment variable SUDO_USER is created. By reading that, I can then run the child process with su -c.

Respondido el 12 de junio de 12 a las 23:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.