Add a debugging option (-d)

Add a -k option which fingerd(8) passes through to finger(1).

MFC after:	2 weeks
This commit is contained in:
Dag-Erling Smørgrav 2010-04-01 13:11:39 +00:00
parent 4e50c2a20d
commit 9481b5428e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=206038
2 changed files with 47 additions and 12 deletions

View File

@ -32,7 +32,7 @@
.\" @(#)fingerd.8 8.1 (Berkeley) 6/4/93 .\" @(#)fingerd.8 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd June 4, 1993 .Dd April 1, 2010
.Dt FINGERD 8 .Dt FINGERD 8
.Os .Os
.Sh NAME .Sh NAME
@ -40,6 +40,8 @@
.Nd remote user information server .Nd remote user information server
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl d
.Op Fl k
.Op Fl s .Op Fl s
.Op Fl l .Op Fl l
.Op Fl p Ar filename .Op Fl p Ar filename
@ -106,6 +108,25 @@ The following options may be passed to
as server program arguments in as server program arguments in
.Pa /etc/inetd.conf : .Pa /etc/inetd.conf :
.Bl -tag -width indent .Bl -tag -width indent
.It Fl d
Enable debugging mode.
In debugging mode,
.Nm
will not attempt any network-related operations on
.Va stdin ,
and it will print the full
.Nm finger
command line
to
.Va stderr
before executing it.
.It Fl k
Suppress login information.
See the description of the
.Fl k
option in
.Xr finger 1
for details.
.It Fl s .It Fl s
Enable secure mode. Enable secure mode.
Queries without a user name are rejected and Queries without a user name are rejected and

View File

@ -72,17 +72,23 @@ main(int argc, char *argv[])
char *lp; char *lp;
struct sockaddr_storage ss; struct sockaddr_storage ss;
socklen_t sval; socklen_t sval;
int p[2], logging, pflag, secure; int p[2], debug, kflag, logging, pflag, secure;
#define ENTRIES 50 #define ENTRIES 50
char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog; char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog;
char rhost[MAXHOSTNAMELEN]; char rhost[MAXHOSTNAMELEN];
prog = _PATH_FINGER; prog = _PATH_FINGER;
logging = pflag = secure = 0; logging = kflag = pflag = secure = 0;
openlog("fingerd", LOG_PID | LOG_CONS, LOG_DAEMON); openlog("fingerd", LOG_PID | LOG_CONS, LOG_DAEMON);
opterr = 0; opterr = 0;
while ((ch = getopt(argc, argv, "lp:s")) != -1) while ((ch = getopt(argc, argv, "dklp:s")) != -1)
switch (ch) { switch (ch) {
case 'd':
debug = 1;
break;
case 'k':
kflag = 1;
break;
case 'l': case 'l':
logging = 1; logging = 1;
break; break;
@ -101,7 +107,7 @@ main(int argc, char *argv[])
/* /*
* Enable server-side Transaction TCP. * Enable server-side Transaction TCP.
*/ */
{ if (!debug) {
int one = 1; int one = 1;
if (setsockopt(STDOUT_FILENO, IPPROTO_TCP, TCP_NOPUSH, &one, if (setsockopt(STDOUT_FILENO, IPPROTO_TCP, TCP_NOPUSH, &one,
sizeof one) < 0) { sizeof one) < 0) {
@ -112,7 +118,7 @@ main(int argc, char *argv[])
if (!fgets(line, sizeof(line), stdin)) if (!fgets(line, sizeof(line), stdin))
exit(1); exit(1);
if (logging || pflag) { if (!debug && (logging || pflag)) {
sval = sizeof(ss); sval = sizeof(ss);
if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0) if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0)
logerr("getpeername: %s", strerror(errno)); logerr("getpeername: %s", strerror(errno));
@ -143,12 +149,14 @@ main(int argc, char *argv[])
syslog(LOG_NOTICE, "query from %s: `%s'", rhost, t); syslog(LOG_NOTICE, "query from %s: `%s'", rhost, t);
} }
comp = &av[1]; comp = &av[2];
av[2] = "--"; av[3] = "--";
for (lp = line, ap = &av[3];;) { if (kflag)
*comp-- = "-k";
for (lp = line, ap = &av[4];;) {
*ap = strtok(lp, " \t\r\n"); *ap = strtok(lp, " \t\r\n");
if (!*ap) { if (!*ap) {
if (secure && ap == &av[3]) { if (secure && ap == &av[4]) {
puts("must provide username\r\n"); puts("must provide username\r\n");
exit(1); exit(1);
} }
@ -161,8 +169,7 @@ main(int argc, char *argv[])
/* RFC742: "/[Ww]" == "-l" */ /* RFC742: "/[Ww]" == "-l" */
if ((*ap)[0] == '/' && ((*ap)[1] == 'W' || (*ap)[1] == 'w')) { if ((*ap)[0] == '/' && ((*ap)[1] == 'W' || (*ap)[1] == 'w')) {
av[1] = "-l"; *comp-- = "-l";
comp = &av[0];
} }
else if (++ap == av + ENTRIES) { else if (++ap == av + ENTRIES) {
*ap = NULL; *ap = NULL;
@ -178,6 +185,13 @@ main(int argc, char *argv[])
if (pipe(p) < 0) if (pipe(p) < 0)
logerr("pipe: %s", strerror(errno)); logerr("pipe: %s", strerror(errno));
if (debug) {
fprintf(stderr, "%s", prog);
for (ap = comp; *ap != NULL; ++ap)
fprintf(stderr, " %s", *ap);
fprintf(stderr, "\n");
}
switch(vfork()) { switch(vfork()) {
case 0: case 0:
(void)close(p[0]); (void)close(p[0]);