Re: remote login

Kevin Smathers <[email protected]> Sun, 01 Feb 2004 23:22:04 -0800
Newsgroups gmane.linux.redhat.devel
Message-ID <[email protected]>
You'll have to attach the slave side of a pseudo terminal to stdio 
descriptors of the 'ssh' command.

man openpty

Cheers,
-kls

mara ailiez sy wrote:

>Hello...
>
>I am currently developing my undergrad thesis and is
>developing a remote login with the username and
>password supplied. I have created the code below.
>However, I keep getting an error about "Pseudo
>termnial cannot be allocated because the stdin is not
>a terminal". Then a permission denied ... I  was
>wondering if the use of pipe as the communication
>between the processes can be done?
>
>
>
>#include <stdio.h>
>#include <sys/types.h>
>#include <unistd.h>
>#include <string.h>
>#include <errno.h>
>
>#define BUFFERSIZE 256
>
>
>
>int main() {
>
>  int n;
>  char buffer[BUFFERSIZE];
>
>  int fds_ci[2];    // file descriptors - child input
>
>
>  int fds_co[2];    // file descriptors - child output
>
>
>  // create the I/O pipes
>  if (0 != pipe(fds_ci) || 0 != pipe(fds_co)) return
>1;
>
>  // create the child process
>  if (fork() == 0)
>  {
>
>   // in the child process
>    dup2(fds_ci[1], 0);  
>
>    dup2(fds_co[0], 1);
>
>
>    close(fds_ci[0]);
>    close(fds_ci[1]);
>    close(fds_co[0]);
>    close(fds_co[1]);
>
>
>    execl("/usr/bin/ssh", "ssh", "root@localhost",
>NULL);
>    return 2;
>
>  }
>
>  // in parent process
>  close(fds_ci[1]);  
>  close(fds_co[0]); 
>  
>  write(fd_ci[1], "password", BUFFERSIZE);
>
>  // read child's output and redirect it to standard
>output
>  while (0 < (n = read(fds_co[0], buffer,
>BUFFERSIZE))) {
>    // write to the parent's stdout
>    write(stdout, buffer, n);
>  }
>
>
>  // close the remaining pipes
>  close(fds_ci[0]);
>  close(fds_co[1]);
>
>  return 0;
>}
>
>
>__________________________________
>Do you Yahoo!?
>Yahoo! SiteBuilder - Free web site building tool. Try it!
>http://webhosting.yahoo.com/ps/sb/
>
>
>_______________________________________________
>Redhat-devel-list mailing list
>[email protected]
>https://www.redhat.com/mailman/listinfo/redhat-devel-list
>  
>


-- 
Look ma, no threads[1]. 
[1] BitTorrent in C is http://www.sf.net/projects/libbt
	  
          //                               .--=,
 .....::://::::::::::::::::::::::::::::.. (o O &           [email protected]
:::::::://:::://://://:/:://::||_//       / V  K   
 :::::://:::://:/:|//'/' // _,|'         r ,  'qk   
  :'''/____ // /  //  |_// // ||        .'~.  .~`, 
                                   kls   \_/-=\_/