* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)fingerd.c 8.1 (Berkeley) %G%";
void err
__P((const char *, ...));
int p
[2], logging
, secure
, sval
;
char **ap
, *av
[ENTRIES
+ 1], **comp
, line
[1024], *prog
;
openlog("fingerd", LOG_PID
| LOG_CONS
, LOG_DAEMON
);
while ((ch
= getopt(argc
, argv
, "slp:")) != EOF
)
err("illegal option -- %c", ch
);
if (getpeername(0, (struct sockaddr
*)&sin
, &sval
) < 0)
err("getpeername: %s", strerror(errno
));
if (hp
= gethostbyaddr((char *)&sin
.sin_addr
.s_addr
,
sizeof(sin
.sin_addr
.s_addr
), AF_INET
))
lp
= inet_ntoa(sin
.sin_addr
);
syslog(LOG_NOTICE
, "query from %s", lp
);
if (!fgets(line
, sizeof(line
), stdin
))
for (lp
= line
, ap
= &av
[2];;) {
*ap
= strtok(lp
, " \t\r\n");
if (secure
&& ap
== &av
[2]) {
puts("must provide username\r\n");
if (secure
&& strchr(*ap
, '@')) {
puts("fowarding service denied\r\n");
/* RFC742: "/[Ww]" == "-l" */
if ((*ap
)[0] == '/' && ((*ap
)[1] == 'W' || (*ap
)[1] == 'w')) {
else if (++ap
== av
+ ENTRIES
)
if (lp
= strrchr(prog
, '/'))
err("pipe: %s", strerror(errno
));
err("execv: %s: %s", prog
, strerror(errno
));
err("fork: %s", strerror(errno
));
if (!(fp
= fdopen(p
[0], "r")))
err("fdopen: %s", strerror(errno
));
while ((ch
= getc(fp
)) != EOF
) {
err(const char *fmt
, ...)
(void)vsyslog(LOG_ERR
, fmt
, ap
);