I have written a program in c, that do some calculations then creates a folder. That folder’s owner is the root user. With an other user I am trying to run this c application. I’ve got this error:
mkdir: lol: Permission denied
Ok, I know this error is ok, because I don’t have rights for it, but I have read on the internet, that if I set the suid bit on the file, then this file will run with the owner’s rights.
I’ve used this command:
chmod +s filename
But it isn’t working… 🙁 Any ideas?
EDIT:
So, first of all, my Unix distribution is a Mac OS X 10.5.8. And my filename is a.out, since I have compiled it from ic.c with the command: gcc ic.c
And I am running the chmod command with the root user.
I think you also will need to
setuid(0);in your program to become root. Only setting the s-bit is not sufficient.Edit
Jonathan Leffler is right in the comments.
setuid(0);should probably not be necessary in this case. The necessary steps for ie creating a file under/etccreate_file_under_etc.c
…and to test and compile
…you better clean up also