I have the following c program.
$ cat main.c
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int fd;
if((fd = open(argv[1], O_RDONLY)) == -1) {
perror("open");
return 1;
}
if(close(fd) == -1) {
perror("close");
return 1;
}
return 0;
}
But I got the following error.
touch tmpfile
sudo chown root tmpfile
sudo chown root ./main_prog
sudo setcap cap_setuid+ep ./main_prog # There will be no error if I use sudo chmod u+s
./main_prog tmpfile
open: Permission denied
Could anybody show me how to use setcap for setuid?