Multiple choice technology security

A program wants to do some activities with root privileges when it starts up and shuts down. Other activities it does can be done as a lesser privileged user. Which of the options given below is most secure?

  1. The program should be started with root privileges. Then it should use setuid(UID) to change privileges between root and another account.

  2. The program should be started with root privileges. Then it should use seteuid(UID) to change privileges between root and another account.

  3. Starting the program as root is a security risk. The program should run with least privileges and obtain root using seteuid(UID) whenever necessary.

  4. The program has to run with root privileges entirely. Once root privileges are dropped they cannot be regained.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

seteuid changes the effective UID (used for most permission checks) while keeping the saved UID, allowing temporary privilege elevation back to root. setuid permanently changes the effective UID and loses the ability to regain root privileges. Option B correctly uses seteuid to start as root, drop to lesser privileges, then regain root when needed.

AI explanation

seteuid() changes only the effective UID while leaving the real UID (root) intact, so the process can toggle back and forth between elevated and reduced privileges as needed. setuid(), by contrast, permanently sets both the real and effective UID for a non-privileged target, so once you drop from root with setuid() you can't regain root privileges later — which is unsuitable here since the program needs root again at shutdown.