home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / src / user.chk.c < prev   
C/C++ Source or Header  |  1992-03-10  |  2KB  |  89 lines

  1. #include <stdio.h>
  2. #include <pwd.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5.  
  6. /* Any file writable by all will be flagged */
  7. #define DMODE 002
  8.  
  9. #define MODE1 004
  10. #define MODE2 040
  11.  
  12. /* #define DMODE2 020 */
  13.  
  14. /* potentially dangerous files */
  15. char *ftable[] = {
  16.     "rhosts",
  17.     "profile",
  18.     "login",
  19.     "logout",
  20.     "cshrc",
  21.     "bashrc",
  22.     "kshrc",
  23.     "tcshrc",
  24.     "netrc",
  25.     "forward",
  26.     "dbxinit",
  27.     "distfile",
  28.     "exrc",
  29.     "emacsrc"
  30. };
  31. char *ft;
  32. char *ftr, *malloc();
  33.  
  34. char generic_file[100];
  35.  
  36. main(argc,argv)
  37. int argc;
  38. char **argv;
  39. {
  40. register int fmode;
  41. register int index;
  42. struct passwd *pp;
  43. static struct stat statb;
  44.  
  45. if (argc != 1) {
  46.     printf("Usage: %s\n",argv[0]);
  47.     exit(1);
  48.     }
  49.  
  50. ft = malloc(100);
  51. ftr = malloc(100);
  52.  
  53. while ((pp = getpwent()) != (struct passwd *)0) {
  54.     if (stat(pp->pw_dir,&statb) < 0) {
  55.         continue;
  56.         }
  57.  
  58.     index = 0;
  59.     /*
  60.      *   Use the home-dir, and add on each potential security threat
  61.      * file to the path one at a time.  Then check each file to see
  62.      * if it breaks with the modes established up above
  63.      *
  64.     */
  65.     for (ft = ftable[index]; index < 14; ft = ftable[++index]) {
  66.         if (strlen(pp->pw_dir) != 1)
  67.             sprintf(generic_file, "%s/.%s", pp->pw_dir,ft);
  68.         else 
  69.             sprintf(generic_file, "%s.%s", pp->pw_dir,ft);
  70.  
  71.         if (stat(generic_file,&statb) < 0)
  72.             continue;
  73.  
  74.         if (statb.st_mode & DMODE) 
  75.             printf("Warning!  User %s:\t%s is mode \t0%3.3o!\n",
  76.                    pp->pw_name,generic_file,statb.st_mode&~S_IFMT);
  77.  
  78.         /* check for mode on .netrc files; should be non-readable */
  79.         if (!strcmp("netrc", ftable[index]))
  80.             if (statb.st_mode & MODE1 || statb.st_mode & MODE2)
  81.                 printf("Warning!  User %s:\t%s is readable; mode \t0%3.3o!\n",
  82.                        pp->pw_name,generic_file,statb.st_mode&~S_IFMT);
  83.         }
  84.  
  85.     }
  86.  
  87. exit(0);
  88. }
  89.