c - How to intercept SSH stdin and stdout? (not the password) -
i realize question asked frequently, people want intercept password-asking phase of ssh. not want. i'm after post-login text.
i want write wrapper ssh, acts intermediary between ssh , terminal. want configuration:
(typing on keyboard / stdin) ----> (wrapper) ----> (ssh client)
and same output coming ssh:
(ssh client) -----> (wrapper) -----> stdout
i seem able attain effect want stdout doing standard trick found online (simplified code):
pipe(fd) if (!fork()) { close(fd[read_side]); close(stdout_fileno); // close stdout ( fd #1 ) dup(fd[write_side]); // duplicate writing side of pipe ( lowest # free pipe, 1 ) close(stderr_fileno); dup(fd[write_side]); execv(argv[1], argv + 1); // run ssh } else { close(fd[write_side]); output = fdopen(fd[read_side], "r"); while ( (c = fgetc(output)) != eof) { printf("%c", c); fflush(stdout); } } like said, think works. however, can't seem opposite. can't close(stdin_fileno) , dup readside of pipe. seems ssh detects , prevents it. i've read can use "-t -t" option force ssh ignore non-stdin nature of input; when try still doesn't work.
any hints?
thanks much!
use popen (instead of execv) execute ssh cmd , able read , write session.
Comments
Post a Comment