home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / npasswd / part01 / checkpasswd / checkpasswd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-19  |  3.6 KB  |  118 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.c - Password check driver and data initialization
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)checkpasswd.c    1.1 5/18/89 (cc.utexas.edu)";
  20. #endif
  21.  
  22. #include "checkpasswd.h"
  23.  
  24. /*
  25.  *    Table of password check parameters
  26.  *    May be modified via the configuration file
  27.  */
  28. int    single_case =    0,        /* Single-case pwds ok */
  29.     print_only =    0,        /* Printable ASCII chars only */
  30.     run_length =    3,        /* How long chars runs can be */
  31.     min_length =    5,        /* Minimum length */
  32.     max_length =    8;        /* Maximum effective length */
  33.  
  34. /*
  35.  *    Control characters best avoided - commonly-used terminal controls.
  36.  *    Add characters here or replace entire contents via the
  37.  *    configuration file.
  38.  */
  39. #define    ctrl(d)    ('d' & 037)
  40.  
  41. char    illegalcc[sizeof_illegalcc] = {
  42.     ctrl(c),    /* Interrupt character */
  43.     ctrl(d),    /* UNIX end-of-file */
  44.     ctrl(h),    /* Backspace */
  45. /*     ctrl(i), */
  46.     ctrl(j),    /* Newline */
  47.     ctrl(m),    /* Carriage return */
  48.     ctrl(o),    /* Flush output */
  49.     ctrl(r),    /* Retype pending input */
  50.     ctrl(s),    /* Suspend output */
  51.     ctrl(q),    /* Resume output */
  52.     ctrl(y),    /* Suspend program deferred */
  53.     ctrl(z),    /* Suspend program immediate */
  54.     ctrl(\\),    /* Quit signal */
  55.     ctrl([),    /* escape - may do strange things to ttys if echoed */
  56.     ctrl(]),    /* UNIX telnet escape */
  57.     '\0177',    /* rubout */
  58.     0
  59. };
  60.  
  61. /*
  62.  *    The 'pwck_*' routines all use the PWCK_* return
  63.  *    codes, which are then propigated up to the caller of checkpassword().
  64.  *
  65.  *    All pwck_* routines in the table below are called thusly:
  66.  *        pwck_*(password, userid, mesg)
  67.  *            password = plaintext password string to test.
  68.  *            userid = the user id which wants to use <password>.
  69.  *            mesg = buffer to place long explanation into
  70.  *
  71.  *    If more checks are desired, add the functions to the tables below.
  72.  */
  73. extern int
  74.     pwck_lexical(),
  75.     pwck_local(),
  76.     pwck_passwd(),
  77.     pwck_dictionary();
  78.  
  79. typedef    int    (*function)();
  80.  
  81. function checkprocs[] = {
  82.     pwck_lexical,
  83.     pwck_local,
  84.     pwck_passwd,
  85.     pwck_dictionary,
  86.     0
  87. };
  88.  
  89. /*
  90.  *    checkpassword - Password candidate sanity checker.
  91.  *
  92.  *    Arguments;
  93.  *        password = plain text password string to check.
  94.  *        userid = the uid whom the password is for, -1 to disable.
  95.  *
  96.  *    Returns:
  97.  *        PWCK_* values (see checkpasswd.h)
  98.  */
  99. checkpassword(password, userid, mesg)
  100. char    *password;        /* Plaintext of password to check */
  101. int    userid;            /* The user this is for */
  102. char    *mesg;            /* Where to stash explanation message */
  103. {
  104.     int        rcode;        /* General purpose scratch */
  105.     function    *checkfunc;    /* Check function pointer */
  106.  
  107.     if (password == 0 || *password == 0)
  108.         return(PWCK_NULL);        /* Null password */
  109.  
  110.     mesg[0] = 0;
  111.     for (checkfunc = checkprocs; *checkfunc; checkfunc++) {
  112.         if ((rcode = (*checkfunc)(password, userid, mesg)) != PWCK_OK)
  113.             return(rcode);
  114.     }
  115.     return(PWCK_OK);
  116. }
  117. /*    End checkpasswd.c */
  118.