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?