/*
 * Copyright (c) 2004 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 */

#include "sm/generic.h"
SM_RCSID("@(#)$Id: noroot.c,v 1.2 2007/02/14 03:44:43 ca Exp $")

#include "sm/sysexits.h"
#include <stdio.h>

int
main(int argc, char *argv[])
{
	int c;
	bool noroot;
	uid_t uid;

	noroot = true;
	while ((c = getopt(argc, argv, "r")) != -1)
	{
		switch (c)
		{
		  case 'r':
			noroot = false;
			break;
		}
	}

	uid = geteuid();
	if (noroot && uid == 0)
	{
		(void) fprintf(stderr,
			"I'm sorry, Dave, I'm afraid I can't do that\n(running as root)\n");
		exit(EX_USAGE);
	}
	if (!noroot && uid != 0)
	{
		(void) fprintf(stderr,
			"This program must be run with root privileges\n");
		exit(EX_USAGE);
	}
	return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1