Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Nov 1996 14:18:52 +1100 (EST)
From:      Julian Assange <proff@suburbia.net>
To:        julian@whistle.com (Julian Elischer)
Cc:        hackers@freebsd.org
Subject:   Re: still no response
Message-ID:  <199611070318.OAA21381@suburbia.net>
In-Reply-To: <328138CB.41C67EA6@whistle.com> from "Julian Elischer" at Nov 6, 96 05:18:03 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> I still haven't heard back from anyone regarding the
> session limit addition in inetd.
> 
> does everyone think it's a boring idea?
> doesn no one dislikr it?
> should I just check it in?

I like it. Now, what do you think of mine ;)

--- inetd.8.orig	Sat Aug 10 02:56:32 1996
+++ inetd.8	Tue Nov  5 20:35:24 1996
@@ -312,6 +312,21 @@
 .Tn RFC
 document.
 .Pp
+Lines starting with '/' in the configuration file are special directives to
+.Nm inetd .
+At present the following directives are supported:
+.Bd -literal
+/bind	iface1|ANY...iface_n	bind following service entries to
+				these interfaces
+/bind+	iface1...iface_n	as above, but add specified ifaces to
+				the previous bind list
+.Ed
+.Pp
+If the iface name begins with "<", then the iface name is treated
+as a file with interface addresses listed as the first word per line. 
+If the iface name is multi-homed in the DNS, then all addresses belonging
+to that iface name will be bound.
+.Pp
 When given the
 .Fl l
 option
@@ -376,6 +391,22 @@
 .Bd -literal
 ftp          stream  tcp   nowait root  /usr/libexec/ftpd        ftpd -l
 ntalk        dgram   udp   wait   root  /usr/libexec/ntalkd      ntalkd
+tcpmux/+date stream  tcp   nowait guest /bin/date                date
+tcpmux/phonebook stream tcp nowait guest /usr/local/bin/phonebook phonebook
+rstatd/1-3   dgram   rpc/udp wait root  /usr/libexec/rpc.rstatd  rpc.rstatd
+.Ed
+.Pp
+Here is a similar example with binding directives:
+.Bd -literal
+/bind </etc/ftp_ifaces
+ftp          stream  tcp   nowait root  /usr/libexec/ftpd        ftpd -l
+/bind localhost 10.0.0.2
+ftp          stream  tcp   nowait root  /usr/libexec/ftpd        ftpd
+ntalk        dgram   udp   wait   root  /usr/libexec/ntalkd      ntalkd
+finger       stream  tcp   nowait root  /usr/libexec/fingerd     fingerd
+/bind dmz.my.sexy.net
+finger       stream  tcp   nowait root  /usr/local/bin/goaway	goaway
+/bind ANY
 tcpmux/+date stream  tcp   nowait guest /bin/date                date
 tcpmux/phonebook stream tcp nowait guest /usr/local/bin/phonebook phonebook
 rstatd/1-3   dgram   rpc/udp wait root  /usr/libexec/rpc.rstatd  rpc.rstatd
--- inetd.c.orig	Tue Nov  5 11:46:15 1996
+++ /r/inetd.c	Thu Nov  7 09:15:55 1996
@@ -75,6 +75,19 @@
  *	server program			full path name
  *	server program arguments	maximum of MAXARGS (20)
  *
+ * Lines starting with '/' are directives to inetd. 
+ *
+ *	/bind	iface1|ANY...iface_n	bind following services to
+ *					these interfaces
+ *	/bind+	iface1...iface_n	as above, but add ifaces to
+ *					the previous bind list
+ *
+ * If the iface name begins with "<", then the iface name is treated
+ * as a file with interface addresses listed as the first word per line. 
+ *
+ * if address is multi-homed in the DNS, then all addresses for the
+ * host name will be bound.
+ *
  * TCP services without official port numbers are handled with the
  * RFC1078-based tcpmux internal service. Tcpmux listens on port 1 for
  * requests. When a connection is made from a foreign host, the service
@@ -112,6 +125,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <rpc/rpc.h>
+#include <netdb.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -144,6 +158,10 @@
 struct	servent *sp;
 struct	rpcent *rpc;
 struct	in_addr bind_address;
+struct	se_bind {
+	struct se_bind *next;
+	struct in_addr addr;
+} *addrs, *addrs_tail;
 
 struct	servtab {
 	char	*se_service;		/* name of service */
@@ -202,6 +220,7 @@
 char	       *sskip __P((char **));
 char	       *skip __P((char **));
 struct servtab *tcpmux __P((int));
+void	       *xmalloc __P((int));
 
 void		unregisterrpc __P((register struct servtab *sep));
 
@@ -595,7 +614,8 @@
 		}
 		for (sep = servtab; sep; sep = sep->se_next)
 			if (strcmp(sep->se_service, cp->se_service) == 0 &&
-			    strcmp(sep->se_proto, cp->se_proto) == 0)
+			    strcmp(sep->se_proto, cp->se_proto) == 0 &&
+			    memcmp(&sep->se_ctrladdr.sin_addr, &cp->se_ctrladdr.sin_addr, sizeof(struct in_addr)) == 0)
 				break;
 		if (sep != 0) {
 			int i;
@@ -665,7 +685,16 @@
 			}
 		}
 		if (sep->se_fd == -1)
