0

So I have a very simple code snippet, which simply checks if the process is running as root:

int main()
{
    if(getegid() == 80 || setegid(80) == 0){
        printf("We are root\n");
    }else{
        printf("We are not root\n");
    }
    return 0;
}

I want to elevate to root "automatically" by asking the user password through a GUI. Using the terminal (or just asking the user to re-run the program with sudo) is not an option unfortunately. Similarly, the answers posed in this question are also not suitable, as this is using objective C, not C, and requires the Xcode tools, which I would prefer to not have the user have to install. This question is closer, but also assumes Objective-C, and the SMJobBless examples do not seem to exist for C(?).

What are my options for achieving elevation to root under the specified restrictions?

GhostDog98
  • 29
  • 5
  • 1
    Why are you checking for group 80 (admin)? This might (or might not) be root. Check for uid of 0 instead. – jmq Nov 28 '22 at 01:04
  • 1
    Well, the best way to do this is sudo but you ruled that out. Can you make the executable setuid root and restrict it to a specific group? – jmq Nov 28 '22 at 01:06
  • Not really. My end goal is for this to be distributed as part of a program where users do not have access to the terminal anyways (due to security restrictions). – GhostDog98 Nov 28 '22 at 21:16

0 Answers0