From bee39b42f3a3aacf7b624ff057b0f27c3a54c884 Mon Sep 17 00:00:00 2001 From: Geoff Rehmet Date: Sun, 11 Sep 1994 11:16:32 +0000 Subject: [PATCH] - increase TOOMANY, in line with 1.x - add logging option from 1.x --- usr.sbin/inetd/inetd.8 | 12 ++++++++++++ usr.sbin/inetd/inetd.c | 25 ++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/usr.sbin/inetd/inetd.8 b/usr.sbin/inetd/inetd.8 index 07392a133ad0..cfb8b8687351 100644 --- a/usr.sbin/inetd/inetd.8 +++ b/usr.sbin/inetd/inetd.8 @@ -42,6 +42,7 @@ .Sh SYNOPSIS .Nm inetd .Op Fl d +.Op Fl l .Op Fl R Ar rate .Op Ar configuration file .Sh DESCRIPTION @@ -72,6 +73,8 @@ The options available for .Bl -tag -width Ds .It Fl d Turns on debugging. +.It Fl l +Turns on logging. .It Fl R Ar rate Specifies the maximum number of times a service can be invoked in one minute; the default is 1000. @@ -299,6 +302,15 @@ details of these services, consult the appropriate .Tn RFC from the Network Information Center. .Pp +When given the +.Fl l +option +.Nm Inetd +will log an entry to syslog each time an +.Xr accept 2 +is made, which notes the +service selected and the IP-number of the remote requestor. +.Pp The .Nm inetd program diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c index 11a880dabc16..e3e79c67df22 100644 --- a/usr.sbin/inetd/inetd.c +++ b/usr.sbin/inetd/inetd.c @@ -125,7 +125,7 @@ static char RCSid[] = "$Id"; #include "pathnames.h" -#define TOOMANY 40 /* don't start more than TOOMANY */ +#define TOOMANY 256 /* don't start more than TOOMANY */ #define CNT_INTVL 60 /* servers in CNT_INTVL sec. */ #define RETRYTIME (60*10) /* retry after bind or server fail */ @@ -133,6 +133,7 @@ static char RCSid[] = "$Id"; int debug = 0; +int log = 0; int nsock, maxsock; fd_set allsock; int options; @@ -249,6 +250,8 @@ main(argc, argv, envp) int tmpint, ch, dofork; pid_t pid; char buf[50]; + struct sockaddr_in peer; + int i; Argv = argv; if (envp == 0 || *envp == 0) @@ -259,12 +262,15 @@ main(argc, argv, envp) openlog("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON); - while ((ch = getopt(argc, argv, "dR:")) != EOF) + while ((ch = getopt(argc, argv, "dlR:")) != EOF) switch(ch) { case 'd': debug = 1; options |= SO_DEBUG; break; + case 'l': + log = 1; + break; case 'R': { /* invocation rate */ char *p; @@ -280,7 +286,7 @@ main(argc, argv, envp) case '?': default: syslog(LOG_ERR, - "usage: inetd [-d] [-R rate] [conf-file]"); + "usage: inetd [-dl] [-R rate] [conf-file]"); exit(1); } argc -= optind; @@ -347,6 +353,19 @@ main(argc, argv, envp) sep->se_service); continue; } + if(log) { + i = sizeof peer; + if(getpeername(ctrl, (struct sockaddr *) + &peer, &i)) { + syslog(LOG_WARNING, + "getpeername(for %s): %m", + sep->se_service); + continue; + } + syslog(LOG_INFO,"%s from %s", + sep->se_service, + inet_ntoa(peer.sin_addr)); + } /* * Call tcpmux to find the real service to exec. */