From my mono application, running under Linux, I want to run another one as root
user. At the moment I use Process.Start
, running gksudo
.
This solution works quite well under one condition - there is gksudo
installed.
I need a mechanism to elevate privileges for a mono assembly (not necessarily as another process) that does not rely on a particular, desktop-dependant application like gksudo
or kdesu
and is not console-based (like good ol' sudo
).
Actually I believe I need a way to PAM-ify my application.
The solution does not have to be Windows compliant, but it would be a nice bonus.
I've seen many possible answers to my problem, but none did resolve all the issues.
A very nice approach was https://stackoverflow.com/a/16276287/882200, but it requires an assembly to be ran as root, which is not possible.
This inspired me to try a new approach. I've tried running
Process.Start("whoami", "otheruser", password, "");
The output should be otheruser
, but it is not.
Please mind that I leave the domain (last parameter) empty (is that OK?) and I fill password according to this example.
This solution is not the best one - it requires me to provide means to grab a password, but it is acceptable, although not working.
The best option for me would be to make my environment choose the correct way to receive a password - either by a Qt/GTK popup or a console prompt.
The last thing to keep in mind - to run an app as root I'd love to be able to provide a sudoer password, not necessarily a root password (according to sudoers
configuration).