...
Description | Code | EUID | RUID | SSUID |
---|---|---|---|---|
program startup |
| 0 | user | 0 |
temporary drop | | user | user | 0 |
restore | | user | user | 0 |
permanent drop | | user | user | 0 |
restore (attacker) | | 0 | 0 | 0 |
...
Code Block | ||
---|---|---|
| ||
/* Store the privileged ID for later verification */ uid_t privid = geteuid(); /* Code intended to run with elevated privileges */ /* Temporarily drop privileges */ if (seteuid(getuid()) != 0) { /* Handle error */ } /* Code intended to run with lower privileges */ if (need_more_privileges) { /* Restore Privileges */ if (seteuid(privid) != 0) { /* Handle error */ } /* Code intended to run with elevated privileges */ } /* ... */ /* Restore privileges if needed */ if (geteuid() != privid) { if (seteuid(privid()) != 0) { /* Handle Errorerror */ } } /* Permanently drop privileges */ if (setuid(getuid()) != 0) { /* Handle error */ } if (setuid(0) != -1) { /* Privileges can be restored, handle error */ } /* Code intended to run with lower privileges */ |
...