Solved

change group and user of process

Posted on 2004-03-24
3
211 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux daemon 11 356
Bash Script to find & Kill Multiple Process 3 98
Automating a set of commands run on linux 7 98
centOS 7 GUI is now showing. 20 1,382
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

810 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