[sork] passwd_expect patch

Andrew Suffield asuffield at suffields.me.uk
Thu Nov 9 03:13:14 PST 2006


The following patch was required for me to get passwd_expect to work
correctly.

--- passwd_expect	2006-11-09 10:58:53.000000000 +0000
+++ passwd_expect	2006-11-09 10:59:33.000000000 +0000
@@ -54,6 +53,8 @@
 
 # read input from stdin
 
+fconfigure stdin -blocking 1
+
 gets stdin user
 gets stdin password(old)
 gets stdin password(new)
@@ -172,7 +168,8 @@
 # log in
 expect {
   -re $fingerprint_string {sleep .5
-                           send yes\r}
+                           send yes\r
+                           exp_continue}
   -re $password_string    {sleep .5
                            send $password(old)\r}
   timeout                 {puts $err "Could not login to system (no password prompt)\n"

I cannot explain why stdin might be in non-blocking mode, but it was,
and so sometimes expect would miss the username/password strings. I
can only put this one down to deep crackfulness on the part of tcl,
expect, apache, or php, and express my strong desire to never know
what is going on there. Understanding this can only lead to
pain. Forcing stdin into blocking mode ensures that it always works.

The exp_continue is necessary because otherwise, if expect sees
$fingerprint_string, it does not bother looking for $password_string
or sending the old password. Obviously nobody ever tested this, it
can't ever have worked.


More information about the sork mailing list