ssh is reading and writing directly to /dev/tty. In order to control this, you need to do a bit of hokey pokey with setsid, open a new tty for your new process group, and then dup those file descriptors in your parent to pipes that speak to your child. It's a hassle.
I ran across this trying to do y2k testing with sudo, which does the same thing. I'll update this node with code if I can find it ...
Updated:
Admittedly, this isn't perl, but you should be able to adapt ...
pipe(toslave);
pipe(frslave);
if (fork() == 0)
{
int fd;
close(0);
dup(toslave[0]);
close(1);
dup(frslave[1]);
(void)setsid(); /* become session leader and */
/* lose controlling tty */
fd = open("/dev/console", O_RDWR);
#ifndef hpux
(void)ioctl(fd,TIOCSCTTY,0);
#endif
free(argv[0]);
argv[0] = (char *)malloc(5 * sizeof(char));
sprintf(argv[0],"ssh");
execv("/usr/bin/ssh", argv);
fprintf(stderr,"Bad exec (%u)\n", errno);
exit(0);
}
write(toslave[1],PASSWORD, strlen(PASSWORD));
if (! strncmp("-v", argv[1])) exit(wait(NULL));
if (! strncmp("-k", argv[1])) exit(wait(NULL));
num=read(frslave[0],buf,359);
buf[num]='\0';
printf("%s", buf);
exit(wait(NULL));
}
I'll perlify later this weekend ...
Remember, when you stare long into the abyss, you could have been home eating ice cream.
|