home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1704 / age.c next >
C/C++ Source or Header  |  1990-12-28  |  3KB  |  172 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.5    07:46:56    8/14/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 (last, min, max, incr)
  112. long    last;
  113. int    min;
  114. int    max;
  115. int    incr;
  116. {
  117.     long    clock;
  118.     long    week;
  119.     long    expires;
  120.     extern    char    name[];
  121.     extern    int    errno;
  122.  
  123.     (void) time (&clock);
  124.     clock /= (24L * 60L * 60L);
  125.  
  126.     if (last == 0L)
  127.         expires = 0L;
  128.     else
  129.         expires = (last + max) * incr;
  130.  
  131.     if (clock >= expires || min == max) {
  132. #ifndef    SU
  133.         printf ("Your password has expired.");
  134.  
  135.         if (max < min) {
  136.             puts ("  Contact the system administrator.\n");
  137.             exit (1);
  138.         }
  139.         puts ("  Choose a new one.\n");
  140.  
  141.         execl ("/bin/passwd", "-passwd", name, (char *) 0);
  142.         puts ("Can't execute /bin/passwd");
  143.         exit (errno);
  144. #else
  145.         printf ("Your password has expired.\n");
  146. #ifdef    SULOG
  147.         sulog (0);
  148. #endif
  149.         exit (1);
  150. #endif
  151.     }
  152. }
  153.  
  154. void    agecheck (last, min, max, incr)
  155. long    last;
  156. int    min;
  157. int    max;
  158. int    incr;
  159. {
  160.     long    clock = time ((long *) 0) / (24L * 3600);
  161.     long    remain;
  162.  
  163.     if (last == 0)
  164.         return;
  165.  
  166.     if ((remain = ((last + max) * incr) - clock) <= WARNAGE)
  167.         printf ("Your password will expire in %d %s.\n",
  168.             remain, remain == 1 ? "day":"days");
  169. }
  170. #endif
  171. #endif
  172.