-			setup(sep);
+		{
+			if (addrs) {
+				struct se_bind *p = addrs;
+				do {
+					sep->se_ctrladdr.sin_addr = p->addr;
+					setup(sep);
+				} while ((p = p->next) && (sep = enter(sep)));
+			} else
+				setup(sep);
+		}
 	}
 	endconfig();
 	/*
@@ -828,6 +857,22 @@
 		sep->se_wait = 1;
 }
 
+void *
+xmalloc(int n)
+{
+	void *p;
+	int count;
+	for (count=0; !(p = malloc(n)); ) {
+		if (count++>50) {
+			syslog(LOG_ERR, "Out of memory. terminating!");
+			exit(-1);
+		}
+		syslog(LOG_ERR, "Out of memory sleeping... retrying malloc()");
+		sleep(10);
+	}
+	return p;
+}
+
 struct servtab *
 enter(cp)
 	struct servtab *cp;
@@ -835,11 +880,7 @@
 	struct servtab *sep;
 	long omask;
 
-	sep = (struct servtab *)malloc(sizeof (*sep));
-	if (sep == (struct servtab *)0) {
-		syslog(LOG_ERR, "Out of memory.");
-		exit(-1);
-	}
+	sep = xmalloc(sizeof (*sep));
 	*sep = *cp;
 	sep->se_fd = -1;
 	omask = sigblock(SIGBLOCK);
@@ -874,6 +915,89 @@
 	}
 }
 
+void
+add_addr(struct in_addr *in)
+{
+	if (!addrs) {
+		addrs_tail = addrs = xmalloc (sizeof *addrs_tail);
+	} else {
+		addrs_tail->next = xmalloc (sizeof *addrs_tail);
+		addrs_tail = addrs->next;
+	}
+	addrs_tail->addr = *in;
+	addrs_tail->next = NULL;
+}
+
+void
+free_addrs()
+{
+	struct se_bind *p;
+	for (p = addrs; p; ) {
+		struct se_bind *p2 = p;
+		p = p2->next;
+		free (p2);
+	}
+	addrs_tail = addrs = NULL;
+}
+
+void
+add_binding(char *arg)
+{
+	struct in_addr in;
+	if (strcmp(arg, "ANY") == 0) {
+		free_addrs();
+		return;
+	}
+	if (inet_aton(arg, &in))
+		add_addr(&in);
+	else {
+		struct hostent *h;
+		char **inp;
+		h = gethostbyname(arg);
+		if (!h) {
+			syslog(LOG_ERR, "%s: couldn't resolve /bind %s [skipped binding]", CONFIG, arg);
+			return;
+		}
+		if (h->h_addrtype!=AF_INET) {
+			syslog(LOG_ERR, "%s: \"%s\" not an AF_INET address [skipped binding]", CONFIG, arg);
+			return;
+		}
+		/* host may be multi-homed, so attach all addresses */
+		for (inp = h->h_addr_list; *inp; inp++)
+			add_addr((struct in_addr *)*inp);
+	}
+}
+
+void
+slash_bind(char *cp, int add_flag)
+{
+	char *arg;
+	if (!add_flag)
+		free_addrs();
+	for (arg = sskip(&cp); arg; arg = skip(&cp)) {
+		if (*arg == '<') {
+			char nam[128];
+			FILE *fp = fopen(++arg, "r");
+			if (!fp) {
+				syslog(LOG_ERR, "%s: couldn't open addr file '%s': %m", CONFIG, arg);
+				exit(-1);
+			}
+			while (fscanf(fp, "%127s%*[^\n]", nam)==1)
+			{
+				if (*nam == '#')
+					continue;
+				add_binding(nam);
+			}
+			if (ferror(fp)) {
+				syslog(LOG_ERR, "%s: error reading addr file '%s': %m", CONFIG, arg);
+				exit(-1);
+			}
+			fclose(fp);
+		} else
+			add_binding(arg);
+	}
+}
+
 struct servtab *
 getconfigent()
 {
@@ -883,12 +1007,30 @@
 	char *versp;
 	static char TCPMUX_TOKEN[] = "tcpmux/";
 #define MUX_LEN		(sizeof(TCPMUX_TOKEN)-1)
-
+	struct	se_bind {
+		struct se_bind *next;
+		struct in_addr addr;
+	} *addrs = NULL;
 more:
 	while ((cp = nextline(fconfig)) && (*cp == '#' || *cp == '\0'))
 		;
 	if (cp == NULL)
 		return ((struct servtab *)0);
+
+	if (*cp == '/') {
+		/* processing directives */
+		++cp;
+		arg = sskip(&cp);
+		if (strcmp(arg, "bind") == 0)
+			slash_bind(cp, 0);
+		else if (strcmp(arg, "bind+") == 0)
+			slash_bind(cp, 1);
+		else {
+			syslog(LOG_ERR, "%s: invalid /directive \"%s\"", CONFIG, arg);
+			exit (-1);
+		}
+		goto more;
+	}
 	/*
 	 * clear the static buffer, since some fields (se_ctrladdr,
 	 * for example) don't get initialized here.
@@ -947,7 +1089,7 @@
                                 break;
                         default:
                                 syslog(LOG_ERR,
-					"bad RPC version specifier; %s\n",
+					"bad RPC version specifier; %s",
 					sep->se_service);
                                 freeconfig(sep);
                                 goto more;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199611070318.OAA21381>