473,669 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6276
"Justin Johnson" <ju***********@ fastmail.fm> wrote in message news:<ma******* *************** ************@py thon.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********@yah oo.com> said:
"Justin Johnson" <ju***********@ fastmail.fm> wrote in message
news:<ma******* *************** ************@py thon.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****@unpytho nic.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******* *************** ************@py thon.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("u tmp")

('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
1845
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 Groups but Google only brought back entries from PHP-DEV. I'm sure this has been asked before but I can't find a mention of it. How do you change the user name or id that PHP runs as. Right now PHP seems to be running as either root or nobody (I...
4
3201
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 password (plain text): 1) Validate that the password is correct for that user *without actually logging in*. 2) If the password is valid, return a list of all the groups the user belongs to. Otherwise, return some error string.
14
2496
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. For example, here is the main page: <html> <head> <script type="text/javascript">
3
2674
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
6857
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 tried altering PRIMARY to have multiple data files and I get and error. I have tried creating a new database with multiple PRIMARY files and get an error. I can ALTER and CREATE secondary files with multiple data files with no
18
12646
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 relations with the table containing no primary key. Do I just create two primary keys on the table that does not contain any primary key for this to become a composite primary key? Thank you in advance! Still a newbie,
5
6345
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 worth of records and the numbering has restarted from 1. I realize now that I should have set it to double. Can someone please advise how I can save my existing records and restart the numbering from say
115
6223
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 I use them as primary keys or should I define an autonum primary key? One table has information about the 50 states in the US. The table looks like this:
0
1617
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. On my system (Mac OS 10.3.7) I specifically have ncurses. The programs I'm running turn off echoing and set raw mode but don't disable interrupts. For development purposes I like having interrupts, but my preferred keystrokes (WordStar) conflict...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8587
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.