slackware-current/source/n/inetd/inetd-OpenBSD-1.79.diff
Patrick J Volkerding 5a12e7c134 Slackware 13.0
Wed Aug 26 10:00:38 CDT 2009
Slackware 13.0 x86_64 is released as stable!  Thanks to everyone who
helped make this release possible -- see the RELEASE_NOTES for the
credits.  The ISOs are off to the replicator.  This time it will be a
6 CD-ROM 32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD.
We're taking pre-orders now at store.slackware.com.  Please consider
picking up a copy to help support the project.  Once again, thanks to
the entire Slackware community for all the help testing and fixing
things and offering suggestions during this development cycle.
As always, have fun and enjoy!  -P.
2018-05-31 22:41:17 +02:00

890 lines
21 KiB
Diff

--- ./inetd.c.orig Tue Jan 30 20:00:10 2001
+++ ./inetd.c Tue Feb 6 17:17:14 2001
@@ -1,3 +1,4 @@
+/* $Slackware: inetd.c 1.79s 2001/02/06 13:18:00 volkerdi Exp $ */
/* $OpenBSD: inetd.c,v 1.79 2001/01/30 08:30:57 deraadt Exp $ */
/* $NetBSD: inetd.c,v 1.11 1996/02/22 11:14:41 mycroft Exp $ */
/*
@@ -40,8 +41,9 @@
#endif /* not lint */
#ifndef lint
-/*static char sccsid[] = "from: @(#)inetd.c 5.30 (Berkeley) 6/3/91";*/
+static char sccsid[] = "from: @(#)inetd.c 5.30 (Berkeley) 6/3/91";
static char rcsid[] = "$OpenBSD: inetd.c,v 1.79 2001/01/30 08:30:57 deraadt Exp $";
+static char xtraid[] = "$Slackware: inetd.c 1.79s 2001/02/06 13:18:00 volkerdi Exp $";
#endif /* not lint */
/*
@@ -163,7 +165,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <login_cap.h>
+/* #include <login_cap.h> */
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpcsvc/nfs_prot.h>
@@ -176,17 +178,20 @@
#define SIGBLOCK (sigmask(SIGCHLD)|sigmask(SIGHUP)|sigmask(SIGALRM))
void config __P((int));
-void doconfig __P((void));
-void reap __P((int));
-void doreap __P((void));
+/* void doconfig __P((void)); */
+/* void reap __P((int)); */
+/* void doreap __P((void)); */
+void reapchild __P ((int));
void retry __P((int));
-void doretry __P((void));
+/* void doretry __P((void)); */
void goaway __P((int));
-int debug = 0;
+static int debug = 0;
+static int global_queuelen = 128;
int nsock, maxsock;
-fd_set *allsockp;
-int allsockn;
+/* fd_set *allsockp; */
+fd_set allsock;
+/* int allsockn; */
int toomany = TOOMANY;
int options;
int timingout;
@@ -230,13 +235,13 @@
struct sockaddr_in se_un_ctrladdr_in;
struct sockaddr_in6 se_un_ctrladdr_in6;
struct sockaddr_un se_un_ctrladdr_un;
- struct sockaddr_storage se_un_ctrladdr_storage;
+ /* struct sockaddr_storage se_un_ctrladdr_storage; */
} se_un; /* bound address */
#define se_ctrladdr se_un.se_un_ctrladdr
#define se_ctrladdr_in se_un.se_un_ctrladdr_in
#define se_ctrladdr_in6 se_un.se_un_ctrladdr_in6
#define se_ctrladdr_un se_un.se_un_ctrladdr_un
-#define se_ctrladdr_storage se_un.se_un_ctrladdr_storage
+/* #define se_ctrladdr_storage se_un.se_un_ctrladdr_storage */
int se_ctrladdr_size;
int se_max; /* max # of instances of this service */
int se_count; /* number started since se_time */
@@ -282,12 +287,12 @@
{ "chargen", SOCK_STREAM, 1, 0, chargen_stream },
{ "chargen", SOCK_DGRAM, 0, 0, chargen_dg },
- { 0 }
+ { NULL, 0, 0, 0, NULL }
};
-sig_atomic_t wantretry;
-sig_atomic_t wantconfig;
-sig_atomic_t wantreap;
+/* sig_atomic_t wantretry; */
+/* sig_atomic_t wantconfig; */
+/* sig_atomic_t wantreap; */
#define NUMINT (sizeof(intab) / sizeof(struct inent))
char *CONFIG = _PATH_INETDCONF;
@@ -297,6 +302,8 @@
void logpid __P((void));
+/* This function is unused in the Linux port */
+#ifdef OpenBSD
void
fd_grow(fd_set **fdsp, int *bytes, int fd)
{
@@ -316,24 +323,26 @@
*bytes = newbytes;
}
}
+#endif
int
main(argc, argv, envp)
int argc;
char *argv[], *envp[];
{
- extern char *optarg;
- extern int optind;
+ /* extern char *optarg; */
+ /* extern int optind; */
register struct servtab *sep;
register struct passwd *pwd;
register struct group *grp = NULL;
register int tmpint;
struct sigaction sa, sapipe;
int ch, dofork;
+ int nodaemon = 0;
pid_t pid;
char buf[50];
- fd_set *readablep = NULL;
- int readablen = 0;
+ /* fd_set *readablep = NULL; */
+ /* int readablen = 0; */
Argv = argv;
if (envp == 0 || *envp == 0)
@@ -356,7 +365,7 @@
int val;
val = strtoul(optarg, &p, 0);
- if (val >= 1 && *p == NULL) {
+ if (val >= 1 && *p == (char) NULL) {
toomany = val;
break;
}
@@ -385,10 +394,13 @@
exit(1);
}
- if (debug == 0) {
- daemon(0, 0);
- if (uid == 0)
- (void) setlogin("");
+ if (nodaemon == 0)
+ daemon (0, 0);
+ else if (debug == 0) {
+ /* daemon(0, 0); */
+ /* if (uid == 0) */
+ /* (void) setlogin(""); */
+ setsid ();
}
if (uid == 0) {
@@ -418,10 +430,12 @@
sigaddset(&sa.sa_mask, SIGHUP);
sa.sa_handler = retry;
sigaction(SIGALRM, &sa, NULL);
- doconfig();
+ /* doconfig(); */
+ config (SIGHUP);
sa.sa_handler = config;
sigaction(SIGHUP, &sa, NULL);
- sa.sa_handler = reap;
+ /* sa.sa_handler = reap; */
+ sa.sa_handler = reapchild;
sigaction(SIGCHLD, &sa, NULL);
sa.sa_handler = goaway;
sigaction(SIGTERM, &sa, NULL);
@@ -443,6 +457,7 @@
for (;;) {
int n, ctrl = -1;
+ fd_set readable;
if (nsock == 0) {
(void) sigblock(SIGBLOCK);
@@ -451,6 +466,8 @@
(void) sigsetmask(0L);
}
+ /* Well, this all looks like cruft to me ;^) */
+#ifdef OpenBSD
if (readablen != allsockn) {
if (readablep)
free(readablep);
@@ -478,8 +495,10 @@
wantreap = 0;
continue;
}
+#endif
- if ((n = select(maxsock + 1, readablep, NULL, NULL, NULL)) <= 0) {
+ readable = allsock;
+ if ((n = select(maxsock + 1, &readable, NULL, NULL, NULL)) <= 0) {
if (n < 0 && errno != EINTR) {
syslog(LOG_WARNING, "select: %m");
sleep(1);
@@ -487,7 +506,7 @@
continue;
}
for (sep = servtab; n && sep; sep = sep->se_next)
- if (sep->se_fd != -1 && FD_ISSET(sep->se_fd, readablep)) {
+ if (sep->se_fd != -1 && FD_ISSET(sep->se_fd, &readable)) {
n--;
if (debug)
fprintf(stderr, "someone wants %s\n", sep->se_service);
@@ -556,7 +575,7 @@
if (!sep->se_wait &&
sep->se_socktype == SOCK_STREAM)
close(ctrl);
- FD_CLR(sep->se_fd, allsockp);
+ FD_CLR(sep->se_fd, &allsock);
(void) close(sep->se_fd);
sep->se_fd = -1;
sep->se_count = 0;
@@ -581,7 +600,7 @@
}
if (pid && sep->se_wait) {
sep->se_wait = pid;
- FD_CLR(sep->se_fd, allsockp);
+ FD_CLR(sep->se_fd, &allsock);
nsock--;
}
sigsetmask(0L);
@@ -595,7 +614,7 @@
sep->se_user);
if (sep->se_socktype != SOCK_STREAM)
recv(0, buf, sizeof (buf), 0);
- exit(1);
+ _exit(1);
}
if (setsid() <0)
syslog(LOG_ERR, "%s: setsid: %m",
@@ -607,27 +626,33 @@
sep->se_group);
if (sep->se_socktype != SOCK_STREAM)
recv(0, buf, sizeof (buf), 0);
- exit(1);
+ _exit(1);
}
if (uid != 0) {
/* a user running private inetd */
if (uid != pwd->pw_uid)
- exit(1);
- } else {
- tmpint = LOGIN_SETALL &
- ~(LOGIN_SETGROUP|LOGIN_SETLOGIN);
- if (pwd->pw_uid)
- tmpint |= LOGIN_SETGROUP|LOGIN_SETLOGIN;
+ _exit(1);
+ } else if (pwd->pw_uid) {
+ /* tmpint = LOGIN_SETALL & */
+ /* ~(LOGIN_SETGROUP|LOGIN_SETLOGIN); */
+ /* if (pwd->pw_uid) */
+ /* tmpint |= LOGIN_SETGROUP|LOGIN_SETLOGIN; */
if (sep->se_group) {
pwd->pw_gid = grp->gr_gid;
- tmpint |= LOGIN_SETGROUP;
+ /* tmpint |= LOGIN_SETGROUP; */
}
- if (setusercontext(0, pwd, pwd->pw_uid,
- tmpint) < 0)
- syslog(LOG_ERR,
- "%s/%s: setusercontext: %m",
- sep->se_service,
- sep->se_proto);
+ setgid ((gid_t) pwd->pw_gid);
+ initgroups (pwd->pw_name, pwd->pw_gid);
+ setuid ((uid_t) pwd->pw_uid);
+ /* if (setusercontext(0, pwd, pwd->pw_uid, */
+ /* tmpint) < 0) */
+ /* syslog(LOG_ERR, */
+ /* "%s/%s: setusercontext: %m", */
+ /* sep->se_service, */
+ /* sep->se_proto); */
+ } else if (sep->se_group) {
+ setgid (grp->gr_gid);
+ setgroups (1, &grp->gr_gid);
}
if (debug)
fprintf(stderr, "%d execl %s\n",
@@ -636,6 +661,9 @@
close(ctrl);
dup2(0, 1);
dup2(0, 2);
+ if (rlim_ofile.rlim_cur != rlim_ofile_cur)
+ if (setrlimit (RLIMIT_NOFILE, &rlim_ofile) < 0)
+ syslog (LOG_ERR, "setrlimit: %m");
closelog();
for (tmpint = rlim_ofile_cur-1; --tmpint > 2; )
(void)close(tmpint);
@@ -644,7 +672,7 @@
if (sep->se_socktype != SOCK_STREAM)
recv(0, buf, sizeof (buf), 0);
syslog(LOG_ERR, "execv %s: %m", sep->se_server);
- exit(1);
+ _exit(1);
}
}
if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
@@ -654,13 +682,14 @@
}
int
-dg_badinput(sa)
- struct sockaddr *sa;
+dg_badinput(sin)
+ struct sockaddr_in *sin;
{
struct in_addr in;
#ifdef INET6
struct in6_addr *in6;
#endif
+#ifdef OpenBSD
u_int16_t port;
int i;
@@ -703,28 +732,40 @@
if (port < IPPORT_RESERVED || port == NFS_PORT)
goto bad;
+#endif
+ if (ntohs (sin->sin_port) < IPPORT_RESERVED)
+ return (1);
+ if (sin->sin_addr.s_addr == htonl (INADDR_BROADCAST))
+ return (1);
+ /* XXX compare against broadcast addresses in SIOCGIFCONF list? */
return (0);
+#ifdef OpenBSD
bad:
return (1);
+#endif
}
+#ifdef OpenBSD
void
reap(int sig)
{
wantreap = 1;
}
+#endif
void
-doreap(void)
+reapchild(int sig)
{
pid_t pid;
int save_errno = errno, status;
register struct servtab *sep;
+#ifdef OpenBSD
if (debug)
fprintf(stderr, "reaping asked for\n");
+#endif
for (;;) {
pid = wait3(&status, WNOHANG, NULL);
@@ -743,8 +784,8 @@
"%s: exit signal 0x%x",
sep->se_server, WTERMSIG(status));
sep->se_wait = 1;
- fd_grow(&allsockp, &allsockn, sep->se_fd);
- FD_SET(sep->se_fd, allsockp);
+ /* fd_grow(&allsockp, &allsockn, sep->se_fd); */
+ FD_SET(sep->se_fd, &allsock);
nsock++;
if (debug)
fprintf(stderr, "restored %s, fd %d\n",
@@ -766,14 +807,16 @@
struct servtab *enter __P((struct servtab *));
int matchconf __P((struct servtab *, struct servtab *));
+#ifdef OpenBSD
void
config(int sig)
{
wantconfig = 1;
}
+#endif
void
-doconfig(void)
+config(int sig)
{
register struct servtab *sep, *cp, **sepp;
int omask;
@@ -887,7 +930,7 @@
if (port != sep->se_ctrladdr_in.sin_port) {
sep->se_ctrladdr_in.sin_port = port;
if (sep->se_fd != -1) {
- FD_CLR(sep->se_fd, allsockp);
+ FD_CLR(sep->se_fd, &allsock);
nsock--;
(void) close(sep->se_fd);
}
@@ -942,7 +985,7 @@
if (port != sep->se_ctrladdr_in6.sin6_port) {
sep->se_ctrladdr_in6.sin6_port = port;
if (sep->se_fd != -1) {
- FD_CLR(sep->se_fd, allsockp);
+ FD_CLR(sep->se_fd, &allsock);
nsock--;
(void) close(sep->se_fd);
}
@@ -979,7 +1022,7 @@
}
*sepp = sep->se_next;
if (sep->se_fd != -1) {
- FD_CLR(sep->se_fd, allsockp);
+ FD_CLR(sep->se_fd, &allsock);
nsock--;
(void) close(sep->se_fd);
}
@@ -995,14 +1038,16 @@
(void) sigsetmask(omask);
}
+#ifdef OpenBSD
void
retry(int sig)
{
wantretry = 1;
}
+#endif
void
-doretry(void)
+retry(int sig)
{
register struct servtab *sep;
@@ -1046,7 +1091,7 @@
(void)close(sep->se_fd);
}
(void)unlink(_PATH_INETDPID);
- _exit(0);
+ exit(0);
}
int bump_nofile __P((void));
@@ -1102,9 +1147,9 @@
} else
r = bind(sep->se_fd, &sep->se_ctrladdr, sep->se_ctrladdr_size);
if (r < 0) {
- syslog(LOG_ERR, "%s/%s: bind: %m",
- sep->se_service, sep->se_proto);
- (void) close(sep->se_fd);
+ syslog(LOG_ERR, "%s/%s (%d): bind: %m",
+ sep->se_service, sep->se_proto, sep->se_ctrladdr.sa_family);
+ close(sep->se_fd);
sep->se_fd = -1;
if (!timingout) {
timingout = 1;
@@ -1113,10 +1158,10 @@
return;
}
if (sep->se_socktype == SOCK_STREAM)
- listen(sep->se_fd, 10);
+ listen(sep->se_fd, global_queuelen);
- fd_grow(&allsockp, &allsockn, sep->se_fd);
- FD_SET(sep->se_fd, allsockp);
+ /* fd_grow(&allsockp, &allsockn, sep->se_fd); */
+ FD_SET(sep->se_fd, &allsock);
nsock++;
if (sep->se_fd > maxsock) {
maxsock = sep->se_fd;
@@ -1230,10 +1275,12 @@
&new->se_ctrladdr_in6.sin6_addr,
sizeof(new->se_ctrladdr_in6.sin6_addr)) != 0)
return (0);
+#ifdef OpenBSD
if (old->se_family == AF_INET6 && new->se_family == AF_INET6 &&
old->se_ctrladdr_in6.sin6_scope_id !=
new->se_ctrladdr_in6.sin6_scope_id)
return (0);
+#endif
return (1);
}
@@ -1241,7 +1288,7 @@
FILE *fconfig = NULL;
char line[1024];
char *defhost;
-char *skip __P((char **, int));
+char *skip __P((char **));
char *nextline __P((FILE *));
char *newstr __P((char *));
struct servtab *dupconfig __P((struct servtab *));
@@ -1277,7 +1324,7 @@
{
register struct servtab *sep;
int argc;
- char *cp, *arg, *s;
+ char *cp, *arg;
char *hostdelim;
struct servtab *nsep;
struct servtab *psep;
@@ -1288,19 +1335,19 @@
exit(1);
}
- memset(sep, 0, sizeof *sep);
+ /* memset(sep, 0, sizeof *sep); */
more:
- freeconfig(sep);
+ /* freeconfig(sep); */
while ((cp = nextline(fconfig)) && *cp == '#')
;
if (cp == NULL) {
- free(sep);
+ /* free(sep); */
return (NULL);
}
memset((char *)sep, 0, sizeof *sep);
- arg = skip(&cp, 0);
+ arg = skip(&cp);
if (arg == NULL) {
/* A blank line. */
goto more;
@@ -1310,10 +1357,12 @@
hostdelim = strrchr(arg, ':');
if (hostdelim) {
*hostdelim = '\0';
+#ifdef OpenBSD
if (arg[0] == '[' && hostdelim > arg && hostdelim[-1] == ']') {
hostdelim[-1] = '\0';
sep->se_hostaddr = newstr(arg + 1);
} else
+#endif
sep->se_hostaddr = newstr(arg);
arg = hostdelim + 1;
/*
@@ -1321,10 +1370,10 @@
* default host for the following lines.
*/
if (*arg == '\0') {
- arg = skip(&cp, 0);
+ arg = skip(&cp);
if (cp == NULL) {
free(defhost);
- defhost = newstr(sep->se_hostaddr);
+ defhost = sep->se_hostaddr;
goto more;
}
}
@@ -1332,8 +1381,11 @@
sep->se_hostaddr = newstr(defhost);
sep->se_service = newstr(arg);
+#ifdef OpenBSD
if ((arg = skip(&cp, 1)) == NULL)
goto more;
+#endif
+ arg = skip (&cp);
if (strcmp(arg, "stream") == 0)
sep->se_socktype = SOCK_STREAM;
@@ -1348,10 +1400,12 @@
else
sep->se_socktype = -1;
+#ifdef OpenBSD
if ((arg = skip(&cp, 1)) == NULL)
goto more;
+#endif
- sep->se_proto = newstr(arg);
+ sep->se_proto = newstr(skip (&cp));
if (strcmp(sep->se_proto, "unix") == 0) {
sep->se_family = AF_UNIX;
@@ -1389,10 +1443,11 @@
goto badafterall;
}
}
- arg = skip(&cp, 1);
+ arg = skip(&cp);
if (arg == NULL)
goto more;
+#ifdef OpenBSD
s = strchr(arg, '.');
if (s) {
char *p;
@@ -1406,11 +1461,20 @@
}
} else
sep->se_max = toomany;
+#endif
+ {
+ char *s = strchr (arg, '.');
+ if (s) {
+ *s++ = '\0';
+ sep->se_max = atoi (s);
+ } else
+ sep->se_max = toomany;
+ }
sep->se_wait = strcmp(arg, "wait") == 0;
- if ((arg = skip(&cp, 1)) == NULL)
- goto more;
- sep->se_user = newstr(arg);
+ /* if ((arg = skip(&cp, 1)) == NULL) */
+ /* goto more; */
+ sep->se_user = newstr(skip (&cp));
arg = strchr(sep->se_user, '.');
if (arg == NULL)
arg = strchr(sep->se_user, ':');
@@ -1418,12 +1482,12 @@
*arg++ = '\0';
sep->se_group = newstr(arg);
}
- if ((arg = skip(&cp, 1)) == NULL)
- goto more;
+ /* if ((arg = skip(&cp, 1)) == NULL) */
+ /* goto more; */
- sep->se_server = newstr(arg);
+ sep->se_server = newstr(skip (&cp));
if (strcmp(sep->se_server, "internal") == 0) {
- struct biltin *bi;
+ register struct biltin *bi;
for (bi = biltins; bi->bi_service; bi++)
if (bi->bi_socktype == sep->se_socktype &&
@@ -1439,7 +1503,7 @@
} else
sep->se_bi = NULL;
argc = 0;
- for (arg = skip(&cp, 0); cp; arg = skip(&cp, 0)) {
+ for (arg = skip(&cp); cp; arg = skip(&cp)) {
if (argc < MAXARGV)
sep->se_argv[argc++] = newstr(arg);
}
@@ -1468,7 +1532,9 @@
nsep = sep;
while (nsep != NULL) {
nsep->se_checked = 1;
- switch (nsep->se_family) {
+ /* switch (nsep->se_family) { */
+ if (nsep->se_family == AF_INET) {
+#ifdef OpenBSD
case AF_INET:
case AF_INET6:
{
@@ -1488,7 +1554,13 @@
goto skip;
}
close(s);
+#endif
+ if (!strcmp (nsep->se_hostaddr, "*"))
+ nsep->se_ctrladdr_in.sin_addr.s_addr = INADDR_ANY;
+ else if (!inet_aton (nsep->se_hostaddr, &nsep->se_ctrladdr_in.sin_addr)) {
+ struct hostent *hp;
+#ifdef OpenBSD
memset(&hints, 0, sizeof(hints));
hints.ai_family = nsep->se_family;
hints.ai_socktype = nsep->se_socktype;
@@ -1517,7 +1589,22 @@
res->ai_addr, res->ai_addrlen);
continue;
}
+#endif
+ hp = gethostbyname (nsep->se_hostaddr);
+ if (hp == 0) {
+ syslog (LOG_ERR, "%s: unknown host", nsep->se_hostaddr);
+ nsep->se_checked = 0;
+ goto skip;
+ } else if (hp->h_addrtype != AF_INET) {
+ syslog (LOG_ERR,
+ "%s: address isn't an Internet "
+ "address", nsep->se_hostaddr);
+ nsep->se_checked = 0;
+ goto skip;
+ } else {
+ int i = 1;
+#ifdef OpenBSD
psep = dupconfig(nsep);
psep->se_hostaddr = newstr(nsep->se_hostaddr);
psep->se_checked = 1;
@@ -1535,7 +1622,26 @@
freeaddrinfo(res0);
break;
}
+#endif
+ memmove (&nsep->se_ctrladdr_in.sin_addr,
+ hp->h_addr_list[0], sizeof (struct in_addr));
+ while (hp->h_addr_list[i] != NULL) {
+ psep = dupconfig (nsep);
+ psep->se_hostaddr = newstr (nsep->se_hostaddr);
+ psep->se_checked = 1;
+ memmove (&psep->se_ctrladdr_in.sin_addr,
+ hp->h_addr_list[i], sizeof (struct in_addr));
+ psep->se_ctrladdr_size = sizeof (psep->se_ctrladdr_in);
+ i++;
+ /* Prepend to list, don't want to look up its */
+ /* hostname again. */
+ psep->se_next = sep;
+ sep = psep;
+ }
+ }
+ }
}
+/* XXX BUG?: is this skip: label supposed to remain? */
skip:
nsep = nsep->se_next;
}
@@ -1593,17 +1699,17 @@
}
char *
-skip(cpp, report)
+skip(cpp)
char **cpp;
- int report;
+ /* int report; */
{
- char *cp = *cpp;
+ register char *cp = *cpp;
char *start;
-erp:
+/* erp: */
if (*cpp == NULL) {
- if (report)
- syslog(LOG_ERR, "syntax error in inetd config file");
+ /* if (report) */
+ /* syslog(LOG_ERR, "syntax error in inetd config file"); */
return (NULL);
}
@@ -1619,16 +1725,18 @@
if ((cp = nextline(fconfig)))
goto again;
*cpp = NULL;
- goto erp;
+ /* goto erp; */
+ return (NULL);
}
start = cp;
while (*cp && *cp != ' ' && *cp != '\t')
cp++;
if (*cp != '\0')
*cp++ = '\0';
- if ((*cpp = cp) == NULL)
- goto erp;
+ /* if ((*cpp = cp) == NULL) */
+ /* goto erp; */
+ *cpp = cp;
return (start);
}
@@ -1796,15 +1904,16 @@
{
char buffer[BUFSIZE];
int i, size;
- struct sockaddr_storage ss;
+ /* struct sockaddr_storage ss; */
+ struct sockaddr sa;
- size = sizeof(ss);
- if ((i = recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr *)&ss,
+ size = sizeof(sa);
+ if ((i = recvfrom(s, buffer, sizeof(buffer), 0, &sa,
&size)) < 0)
return;
- if (dg_badinput((struct sockaddr *)&ss))
+ if (dg_badinput((struct sockaddr_in *)&sa))
return;
- (void) sendto(s, buffer, i, 0, (struct sockaddr *)&ss, size);
+ (void) sendto(s, buffer, i, 0, &sa, sizeof(sa));
}
/* ARGSUSED */
@@ -1890,7 +1999,8 @@
int s;
struct servtab *sep;
{
- struct sockaddr_storage ss;
+ /* struct sockaddr_storage ss; */
+ struct sockaddr sa;
static char *rs;
int len, size;
char text[LINESIZ+2];
@@ -1900,11 +2010,11 @@
rs = ring;
}
- size = sizeof(ss);
- if (recvfrom(s, text, sizeof(text), 0, (struct sockaddr *)&ss,
+ size = sizeof(sa);
+ if (recvfrom(s, text, sizeof(text), 0, &sa,
&size) < 0)
return;
- if (dg_badinput((struct sockaddr *)&ss))
+ if (dg_badinput((struct sockaddr_in *)&sa))
return;
if ((len = endring - rs) >= LINESIZ)
@@ -1917,7 +2027,7 @@
rs = ring;
text[LINESIZ] = '\r';
text[LINESIZ + 1] = '\n';
- (void) sendto(s, text, sizeof(text), 0, (struct sockaddr *)&ss, size);
+ (void) sendto(s, text, sizeof(text), 0, &sa, sizeof(sa));
}
/*
@@ -1959,18 +2069,23 @@
struct servtab *sep;
{
u_int result;
- struct sockaddr_storage ss;
+ /* struct sockaddr_storage ss; */
+ struct sockaddr sa;
+ struct sockaddr_in *sin;
int size;
- size = sizeof(ss);
+ size = sizeof(sa);
if (recvfrom(s, (char *)&result, sizeof(result), 0,
- (struct sockaddr *)&ss, &size) < 0)
+ &sa, &size) < 0)
return;
- if (dg_badinput((struct sockaddr *)&ss))
+ /* if (dg_badinput((struct sockaddr *)&ss)) */
+ sin = (struct sockaddr_in *) &sa;
+ if (sin->sin_addr.s_addr == htonl (INADDR_BROADCAST) ||
+ ntohs (sin->sin_port) < IPPORT_RESERVED / 2)
return;
result = machtime();
(void) sendto(s, (char *) &result, sizeof(result), 0,
- (struct sockaddr *)&ss, size);
+ &sa, sizeof(sa));
}
/* ARGSUSED */
@@ -1996,20 +2111,21 @@
{
char buffer[256];
time_t time(), clock;
- struct sockaddr_storage ss;
+ /* struct sockaddr_storage ss; */
+ struct sockaddr sa;
int size;
clock = time((time_t *) 0);
- size = sizeof(ss);
- if (recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr *)&ss,
+ size = sizeof(sa);
+ if (recvfrom(s, buffer, sizeof(buffer), 0, &sa,
&size) < 0)
return;
- if (dg_badinput((struct sockaddr *)&ss))
+ if (dg_badinput((struct sockaddr_in *)&sa))
return;
(void) sprintf(buffer, "%.24s\r\n", ctime(&clock));
- (void) sendto(s, buffer, strlen(buffer), 0, (struct sockaddr *)&ss,
- size);
+ (void) sendto(s, buffer, strlen(buffer), 0, &sa,
+ sizeof(sa));
}
/*
--- ./Makefile.orig Thu Mar 30 17:00:49 2000
+++ ./Makefile Tue Feb 6 17:18:05 2001
@@ -1,7 +1,6 @@
-# $OpenBSD: Makefile,v 1.3 2000/03/31 01:00:49 deraadt Exp $
+CC = gcc
+CFLAGS = -O2
+LDFLAGS = -s
-PROG= inetd
-MAN= inetd.8
-MLINKS= inetd.8 inetd.conf.5
-
-.include <bsd.prog.mk>
+all:
+ $(CC) $(CFLAGS) $(LDFLAGS) -o inetd inetd.c