1 #include <sys/types.h> 2 #include <sys/dir.h> 3 #include <sys/param.h> 4 #include <sys/stat.h> 5 #include <stdio.h> 6 #include <unistd.h> 7 8 /* Check directory Access */ check_directory_access(char * directory)9int check_directory_access(char *directory) 10 { 11 12 struct stat statbuf; 13 14 printf("Checking %s\n", directory); 15 16 if (stat(directory, &statbuf) == -1) { 17 printf("FAIL: %s. Could not obtain directory status\n", 18 directory); 19 return 1; 20 } 21 22 if (statbuf.st_uid != 0) { 23 printf("FAIL: %s. Invalid owner\n", directory); 24 return 1; 25 } 26 27 if ((statbuf.st_mode & S_IWGRP) || (statbuf.st_mode & S_IWOTH)) { 28 printf("FAIL: %s. Invalid write access\n", directory); 29 return 1; 30 } 31 32 printf("PASS: %s\n", directory); 33 return 0; 34 } 35 main(int argc,char * argv[])36int main(int argc, char *argv[]) 37 { 38 39 if (argc != 2) { 40 printf("Please enter target directory"); 41 return 1; 42 } 43 44 return check_directory_access(argv[1]); 45 } 46