Bug 4788 - autopasswd broken -- fix supplied
Summary: autopasswd broken -- fix supplied
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: tcltk
Version: 6.0
Hardware: i386
OS: Linux
medium
low
Target Milestone: ---
Assignee: Jens Petersen
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 1999-08-30 21:01 UTC by Robert K. Moniot
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2000-03-18 21:00:17 UTC
Embargoed:


Attachments (Terms of Use)

Description Robert K. Moniot 1999-08-30 21:01:01 UTC
This is not a bug in passwd, but in autopasswd, which is
part of the expect rpm.  (I did not find expect in the list
of components above.)

The /usr/bin/autopasswd expect script does not work on
recent systems such as pentium 200+ MHz.  It does not give
the passwd program time to change the tty mode, so the first
password is printed in clear before passwd is ready to read
it.

Below is my fixed version.  It has two improvements, in
addition to working correctly: (1) it allows the username
and password to be piped in on standard input so they do not
appear in the process table (the command-line form is also
accepted as an alternative), and (2) it returns a nonzero
error code if passwd rejects the proposed password, allowing
the script that calls autopassword to use a loop that tries
different passwords until one is accepted.

#!/usr/bin/expect -f
# $Id: autopasswd.expect,v 1.6 1999/08/27 19:39:18 moniot
Exp $
# Wrapper to run passwd(1 non-interactively
#  Usage:  autopasswd username password
#    or    echo " username password" | autopasswd
#  Returns code 0 if successful, nonzero otherwise (bad
password)
#
#  Author: R. Moniot, based on simpler version found in
expect distribution
#  Date:   27 August 1999

if "$argc > 0" {

#  Get username and password from commandline if present.

		set username	[lindex $argv 0]
		set password	[lindex $argv 1]
} else {

#  Otherwise read username and password from stdin: they
must be separated
#  by exactly one blank space and contain no blanks
themselves.

  expect_user {
	-re "(.*) (.*)"	{
		set username $expect_out(1,string);
		set password $expect_out(2,string)
	}
  }
}


spawn passwd $username

			# The sleep is needed to give passwd time
			# to get ready.
expect {
	"password:" 		{sleep 1; send "$password\r"}	# send
}

expect {
	"BAD PASSWORD:*"	{exit 1}
	"password:"		{sleep 1; send "$password\r"}	# resend
}

expect {
	"successfully"		{exit 0}	# OK (Linux flavor)
	eof			{exit 0}	# OK (AIX flavor)
	timeout			{exit 2}	# something went wrong
}

exit 0

Comment 1 Bernhard Rosenkraenzer 2000-02-16 13:01:59 UTC
expect is a part of tcltk. Reassigning.

Comment 2 Jeff Johnson 2000-03-18 21:00:59 UTC
Fixed (by adding a slightly modified copy of your patch) in tcltk-8.2.3-36
in Raw Hide.


Note You need to log in before you can comment on or make changes to this bug.