DragonFly bugs List (threaded) for 2007-01
DragonFly BSD
DragonFly bugs List (threaded) for 2007-01
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: at/batch broken


From: YONETANI Tomokazu <qhwt+dfly@xxxxxxxxxx>
Date: Sun, 7 Jan 2007 17:30:39 +0900

On Sun, Jan 07, 2007 at 05:06:05PM +0900, YONETANI Tomokazu wrote:
> I'm attaching the sample code again.

*blush* here you are.

Cheers.
/*
 * usage:
 * $ gcc -W -Wall at.c
 * $ su
 * # chown root a.out; chmod u+s a.out
 * # exit
 * $ ./a.out
 */
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define CHECK(expr) \
if ((expr) != 0) \
  err(1, #expr)

int
main()
{
	uid_t real_uid, effective_uid;
	int fd;

	real_uid = getuid();
	effective_uid = geteuid();
	CHECK(setreuid(effective_uid, real_uid));

	CHECK(setreuid(real_uid, effective_uid));
	fd = open("/etc/hosts", O_RDONLY);
	CHECK(setreuid(effective_uid, real_uid));
	close(fd), fd = -1;	/* move this above the previous line */

	CHECK(setreuid(real_uid, effective_uid));
	printf("uid %d, euid %d\n", getuid(), geteuid());
	CHECK(setreuid(effective_uid, real_uid));
	return 0;
}


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]