On Sat, Jul 21, 2001 at 07:47:21AM +0000, Geoff Wing wrote:
> Chris Green <[EMAIL PROTECTED]> typed:
> : I have a short 'C' program which automates login via telnet to a
> : remote system. I.e. the 'C' program uses ioctl(fd, TIOCSTI, cp) to
> : stuff the following into the keyboard buffer:-
> : "telnet -l chris <name of system>\n"
> : It then sleeps for a few seconds and stuffs the password for the
> : remote system into the keyboard buffer.
>
> OK, here's a quick version I just whipped up. Worked fine for me.
> I didn't bother putting in several checks for correct handling.
>
> If you want to start it without using passwords wouldn't using
> rlogin or ssh be easier? e.g. "rxvt -e rlogin -l chris somesystem"
>
I can't use rlogin as the remote system isn't running rshd/rlogind,
the *only* remote access daemon running is telnetd. They used to run
sshd (which is what I used to use) but discontinued that for
'security reasons'. It wasn't totally unthought about, apparently
sshd has a security problem of some sort which will allow logins
although it's better from the point of view of the data itself being
secure across the link.
> #include <stdio.h>
> #include <sys/ioctl.h>
>
> main()
> {
> int i;
> char *cp;
> char buf1[] = "username\n";
> char buf2[] = "password\n";
>
> switch(fork()) {
> default: /* parent must do this bit */
> execl("/usr/bin/telnet", "telnet", "192.168.1.1", NULL);
> fprintf(stderr, "execl() failed\n");
> exit(1);
> case 0:
> break;
> }
> /* in the hands of a child */
> sleep(5);
> for (cp = buf1, i = sizeof(buf1); --i; cp++)
> if (ioctl(0, TIOCSTI, cp) == -1)
> exit(2);
> sleep(2);
> for (cp = buf2, i = sizeof(buf2); --i; cp++)
> if (ioctl(0, TIOCSTI, cp) == -1)
> exit(2);
> /* child terminated. parent lives */
> }
:-) That works for me too (except that I had to add an include of
termios.h). What I don't understand is why my version didn't work, I
think there must be some subtlety of how the child/parent intereacts
as mine wasn't exactly the same as yours on that front.
Thanks!
--
Chris Green ([EMAIL PROTECTED])
Home: [EMAIL PROTECTED] Work: [EMAIL PROTECTED]
WWW: http://www.isbd.co.uk/