473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Changing UNIX primary group

I have a unix id that has group1 for a primary group, and group2, group3,
and group4 for supplementary groups. I'd like to change my primary group
before running certain commands. So sometimes I might want group2 to be
the primary group, and other times group3 or group4.

I saw the posix module's setgid method, but it failed for me unless I was
running as root. Also it only accepts the gid, but I'd rather pass in
the group name, or somehow lookup the gid based on the name.

Does anyone know a way to do all of this?
Thanks much.
-Justin

Jul 18 '05 #1
3 6259
"Justin Johnson" <ju***********@fastmail.fm> wrote in message news:<ma**********************************@python. org>...
I have a unix id that has group1 for a primary group, and group2, group3,
and group4 for supplementary groups. I'd like to change my primary group
before running certain commands. So sometimes I might want group2 to be
the primary group, and other times group3 or group4.

I saw the posix module's setgid method, but it failed for me unless I was
running as root. Also it only accepts the gid, but I'd rather pass in
the group name, or somehow lookup the gid based on the name.

Does anyone know a way to do all of this?
Thanks much.
-Justin


These are not python solution;

1) make a setgid script and put your commands there, or
2) use shell commands;

echo "command1; command2;" | newgrp group2

-Inyeol
Jul 18 '05 #2
Thanks. I was hoping for a python solution though. :-( Does anyone
know of a way to do this in python?

On 13 Aug 2003 08:52:40 -0700, "Inyeol Lee" <In********@yahoo.com> said:
"Justin Johnson" <ju***********@fastmail.fm> wrote in message
news:<ma**********************************@python. org>...
I have a unix id that has group1 for a primary group, and group2, group3,
and group4 for supplementary groups. I'd like to change my primary group
before running certain commands. So sometimes I might want group2 to be
the primary group, and other times group3 or group4.

I saw the posix module's setgid method, but it failed for me unless I was
running as root. Also it only accepts the gid, but I'd rather pass in
the group name, or somehow lookup the gid based on the name.

Does anyone know a way to do all of this?
Thanks much.
-Justin


These are not python solution;

1) make a setgid script and put your commands there, or
2) use shell commands;

echo "command1; command2;" | newgrp group2

-Inyeol
--
http://mail.python.org/mailman/listinfo/python-list


Jul 18 '05 #3
Okay, I'll have to do some more research. Maybe I *will* have to run the
script setuid root. Shucks! Thanks for the grp.getgrnam help. Just
what I needed. :-)

On Wed, 13 Aug 2003 14:11:01 -0500, "Jeff Epler" <je****@unpythonic.net>
said:
On Wed, Aug 13, 2003 at 12:10:02PM -0600, Justin Johnson wrote:
Thanks. I was hoping for a python solution though. :-( Does anyone
know of a way to do this in python?


Unix doesn't let you setgid() to groups in the supplemental group list
without the same permission needed to change to any group.

But depending what you need to do, you might be able to use set-group-id
directories. For instance, if I am group g1 and have a group list [g1,
g2, g3], then I can read files readable by any of those groups, and
create files in directories writable by any of those groups. But if you
make a directory d2 that is setgid g2 and d3 setgid g3, then when I
create a file in d2 it will belong to group g2.

Barring that, you could modify the setgid() call in the kernel, to permit
the change if the requested group is in the auxiliary group list.
It looks like something you could do in an afternoon if you have the
source for your kernel (bsd, linux, etc) and can program C.

"Justin Johnson" <ju***********@fastmail.fm> wrote in message
news:<ma**********************************@python. org>...
Also [setgid] only accepts the gid, but I'd rather pass in
the group name, or somehow lookup the gid based on the name.


See grp.getgrnam(). Example:
>>> grp.getgrnam("utmp")

('utmp', 'x', 22, [])

Jeff


Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lawrence | last post by:
> If anything, set up PHP to run as the user that owns htdocs, rather > than the other way around, it is somewhat safer that way, unless PHP > requires root permissions I ran a search on Google...
4
by: Tim Daneliuk | last post by:
OK, I've Googled for this and cannot seem to quite find what I need. So, I turn to the Gentle Geniuses here for help. Here is what I need to do from within a script: Given a username and a...
14
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only....
3
by: labzilla | last post by:
I want to modify the value of $@ so that if( $@ ) becomes a true statement. Sorry if this is a newbie question.
9
by: 101 | last post by:
Taking a course on SQL. They are saying you can get better performance by having multiple files for a group. They then graphically show an example of "Primary" with multiple data files. I have...
18
by: Thomas A. Anderson | last post by:
I am a bit confused in creating a composite primary key. I have three table with two of the tables containing primary keys. I have two of the tables (each with a primary key) having one to many...
5
by: Nonoize | last post by:
Hi all, Really dumb question but I don't know how to resolve it. Looked in help and evry book I have. I have a table where the primary key was set as an Integer and its reached over 140K...
115
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can...
0
by: Derek Peschel | last post by:
Should I add an RFE to SourceForge too? I'd like a wide audience in case someone has enough experience to comment or is solving the same problem. I'm using the urwid library which uses curses. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.