2004-04-22 04:10:48 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Danny Gasparovski.
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-04-22 04:10:48 +04:00
|
|
|
* Please read the file COPYRIGHT for the
|
|
|
|
* terms and conditions of the copyright.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <slirp.h>
|
|
|
|
|
2007-10-26 23:01:16 +04:00
|
|
|
u_int curtime, time_fasttimo, last_slowtimo;
|
2004-04-22 04:10:48 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
int x_port = -1;
|
|
|
|
int x_display = 0;
|
|
|
|
int x_screen = 0;
|
|
|
|
|
|
|
|
int
|
|
|
|
show_x(buff, inso)
|
|
|
|
char *buff;
|
|
|
|
struct socket *inso;
|
|
|
|
{
|
|
|
|
if (x_port < 0) {
|
|
|
|
lprint("X Redir: X not being redirected.\r\n");
|
|
|
|
} else {
|
|
|
|
lprint("X Redir: In sh/bash/zsh/etc. type: DISPLAY=%s:%d.%d; export DISPLAY\r\n",
|
|
|
|
inet_ntoa(our_addr), x_port, x_screen);
|
|
|
|
lprint("X Redir: In csh/tcsh/etc. type: setenv DISPLAY %s:%d.%d\r\n",
|
|
|
|
inet_ntoa(our_addr), x_port, x_screen);
|
|
|
|
if (x_display)
|
|
|
|
lprint("X Redir: Redirecting to display %d\r\n", x_display);
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
return CFG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Allow more than one X redirection?
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
redir_x(inaddr, start_port, display, screen)
|
|
|
|
u_int32_t inaddr;
|
|
|
|
int start_port;
|
|
|
|
int display;
|
|
|
|
int screen;
|
|
|
|
{
|
|
|
|
int i;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (x_port >= 0) {
|
|
|
|
lprint("X Redir: X already being redirected.\r\n");
|
|
|
|
show_x(0, 0);
|
|
|
|
} else {
|
|
|
|
for (i = 6001 + (start_port-1); i <= 6100; i++) {
|
|
|
|
if (solisten(htons(i), inaddr, htons(6000 + display), 0)) {
|
|
|
|
/* Success */
|
|
|
|
x_port = i - 6000;
|
|
|
|
x_display = display;
|
|
|
|
x_screen = screen;
|
|
|
|
show_x(0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lprint("X Redir: Error: Couldn't redirect a port for X. Weird.\r\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get our IP address and put it in our_addr
|
|
|
|
*/
|
|
|
|
void
|
2009-03-07 18:32:56 +03:00
|
|
|
getouraddr(void)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
char buff[256];
|
2006-04-23 23:41:17 +04:00
|
|
|
struct hostent *he = NULL;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2006-04-23 23:41:17 +04:00
|
|
|
if (gethostname(buff,256) == 0)
|
|
|
|
he = gethostbyname(buff);
|
|
|
|
if (he)
|
|
|
|
our_addr = *(struct in_addr *)he->h_addr;
|
2006-05-03 23:58:17 +04:00
|
|
|
if (our_addr.s_addr == 0)
|
|
|
|
our_addr.s_addr = loopback_addr.s_addr;
|
2004-04-22 04:10:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct quehead {
|
|
|
|
struct quehead *qh_link;
|
|
|
|
struct quehead *qh_rlink;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void
|
2009-03-07 18:32:56 +03:00
|
|
|
insque(void *a, void *b)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
register struct quehead *element = (struct quehead *) a;
|
|
|
|
register struct quehead *head = (struct quehead *) b;
|
|
|
|
element->qh_link = head->qh_link;
|
|
|
|
head->qh_link = (struct quehead *)element;
|
|
|
|
element->qh_rlink = (struct quehead *)head;
|
|
|
|
((struct quehead *)(element->qh_link))->qh_rlink
|
|
|
|
= (struct quehead *)element;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2009-03-07 18:32:56 +03:00
|
|
|
remque(void *a)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
register struct quehead *element = (struct quehead *) a;
|
|
|
|
((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
|
|
|
|
((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
|
|
|
|
element->qh_rlink = NULL;
|
|
|
|
/* element->qh_link = NULL; TCP FIN1 crashes if you do this. Why ? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* #endif */
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2009-03-07 18:32:56 +03:00
|
|
|
add_exec(struct ex_list **ex_ptr, int do_pty, char *exec, int addr, int port)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
struct ex_list *tmp_ptr;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* First, check if the port is "bound" */
|
|
|
|
for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
|
|
|
|
if (port == tmp_ptr->ex_fport && addr == tmp_ptr->ex_addr)
|
|
|
|
return -1;
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
tmp_ptr = *ex_ptr;
|
|
|
|
*ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
|
|
|
|
(*ex_ptr)->ex_fport = port;
|
|
|
|
(*ex_ptr)->ex_addr = addr;
|
|
|
|
(*ex_ptr)->ex_pty = do_pty;
|
2009-01-08 22:18:21 +03:00
|
|
|
(*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
|
2004-04-22 04:10:48 +04:00
|
|
|
(*ex_ptr)->ex_next = tmp_ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_STRERROR
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For systems with no strerror
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern int sys_nerr;
|
|
|
|
extern char *sys_errlist[];
|
|
|
|
|
|
|
|
char *
|
|
|
|
strerror(error)
|
|
|
|
int error;
|
|
|
|
{
|
|
|
|
if (error < sys_nerr)
|
|
|
|
return sys_errlist[error];
|
|
|
|
else
|
|
|
|
return "Unknown error.";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2004-09-06 03:10:26 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
int
|
2007-10-26 23:01:16 +04:00
|
|
|
fork_exec(struct socket *so, const char *ex, int do_pty)
|
2004-09-06 03:10:26 +04:00
|
|
|
{
|
|
|
|
/* not implemented */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2007-10-26 23:01:16 +04:00
|
|
|
#ifndef CONFIG_QEMU
|
2004-04-22 04:10:48 +04:00
|
|
|
int
|
2004-10-10 22:00:00 +04:00
|
|
|
slirp_openpty(amaster, aslave)
|
|
|
|
int *amaster, *aslave;
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
register int master, slave;
|
|
|
|
|
|
|
|
#ifdef HAVE_GRANTPT
|
|
|
|
char *ptr;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if ((master = open("/dev/ptmx", O_RDWR)) < 0 ||
|
|
|
|
grantpt(master) < 0 ||
|
|
|
|
unlockpt(master) < 0 ||
|
|
|
|
(ptr = ptsname(master)) == NULL) {
|
|
|
|
close(master);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if ((slave = open(ptr, O_RDWR)) < 0 ||
|
|
|
|
ioctl(slave, I_PUSH, "ptem") < 0 ||
|
|
|
|
ioctl(slave, I_PUSH, "ldterm") < 0 ||
|
|
|
|
ioctl(slave, I_PUSH, "ttcompat") < 0) {
|
|
|
|
close(master);
|
|
|
|
close(slave);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
*amaster = master;
|
|
|
|
*aslave = slave;
|
|
|
|
return 0;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
#else
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
static char line[] = "/dev/ptyXX";
|
|
|
|
register const char *cp1, *cp2;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
for (cp1 = "pqrsPQRS"; *cp1; cp1++) {
|
|
|
|
line[8] = *cp1;
|
|
|
|
for (cp2 = "0123456789abcdefghijklmnopqrstuv"; *cp2; cp2++) {
|
|
|
|
line[9] = *cp2;
|
|
|
|
if ((master = open(line, O_RDWR, 0)) == -1) {
|
|
|
|
if (errno == ENOENT)
|
|
|
|
return (-1); /* out of ptys */
|
|
|
|
} else {
|
|
|
|
line[5] = 't';
|
|
|
|
/* These will fail */
|
|
|
|
(void) chown(line, getuid(), 0);
|
|
|
|
(void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
|
|
|
|
#ifdef HAVE_REVOKE
|
|
|
|
(void) revoke(line);
|
|
|
|
#endif
|
|
|
|
if ((slave = open(line, O_RDWR, 0)) != -1) {
|
|
|
|
*amaster = master;
|
|
|
|
*aslave = slave;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
(void) close(master);
|
|
|
|
line[5] = 'p';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errno = ENOENT; /* out of ptys */
|
|
|
|
return (-1);
|
|
|
|
#endif
|
|
|
|
}
|
2007-10-26 23:01:16 +04:00
|
|
|
#endif
|
2004-04-22 04:10:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX This is ugly
|
|
|
|
* We create and bind a socket, then fork off to another
|
|
|
|
* process, which connects to this socket, after which we
|
|
|
|
* exec the wanted program. If something (strange) happens,
|
|
|
|
* the accept() call could block us forever.
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-04-22 04:10:48 +04:00
|
|
|
* do_pty = 0 Fork/exec inetd style
|
|
|
|
* do_pty = 1 Fork/exec using slirp.telnetd
|
|
|
|
* do_ptr = 2 Fork/exec using pty
|
|
|
|
*/
|
|
|
|
int
|
2007-10-26 23:01:16 +04:00
|
|
|
fork_exec(struct socket *so, const char *ex, int do_pty)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct sockaddr_in addr;
|
2008-05-10 05:49:53 +04:00
|
|
|
socklen_t addrlen = sizeof(addr);
|
2004-04-22 04:10:48 +04:00
|
|
|
int opt;
|
2007-10-26 23:01:16 +04:00
|
|
|
int master = -1;
|
2008-09-14 10:45:34 +04:00
|
|
|
const char *argv[256];
|
2004-09-06 03:10:26 +04:00
|
|
|
#if 0
|
2004-04-22 04:10:48 +04:00
|
|
|
char buff[256];
|
2004-09-06 03:10:26 +04:00
|
|
|
#endif
|
2004-04-22 04:10:48 +04:00
|
|
|
/* don't want to clobber the original */
|
|
|
|
char *bptr;
|
2007-10-26 23:01:16 +04:00
|
|
|
const char *curarg;
|
2004-12-12 14:45:10 +03:00
|
|
|
int c, i, ret;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
DEBUG_CALL("fork_exec");
|
|
|
|
DEBUG_ARG("so = %lx", (long)so);
|
|
|
|
DEBUG_ARG("ex = %lx", (long)ex);
|
|
|
|
DEBUG_ARG("do_pty = %lx", (long)do_pty);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (do_pty == 2) {
|
2007-10-26 23:01:16 +04:00
|
|
|
#if 0
|
2004-10-10 22:00:00 +04:00
|
|
|
if (slirp_openpty(&master, &s) == -1) {
|
2004-04-22 04:10:48 +04:00
|
|
|
lprint("Error: openpty failed: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-13 04:56:12 +03:00
|
|
|
#else
|
|
|
|
return 0;
|
2007-10-26 23:01:16 +04:00
|
|
|
#endif
|
2004-04-22 04:10:48 +04:00
|
|
|
} else {
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = 0;
|
|
|
|
addr.sin_addr.s_addr = INADDR_ANY;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
|
|
|
|
bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
|
|
|
|
listen(s, 1) < 0) {
|
|
|
|
lprint("Error: inet socket: %s\n", strerror(errno));
|
2004-07-13 02:33:07 +04:00
|
|
|
closesocket(s);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
switch(fork()) {
|
|
|
|
case -1:
|
|
|
|
lprint("Error: fork failed: %s\n", strerror(errno));
|
|
|
|
close(s);
|
|
|
|
if (do_pty == 2)
|
|
|
|
close(master);
|
|
|
|
return 0;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
case 0:
|
|
|
|
/* Set the DISPLAY */
|
|
|
|
if (do_pty == 2) {
|
|
|
|
(void) close(master);
|
|
|
|
#ifdef TIOCSCTTY /* XXXXX */
|
|
|
|
(void) setsid();
|
|
|
|
ioctl(s, TIOCSCTTY, (char *)NULL);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
getsockname(s, (struct sockaddr *)&addr, &addrlen);
|
|
|
|
close(s);
|
|
|
|
/*
|
|
|
|
* Connect to the socket
|
|
|
|
* XXX If any of these fail, we're in trouble!
|
|
|
|
*/
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
addr.sin_addr = loopback_addr;
|
2004-12-12 14:45:10 +03:00
|
|
|
do {
|
|
|
|
ret = connect(s, (struct sockaddr *)&addr, addrlen);
|
|
|
|
} while (ret < 0 && errno == EINTR);
|
2004-04-22 04:10:48 +04:00
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-09-06 03:10:26 +04:00
|
|
|
#if 0
|
2004-04-22 04:10:48 +04:00
|
|
|
if (x_port >= 0) {
|
|
|
|
#ifdef HAVE_SETENV
|
|
|
|
sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
|
|
|
|
setenv("DISPLAY", buff, 1);
|
|
|
|
#else
|
|
|
|
sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
|
|
|
|
putenv(buff);
|
|
|
|
#endif
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
#endif
|
2004-04-22 04:10:48 +04:00
|
|
|
dup2(s, 0);
|
|
|
|
dup2(s, 1);
|
|
|
|
dup2(s, 2);
|
2007-10-26 23:01:16 +04:00
|
|
|
for (s = getdtablesize() - 1; s >= 3; s--)
|
2004-04-22 04:10:48 +04:00
|
|
|
close(s);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
i = 0;
|
|
|
|
bptr = strdup(ex); /* No need to free() this */
|
|
|
|
if (do_pty == 1) {
|
|
|
|
/* Setup "slirp.telnetd -x" */
|
|
|
|
argv[i++] = "slirp.telnetd";
|
|
|
|
argv[i++] = "-x";
|
|
|
|
argv[i++] = bptr;
|
|
|
|
} else
|
|
|
|
do {
|
|
|
|
/* Change the string into argv[] */
|
|
|
|
curarg = bptr;
|
|
|
|
while (*bptr != ' ' && *bptr != (char)0)
|
|
|
|
bptr++;
|
|
|
|
c = *bptr;
|
|
|
|
*bptr++ = (char)0;
|
|
|
|
argv[i++] = strdup(curarg);
|
|
|
|
} while (c);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2009-03-07 18:32:56 +03:00
|
|
|
argv[i] = NULL;
|
2008-09-14 10:45:34 +04:00
|
|
|
execvp(argv[0], (char **)argv);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Ooops, failed, let's tell the user why */
|
|
|
|
{
|
|
|
|
char buff[256];
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2008-08-21 21:58:08 +04:00
|
|
|
snprintf(buff, sizeof(buff),
|
|
|
|
"Error: execvp of %s failed: %s\n",
|
|
|
|
argv[0], strerror(errno));
|
2004-04-22 04:10:48 +04:00
|
|
|
write(2, buff, strlen(buff)+1);
|
|
|
|
}
|
|
|
|
close(0); close(1); close(2); /* XXX */
|
|
|
|
exit(1);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
default:
|
|
|
|
if (do_pty == 2) {
|
|
|
|
close(s);
|
|
|
|
so->s = master;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* XXX this could block us...
|
|
|
|
* XXX Should set a timer here, and if accept() doesn't
|
|
|
|
* return after X seconds, declare it a failure
|
|
|
|
* The only reason this will block forever is if socket()
|
|
|
|
* of connect() fail in the child process
|
|
|
|
*/
|
2004-12-12 14:45:10 +03:00
|
|
|
do {
|
|
|
|
so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
|
|
|
|
} while (so->s < 0 && errno == EINTR);
|
|
|
|
closesocket(s);
|
2004-04-22 04:10:48 +04:00
|
|
|
opt = 1;
|
|
|
|
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
|
|
|
|
opt = 1;
|
|
|
|
setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
|
|
|
|
}
|
|
|
|
fd_nonblock(so->s);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Append the telnet options now */
|
2009-03-07 18:32:56 +03:00
|
|
|
if (so->so_m != NULL && do_pty == 1) {
|
2004-04-22 04:10:48 +04:00
|
|
|
sbappend(so, so->so_m);
|
2009-03-07 18:32:56 +03:00
|
|
|
so->so_m = NULL;
|
2004-04-22 04:10:48 +04:00
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRDUP
|
|
|
|
char *
|
|
|
|
strdup(str)
|
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
char *bptr;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
bptr = (char *)malloc(strlen(str)+1);
|
|
|
|
strcpy(bptr, str);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
return bptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void
|
|
|
|
snooze_hup(num)
|
|
|
|
int num;
|
|
|
|
{
|
|
|
|
int s, ret;
|
|
|
|
#ifndef NO_UNIX_SOCKETS
|
|
|
|
struct sockaddr_un sock_un;
|
|
|
|
#endif
|
|
|
|
struct sockaddr_in sock_in;
|
|
|
|
char buff[256];
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
ret = -1;
|
|
|
|
if (slirp_socket_passwd) {
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
slirp_exit(1);
|
|
|
|
sock_in.sin_family = AF_INET;
|
|
|
|
sock_in.sin_addr.s_addr = slirp_socket_addr;
|
|
|
|
sock_in.sin_port = htons(slirp_socket_port);
|
|
|
|
if (connect(s, (struct sockaddr *)&sock_in, sizeof(sock_in)) != 0)
|
|
|
|
slirp_exit(1); /* just exit...*/
|
|
|
|
sprintf(buff, "kill %s:%d", slirp_socket_passwd, slirp_socket_unit);
|
|
|
|
write(s, buff, strlen(buff)+1);
|
|
|
|
}
|
|
|
|
#ifndef NO_UNIX_SOCKETS
|
|
|
|
else {
|
|
|
|
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
slirp_exit(1);
|
|
|
|
sock_un.sun_family = AF_UNIX;
|
|
|
|
strcpy(sock_un.sun_path, socket_path);
|
|
|
|
if (connect(s, (struct sockaddr *)&sock_un,
|
|
|
|
sizeof(sock_un.sun_family) + sizeof(sock_un.sun_path)) != 0)
|
|
|
|
slirp_exit(1);
|
|
|
|
sprintf(buff, "kill none:%d", slirp_socket_unit);
|
|
|
|
write(s, buff, strlen(buff)+1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
slirp_exit(0);
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
void
|
|
|
|
snooze()
|
|
|
|
{
|
|
|
|
sigset_t s;
|
|
|
|
int i;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Don't need our data anymore */
|
|
|
|
/* XXX This makes SunOS barf */
|
|
|
|
/* brk(0); */
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Close all fd's */
|
|
|
|
for (i = 255; i >= 0; i--)
|
|
|
|
close(i);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
signal(SIGQUIT, slirp_exit);
|
|
|
|
signal(SIGHUP, snooze_hup);
|
|
|
|
sigemptyset(&s);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Wait for any signal */
|
|
|
|
sigsuspend(&s);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Just in case ... */
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
relay(s)
|
|
|
|
int s;
|
|
|
|
{
|
|
|
|
char buf[8192];
|
|
|
|
int n;
|
|
|
|
fd_set readfds;
|
|
|
|
struct ttys *ttyp;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Don't need our data anymore */
|
|
|
|
/* XXX This makes SunOS barf */
|
|
|
|
/* brk(0); */
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
signal(SIGQUIT, slirp_exit);
|
|
|
|
signal(SIGHUP, slirp_exit);
|
|
|
|
signal(SIGINT, slirp_exit);
|
|
|
|
signal(SIGTERM, slirp_exit);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Fudge to get term_raw and term_restore to work */
|
|
|
|
if (NULL == (ttyp = tty_attach (0, slirp_tty))) {
|
|
|
|
lprint ("Error: tty_attach failed in misc.c:relay()\r\n");
|
|
|
|
slirp_exit (1);
|
|
|
|
}
|
|
|
|
ttyp->fd = 0;
|
|
|
|
ttyp->flags |= TTY_CTTY;
|
|
|
|
term_raw(ttyp);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
while (1) {
|
|
|
|
FD_ZERO(&readfds);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
FD_SET(0, &readfds);
|
|
|
|
FD_SET(s, &readfds);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (n <= 0)
|
|
|
|
slirp_exit(0);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (FD_ISSET(0, &readfds)) {
|
|
|
|
n = read(0, buf, 8192);
|
|
|
|
if (n <= 0)
|
|
|
|
slirp_exit(0);
|
|
|
|
n = writen(s, buf, n);
|
|
|
|
if (n <= 0)
|
|
|
|
slirp_exit(0);
|
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (FD_ISSET(s, &readfds)) {
|
|
|
|
n = read(s, buf, 8192);
|
|
|
|
if (n <= 0)
|
|
|
|
slirp_exit(0);
|
|
|
|
n = writen(0, buf, n);
|
|
|
|
if (n <= 0)
|
|
|
|
slirp_exit(0);
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Just in case.... */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-26 22:42:59 +04:00
|
|
|
#ifdef CONFIG_QEMU
|
2009-03-06 02:01:23 +03:00
|
|
|
#include "monitor.h"
|
2007-10-31 02:19:52 +03:00
|
|
|
|
2007-10-26 22:42:59 +04:00
|
|
|
void lprint(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_vprintf(cur_mon, format, args);
|
2007-10-26 22:42:59 +04:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
#else
|
2004-04-22 04:10:48 +04:00
|
|
|
int (*lprint_print) _P((void *, const char *, va_list));
|
|
|
|
char *lprint_ptr, *lprint_ptr2, **lprint_arg;
|
|
|
|
|
|
|
|
void
|
|
|
|
#ifdef __STDC__
|
|
|
|
lprint(const char *format, ...)
|
|
|
|
#else
|
|
|
|
lprint(va_alist) va_dcl
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
va_list args;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
#ifdef __STDC__
|
|
|
|
va_start(args, format);
|
|
|
|
#else
|
|
|
|
char *format;
|
|
|
|
va_start(args);
|
|
|
|
format = va_arg(args, char *);
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
/* If we're printing to an sbuf, make sure there's enough room */
|
|
|
|
/* XXX +100? */
|
|
|
|
if (lprint_sb) {
|
|
|
|
if ((lprint_ptr - lprint_sb->sb_wptr) >=
|
|
|
|
(lprint_sb->sb_datalen - (strlen(format) + 100))) {
|
|
|
|
int deltaw = lprint_sb->sb_wptr - lprint_sb->sb_data;
|
|
|
|
int deltar = lprint_sb->sb_rptr - lprint_sb->sb_data;
|
|
|
|
int deltap = lprint_ptr - lprint_sb->sb_data;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
lprint_sb->sb_data = (char *)realloc(lprint_sb->sb_data,
|
|
|
|
lprint_sb->sb_datalen + TCP_SNDSPACE);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Adjust all values */
|
|
|
|
lprint_sb->sb_wptr = lprint_sb->sb_data + deltaw;
|
|
|
|
lprint_sb->sb_rptr = lprint_sb->sb_data + deltar;
|
|
|
|
lprint_ptr = lprint_sb->sb_data + deltap;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
lprint_sb->sb_datalen += TCP_SNDSPACE;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
#endif
|
2004-04-22 04:10:48 +04:00
|
|
|
if (lprint_print)
|
|
|
|
lprint_ptr += (*lprint_print)(*lprint_arg, format, args);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Check if they want output to be logged to file as well */
|
|
|
|
if (lfd) {
|
2007-09-17 01:08:06 +04:00
|
|
|
/*
|
2004-04-22 04:10:48 +04:00
|
|
|
* Remove \r's
|
|
|
|
* otherwise you'll get ^M all over the file
|
|
|
|
*/
|
|
|
|
int len = strlen(format);
|
|
|
|
char *bptr1, *bptr2;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
bptr1 = bptr2 = strdup(format);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
while (len--) {
|
|
|
|
if (*bptr1 == '\r')
|
|
|
|
memcpy(bptr1, bptr1+1, len+1);
|
|
|
|
else
|
|
|
|
bptr1++;
|
|
|
|
}
|
|
|
|
vfprintf(lfd, bptr2, args);
|
|
|
|
free(bptr2);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_emu(buff)
|
|
|
|
char *buff;
|
|
|
|
{
|
|
|
|
u_int lport, fport;
|
|
|
|
u_int8_t tos = 0, emu = 0;
|
|
|
|
char buff1[256], buff2[256], buff4[128];
|
|
|
|
char *buff3 = buff4;
|
|
|
|
struct emu_t *emup;
|
|
|
|
struct socket *so;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (sscanf(buff, "%256s %256s", buff2, buff1) != 2) {
|
|
|
|
lprint("Error: Bad arguments\r\n");
|
|
|
|
return;
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (sscanf(buff1, "%d:%d", &lport, &fport) != 2) {
|
|
|
|
lport = 0;
|
|
|
|
if (sscanf(buff1, "%d", &fport) != 1) {
|
|
|
|
lprint("Error: Bad first argument\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (sscanf(buff2, "%128[^:]:%128s", buff1, buff3) != 2) {
|
|
|
|
buff3 = 0;
|
|
|
|
if (sscanf(buff2, "%256s", buff1) != 1) {
|
|
|
|
lprint("Error: Bad second argument\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (buff3) {
|
|
|
|
if (strcmp(buff3, "lowdelay") == 0)
|
|
|
|
tos = IPTOS_LOWDELAY;
|
|
|
|
else if (strcmp(buff3, "throughput") == 0)
|
|
|
|
tos = IPTOS_THROUGHPUT;
|
|
|
|
else {
|
|
|
|
lprint("Error: Expecting \"lowdelay\"/\"throughput\"\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (strcmp(buff1, "ftp") == 0)
|
|
|
|
emu = EMU_FTP;
|
|
|
|
else if (strcmp(buff1, "irc") == 0)
|
|
|
|
emu = EMU_IRC;
|
|
|
|
else if (strcmp(buff1, "none") == 0)
|
|
|
|
emu = EMU_NONE; /* ie: no emulation */
|
|
|
|
else {
|
|
|
|
lprint("Error: Unknown service\r\n");
|
|
|
|
return;
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* First, check that it isn't already emulated */
|
|
|
|
for (emup = tcpemu; emup; emup = emup->next) {
|
|
|
|
if (emup->lport == lport && emup->fport == fport) {
|
|
|
|
lprint("Error: port already emulated\r\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* link it */
|
|
|
|
emup = (struct emu_t *)malloc(sizeof (struct emu_t));
|
|
|
|
emup->lport = (u_int16_t)lport;
|
|
|
|
emup->fport = (u_int16_t)fport;
|
|
|
|
emup->tos = tos;
|
|
|
|
emup->emu = emu;
|
|
|
|
emup->next = tcpemu;
|
|
|
|
tcpemu = emup;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* And finally, mark all current sessions, if any, as being emulated */
|
|
|
|
for (so = tcb.so_next; so != &tcb; so = so->so_next) {
|
|
|
|
if ((lport && lport == ntohs(so->so_lport)) ||
|
|
|
|
(fport && fport == ntohs(so->so_fport))) {
|
|
|
|
if (emu)
|
|
|
|
so->so_emu = emu;
|
|
|
|
if (tos)
|
|
|
|
so->so_iptos = tos;
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport);
|
|
|
|
}
|
2007-10-26 22:42:59 +04:00
|
|
|
#endif
|
2004-04-22 04:10:48 +04:00
|
|
|
|
|
|
|
#ifdef BAD_SPRINTF
|
|
|
|
|
|
|
|
#undef vsprintf
|
|
|
|
#undef sprintf
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some BSD-derived systems have a sprintf which returns char *
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
vsprintf_len(string, format, args)
|
|
|
|
char *string;
|
|
|
|
const char *format;
|
|
|
|
va_list args;
|
|
|
|
{
|
|
|
|
vsprintf(string, format, args);
|
|
|
|
return strlen(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
#ifdef __STDC__
|
|
|
|
sprintf_len(char *string, const char *format, ...)
|
|
|
|
#else
|
|
|
|
sprintf_len(va_alist) va_dcl
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
#ifdef __STDC__
|
|
|
|
va_start(args, format);
|
|
|
|
#else
|
|
|
|
char *string;
|
|
|
|
char *format;
|
|
|
|
va_start(args);
|
|
|
|
string = va_arg(args, char *);
|
|
|
|
format = va_arg(args, char *);
|
|
|
|
#endif
|
|
|
|
vsprintf(string, format, args);
|
|
|
|
return strlen(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2009-03-07 18:32:56 +03:00
|
|
|
u_sleep(int usec)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
struct timeval t;
|
|
|
|
fd_set fdset;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
FD_ZERO(&fdset);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
t.tv_sec = 0;
|
|
|
|
t.tv_usec = usec * 1000;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
select(0, &fdset, &fdset, &fdset, &t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set fd blocking and non-blocking
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2009-03-07 18:32:56 +03:00
|
|
|
fd_nonblock(int fd)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
#ifdef FIONBIO
|
2009-04-05 22:03:31 +04:00
|
|
|
#ifdef _WIN32
|
2009-06-13 12:44:31 +04:00
|
|
|
unsigned long opt = 1;
|
2009-04-05 22:03:31 +04:00
|
|
|
#else
|
|
|
|
int opt = 1;
|
|
|
|
#endif
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-07-13 02:33:07 +04:00
|
|
|
ioctlsocket(fd, FIONBIO, &opt);
|
2004-04-22 04:10:48 +04:00
|
|
|
#else
|
|
|
|
int opt;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
opt = fcntl(fd, F_GETFL, 0);
|
|
|
|
opt |= O_NONBLOCK;
|
|
|
|
fcntl(fd, F_SETFL, opt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-07 18:32:56 +03:00
|
|
|
fd_block(int fd)
|
2004-04-22 04:10:48 +04:00
|
|
|
{
|
|
|
|
#ifdef FIONBIO
|
2009-06-13 12:44:31 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
unsigned long opt = 0;
|
|
|
|
#else
|
2004-04-22 04:10:48 +04:00
|
|
|
int opt = 0;
|
2009-06-13 12:44:31 +04:00
|
|
|
#endif
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-07-13 02:33:07 +04:00
|
|
|
ioctlsocket(fd, FIONBIO, &opt);
|
2004-04-22 04:10:48 +04:00
|
|
|
#else
|
|
|
|
int opt;
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
opt = fcntl(fd, F_GETFL, 0);
|
|
|
|
opt &= ~O_NONBLOCK;
|
|
|
|
fcntl(fd, F_SETFL, opt);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* invoke RSH
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rsh_exec(so,ns, user, host, args)
|
|
|
|
struct socket *so;
|
|
|
|
struct socket *ns;
|
|
|
|
char *user;
|
|
|
|
char *host;
|
|
|
|
char *args;
|
|
|
|
{
|
|
|
|
int fd[2];
|
|
|
|
int fd0[2];
|
|
|
|
int s;
|
|
|
|
char buff[256];
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
DEBUG_CALL("rsh_exec");
|
|
|
|
DEBUG_ARG("so = %lx", (long)so);
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
if (pipe(fd)<0) {
|
|
|
|
lprint("Error: pipe failed: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* #ifdef HAVE_SOCKETPAIR */
|
|
|
|
#if 1
|
|
|
|
if (socketpair(PF_UNIX,SOCK_STREAM,0, fd0) == -1) {
|
|
|
|
close(fd[0]);
|
|
|
|
close(fd[1]);
|
|
|
|
lprint("Error: openpty failed: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2004-10-10 22:00:00 +04:00
|
|
|
if (slirp_openpty(&fd0[0], &fd0[1]) == -1) {
|
2004-04-22 04:10:48 +04:00
|
|
|
close(fd[0]);
|
|
|
|
close(fd[1]);
|
|
|
|
lprint("Error: openpty failed: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-17 01:08:06 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
switch(fork()) {
|
|
|
|
case -1:
|
|
|
|
lprint("Error: fork failed: %s\n", strerror(errno));
|
|
|
|
close(fd[0]);
|
|
|
|
close(fd[1]);
|
|
|
|
close(fd0[0]);
|
|
|
|
close(fd0[1]);
|
|
|
|
return 0;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
case 0:
|
|
|
|
close(fd[0]);
|
|
|
|
close(fd0[0]);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Set the DISPLAY */
|
|
|
|
if (x_port >= 0) {
|
|
|
|
#ifdef HAVE_SETENV
|
|
|
|
sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
|
|
|
|
setenv("DISPLAY", buff, 1);
|
|
|
|
#else
|
|
|
|
sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
|
|
|
|
putenv(buff);
|
|
|
|
#endif
|
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
dup2(fd0[1], 0);
|
|
|
|
dup2(fd0[1], 1);
|
|
|
|
dup2(fd[1], 2);
|
|
|
|
for (s = 3; s <= 255; s++)
|
|
|
|
close(s);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
execlp("rsh","rsh","-l", user, host, args, NULL);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
/* Ooops, failed, let's tell the user why */
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
sprintf(buff, "Error: execlp of %s failed: %s\n",
|
2004-04-22 04:10:48 +04:00
|
|
|
"rsh", strerror(errno));
|
|
|
|
write(2, buff, strlen(buff)+1);
|
|
|
|
close(0); close(1); close(2); /* XXX */
|
|
|
|
exit(1);
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
default:
|
|
|
|
close(fd[1]);
|
|
|
|
close(fd0[1]);
|
|
|
|
ns->s=fd[0];
|
|
|
|
so->s=fd0[0];
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-04-22 04:10:48 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|