Solved

change group and user of process

Posted on 2004-03-24
3
209 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

13 Experts available now in Live!

Get 1:1 Help Now