From owner-freebsd-hackers Wed Nov 6 19:19:51 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id TAA21001 for hackers-outgoing; Wed, 6 Nov 1996 19:19:51 -0800 (PST) Received: from pdx1.world.net (pdx1.world.net [192.243.32.18]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id TAA20996 for ; Wed, 6 Nov 1996 19:19:48 -0800 (PST) Received: from suburbia.net (suburbia.net [198.142.2.24]) by pdx1.world.net (8.7.5/8.7.3) with ESMTP id TAA17073; Wed, 6 Nov 1996 19:19:23 -0800 (PST) Received: (proff@localhost) by suburbia.net (8.7.4/Proff-950810) id OAA21381; Thu, 7 Nov 1996 14:18:52 +1100 From: Julian Assange Message-Id: <199611070318.OAA21381@suburbia.net> Subject: Re: still no response To: julian@whistle.com (Julian Elischer) Date: Thu, 7 Nov 1996 14:18:52 +1100 (EST) Cc: hackers@freebsd.org In-Reply-To: <328138CB.41C67EA6@whistle.com> from "Julian Elischer" at Nov 6, 96 05:18:03 pm X-Mailer: ELM [version 2.4 PL23] Content-Type: text Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > 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 #include #include +#include #include #include @@ -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;