/* Wrapper for running CGI's with the correct UID.
 * Copyright (c) 2000, Christopher Wilson, All Rights Reserved.
 *
 * This software is licenced to Purlip for use on reachoxbridge.co.uk
 * it may not be copied and used for any other use.
 * For more information email jakdaw@xmms.org
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	struct stat s;
	
	if(argc!=2)
		return 1;
		
	if(stat(argv[1], &s)!=0)
		return 2;
	
	if(s.st_uid!=geteuid())
		return 3;
		
	setreuid(geteuid(), geteuid());
	
	system(argv[1]);
	
	return 0;
}
