lchown.c (1221B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <sys/stat.h> 5 #include <unistd.h> 6 #include <fcntl.h> 7 #include <errno.h> 8 9 int main(void) 10 { 11 char *template = "/tmp/sfakeroot.test.XXXXXX"; 12 char path[strlen(template) + 1]; 13 struct stat st_before; 14 struct stat st_after; 15 16 strcpy(path, template); 17 printf("test making path %s\n", mktemp(path)); 18 19 if (symlink("foobar", path) == -1) { 20 fprintf(stderr, "symlink '%s' failed: %s\n", path, strerror(errno)); 21 return 1; 22 } 23 24 if (lstat(path, &st_before) == -1) 25 { 26 fprintf(stderr, "stat failed\n"); 27 return 1; 28 } 29 if (st_before.st_uid != 0 || st_before.st_gid != 0) { 30 fprintf(stderr, "uid/gid not 0\n"); 31 return 1; 32 } 33 34 if (lchown(path, 42, 43) == -1) { 35 fprintf(stderr, "chown '%s' failed: %s\n", path, strerror(errno)); 36 return 1; 37 } 38 39 if (lstat(path, &st_after) == -1) 40 { 41 fprintf(stderr, "stat failed\n"); 42 return 1; 43 } 44 if (st_after.st_uid != 42) { 45 fprintf(stderr, "uid not 42\n"); 46 return 1; 47 } 48 if (st_after.st_gid != 43) { 49 fprintf(stderr, "gid not 43\n"); 50 return 1; 51 } 52 53 return 0; 54 }