[sudo-users] Problem with 'sudo' ignoring switches
Madison Kelly
linux at alteeve.com
Fri Jul 29 08:13:14 EDT 2005
Hi all,
I've got a program (perl script) where I use 'sudo' to perform
certain shell tasks. Most of the time this works fine but every now and
then the 'sudo' prompts for a password regardless of the switches, which
kills my running program because I can't enter the password from the
shell even if I did assume users would know the password.
Specifically how I use 'sudo':
When I need to perform a priviledged task I call a small sub routine
called 'prep_sudo' where I first enter:
system "sudo -K\n";
To make sure there wasn't already a valid time stamp. Then I set the
timestamp by entering:
open (SUDO, '|sudo -S -v -p '.$say_sudo);
print SUDO "$passwd\n";
close (SUDO);
The initial '|' is supposed to tell 'sudo' to take the input from the
script. The '-S -v -p <string>' is supposed to prompt from the password
but also tell sudo to take the password from a shell. I use '-p
<string>' to make the request look more like my program.
When it works I then perform whatever task using 'sudo' I need and
then as soon as I am done I enter:
system "sudo -K\n";
Again to make sure that the timestamp is gone, keeping the period of
time where 'sudo' is available as short as possible.
90% of the time this works perfectly. Every now and then though it
seems to act like it didn't catch the switches. The reason I say this is
because when this doesn't work my defined '-p <string>' is not printed
and the default 'Password:' prompt is.
Is there any know cases when 'sudo' ignores it's command line
switches? I thought this might be a race condition so I tried adding a:
'sleep 1;'
After killing the timestamp and before recreating the new timestamp
but that didn't seem to help.
Any advice would be much appreciated!
Madison
More information about the sudo-users
mailing list