home *** CD-ROM | disk | FTP | other *** search
- /*
- * Spawn a shell with the stdin and stdout swapped with the remote
- * system. An undocumented feature: The external protocol gateway
- * can be used to pipe the output of a normal Unix command to the
- * remote system.
- */
-
- #include <stdio.h>
- #include <signal.h>
- #include <curses.h>
- #include <fcntl.h>
- #include "config.h"
-
- void
- extrnl(cmd)
- char *cmd;
- {
- extern int fd;
- WINDOW *xt_win, *newwin();
- int (*istat)(), (*qstat)(), status, epid, w;
- char *shell, *shellpath, *getenv(), *strrchr(), buf[40], *ttyname();
- char *strcpy();
- unsigned int sleep();
- void _exit(), input_off();
-
- input_off();
- /* a full window */
- xt_win = newwin(LINES, COLS, 0, 0);
- touchwin(xt_win);
- wrefresh(xt_win);
- /* out of curses mode */
- resetterm();
-
- shellpath = getenv("SHELL");
- if (shellpath == NULL || *shellpath == NULL)
- shellpath = "/bin/sh";
-
- shell = strrchr(shellpath, '/') + 1;
-
- if (!(epid = fork())) {
- /* recreate the device name */
- strcpy(buf, ttyname(fd));
- close(fd);
- /* swap the stdin */
- close(0);
- open(buf, O_RDONLY);
- /* swap the stdout */
- close(1);
- open(buf, O_WRONLY);
- #ifdef SETUGID
- setgid(getgid());
- setuid(getuid());
- #endif /* SETUGID */
- execl(shellpath, shell, "-c", cmd, (char *) 0);
- _exit(1);
- }
- istat = signal(SIGINT, SIG_IGN);
- qstat = signal(SIGQUIT, SIG_IGN);
-
- while ((w = wait(&status)) != epid && w != -1)
- ;
-
- signal(SIGINT, istat);
- signal(SIGQUIT, qstat);
- /* back to curses mode */
- sleep(1);
- fixterm();
-
- clearok(curscr, TRUE);
- werase(xt_win);
- wrefresh(xt_win);
- delwin(xt_win);
- return;
- }
-