Importing libexec/fingerd

This commit is contained in:
Thomas Cort 2013-06-01 14:14:33 +00:00
parent 406cdd95a6
commit 1d842c6a57
13 changed files with 461 additions and 156 deletions

View File

@ -9,7 +9,7 @@ SUBDIR= add_route arp ash at backup basename btrace \
dd decomp16 DESCRIBE devmand devsize df dhcpd \
dhrystone diff dirname diskctl dumpcore \
eject env expand factor fbdctl \
find fingerd fix fold format fortune fsck.mfs \
find fix fold format fortune fsck.mfs \
gcore gcov-pull getty grep hexdump host \
hostaddr id ifconfig ifdef \
intr ipcrm ipcs irdpd isoread last \

View File

@ -1,5 +0,0 @@
PROG= in.fingerd
SRCS= fingerd.c
MAN=
.include <bsd.prog.mk>

View File

@ -1,94 +0,0 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#ifndef lint
static char sccsid[] = "@(#)in.fingerd.c 1.1 87/12/21 SMI"; /* from UCB 5.1 6/6/85 */
#endif /* not lint */
/*
* Finger server.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main( int argc, char *argv[] );
void fatal( char *prog, char *s );
int main(argc, argv)
char *argv[];
{
register char *sp;
char line[512];
int i, p[2], pid, status;
FILE *fp;
char *av[4];
line[0] = '\0';
fgets(line, sizeof(line), stdin);
sp = line + strlen(line);
if (sp > line && *--sp == '\n') *sp = '\0';
sp = line;
av[0] = "finger";
i = 1;
while (1) {
while (isspace(*sp))
sp++;
if (!*sp)
break;
if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) {
sp += 2;
av[i++] = "-l";
}
if (*sp && !isspace(*sp)) {
av[i++] = sp;
while (*sp && !isspace(*sp))
sp++;
*sp = '\0';
}
}
av[i] = 0;
if (pipe(p) < 0)
fatal(argv[0], "pipe");
if ((pid = fork()) == 0) {
close(p[0]);
if (p[1] != 1) {
dup2(p[1], 1);
close(p[1]);
}
execv("/usr/bin/finger", av);
printf("No finger program found\n");
fflush(stdout);
_exit(1);
}
if (pid == -1)
fatal(argv[0], "fork");
close(p[1]);
if ((fp = fdopen(p[0], "r")) == NULL)
fatal(argv[0], "fdopen");
while ((i = getc(fp)) != EOF) {
if (i == '\n')
putchar('\r');
putchar(i);
}
fclose(fp);
while ((i = wait(&status)) != pid && i != -1)
;
return(0);
}
void fatal(prog, s)
char *prog, *s;
{
fprintf(stderr, "%s: ", prog);
perror(s);
exit(1);
}

View File

@ -128,6 +128,7 @@
./lib minix-sys
./lib/cpp minix-sys
./libexec minix-sys
./usr/libexec/fingerd minix-sys
./usr/libexec/ftpd minix-sys
./libexec/ld.elf_so minix-sys
./libexec/ld-elf.so.1 minix-sys
@ -314,7 +315,6 @@
./usr/bin/ifconfig minix-sys
./usr/bin/ifdef minix-sys
./usr/bin/indent minix-sys
./usr/bin/in.fingerd minix-sys
./usr/bin/infocmp minix-sys
./usr/bin/in.rshd minix-sys
./usr/bin/install minix-sys

View File

@ -2,3 +2,4 @@ daemonize talkd
daemonize tcpd shell in.rshd
daemonize tcpd telnet in.telnetd
daemonize tcpd ftp /usr/libexec/ftpd
daemonize tcpd finger /usr/libexec/fingerd

View File

@ -4,7 +4,7 @@
.include <bsd.own.mk>
SUBDIR= \
ftpd \
fingerd ftpd \
ld.elf_so
.if defined(__MINIX)

13
libexec/fingerd/Makefile Normal file
View File

@ -0,0 +1,13 @@
# $NetBSD: Makefile,v 1.9 2005/01/10 02:58:58 lukem Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/4/93
.include <bsd.own.mk>
PROG= fingerd
MAN= fingerd.8
.if (${USE_INET6} != "no")
CPPFLAGS+=-DINET6
.endif
.include <bsd.prog.mk>

175
libexec/fingerd/fingerd.8 Normal file
View File

@ -0,0 +1,175 @@
.\" $NetBSD: fingerd.8,v 1.20 2003/11/02 11:27:49 wiz Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)fingerd.8 8.1 (Berkeley) 6/4/93
.\"
.Dd September 12, 2002
.Dt FINGERD 8
.Os
.Sh NAME
.Nm fingerd
.Nd remote user information server
.Sh SYNOPSIS
.Nm
.Op Fl 8ghlmpSsu
.Op Fl P Ar filename
.Sh DESCRIPTION
.Nm
is a simple protocol based on RFC 1288
that provides an interface to the
Name and Finger programs at several network sites.
The program is supposed to return a friendly,
human-oriented status report on either the system at the moment
or a particular person in depth.
There is no required format and the
protocol consists mostly of specifying a single
.Dq command line .
.Pp
.Nm
is started by
.Xr inetd 8 ,
which listens for
.Tn TCP
requests at port 79.
Once handed a connection,
.Nm
reads a single command line
terminated by a
.Aq Tn CRLF
which it then passes to
.Xr finger 1 .
.Nm
closes its connections as soon as the output is finished.
.Pp
If the line is null (i.e., just a
.Aq Tn CRLF
is sent) then
.Xr finger 1
returns a
.Dq default
report that lists all people logged into
the system at that moment.
.Pp
If a user name is specified (e.g.,
.Pf eric Aq Tn CRLF )
then the
response lists more extended information for only that particular user,
whether logged in or not.
Allowable
.Dq names
in the command line include both
.Dq login names
and
.Dq user names .
If a name is ambiguous, all possible derivations are returned.
.Pp
The following options may be passed to
.Nm
as server program arguments in
.Pa /etc/inetd.conf :
.Bl -tag -width XPXfilenameX
.It Fl 8
Enable 8-bit output.
.It Fl g
Do not show any gecos information besides the users' real names.
.It Fl h
Display the name of the remote host in short mode,
instead of the office location and office phone.
.It Fl l
Enable logging.
The name of the host originating the query, and the actual request
is reported via
.Xr syslog 3
at LOG_NOTICE priority.
A request of the form
.Sq /W
or
.Sq /w
will return long output.
Empty requests will return all currently logged in users.
All other requests look for specific users.
See RFC 1288 for details.
.It Fl m
Prevent matching of
.Ar user
names.
.Ar User
is usually a login name; however, matching will also be done on the
users' real names, unless the
.Fl m
option is supplied.
.It Fl P Ar filename
Use an alternate program as the local information provider.
The default local program executed by
.Nm
is
.Xr finger 1 .
By specifying a customized local server, this option allows a system manager
to have more control over what information is provided to remote sites.
.It Fl p
Prevents
.Xr finger 1
from displaying the contents of the
.Dq Pa .plan
and
.Dq Pa .project
files.
.It Fl S
Prints user information in short mode, one line per user.
This overrides the
.Dq Pa Whois switch
that may be passed in from the remote client.
.It Fl s
Disable forwarding of queries to other remote hosts.
.It Fl u
Queries without a user name are rejected.
.El
.Sh SEE ALSO
.Xr finger 1 ,
.Xr inetd 8
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.3 .
.Sh BUGS
Connecting directly to the server from a
.Tn TIP
or an equally narrow-minded
.Tn TELNET Ns -protocol
user program can result
in meaningless attempts at option negotiation being sent to the
server, which will foul up the command line interpretation.
.Nm
should be taught to filter out
.Tn IAC Ns 's
and perhaps even respond
negatively
.Pq Tn IAC WON'T
to all option commands received.

233
libexec/fingerd/fingerd.c Normal file
View File

@ -0,0 +1,233 @@
/* $NetBSD: fingerd.c,v 1.27 2012/03/15 02:02:21 joerg Exp $ */
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)fingerd.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: fingerd.c,v 1.27 2012/03/15 02:02:21 joerg Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pathnames.h"
__dead static void my_err(const char *, ...) __printflike(1, 2);
int
main(int argc, char *argv[])
{
FILE *fp;
int ch, ac = 2;
char *lp = NULL /* XXX gcc */;
struct sockaddr_storage ss;
int p[2], logging, no_forward, user_required, short_list;
socklen_t sval;
#define ENTRIES 50
char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog, *s;
#if 0
const char *av[ENTRIES + 1], **comp;
const char *prog;
#endif
char hostbuf[MAXHOSTNAMELEN];
prog = __UNCONST(_PATH_FINGER);
logging = no_forward = user_required = short_list = 0;
openlog("fingerd", LOG_PID, LOG_DAEMON);
opterr = 0;
while ((ch = getopt(argc, argv, "gsluShmpP:8")) != -1) {
switch (ch) {
case 'l':
logging = 1;
break;
case 'P':
prog = optarg;
break;
case 's':
no_forward = 1;
break;
case 'u':
user_required = 1;
break;
case 'S':
short_list = 1;
av[ac++] = __UNCONST("-s");
break;
case 'h':
av[ac++] = __UNCONST("-h");
break;
case 'm':
av[ac++] = __UNCONST("-m");
break;
case 'p':
av[ac++] = __UNCONST("-p");
break;
case 'g':
av[ac++] = __UNCONST("-g");
break;
case '8':
av[ac++] = __UNCONST("-8");
break;
case '?':
default:
my_err("illegal option -- %c", optopt);
}
if (ac >= ENTRIES)
my_err("Too many options provided");
}
if (logging) {
sval = sizeof(ss);
if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0)
my_err("getpeername: %s", strerror(errno));
(void)getnameinfo((struct sockaddr *)&ss, sval,
hostbuf, sizeof(hostbuf), NULL, 0, 0);
lp = hostbuf;
}
if (!fgets(line, sizeof(line), stdin)) {
if (logging)
syslog(LOG_NOTICE, "query from %s", lp);
exit(1);
}
while ((s = strrchr(line, '\n')) != NULL ||
(s = strrchr(line, '\r')) != NULL)
*s = '\0';
if (logging) {
if (*line == '\0')
syslog(LOG_NOTICE, "query from %s", lp);
else
syslog(LOG_NOTICE, "query from %s: %s", lp, line);
}
if (ac >= ENTRIES)
my_err("Too many options provided");
av[ac++] = __UNCONST("--");
comp = &av[1];
for (lp = line, ap = &av[ac]; ac < ENTRIES;) {
if ((*ap = strtok(lp, " \t\r\n")) == NULL)
break;
lp = NULL;
if (no_forward && strchr(*ap, '@')) {
(void) puts("forwarding service denied\r\n");
exit(1);
}
ch = strlen(*ap);
while ((*ap)[ch-1] == '@')
(*ap)[--ch] = '\0';
if (**ap == '\0')
continue;
/* RFC1196: "/[Ww]" == "-l" */
if ((*ap)[0] == '/' && ((*ap)[1] == 'W' || (*ap)[1] == 'w')) {
if (!short_list) {
av[1] = __UNCONST("-l");
comp = &av[0];
}
} else {
ap++;
ac++;
}
}
av[ENTRIES - 1] = NULL;
if ((lp = strrchr(prog, '/')))
*comp = ++lp;
else
*comp = prog;
if (user_required) {
for (ap = comp + 1; strcmp("--", *(ap++)); );
if (*ap == NULL) {
(void) puts("must provide username\r\n");
exit(1);
}
}
if (pipe(p) < 0)
my_err("pipe: %s", strerror(errno));
switch(fork()) {
case 0:
(void) close(p[0]);
if (p[1] != 1) {
(void) dup2(p[1], 1);
(void) close(p[1]);
}
execv(prog, comp);
my_err("execv: %s: %s", prog, strerror(errno));
_exit(1);
case -1:
my_err("fork: %s", strerror(errno));
}
(void) close(p[1]);
if (!(fp = fdopen(p[0], "r")))
my_err("fdopen: %s", strerror(errno));
while ((ch = getc(fp)) != EOF) {
if (ch == '\n')
putchar('\r');
putchar(ch);
}
exit(0);
}
static void
my_err(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
(void) vsyslog(LOG_ERR, fmt, ap);
va_end(ap);
exit(1);
/* NOTREACHED */
}

