?
Solved

change group and user of process

Posted on 2004-03-24
3
Medium Priority
?
215 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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 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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
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…

752 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