122492Sdist /* 2*35556Sbostic * Copyright (c) 1983 The Regents of the University of California. 3*35556Sbostic * All rights reserved. 4*35556Sbostic * 5*35556Sbostic * Redistribution and use in source and binary forms are permitted 6*35556Sbostic * provided that the above copyright notice and this paragraph are 7*35556Sbostic * duplicated in all such forms and that any documentation, 8*35556Sbostic * advertising materials, and other materials related to such 9*35556Sbostic * distribution and use acknowledge that the software was developed 10*35556Sbostic * by the University of California, Berkeley. The name of the 11*35556Sbostic * University may not be used to endorse or promote products derived 12*35556Sbostic * from this software without specific prior written permission. 13*35556Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*35556Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*35556Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622492Sdist */ 1722492Sdist 1816471Ssam #ifndef lint 1922492Sdist char copyright[] = 20*35556Sbostic "@(#) Copyright (c) 1983 The Regents of the University of California.\n\ 2122492Sdist All rights reserved.\n"; 22*35556Sbostic #endif /* not lint */ 2316471Ssam 2422492Sdist #ifndef lint 25*35556Sbostic static char sccsid[] = "@(#)fingerd.c 5.2 (Berkeley) 09/19/88"; 26*35556Sbostic #endif /* not lint */ 2722492Sdist 2816471Ssam /* 2916471Ssam * Finger server. 3016471Ssam */ 3116471Ssam #include <sys/types.h> 3216471Ssam #include <netinet/in.h> 3316471Ssam 3416471Ssam #include <stdio.h> 3516471Ssam #include <ctype.h> 3616471Ssam 3716471Ssam main(argc, argv) 38*35556Sbostic int argc; 3916471Ssam char *argv[]; 4016471Ssam { 4116770Sralph register char *sp; 4216770Sralph char line[512]; 4316471Ssam struct sockaddr_in sin; 4416770Sralph int i, p[2], pid, status; 4516595Sralph FILE *fp; 4616770Sralph char *av[4]; 4716471Ssam 4816471Ssam i = sizeof (sin); 4916471Ssam if (getpeername(0, &sin, &i) < 0) 5016471Ssam fatal(argv[0], "getpeername"); 5116471Ssam line[0] = '\0'; 5216471Ssam gets(line); 5316595Sralph sp = line; 5416770Sralph av[0] = "finger"; 5516770Sralph i = 1; 5616471Ssam while (1) { 5716595Sralph while (isspace(*sp)) 5816595Sralph sp++; 5916595Sralph if (!*sp) 6016471Ssam break; 6116595Sralph if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) { 6216595Sralph sp += 2; 6316770Sralph av[i++] = "-l"; 6416471Ssam } 6516770Sralph if (*sp && !isspace(*sp)) { 6616770Sralph av[i++] = sp; 6716770Sralph while (*sp && !isspace(*sp)) 6816770Sralph sp++; 6916770Sralph *sp = '\0'; 7016770Sralph } 7116471Ssam } 7216770Sralph av[i] = 0; 7316770Sralph if (pipe(p) < 0) 7416770Sralph fatal(argv[0], "pipe"); 7516770Sralph if ((pid = fork()) == 0) { 7616770Sralph close(p[0]); 7716770Sralph if (p[1] != 1) { 7816770Sralph dup2(p[1], 1); 7916770Sralph close(p[1]); 8016770Sralph } 8116770Sralph execv("/usr/ucb/finger", av); 8216770Sralph _exit(1); 8316770Sralph } 8416770Sralph if (pid == -1) 8516770Sralph fatal(argv[0], "fork"); 8616770Sralph close(p[1]); 8716770Sralph if ((fp = fdopen(p[0], "r")) == NULL) 8816770Sralph fatal(argv[0], "fdopen"); 8916595Sralph while ((i = getc(fp)) != EOF) { 9016595Sralph if (i == '\n') 9116595Sralph putchar('\r'); 9216595Sralph putchar(i); 9316595Sralph } 9416770Sralph fclose(fp); 9516770Sralph while ((i = wait(&status)) != pid && i != -1) 9616770Sralph ; 9716595Sralph return(0); 9816471Ssam } 9916471Ssam 10016471Ssam fatal(prog, s) 10116471Ssam char *prog, *s; 10216471Ssam { 10316471Ssam 10416471Ssam fprintf(stderr, "%s: ", prog); 10516471Ssam perror(s); 10616471Ssam exit(1); 10716471Ssam } 108