View File

@ -0,0 +1,34 @@
/* $NetBSD: pathnames.h,v 1.4 2003/08/07 09:46:38 agc Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)pathnames.h 5.3 (Berkeley) 6/1/90
*/
#define _PATH_FINGER "/usr/bin/finger"

View File

@ -1,6 +1,6 @@
MAN= add_route.8 backup.8 boot.8 btrace.8 \
cdprobe.8 chown.8 cleantmp.8 config.8 cron.8 \
dhcpd.8 diskctl.8 fbdctl.8 fdisk.8 fingerd.8 \
dhcpd.8 diskctl.8 fbdctl.8 fdisk.8 \
getty.8 halt.8 hgfs.8 httpd.8 ifconfig.8 inet.8 init.8 \
intr.8 irdpd.8 loadramdisk.8 MAKEDEV.8 \
netconf.8 newroot.8 nonamed.8 \

View File

@ -1,53 +0,0 @@
.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.\" @(#)fingerd.8c 6.1 (Berkeley) 5/23/86
.\"
.TH FINGERD 8 "May 23, 1986"
.UC 6
.SH NAME
fingerd, in.fingerd \- remote user information server
.SH SYNOPSIS
.B "finger stream tcp nowait nobody /usr/sbin/in.fingerd in.fingerd"
.br
.B "tcpd finger /usr/sbin/in.fingerd in.fingerd"
.SH DESCRIPTION
.B Fingerd
is a simple protocol based on RFC742 that provides an interface to the
Name and Finger programs at several network sites.
The program is supposed to return a friendly,
human-oriented status report on either the system at the moment
or a particular person in depth.
There is no required format and the
protocol consists mostly of specifying a single ``command line''.
.PP
.B Fingerd
listens for TCP requests at port 79.
Once connected it reads a single command line
terminated by a <CRLF> which is passed to
.BR finger (1).
.B Fingerd
closes its connections as soon as the output is finished.
.PP
If the line is null (i.e. just a <CRLF> is sent) then
.B finger
returns a ``default'' report that lists all people logged into
the system at that moment.
.PP
If a user name is specified (e.g. eric<CRLF>) then the
response lists more extended information for only that particular user,
whether logged in or not.
Allowable ``names'' in the command line include both ``login names''
and ``user names''.
If a name is ambiguous, all possible derivations are returned.
.SH SEE ALSO
.BR finger (1).
.SH BUGS
Connecting directly to the server from a TIP
or an equally narrow-minded TELNET-protocol user program can result
in meaningless attempts at option negotiation being sent to the
server, which will foul up the command line interpretation.
.B Fingerd
should be taught to filter out IAC's and perhaps even respond
negatively (IAC WON'T) to all option commands received.

View File

@ -59,6 +59,7 @@
2011/05/26 00:00:00,external/public-domain/xz
2012/10/17 12:00:00,external/README
2012/10/17 12:00:00,include
2013/05/31 12:00:00,libexec/fingerd
2012/10/17 12:00:00,libexec/ftpd
2012/10/17 12:00:00,libexec/ld.elf_so
2012/10/17 12:00:00,libexec/Makefile