I have a sudden urge to remove the only expect script on my
systems. To do that I have to be able to set passwords with Solaris
passwd. I've tried this once before, and failed.
Short version of the expect script:
----8<-------------------------------------
spawn /usr/bin/passwd -r nis $uname
expect { -re assword: { send "$password\n" } }
expect { -re assword: { send "$password\n" } }
expect { eof { wait } }
----8<-------------------------------------
In pike that should be something like this:
----8<-------------------------------------
#!/usr/bin/env pike
array(Stdio.File) make_ptypair()
{
Stdio.File pf = Stdio.File(), tf = Stdio.File();
foreach(get_dir("/dev/"), string pty_name)
if(pty_name[..2]=="pty" && pf->open("/dev/"+pty_name, "rw")) {
if(tf->open("/dev/t"+pty_name[1..], "rw"))
return ({ pf, tf });
pf->close();
}
return 0;
}
int main()
{
string luser = "victim";
array(Stdio.File) f = make_ptypair();
if(!f) {
werror("No PTYs available.\n");
return 1;
}
object p = Process.create_process( ({ "/usr/bin/passwd", luser }),
([ "setsid":f[1] ]) );
f[1]->close();
f[0]->write("bogus\n");
f[0]->write("bogus\n");
return p->wait();
}
----8<-------------------------------------
But no, that still gives the password question on the command line:
[root] ./setsid.pike
New password:
Any ideas?