[sork] scripts/passwd_expect and "passwd is shell"

Lionel Elie Mamane lionel at mamane.lu
Wed Mar 12 22:01:51 PST 2003


Hi,

I adapted the passwd_expect script to the case where the user has the
"passwd" program as login shell. My modified script still works if the
user has a regular shell.

I'm currently packaging passwd for Debian.

Here is the patch:

--- sork-passwd-2.2.orig/scripts/passwd_expect
+++ sork-passwd-2.2/scripts/passwd_expect
@@ -8,6 +8,9 @@
 # @version $Revision: 1.1 $
 # @since   Passwd 2.2
 
+# Modified by Lionel Elie Mamane <lionel at mamane.lu>
+# to manage case where passwd is the login shell.
+
 # @stdin         The username, oldpassword, newpassword (in this order)
 #                will be taken from stdin
 # @param -prompt      regexp for the shell prompt
@@ -171,21 +174,28 @@
 }
 
 # start password changing program
+set old_password_notentered true
 expect {
   -re $prompt_string      {sleep .5
                            send $program\r}
+  # The following is for when passwd is the login shell
+  -re $oldpassword_string {sleep .5
+                           send $password(old)\r
+                           set old_password_notentered false}
   timeout                 {puts $err  "Could not login to system (bad old password?)\n"
                            close $err
                            exit 1}
 }
 
 # send old password
-expect {
-  -re $oldpassword_string {sleep .5
-                           send $password(old)\r}
-  timeout                 {puts $err "Could not start passwd program (no old password prompt)\n"
-                           close $err
-                           exit 1}
+if {$old_password_notentered} {
+  expect {
+    -re $oldpassword_string {sleep .5
+                             send $password(old)\r}
+    timeout                 {puts $err "Could not start passwd program (no old password prompt)\n"
+                             close $err
+                             exit 1}
+  }
 }
 
 # send new password



More information about the sork mailing list