sudo in c?

mlh at mlh at
Mon Jun 23 00:09:47 EDT 2003

On Sun, Jun 22, 2003 at 05:15:20PM +0200, Martin Klaffenboeck wrote:
> Am 2003.06.22 15:44 schrieb(en) Reznic Valery:
> >When you use popen you can ONLY read from the command's stdout
> >or ONLY write to it's stdin.
> >I you want both of them (and may be stderr too) you need play with
> >fork/exec/dup call's.
> >
> >This is not something sudo specific it's pretty general for all
> >commands,
> >which needs both input and output.
> Yes, I found a thing how I can do it with fork and dup, now I'm trying 
> to do that.

Since popen uses the shell, you can also do something
	popen("sudo -S whatever 2>&1");

the 2>&1 means put stderr to the same place as stdout.
(That's if you don't mind the stderr getting mixed up
with stdout)

Perhaps you're better off not asking for the password
at all (NOPASSWD option in the sudoers file)

Or asking for it separately -- do a "sudo -l" to 
validate the password, before every sudo command
run, then make sure you run the real sudo command
within the next 5 minutes (or whatever you've set
the timeout to be)


More information about the sudo-users mailing list