#include #include #include #include int main(int argc, char **argv) { struct stat statbuf; if ( stat("foo", &statbuf) == -1 ) { perror("can't stat foo"); exit(1); } /* turn off group execute and turn on set-group-ID */ if ( chmod("foo", (statbuf.st_mode & ~S_IXGRP) | S_ISGID) == -1 ) { perror("can't chmod foo"); exit(1); } /* set absolute mode to rw-r--r-- */ if ( chmod("bar", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1 ) { perror("can't chmod bar"); exit(1); } exit(0); }