home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2290 / age.c next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  2.5 KB  |  177 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <sys/types.h>
  10. #include <stdio.h>
  11. #include <pwd.h>
  12. #include "config.h"
  13.  
  14. #ifndef    lint
  15. static    char    _sccsid[] = "@(#)age.c    2.6    10:20:04    11/9/90";
  16. #endif
  17.  
  18. #ifndef    PASSWD
  19. extern    char    *newenvp[];
  20. #endif
  21.  
  22. #ifndef    WARNAGE
  23. #define    WARNAGE    10
  24. #endif
  25.  
  26. time_t    time ();
  27.  
  28. int    c64i (c)
  29. char    c;
  30. {
  31.     if (c == '.')
  32.         return (0);
  33.  
  34.     if (c == '/')
  35.         return (1);
  36.  
  37.     if (c >= '0' && c <= '9')
  38.         return (c - '0' + 2);
  39.  
  40.     if (c >= 'A' && c <= 'Z')
  41.         return (c - 'A' + 12);
  42.  
  43.     if (c >= 'a' && c <= 'z')
  44.         return (c - 'a' + 38);
  45.     else
  46.         return (-1);
  47. }
  48.  
  49. int    i64c (i)
  50. int    i;
  51. {
  52.     if (i < 0)
  53.         return ('.');
  54.     else if (i > 63)
  55.         return ('z');
  56.  
  57.     if (i == 0)
  58.         return ('.');
  59.  
  60.     if (i == 1)
  61.         return ('/');
  62.  
  63.     if (i >= 2 && i <= 11)
  64.         return ('0' - 2 + i);
  65.  
  66.     if (i >= 12 && i <= 37)
  67.         return ('A' - 12 + i);
  68.  
  69.     if (i >= 38 && i <= 63)
  70.         return ('a' - 38 + i);
  71.  
  72.     return ('\0');
  73. }
  74.  
  75. #ifdef    AGING
  76. #ifdef    NEED_AL64
  77. #ifdef    PASSWD
  78. char    *l64a (l)
  79. long    l;
  80. {
  81.     static    char    buf[8];
  82.     int    i = 0;
  83.  
  84.     if (i < 0L)
  85.         return ((char *) 0);
  86.  
  87.     do {
  88.         buf[i++] = i64c ((int) (l % 64));
  89.         buf[i] = '\0';
  90.     } while (l /= 64L, l > 0 && i < 6);
  91.  
  92.     return (buf);
  93. }
  94. #endif
  95.  
  96. long    a64l (s)
  97. char    *s;
  98. {
  99.     int    i;
  100.     long    value;
  101.     long    shift = 0;
  102.  
  103.     for (i = 0, value = 0L;i < 6 && *s;s++) {
  104.         value += (c64i (*s) << shift);
  105.         shift += 6;
  106.     }
  107.     return (value);
  108. }
  109. #endif
  110. #ifndef    PASSWD
  111. void    expire (name, last, min, max)
  112. char    *name;
  113. long    last;
  114. int    min;
  115. int    max;
  116. {
  117.     long    clock;
  118.     long    week;
  119.     long    expires;
  120.     extern    int    errno;
  121.  
  122.     (void) time (&clock);
  123.     clock /= (24L * 60L * 60L);
  124.  
  125.     if (min < 0)
  126.         min = 0;
  127.  
  128.     if (max < 0)
  129.         max = 10000;    /* 10000 is infinity */
  130.  
  131.     if (last <= 0L)
  132.         expires = 0L;
  133.     else
  134.         expires = last + max;
  135.  
  136.     if (max < 10000 && (clock >= expires || min == max)) {
  137. #ifndef    SU
  138.         printf ("Your password has expired.");
  139.  
  140.         if (max < min) {
  141.             puts ("  Contact the system administrator.\n");
  142.             exit (1);
  143.         }
  144.         puts ("  Choose a new one.\n");
  145.  
  146.         execl ("/bin/passwd", "-passwd", name, (char *) 0);
  147.         puts ("Can't execute /bin/passwd");
  148.         exit (errno);
  149. #else
  150.         printf ("Your password has expired.\n");
  151. #ifdef    SULOG
  152.         sulog (0);
  153. #endif
  154.         exit (1);
  155. #endif
  156.     }
  157. }
  158.  
  159. void    agecheck (last, min, max, warn)
  160. long    last;
  161. int    min;
  162. int    max;
  163. int    warn;
  164. {
  165.     long    clock = time ((long *) 0) / (24L * 3600);
  166.     long    remain;
  167.  
  168.     if (last == 0)
  169.         return;
  170.  
  171.     if ((remain = (last + max) - clock) <= warn)
  172.         printf ("Your password will expire in %d %s.\n",
  173.             remain, remain == 1 ? "day":"days");
  174. }
  175. #endif
  176. #endif
  177.