Well it works. The changes I made seem trivial to me, but it does work now.
I can both authenticate and change passwords (using the authpam scheme). The
file now looks like:
(excepting the comments of course)
set timeout 30
expect {
-re "(.*)\n(.*)\n" { set oldpass "$expect_out(1,string)" ; set newpass
"$expect_out(2,string)" }
eof { exit 1 }
timeout { exit 1 }
}
spawn "/usr/bin/passwd"
expect {
-re "Old" { sleep 2; send "$oldpass\n" }
eof { exit 1 }
timeout { exit 1 }
}
expect {
-re "nvalid" { exit 1 }
-re "New" { sleep 2; send "$newpass\n" }
eof { exit 1 }
timeout { exit 1 }
}
expect {
-re "nvalid" { exit 1 }
-re "NVALID" { exit 1 }
-re "bad pass" { exit 1 }
-re "BAD PASS" { exit 1 }
-re "dictionary" { exit 1 }
-re "common" { exit 1 }
-re "short" { exit 1 }
-re "Retype" { sleep 2; send "$newpass\n" }
eof { exit 1 }
timeout { exit 1 }
}
expect {
-re "nvalid" { exit 1 }
-re "nchange" { exit 1 }
-re "same" { exit 1 }
-re "passwd:" { exit 0 }
eof { exit 0 }
timeout { exit 1 }
}
exit 1
All I did was tweak a couple of things, most notably in the last expect
clause, where I added the "passwd:" line. Hope someone finds it useful. If
someone thinks it's grotesquely incorrect, just let me know.
Thanks Sam.
john
Sam Varshavchik writes:
> J. Goodleaf writes:
>
>> I assume you mean the authsystem.passwd file?
>
> That's the one.
>
>>
>> I don't know a thing about expect... Before I go into this, have any of
>> you out there solved this problem for FreeBSD 4.4. I'm not sure how this
>> stuff works, but it seems that FreeBSD's passwd progra
>
> passwd will be invoked by as the userid.
>
> Even if you don't know anything about expect, you can pretty much figure
> it out. It's real easy. It waits for passwd to print something it
> recognizes, then it sends a response to that. So, you need to look at the
> prompts from your passwd, and adjust the script accordingly. For example:
>
> spawn "/usr/bin/passwd"
>
> expect {
> -re "word:" { sleep 2; send "$oldpass\n" }
> eof { exit 1 }
> timeout { exit 1 }
> }
>
> So the first thing expect does is wait for the string "word:" after
> starting passwd, which should pick up the "Old password:" prompt from
> passwd. The rest of the dialogue is similar.
>
> --
> Sam
>