I'm writing a program which temporarily needs root the first time it is run to perform a configuration change (create a file in /etc
).
How can I temporarily gain root, by asking the user for their password in a graphical dialog box?
The program uses Qt and I am reasonably happy if it only works on Ubuntu, but I don't want to assume that they have gksudo
or whatever installed. I also cannot use SUID
.
The only thing I can think of is providing my own password dialog, and feeding that to the command line sudo
binary via system()
(or one of its less insecure cousins).
That seems pretty hacky though - command-line front-ends are generally an awful awful idea and should be avoided at all costs. So is there a better way? Perhaps there is a libsudo, or some method using IPC?
NB: This is not a duplicate. Or at least, the answers there do not treat it as the question I am asking.