Subject: Re: setegid() magic..
To: Jorgen Lundman <lundman@lundman.net>
From: Luke Mewburn <lukem@netbsd.org>
List: netbsd-users
Date: 04/21/2003 20:25:37
On Mon, Apr 21, 2003 at 03:03:47PM +0900, Jorgen Lundman wrote:
|
| Just out of curiosity,
|
| If I write a piece of code, run as root, or setuid root, that does:
|
| unlink("testfile");
| seteuid(10000);
| F=fopen("testfile", "w");
|
| It creates the file as the user I want. Now I also want to do the same with
| groups, so we add:
|
| unlink("testfile");
| setegid(10001);
| seteuid(10000);
| F=fopen("testfile", "w");
|
| It creates the file as 10000, but the group is "wheel". Or to be precise,
| it is the same group as "." of the directory.
That's standard "BSD" file creation semantics, no matter what group
you're a part of.
(System V file creation semantics use the "primary" group of the user
as the group of the file, BSD uses the group of the parent directory).