I want to create a simple script to restart the Mac. The command requires root privileges, so I decided to create an executable with the setuid bit set and the owner being root.
For testing the setuid behaviour, the C file:
#include<stdio.h>
#include<stdlib.h>
int main() {
system("echo $UID");
system("echo $EUID");
system("sudo echo hello");
}
I have put the executable in /usr/local/bin
directory. I read somewhere on the internet that Mac only allows setuid bit for the owner root when all the directories till /
are owned by root. So, I moved my executable in this directory.
-rwsr-xr-x 1 root wheel 33016 Apr 2 08:50 somethingsdfsdf
However, the output of the executable is,
$ ./somethingsdfsdf
501
501
Password:
hello
As you can see, it is not the root user id but mine. Does anybody know what am I missing?