home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / shadow-2.pt3 / age.c next >
C/C++ Source or Header  |  1989-02-03  |  2KB  |  124 lines

  1. #include <sys/types.h>
  2. #include <stdio.h>
  3. #include <pwd.h>
  4. #include "config.h"
  5.  
  6. #ifndef    PASSWD
  7. extern    char    *newenvp[];
  8. #endif
  9.  
  10. time_t    time ();
  11.  
  12. #ifdef    AGING
  13. #ifdef    PASSWD
  14. char    *l64a (l)
  15. long    l;
  16. {
  17.     static    char    buf[8];
  18.     int    i = 0;
  19.  
  20.     if (i < 0L)
  21.         return ((char *) 0);
  22.  
  23.     do {
  24.         buf[i++] = i64c ((int) (l % 64));
  25.         buf[i] = '\0';
  26.     } while (l /= 64L, l > 0 && i < 6);
  27.  
  28.     return (buf);
  29. }
  30. #endif
  31. int    i64c (i)
  32. int    i;
  33. {
  34.     if (i < 0)
  35.         return ('.');
  36.     else if (i > 63)
  37.         return ('z');
  38.  
  39.     if (i == 0)
  40.         return ('.');
  41.  
  42.     if (i == 1)
  43.         return ('/');
  44.  
  45.     if (i >= 2 && i <= 11)
  46.         return ('0' - 2 + i);
  47.  
  48.     if (i >= 12 && i <= 37)
  49.         return ('A' - 12 + i);
  50.  
  51.     if (i >= 38 && i <= 63)
  52.         return ('a' - 38 + i);
  53.  
  54.     return ('\0');
  55. }
  56.  
  57. int    c64i (c)
  58. char    c;
  59. {
  60.     if (c == '.')
  61.         return (0);
  62.  
  63.     if (c == '/')
  64.         return (1);
  65.  
  66.     if (c >= '0' && c <= '9')
  67.         return (c - '0' + 2);
  68.  
  69.     if (c >= 'A' && c <= 'Z')
  70.         return (c - 'A' + 12);
  71.  
  72.     if (c >= 'a' && c <= 'z')
  73.         return (c - 'a' + 38);
  74.     else
  75.         return (-1);
  76. }
  77.  
  78. long    a64l (s)
  79. char    *s;
  80. {
  81.     int    i;
  82.     long    value;
  83.     long    shift = 0;
  84.  
  85.     for (i = 0, value = 0L;i < 6 && *s;s++) {
  86.         value += (c64i (*s) << shift);
  87.         shift += 6;
  88.     }
  89.     return (value);
  90. }
  91. #ifndef    PASSWD
  92. void    expire (age)
  93. char    *age;
  94. {
  95.     long    clock;
  96.     long    week;
  97.     extern    char    name[];
  98.     extern    int    errno;
  99.  
  100.     (void) time (&clock);
  101.     clock /= (7L * 24L * 60L * 60L);
  102.  
  103.     if (strlen (age) < 4)
  104.         week = 0L;
  105.     else
  106.         week = a64l (age + 2);
  107.  
  108.     if (clock >= week + c64i (age[0])) {
  109.         printf ("Your password has expired.");
  110.  
  111.         if (c64i (age[0]) < c64i (age[1])) {
  112.             puts ("  Contact the system administrator.\n");
  113.             exit (1);
  114.         }
  115.         puts ("  Choose a new one.\n");
  116.  
  117.         execl ("/bin/passwd", "-passwd", name, (char *) 0);
  118.         puts ("Can't execute /bin/passwd");
  119.         exit (errno);
  120.     }
  121. }
  122. #endif
  123. #endif
  124.