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