home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / npasswd / part01 / checkpasswd / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-19  |  3.7 KB  |  124 lines

  1.  
  2. /* --------------------------------------------------------------------  */
  3. /*                                                                       */
  4. /*                         Author: Clyde Hoover                          */
  5. /*                          Computation Center                           */
  6. /*                   The University of Texas at Austin                   */
  7. /*                          Austin, Texas 78712                          */
  8. /*                         clyde@emx.utexas.edu                          */
  9. /*                   uunet!cs.utexas.edu!ut-emx!clyde                    */
  10. /*                                                                       */
  11. /*This code may be distributed freely, provided this notice is retained. */
  12. /*                                                                       */
  13. /* --------------------------------------------------------------------  */
  14. /*
  15.  *    checkpasswd - Main program for standalone version
  16.  *        libmain.c is the driver for the library version
  17.  *
  18.  *    Compilation:    cc -o checkpasswd checkpasswd.c main.c pwck_dict.c
  19.  *            pwck_passwd.c pwck_lexical.c pwck_local.c util.c 
  20.  */
  21.  
  22. #ifndef lint
  23. static char sccsid[] = "@(#)main.c    1.2 11/14/89 (cc.utexas.edu) /usr/src/ut/bin/passwd/checkpasswd/SCCS/s.main.c";
  24. #endif
  25.  
  26. #include "checkpasswd.h"
  27. #include "version.h"
  28.  
  29. char *replies[] = {
  30.     "This password is ok for use",        /* PWCK_OK */
  31.     "Empty password",            /* PWCK_NULL */
  32.     "This password is too easy to guess",    /* PWCK_OBVIOUS */
  33.     "This password is part of your 'finger' information", /* PWCK_FINGER */
  34.     "This password was found in a dictionary",    /* PWCK_INDICT */
  35.     "This password has an illegal character in it",    /* PWCK_ILLCHAR */
  36.     "This password is too short",            /* PWCK_SHORT */
  37.     0
  38. };
  39. #define    NREPLIES    7    /* Number of messages in replies */
  40.  
  41. char    elucidate[BUFSIZ];    /* Expanded error message */
  42.  
  43. int    silent = 0,        /* Silent mode switch */
  44.     oneshot = 0,        /* Check only one password switch */
  45.     errornum = 0;        /* Print error number with message */
  46. int    standalone = 1;        /* Running as standalone application */
  47.  
  48. main(argc, argv)
  49. int    argc;
  50. char    **argv;
  51. {
  52.     int    uid = getuid(),        /* Invoker's uid */
  53.         opt,            /* Argument parser */
  54.         interactive = 0;    /* In interactive mode? */
  55.     char    *configfile = CONFIG_FILE;    /* Configuration file */
  56.     extern char    *optarg;    /* From getopt() */
  57.  
  58.     /* Process argument list */
  59.     while ((opt = getopt(argc, argv, "c:eosu:V?")) != EOF) {
  60.         switch (opt) {
  61.         case 'c':    /* -c config-file */
  62.             configfile = optarg;
  63.             break;
  64.         case 'e':    /* -e [print status number] */
  65.             errornum++;
  66.             break;
  67.         case 'o':    /* -o [check one password & quit] */
  68.             oneshot++;
  69.             break;
  70.         case 's':    /* -s [silent mode] */
  71.             silent++;
  72.             break;
  73.         case 'u':    /* -u [user id] */
  74.             if (uid == 0 && isdigit(*optarg))
  75.                 uid = atoi(optarg);
  76.             break;
  77.         case 'V':    /* -V [print version information] */
  78.             printf("Version %s\nPatch level %s\n",
  79.                 version, patchlevel);
  80.             break;
  81.         case '?':
  82.             printf("Usage: checkpasswd [-c config] [-e] [-o] [-s] [-V] [-u uid]\n");
  83.             exit(0);
  84.         }
  85.     }
  86.     (void) readconfig(configfile);
  87.     interactive = isatty(fileno(stdin));
  88.     for (;;) {
  89.         int    rc;    /* Return code from checkpasswd() */
  90.         char    ibuf[BUFSIZ];        /* Input buffer */
  91.         char    *nl;    /* Newline postition */
  92.  
  93.         if (interactive) {
  94.             printf("Password to check: ");
  95.             fflush(stdout);
  96.         }
  97.         if (fgets(ibuf, sizeof(ibuf), stdin) == NULL)
  98.             break;
  99.         if (nl = index(ibuf, '\n'))
  100.             *nl = 0;
  101.         if (ibuf[0] == 0)
  102.             continue;
  103.         rc = checkpassword(ibuf, uid, elucidate);
  104.         if (!silent) {
  105.             if (errornum)
  106.                 printf("%d ", rc);
  107.             if (rc <= NREPLIES) {
  108.                 if (elucidate[0])
  109.                     printf("%s.\n", elucidate);
  110.                 else if (replies[rc])
  111.                     printf("%s.\n", replies[rc]);
  112.                 else
  113.                     putchar('\n');
  114.             }
  115.             else
  116.                 printf("Error %d\n", rc);
  117.         }
  118.         if (oneshot)
  119.             exit(rc);
  120.     }
  121.     exit(0);
  122. }
  123. /*    End main.c */
  124.