Commit | Line | Data |
---|---|---|
da158ee3 | 1 | /* |
54b3b5b7 KB |
2 | * Copyright (c) 1983 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
da158ee3 DF |
16 | */ |
17 | ||
18 | #ifndef lint | |
19 | char copyright[] = | |
54b3b5b7 | 20 | "@(#) Copyright (c) 1983 The Regents of the University of California.\n\ |
da158ee3 | 21 | All rights reserved.\n"; |
54b3b5b7 | 22 | #endif /* not lint */ |
da158ee3 | 23 | |
0f6570f2 | 24 | #ifndef lint |
fe6179ab | 25 | static char sccsid[] = "@(#)fingerd.c 5.3 (Berkeley) %G%"; |
54b3b5b7 | 26 | #endif /* not lint */ |
0f6570f2 SL |
27 | |
28 | /* | |
29 | * Finger server. | |
30 | */ | |
31 | #include <sys/types.h> | |
32 | #include <netinet/in.h> | |
0f6570f2 SL |
33 | #include <stdio.h> |
34 | #include <ctype.h> | |
35 | ||
36 | main(argc, argv) | |
54b3b5b7 | 37 | int argc; |
0f6570f2 SL |
38 | char *argv[]; |
39 | { | |
d65ec3aa RC |
40 | register char *sp; |
41 | char line[512]; | |
0f6570f2 | 42 | struct sockaddr_in sin; |
d65ec3aa | 43 | int i, p[2], pid, status; |
0b751098 | 44 | FILE *fp; |
d65ec3aa | 45 | char *av[4]; |
0f6570f2 SL |
46 | |
47 | i = sizeof (sin); | |
48 | if (getpeername(0, &sin, &i) < 0) | |
49 | fatal(argv[0], "getpeername"); | |
fe6179ab KB |
50 | if (fgets(line, sizeof(line), stdin) == NULL) |
51 | exit(1); | |
0b751098 | 52 | sp = line; |
d65ec3aa | 53 | av[0] = "finger"; |
fe6179ab | 54 | for (i = 1;;) { |
0b751098 RC |
55 | while (isspace(*sp)) |
56 | sp++; | |
57 | if (!*sp) | |
0f6570f2 | 58 | break; |
0b751098 RC |
59 | if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) { |
60 | sp += 2; | |
d65ec3aa RC |
61 | av[i++] = "-l"; |
62 | } | |
63 | if (*sp && !isspace(*sp)) { | |
64 | av[i++] = sp; | |
65 | while (*sp && !isspace(*sp)) | |
66 | sp++; | |
67 | *sp = '\0'; | |
68 | } | |
69 | } | |
70 | av[i] = 0; | |
71 | if (pipe(p) < 0) | |
72 | fatal(argv[0], "pipe"); | |
73 | if ((pid = fork()) == 0) { | |
74 | close(p[0]); | |
75 | if (p[1] != 1) { | |
76 | dup2(p[1], 1); | |
77 | close(p[1]); | |
0f6570f2 | 78 | } |
d65ec3aa RC |
79 | execv("/usr/ucb/finger", av); |
80 | _exit(1); | |
0b751098 | 81 | } |
d65ec3aa RC |
82 | if (pid == -1) |
83 | fatal(argv[0], "fork"); | |
84 | close(p[1]); | |
85 | if ((fp = fdopen(p[0], "r")) == NULL) | |
86 | fatal(argv[0], "fdopen"); | |
0b751098 RC |
87 | while ((i = getc(fp)) != EOF) { |
88 | if (i == '\n') | |
89 | putchar('\r'); | |
90 | putchar(i); | |
0f6570f2 | 91 | } |
d65ec3aa RC |
92 | fclose(fp); |
93 | while ((i = wait(&status)) != pid && i != -1) | |
94 | ; | |
0b751098 | 95 | return(0); |
0f6570f2 SL |
96 | } |
97 | ||
98 | fatal(prog, s) | |
99 | char *prog, *s; | |
100 | { | |
0f6570f2 SL |
101 | fprintf(stderr, "%s: ", prog); |
102 | perror(s); | |
103 | exit(1); | |
104 | } |