summaryrefslogtreecommitdiffstats
path: root/source/n/inetd/inetd-OpenBSD-1.79.diff
blob: e1550beb3ad893b866c3f8d901ee70a607e0e815 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
--- ./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