1 /* $NetBSD: fingerd.c,v 1.24 2008/07/20 01:09:07 lukem Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "from: @(#)fingerd.c 8.1 (Berkeley) 6/4/93";
42 __RCSID("$NetBSD: fingerd.c,v 1.24 2008/07/20 01:09:07 lukem Exp $");
46 #include <sys/param.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
59 #include "pathnames.h"
61 void err(const char *, ...);
62 int main(int, char *[]);
65 main(int argc
, char *argv
[])
69 char *lp
= NULL
/* XXX gcc */;
70 struct sockaddr_storage ss
;
71 int p
[2], logging
, no_forward
, user_required
, short_list
;
74 char **ap
, *av
[ENTRIES
+ 1], **comp
, line
[1024], *prog
, *s
;
76 const char *av
[ENTRIES
+ 1], **comp
;
79 char hostbuf
[MAXHOSTNAMELEN
];
81 prog
= __UNCONST(_PATH_FINGER
);
82 logging
= no_forward
= user_required
= short_list
= 0;
83 openlog("fingerd", LOG_PID
, LOG_DAEMON
);
85 while ((ch
= getopt(argc
, argv
, "gsluShmpP:8")) != -1) {
101 av
[ac
++] = __UNCONST("-s");
104 av
[ac
++] = __UNCONST("-h");
107 av
[ac
++] = __UNCONST("-m");
110 av
[ac
++] = __UNCONST("-p");
113 av
[ac
++] = __UNCONST("-g");
116 av
[ac
++] = __UNCONST("-8");
120 err("illegal option -- %c", optopt
);
123 err("Too many options provided");
129 if (getpeername(0, (struct sockaddr
*)&ss
, &sval
) < 0)
130 err("getpeername: %s", strerror(errno
));
131 (void)getnameinfo((struct sockaddr
*)&ss
, sval
,
132 hostbuf
, sizeof(hostbuf
), NULL
, 0, 0);
136 if (!fgets(line
, sizeof(line
), stdin
)) {
138 syslog(LOG_NOTICE
, "query from %s", lp
);
141 while ((s
= strrchr(line
, '\n')) != NULL
||
142 (s
= strrchr(line
, '\r')) != NULL
)
147 syslog(LOG_NOTICE
, "query from %s", lp
);
149 syslog(LOG_NOTICE
, "query from %s: %s", lp
, line
);
153 err("Too many options provided");
154 av
[ac
++] = __UNCONST("--");
156 for (lp
= line
, ap
= &av
[ac
]; ac
< ENTRIES
;) {
157 if ((*ap
= strtok(lp
, " \t\r\n")) == NULL
)
160 if (no_forward
&& strchr(*ap
, '@')) {
161 (void) puts("forwarding service denied\r\n");
166 while ((*ap
)[ch
-1] == '@')
171 /* RFC1196: "/[Ww]" == "-l" */
172 if ((*ap
)[0] == '/' && ((*ap
)[1] == 'W' || (*ap
)[1] == 'w')) {
174 av
[1] = __UNCONST("-l");
182 av
[ENTRIES
- 1] = NULL
;
184 if ((lp
= strrchr(prog
, '/')))
190 for (ap
= comp
+ 1; strcmp("--", *(ap
++)); );
192 (void) puts("must provide username\r\n");
198 err("pipe: %s", strerror(errno
));
204 (void) dup2(p
[1], 1);
208 err("execv: %s: %s", prog
, strerror(errno
));
211 err("fork: %s", strerror(errno
));
214 if (!(fp
= fdopen(p
[0], "r")))
215 err("fdopen: %s", strerror(errno
));
216 while ((ch
= getc(fp
)) != EOF
) {
225 err(const char *fmt
, ...)
230 (void) vsyslog(LOG_ERR
, fmt
, ap
);