/*
* safe_finger - finger client wrapper that protects against nasty stuff
* from finger servers. Use this program for automatic reverse finger
* probes, not the raw finger command.
*
* Build with: cc -o safe_finger safe_finger.c
*
* The problem: some programs may react to stuff in the first column. Other
* programs may get upset by thrash anywhere on a line. File systems may
* fill up as the finger server keeps sending data. Text editors may bomb
* out on extremely long lines. The finger server may take forever because
* it is somehow wedged. The code below takes care of all this badness.
*
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
#ifndef lint
#endif
/* System libraries */
#include <signal.h>
#include <stdio.h>
#include <ctype.h>
#include <pwd.h>
extern void exit();
/* Local stuff */
int finger_pid;
int sig;
{
exit(0);
}
int
int argc;
char **argv;
{
int c;
int line_length = 0;
int finger_status;
int wait_pid;
int input_count = 0;
/*
* First of all, let's don't run with superuser privileges.
*/
} else {
}
}
/*
* Redirect our standard input through the raw finger command.
*/
exit(1);
}
argv[0] = FINGER_PROGRAM;
/*
* Don't wait forever (Peter Wemm <peter@gecko.DIALix.oz.au>).
*/
(void) alarm(TIME_LIMIT);
/*
* Main filter loop.
*/
break;
}
if (c == '\n') { /* good: end of line */
putchar(c);
line_length = 0;
} else {
printf("\\\n");
line_length = 0;
}
if (line_length == 0) { /* protect left margin */
putchar(' ');
line_length++;
}
if (c == '\\') {
putchar(c);
line_length++;
}
putchar(c);
line_length++;
} else { /* quote all other thash */
line_length += 4;
}
}
}
/*
* Wait until the finger child process has terminated and account for its
* exit status. Which will always be zero on most systems.
*/
/* void */ ;
}
/* perror_exit - report system error text and terminate */
char *text;
{
exit(1);
}
/* pipe_stdin - pipe stdin through program (from my ANSI to OLD C converter) */
char **argv;
{
int pid;
int i;
/*
* The code that sets up the pipe requires that file descriptors 0,1,2
* are already open. All kinds of mysterious things will happen if that
* is not the case. The following loops makes sure that descriptors 0,1,2
* are set up properly.
*/
for (i = 0; i < 3; i++) {
perror_exit("open /dev/null");
}
/*
* Set up the pipe that interposes the command into our standard input
* stream.
*/
perror_exit("pipe");
case -1: /* error */
perror_exit("fork");
/* NOTREACHED */
case 0: /* child */
perror_exit("dup");
perror_exit(argv[0]);
/* NOTREACHED */
default: /* parent */
(void) close(0); /* connect stdin to pipe */
perror_exit("dup");
return (pid);
}
}