Pseudoterminal Problems
mara ailiez sy <[email protected]> Wed, 4 Feb 2004 07:48:27 -0800 (PST)
| Newsgroups | gmane.linux.redhat.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I want to programmatically control the SSH or telnet to login from a running process. I tried using redirection through pipes but ssh returned an error saying something like stdin is not a terminal. Now, my search has finally led to me a solution: through the use of pseudoterminals. So I made a test program (listed below).
Supposedly I can write to stdin by writing to the file desc of the master pty. But it seems the co-process (ssh) is not reading what I wrote from the slave pty. I don't know what's wrong?
Here is the test program:
#include <pty.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
main()
{
int fds;
char sSlave[80];
int n;
char buffer[256];
pid_t pid;
if (pid = forkpty(&fds,sSlave, NULL, NULL ) == 0)
{
execl("/usr/bin/ssh","ssh", "root@localhost", NULL);
return 2;
}
// Simulate a user typing his username and password
// to the terminal
write(fds, "username", strlen("username"));
write(fds, "password", strlen("password"));
}
Thanks.
Mara Sy
---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!