/*
 * setuid wrapper:  C wrapper for setuid perl programs.
 *
 * Copyright (C) 1996,1997 Andy Wardley.  All Rights Reserved.
 *
 * --
 *
 * guestbook.c: Wrapper for the guestbook script.
 *
 * $Id: guestbook.c,v 1.1 1997/02/20 09:27:46 abw Exp abw $
 *
 */

#include <errno.h>          /* errno, unsurprisingly */
#include <stdio.h>          /* puts, printf, etc.    */
#include <stdarg.h>         /* vprintf, etc          */
#include <string.h>         /* strerror              */
#include <unistd.h>         /* execl                 */


/* change this to contain the FULL path of your guestbook script */
#define PROGPATH	"/usr/people/abw/www/cgi-bin/guestbook.pl"
#define PROGNAME	"Guestbook"



/*
 * void html_error(char *program, char *format, ...)
 *
 * Basic error reporting function.  Formats the error message (as per
 * printf(3S)) for html output.
 */

void html_error(char *program, char *format, ...) 
{
	va_list args;

	/* gack! */
	puts("Content-type: text/html\n\n");
	puts("<html>\n<head>\n<title>Error</title>\n</head>\n\n");
	puts("<body bgcolor=\"#ffffff\">\n");
	puts("<h1>Error!</h1>\n");
	puts("An error has occurred:\n");

	printf("<ul>%s\n<li>", program);
	
	/* print formatted error message */
	va_start(args, format);
	vprintf(format, args);
	va_end(args);

	puts("\n</ul>\n\n");
	puts("</body>\n</html>\n");
}



/*
 * main(int argc, char **argv)
 * 
 * Simply exec's the Perl script, generating an HTML error page on failure.
 */

main(int argc, char **argv)
{
	execl(PROGPATH, PROGPATH, (char *) 0);

	html_error(PROGNAME, "exec failed: %s", strerror(errno));
}
