in reply to getting root permissions via program

I really think you should use sudo for that, and not from within your program, but make a sudo entry to allow running of your program which is otherwise owned and executable by root.
  • Comment on Re: getting root permissions via program

Replies are listed 'Best First'.
Re^2: getting root permissions via program
by Fletch (Bishop) on Feb 25, 2008 at 14:01 UTC

    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.

      One rather important point is that one would not want to make users accustomed to give root passwords to arbitrary programs asking for it.
Re^2: getting root permissions via program
by gri6507 (Deacon) on Feb 25, 2008 at 15:22 UTC
    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?
      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.