Description of problem:
Quoting from the expect FAQ:
"Why does Expect sometimes misbehave when automating passwd on RedHat
(and derived Linux systems)
This is a two-part question.
1. Expect sometimes hangs.
RedHat passwd has a bug. It prompts before it is ready to
receive input. Humans are slow (relatively speaking) so this normally
isn't noticeable. Alas, Expect is fast enough that by the time passwd
is ready, Expect has already sent the password. So passwd sits and
waits and Expect sits and waits. It appears hung.
A simple workaround: Briefly pause before sending the password.
A tenth of a second is probably sufficient but of course since the
passwd program makes no guarantees, I can't either.
2. Expect sometimes seems really slow.
This is really the same bug as above, except that you haven't
explicitly specified a timeout. Expect uses its default of 10 seconds,
meaning that it stops waiting after 10 seconds and resends the
password (presuming you are looping to send the password as long as
/bin/passwd keeps asking). After 10 seconds, /bin/passwd is highly
likely to finally be listening. So /bin/passwd tells Expect it is now
happy and Expect finishes.
The underlying routine containing the bug is traditionally a C
function called getpass. Since it is shared by most other programs
that prompt for passwords (rlogin, su, etc), you are likely to find
this same misbehavior in other programs. I've just used password here
because its the one asked about most frequently.
Could someone get RedHat to fix this bug?"
We decided that Tomas will take the maintenance of passwd because I'm busy with
other items now and he also maintains PAM so please sync with Tomas to have this
issue fixed. I'll be here in Cc to comment things out when needed.
This one is nice. I'm almost sure that it comes from the default PAM
conversation routine where the input buffer is flushed just after the prompt
appears, however I'm really not sure how to fix this problem as I don't want to
introduce any regressions in this pretty critical routine.
It should be fixed now.