122492Sdist /* 235556Sbostic * Copyright (c) 1983 The Regents of the University of California. 335556Sbostic * All rights reserved. 435556Sbostic * 535556Sbostic * Redistribution and use in source and binary forms are permitted 635556Sbostic * provided that the above copyright notice and this paragraph are 735556Sbostic * duplicated in all such forms and that any documentation, 835556Sbostic * advertising materials, and other materials related to such 935556Sbostic * distribution and use acknowledge that the software was developed 1035556Sbostic * by the University of California, Berkeley. The name of the 1135556Sbostic * University may not be used to endorse or promote products derived 1235556Sbostic * from this software without specific prior written permission. 1335556Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1435556Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1535556Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622492Sdist */ 1722492Sdist 1816471Ssam #ifndef lint 1922492Sdist char copyright[] = 2035556Sbostic "@(#) Copyright (c) 1983 The Regents of the University of California.\n\ 2122492Sdist All rights reserved.\n"; 2235556Sbostic #endif /* not lint */ 2316471Ssam 2422492Sdist #ifndef lint 25*36261Sbostic static char sccsid[] = "@(#)fingerd.c 5.4 (Berkeley) 11/23/88"; 2635556Sbostic #endif /* not lint */ 2722492Sdist 2816471Ssam #include <stdio.h> 2916471Ssam 30*36261Sbostic main() 3116471Ssam { 32*36261Sbostic register FILE *fp; 33*36261Sbostic register int ch; 34*36261Sbostic register char *lp; 35*36261Sbostic int p[2]; 36*36261Sbostic #define ENTRIES 50 37*36261Sbostic char **ap, *av[ENTRIES + 1], line[1024], *strtok(); 38*36261Sbostic 39*36261Sbostic #ifdef LOGGING /* unused for now */ 40*36261Sbostic #include <netinet/in.h> 4116471Ssam struct sockaddr_in sin; 42*36261Sbostic int sval; 4316471Ssam 44*36261Sbostic sval = sizeof(sin); 45*36261Sbostic if (getpeername(0, &sin, &sval) < 0) 46*36261Sbostic fatal("getpeername"); 47*36261Sbostic #endif 48*36261Sbostic 49*36261Sbostic if (!fgets(line, sizeof(line), stdin)) 5036199Sbostic exit(1); 51*36261Sbostic 5216770Sralph av[0] = "finger"; 53*36261Sbostic for (lp = line, ap = &av[1];;) { 54*36261Sbostic *ap = strtok(lp, " \t\r\n"); 55*36261Sbostic if (!*ap) 5616471Ssam break; 57*36261Sbostic /* RFC742: "/[Ww]" == "-l" */ 58*36261Sbostic if ((*ap)[0] == '/' && ((*ap)[1] == 'W' || (*ap)[1] == 'w')) 59*36261Sbostic *ap = "-l"; 60*36261Sbostic if (++ap == av + ENTRIES) 61*36261Sbostic break; 62*36261Sbostic lp = NULL; 6316471Ssam } 64*36261Sbostic 6516770Sralph if (pipe(p) < 0) 66*36261Sbostic fatal("pipe"); 67*36261Sbostic 68*36261Sbostic switch(fork()) { 69*36261Sbostic case 0: 70*36261Sbostic (void)close(p[0]); 7116770Sralph if (p[1] != 1) { 72*36261Sbostic (void)dup2(p[1], 1); 73*36261Sbostic (void)close(p[1]); 7416770Sralph } 7516770Sralph execv("/usr/ucb/finger", av); 7616770Sralph _exit(1); 77*36261Sbostic case -1: 78*36261Sbostic fatal("fork"); 7916770Sralph } 80*36261Sbostic (void)close(p[1]); 81*36261Sbostic if (!(fp = fdopen(p[0], "r"))) 82*36261Sbostic fatal("fdopen"); 83*36261Sbostic while ((ch = getc(fp)) != EOF) { 84*36261Sbostic if (ch == '\n') 8516595Sralph putchar('\r'); 86*36261Sbostic putchar(ch); 8716595Sralph } 88*36261Sbostic exit(0); 8916471Ssam } 9016471Ssam 91*36261Sbostic fatal(msg) 92*36261Sbostic char *msg; 9316471Ssam { 94*36261Sbostic extern int errno; 95*36261Sbostic char *strerror(); 96*36261Sbostic 97*36261Sbostic fprintf(stderr, "fingerd: %s: %s\r\n", msg, strerror(errno)); 9816471Ssam exit(1); 9916471Ssam } 100