Solved

change group and user of process

Posted on 2004-03-24
3
210 Views
Last Modified: 2010-04-22
I want a root user to be able to run my program like:

myprog -u someUser -g someGroup

and then have the program switch to that user and group when it starts running.  What functions do I need to use to program this in C?
0
Comment
Question by:lwinkenb
  • 2
3 Comments
 
LVL 5

Expert Comment

by:g0rath
ID: 10671217
look up the man pages for...
User Identiy functions
setuid
seteuid
setreuid
setresuid


Group identity
setgid
setegid
setregid


usage like...

seteuid(uid_of_bob)
// Do stuff as bob
seteuid(0)
// Switch back to Root
seteuid(uid_of_frank)
// Do stuff as frank
// etc...
0
 
LVL 5

Accepted Solution

by:
g0rath earned 125 total points
ID: 10671268
also for the argument parsing, have you looked up getopt()

man 3 getopt

int main( int argc, char **argv )
{

int c;

while (1)
{
    c = getopt(argc,argv,"u:g:")
    if (c == -1)
         break;

    switch (c)
    {
         case 'u':
             printf ("%s\n",optarg); // your user
             break;
         case 'g':
             printf ("%s\n",optarg); // your group
             break;
         
    }
}


return 0;
}
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 10684843
Thanks a lot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LocalRepositoryNotAccessible error when running maven 1 65
Help with Ubuntu 14.04 LTS 10 132
Linux Search 3 66
add some character at the end of line in vi 7 62
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now