projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
no more SIOCDONE
[unix-history]
/
usr
/
src
/
libexec
/
rexecd
/
rexecd.c
diff --git
a/usr/src/libexec/rexecd/rexecd.c
b/usr/src/libexec/rexecd/rexecd.c
index
a632b77
..
3156525
100644
(file)
--- a/
usr/src/libexec/rexecd/rexecd.c
+++ b/
usr/src/libexec/rexecd/rexecd.c
@@
-1,22
+1,24
@@
#ifndef lint
#ifndef lint
-static char sccsid[] = "@(#)rexecd.c 4.
1 82/04/02
";
+static char sccsid[] = "@(#)rexecd.c 4.
6 83/01/07
";
#endif
#endif
-#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/socket.h>
-#include <net/in.h>
+
+#include <netinet/in.h>
+
+#include <stdio.h>
#include <errno.h>
#include <pwd.h>
#include <wait.h>
#include <signal.h>
#include <errno.h>
#include <pwd.h>
#include <wait.h>
#include <signal.h>
+#include <netdb.h>
extern errno;
extern errno;
-struct sockaddr_in sin = { AF_INET
, IPPORT_EXECSERVER
};
+struct sockaddr_in sin = { AF_INET };
struct passwd *getpwnam();
char *crypt(), *rindex(), *sprintf();
struct passwd *getpwnam();
char *crypt(), *rindex(), *sprintf();
-int options = SO_ACCEPTCONN|SO_KEEPALIVE;
/* VARARGS 1 */
int error();
/*
/* VARARGS 1 */
int error();
/*
@@
-33,7
+35,14
@@
main(argc, argv)
union wait status;
int f;
struct sockaddr_in from;
union wait status;
int f;
struct sockaddr_in from;
+ struct servent *sp;
+ sp = getservbyname("exec", "tcp");
+ if (sp == 0) {
+ fprintf(stderr, "tcp/exec: unknown service\n");
+ exit(1);
+ }
+ sin.sin_port = sp->s_port;
#ifndef DEBUG
if (fork())
exit(0);
#ifndef DEBUG
if (fork())
exit(0);
@@
-48,31
+57,31
@@
main(argc, argv)
(void) close(t);
}
}
(void) close(t);
}
}
-#endif
-#if vax
- sin.sin_port = htons(sin.sin_port);
#endif
argc--, argv++;
#endif
argc--, argv++;
- if (argc > 0 && !strcmp(argv[0], "-d"))
- options |= SO_DEBUG;
+ f = socket(AF_INET, SOCK_STREAM, 0, 0);
+ if (f < 0) {
+ perror("rexecd: socket");
+ exit(1);
+ }
+ if (bind(f, &sin, sizeof (sin), 0) < 0) {
+ perror("rexecd: bind:");
+ exit(1);
+ }
+ listen(f, 10);
for (;;) {
for (;;) {
- errno = 0;
- f = socket(SOCK_STREAM, 0, &sin, options);
- if (f < 0) {
- perror("socket");
- sleep(5);
- continue;
- }
- if (accept(f, &from) < 0) {
- perror("accept");
- (void) close(f);
+ int s, len = sizeof (from);
+
+ s = accept(f, &from, &len, 0);
+ if (s < 0) {
+ perror("rexecd: accept");
sleep(1);
continue;
}
if (fork() == 0)
sleep(1);
continue;
}
if (fork() == 0)
- doit(
f
, &from);
- (void) close(
f
);
- while(wait3(status, WNOHANG, 0) > 0)
+ doit(
s
, &from);
+ (void) close(
s
);
+ while
(wait3(status, WNOHANG, 0) > 0)
continue;
}
}
continue;
}
}
@@
-113,9
+122,6
@@
doit(f, fromp)
dup2(f, 0);
dup2(f, 1);
dup2(f, 2);
dup2(f, 0);
dup2(f, 1);
dup2(f, 2);
-#if vax
- fromp->sin_port = ntohs((u_short)fromp->sin_port);
-#endif
(void) alarm(60);
port = 0;
for (;;) {
(void) alarm(60);
port = 0;
for (;;) {
@@
-128,15
+134,14
@@
doit(f, fromp)
}
(void) alarm(0);
if (port != 0) {
}
(void) alarm(0);
if (port != 0) {
- s = socket(
SOCK_STREAM, 0, &asin
, 0);
+ s = socket(
AF_INET, SOCK_STREAM, 0
, 0);
if (s < 0)
exit(1);
if (s < 0)
exit(1);
+ if (bind(s, &asin, sizeof (asin), 0) < 0)
+ exit(1);
(void) alarm(60);
(void) alarm(60);
- fromp->sin_port = port;
-#if vax
- fromp->sin_port = ntohs(fromp->sin_port);
-#endif
- if (connect(s, fromp) < 0)
+ fromp->sin_port = htons((u_short)port);
+ if (connect(s, fromp, sizeof (*fromp), 0) < 0)
exit(1);
(void) alarm(0);
}
exit(1);
(void) alarm(0);
}
@@
-177,7
+182,7
@@
doit(f, fromp)
/* should set s nbio! */
do {
ready = readfrom;
/* should set s nbio! */
do {
ready = readfrom;
- (void) select(
32, &ready, 0, 100000
0);
+ (void) select(
16, &ready, 0, 0,
0);
if (ready & (1<<s)) {
if (read(s, &sig, 1) <= 0)
readfrom &= ~(1<<s);
if (ready & (1<<s)) {
if (read(s, &sig, 1) <= 0)
readfrom &= ~(1<<s);
@@
-187,8
+192,7
@@
doit(f, fromp)
if (ready & (1<<pv[0])) {
cc = read(pv[0], buf, sizeof (buf));
if (cc <= 0) {
if (ready & (1<<pv[0])) {
cc = read(pv[0], buf, sizeof (buf));
if (cc <= 0) {
- int done = 1+1;
- ioctl(s, SIOCDONE, (char *)&done);
+ shutdown(s, 1+1);
readfrom &= ~(1<<pv[0]);
} else
(void) write(s, buf, cc);
readfrom &= ~(1<<pv[0]);
} else
(void) write(s, buf, cc);
@@
-203,7
+207,7
@@
doit(f, fromp)
if (*pwd->pw_shell == '\0')
pwd->pw_shell = "/bin/sh";
(void) close(f);
if (*pwd->pw_shell == '\0')
pwd->pw_shell = "/bin/sh";
(void) close(f);
- ini
grp
(pwd->pw_name, pwd->pw_gid);
+ ini
tgroups
(pwd->pw_name, pwd->pw_gid);
(void) setuid(pwd->pw_uid);
(void) setgid(pwd->pw_gid);
environ = envinit;
(void) setuid(pwd->pw_uid);
(void) setgid(pwd->pw_gid);
environ = envinit;