/***********************************************
 * released under (E) licensing ...            *
 *        (E) RULES AND REGULATIONS            *
 * permission to use/rewrite/add     : granted *
 * permission to trojan/steal        : denied  *
 * permission to use illegally       : denied  *
 * permission to use on /dev/urandom : denied  *
 ***********************************************/
/* contact el8@press.co.jp for full license    */
/* code copyrighted by ~el8 -- don't infringe! */

#include <stdio.h>
#include <sys/stat.h>
#include <ctype.h>
int is_pws(const char *tmp)
{
   int w = 1;
   while (*tmp) {
      switch(w) {
       case 1:
         if (*tmp == '@') {
            w = 2;
         }
         break;
       case 2:
         if (*tmp == '.') {
            w = 3;
         }
         break;
       case 3:
         if (*tmp == ' ') {
            w = 1;
         }
         else w = 4;
         break;
       case 4:
         if (isalpha(*tmp)) {
            return 1;
         } else w = 1;
         break;
       default:
         break;
      }
      tmp++;
   }
   return 0;
}
int main(int argc, char **argv)
{
   FILE *fp;
   struct stat st;
   char buf[255];
   char pws = 0;

   while (1) {
      argv++;
      argc--;

      if (!*argv) {
         break;
      }
      if (stat(*argv, &st) == -1) {
         perror(*argv);
         exit(-1);
      }
      if (st.st_mode & S_IFDIR) {
        continue;
      }
      if ((fp = fopen(*argv, "r")) == NULL) {
         perror(*argv);
         exit(-1);
      }
      memset(&buf,0,sizeof(buf));
      while (!feof(fp)) {
         memset(&buf,0,sizeof(buf));
         fgets(buf,sizeof(buf),fp);
         if (is_pws(buf)) {
            pws = 1;
            break;
         }
      }
      if (pws == 1) {
         printf("%s: passwd stealer detected.\n", *argv);
      } else {
         printf("%s: file is safe!\n", *argv);
      }
      pws = 0;
      fclose(fp);
   }
   return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1