Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change group and user of process

Posted on 2004-03-24
3
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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