#include #include #include #include #include #include #include #include #define FMT_SHIFT 12 #define FMT_BITS 4 int types[1<>FMT_SHIFT] = "regular file", [S_IFDIR>>FMT_SHIFT] = "directory", [S_IFCHR>>FMT_SHIFT] = "char device", [S_IFBLK>>FMT_SHIFT] = "block deice", [S_IFLNK>>FMT_SHIFT] = "symbolic link", [S_IFIFO>>FMT_SHIFT] = "fifo", [S_IFSOCK>>FMT_SHIFT] = "socket" }; int bigfiles; double execsum = 0.0; int execcount; int wrong_owner; int wrong_perms; int worldwrite; ino_t mininode; int minset = 0; ino_t maxinode; int maxset = 0; int maxlinks; char * maxlinksname; int times[27]; int mainuser; int maingroup; void examine (char * dir) { DIR * d = opendir (dir); int dirlen, val; struct stat statbuf; struct dirent * dent; char * buf; if (!d) { fprintf (stderr, "Can't read %s: ", dir); perror ("opendir"); return; } dirlen = strlen (dir); buf = malloc (dirlen + FILENAME_MAX+2); strcpy (buf, dir); while ((dent = readdir (d))) { if (strcmp (dent->d_name, ".") == 0) continue; if (strcmp (dent->d_name, "..") == 0) continue; if (strlen (dent->d_name) > FILENAME_MAX) { fprintf (stderr, "Name %s too long\n", dent->d_name); } buf[dirlen] = '/'; buf[dirlen+1] = 0; strncpy (buf+dirlen+1, dent->d_name, FILENAME_MAX); if (lstat (buf, &statbuf) < 0) { fprintf (stderr, "Cant' stat %s: ", buf); perror ("stat"); } if ((statbuf.st_mode & S_IFMT) == S_IFDIR) { examine (buf); } types[(statbuf.st_mode & S_IFMT) >> FMT_SHIFT]++; if (statbuf.st_size > 5*1024*1024) bigfiles++; if (((statbuf.st_mode & S_IFMT) == S_IFREG) && (statbuf.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))) { execsum += statbuf.st_size; execcount++; } if ((statbuf.st_uid != mainuser) || (statbuf.st_gid != maingroup)) { wrong_owner++; } if (((~(statbuf.st_mode & S_IRWXU) >> 3) & (statbuf.st_mode & S_IRWXG)) || ((~(statbuf.st_mode & S_IRWXG) >> 3) & (statbuf.st_mode & S_IRWXO))) { wrong_perms++; } if (statbuf.st_mode & S_IWOTH) worldwrite++; if (!minset || (mininode > statbuf.st_ino)) { minset = 1; mininode = statbuf.st_ino; } if (!maxset || (maxinode < statbuf.st_ino)) { maxset = 1; maxinode = statbuf.st_ino; } if (maxlinks < statbuf.st_nlink) { maxlinks = statbuf.st_nlink; if (maxlinksname) free (maxlinksname); maxlinksname = strdup (buf); } val = 0; if (statbuf.st_atime < statbuf.st_ctime) val += 1; if (statbuf.st_atime > statbuf.st_ctime) val += 2; if (statbuf.st_atime < statbuf.st_mtime) val += 3; if (statbuf.st_atime > statbuf.st_mtime) val += 6; if (statbuf.st_ctime < statbuf.st_mtime) val += 9; if (statbuf.st_ctime > statbuf.st_mtime) val += 18; times[val]++; } free (buf); closedir (d); } int main () { struct stat statbuf; int i; assert (S_IFMT == (((1<