#!/usr/local/bin/cz --
use b

Main()
	cstr user = "sam"
	getargs(cstr, user)

	# slow way
	int count = 0
	bm_block("setuid with lookup", 1000)
		repeat(1000)
			become(user)
				if !count++
					system("id")

	# quick way
	passwd *pw = Getpwnam(user)
	if !pw
		error("user not found: %s", user)
	new(groups, vec, gid_t, 6)
	int ngroups = Getgrouplist(user, pw->pw_uid, groups)
	count = 0
	warn()
	bm_block("setuid, pre-lookup", 100000)
		repeat(100000)
			Setgroups(ngroups, (gid_t*)vec0(groups))
			Setegid(pw->pw_gid)
			Seteuid(pw->pw_uid)
			if !count++
				system("id")
			Seteuid(0)
			Setegid(0)
			Cleargroups()
