Or make a small helper utility which does the bare minimum of work that requires elevated privileges and run that via sudo. But seconded; you really don't want to try and do it yourself if you can get away with off the shellf. Just let sudo do the heavy lifting for you (something that's its specialized in; not to mention it's high profile and will have way more eyeballs scrutinizing it than your code would).
The cake is a lie.
The cake is a lie.
The cake is a lie.
| [reply] |
One rather important point is that one would not want to make users accustomed to give root passwords to arbitrary programs asking for it.
| [reply] |
ok, I can go with that. In that case, my question becomes how can I test to see that my program was started via sudo? If I'm not mistaken, sudo does not check UID? | [reply] |
If your program is owned by root, and only executable by root, then no one will be allowed to run it unless they are root, or use sudo, so you don't really need to check further.
| [reply] |