/* finger.c -- * "Finger Gateway" * Written by J. Patrick Van Metre for * World Wide Web: Beyond the Basics * CS 6204 at Virginia Polytechnic Institute and State University * * This CGI application is a gateway to the finger utility */ #include #include #include #define STRING_LENGTH 256 #define FINGER_CMD "finger" void main(int argc, char *argv[]) { char Name[STRING_LENGTH]; int i, len; char *execargv[3]; /* If no parameter is given, or if too many are given, */ /* exit gracefully (only one name is expected) */ if (argc != 2) { printf("Content-type: text/html\n\n"); printf("Finger gateway -- ERROR\n\n"); printf("

ERROR:

\n"); printf("Your must provide a name.\n"); exit(1); } /* If the name passed in contains a semicolon or an */ /* ampersand, replace the offending character with */ /* a null character to cut off the rest of the string */ strcpy(Name, argv[1]); len = strlen(Name); for (i = 0; i < len; i++) if ((Name[i] == ';') || (Name[i] == '&')) Name[i] = 0; /* Output header information (followed by blank line): */ /* MIME type of contents of body */ printf("Content-type: text/plain\n\n"); /* Make sure that the output buffer is empty before we */ /* call "finger"; otherwise, we may not output the */ /* header properly. */ fflush(stdout); /* Set up the parameters to be passed to "finger" as */ /* if they were typed at the command line */ execargv[0] = (char *) malloc(STRING_LENGTH); strcpy(execargv[0], FINGER_CMD); execargv[1] = (char *) malloc(STRING_LENGTH); strcpy(execargv[1], Name); execargv[2] = NULL; /* Start the finger utility */ execvp(FINGER_CMD, execargv); }