Date: Fri, 2 Feb 2001 22:58:13 -0600 (CST) From: Mike Meyer <mwm@mired.org> To: Arcady Genkin <a.genkin@utoronto.ca> Cc: questions@freebsd.org Subject: Re: Change group ID in a shell script Message-ID: <14971.36837.748308.357892@guru.mired.org> In-Reply-To: <47177316@toto.iv>
next in thread | previous in thread | raw e-mail | index | archive | help
Arcady Genkin <a.genkin@utoronto.ca> types: > "Crist J. Clark" <cjclark@reflexnet.net> writes: > > > > I solved the problem by writing a Perl script instead of a shell > > > script (using Perl's `setpgrp'). I would still like to know how I > > > could do that in a shell script, though. > > > > It does not seem like it would matter for your purposes. The group ID > > of a newly created file has nothing to do with the group of the user > > creating it (aside from possibly giving permissions to write the > > file) on a BSD system. > > Ooops, you are right. Then I haven't solved the problem (I only > tested the script on the Solaris side until I read your message). In > this case, let me rephrase the question into two: > > 1. How do I change process's user group in a shell script? The same way you change the user id of a running process - grovel through /dev/mem & /dev/kmem, and write the new userid in the proc structure in the kernel. Note that being able to do this is a *major* security hole, so unless you have root privs on the machine, you probably can't. This kind of activity is also a really, really bad idea in general. Sarcasm aside, processes are generally only allowed to fool with their *own* user/group settings. For a shell script, this means the shell has to have a builtin to do it, otherwise you can't sanely do it. I don't know of a shell that has that kind of functionality, but would be interested in hearing about it if one does. You might consider replacing the script with a C program that twiddles the groups to be what you want then execs the shell script. Easier - but with unsettling security implications - is making the script setgid. > 2. How do I make sure files are created with a certain group > ownership in a shell script? You can't, unless you can set the group ownership of the directories they are created in. You can chgrp them after creation, and that's about it. This is one of the differences between SysV and BSD. SysV creates files owned by the group of the creating process; BSD by the group of the containing directory. Solaris provides tools to get both behaviors on a directory-specific basis so that they wouldn't piss off their SunOS (BSD-based) user base any more than necessary - which was quite a bit as it was, seeing as how there were "Death to Solaris" BOFs at USENIX back then. Linux does it the SysV way. The creat man page doesn't state either behavior, but claims compatibility with both SysV and BSD. <mike -- Mike Meyer <mwm@mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?14971.36837.748308.357892>