summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2008-06-27 10:52:33 +0000
committerMarc Kleine-Budde <mkl@pengutronix.de>2008-06-27 10:52:33 +0000
commit4aacbf94c001a4c080c3f17ec2203b2014acd47d (patch)
tree72fe67d55bea1b909c4aa78ed784c88864433afb
parentc4180ae8e4fbdc28fb2afe45f4654ec98dd1c566 (diff)
downloadurshd-4aacbf94c001a4c080c3f17ec2203b2014acd47d.tar.gz
urshd-4aacbf94c001a4c080c3f17ec2203b2014acd47d.tar.xz
* src/urshd.c:
ignore SIGCHLD, so no more defunct childrem cleanups
-rw-r--r--src/urshd.c99
1 files changed, 57 insertions, 42 deletions
diff --git a/src/urshd.c b/src/urshd.c
index 4c35456..7e71dac 100644
--- a/src/urshd.c
+++ b/src/urshd.c
@@ -31,15 +31,17 @@
* SUCH DAMAGE.
*/
-char copyright[] =
+#if 0
+static char copyright[] =
"@(#) Copyright (c) 1988, 1989 The Regents of the University of California.\n"
"All rights reserved.\n";
/*
* From: @(#)rshd.c 5.38 (Berkeley) 3/2/91
*/
-char rcsid[] =
+static char rcsid[] =
"$Id: rshd.c,v 1.25 2000/07/23 04:16:24 dholland Exp $";
+#endif
/*
* remote shell server:
@@ -99,25 +101,24 @@ char rcsid[] =
#define SYSLOG 2
static struct option long_options[] = {
- { "help", no_argument, 0, 'h' },
- { "disable-keepalive", no_argument, 0, 'n' },
- { "priority", required_argument, 0, 'p' },
- { "command-priority", required_argument, 0, 'P' },
- { 0, 0, 0, 0}
+ { "help", no_argument, NULL, 'h' },
+ { "disable-keepalive", no_argument, NULL, 'n' },
+ { "priority", required_argument, NULL, 'p' },
+ { "command-priority", required_argument, NULL, 'P' },
+ { NULL, 0, NULL, 0}
};
static int keepalive = 1;
static int sent_null;
-static int priority = 0;
-static int cmd_priority = 0;
+static int priority;
+static int cmd_priority;
-char username[20] = "USER=";
-char homedir[64] = "HOME=";
-char shell[64] = "SHELL=";
-char path[100] = "PATH=";
-char *envinit[] =
- {homedir, shell, path, username, 0};
-extern char **environ;
+static char username[20] = "USER=";
+static char homedir[64] = "HOME=";
+static char shell[64] = "SHELL=";
+static char path[100] = "PATH=";
+static char *envinit[] = {homedir, shell, path, username, NULL};
+extern char **environ;
static void error(const char *fmt, ...);
static void doit(struct sockaddr_in *fromp);
@@ -126,10 +127,10 @@ static void getstr(char *buf, int cnt, const char *err);
static void
set_priority(int sched_priority)
{
- struct sched_param schedp;
+ struct sched_param schedp = {
+ .sched_priority = sched_priority,
+ };
- memset(&schedp, 0, sizeof(schedp));
- schedp.sched_priority = sched_priority;
sched_setscheduler(0, SCHED_FIFO, &schedp);
}
@@ -220,8 +221,10 @@ getint(void)
int port = 0;
char c;
do {
- if (read(0, &c, 1) != 1) exit(1);
- if (isascii(c) && isdigit(c)) port = port*10 + c-'0';
+ if (read(0, &c, 1) != 1)
+ exit(1);
+ if (isascii(c) && isdigit(c))
+ port = port*10 + c-'0';
} while (c != 0);
return port;
}
@@ -233,16 +236,19 @@ stderr_parent(int sock, int pype, int pid)
char buf[BUFSIZ], sig;
int one = 1;
int nfd, cc, guys=2;
-
+
ioctl(pype, FIONBIO, (char *)&one);
/* should set s nbio! */
-
+
FD_ZERO(&readfrom);
FD_SET(sock, &readfrom);
FD_SET(pype, &readfrom);
- if (pype > sock) nfd = pype+1;
- else nfd = sock+1;
-
+
+ if (pype > sock)
+ nfd = pype+1;
+ else
+ nfd = sock+1;
+
while (guys > 0) {
ready = readfrom;
if (select(nfd, &ready, NULL, NULL, NULL) < 0) {
@@ -256,8 +262,8 @@ stderr_parent(int sock, int pype, int pid)
if (cc <= 0) {
FD_CLR(sock, &readfrom);
guys--;
- }
- else killpg(pid, sig);
+ } else
+ killpg(pid, sig);
}
if (FD_ISSET(pype, &ready)) {
cc = read(pype, buf, sizeof(buf));
@@ -265,11 +271,14 @@ stderr_parent(int sock, int pype, int pid)
shutdown(sock, 2);
FD_CLR(pype, &readfrom);
guys--;
- }
- else write(sock, buf, cc);
+ } else
+ write(sock, buf, cc);
}
}
+ close(sock);
+ close(pype);
+
exit(0);
}
@@ -352,19 +361,20 @@ doit(struct sockaddr_in *fromp)
exit(1);
}
if (pid) {
- close(0);
+ close(0);
close(1);
- close(2);
+ close(2);
close(pv[1]);
stderr_parent(sock, pv[0], pid);
/* NOTREACHED */
}
setpgrp();
- close(sock);
+ close(sock);
close(pv[0]);
dup2(pv[1], 2);
close(pv[1]);
}
+
theshell = pwd->pw_shell;
if (!theshell || !*theshell) {
/* shouldn't we deny access? */
@@ -402,19 +412,23 @@ doit(struct sockaddr_in *fromp)
username[sizeof(username)-1] = 0;
shellname = strrchr(theshell, '/');
- if (shellname) shellname++;
- else shellname = theshell;
+ if (shellname)
+ shellname++;
+ else
+ shellname = theshell;
endpwent();
+
if (0) {
syslog(LOG_INFO|LOG_AUTH, "%s as %s: cmd='%s'", remuser, locuser, cmdbuf);
}
/*
- * Close all fds, in case libc has left fun stuff like
+ * Close all fds, in case libc has left fun stuff like
* /etc/shadow open.
*/
- for (ifd = getdtablesize()-1; ifd > 2; ifd--) close(ifd);
+ for (ifd = getdtablesize()-1; ifd > 2; ifd--)
+ close(ifd);
if (cmd_priority) {
set_priority(cmd_priority);
@@ -490,11 +504,12 @@ mainloop(char *port)
{
int s;
struct servent *sp;
- struct sockaddr_in sn;
+ struct sockaddr_in sn = {
+ .sin_family = AF_INET,
+ };
int on = 1;
- memset(&sn, 0, sizeof(sn));
- sn.sin_family = AF_INET;
+ signal(SIGCHLD, SIG_IGN);
if (priority) {
set_priority(priority);
@@ -512,7 +527,7 @@ mainloop(char *port)
}
} else {
sp = getservbyname("shell", "tcp");
- if (sp == 0) {
+ if (!sp) {
fatal("tcp/shell: unknown service");
}
sn.sin_port = sp->s_port;
@@ -601,6 +616,6 @@ main(int argc, char *argv[])
usage(STDERR | SYSLOG, "Unexpected argument: %s", argv[optind]);
}
- mainloop(0);
+ mainloop(NULL);
return 0;
}