I have the code shown below. I have compiled it and changed the
ownership of a.out to user2:user2 and set the setuid bit (chmod 04755
a.out). Now I tried to run it as user1. The readdir system call
function works fine, the directory contents of /home/user2 get printed.
But, the 'system("ls -l /home/user2")', doesn't work, it gives the
error "ls: /home/user2: Permission denied". Any ideas how to make this
work? (btw, /home/user2 has the perms 700)


int main(){

DIR *dirp = opendir("/home/user2");
struct dirent* dp;
while (dirp) {
int errno = 0;
if ((dp = readdir(dirp)) != 0) {


system("ls -l /home/user2");