remote login

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux