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 >
Wrap
C/C++ Source or Header
|
1990-12-28
|
3KB
|
172 lines
/*
* Copyright 1989, 1990, John F. Haugh II
* All rights reserved.
*
* Use, duplication, and disclosure prohibited without
* the express written permission of the author.
*/
#include <sys/types.h>
#include <stdio.h>
#include <pwd.h>
#include "config.h"
#ifndef lint
static char _sccsid[] = "@(#)age.c 2.5 07:46:56 8/14/90";
#endif
#ifndef PASSWD
extern char *newenvp[];
#endif
#ifndef WARNAGE
#define WARNAGE 10
#endif
time_t time ();
int c64i (c)
char c;
{
if (c == '.')
return (0);
if (c == '/')
return (1);
if (c >= '0' && c <= '9')
return (c - '0' + 2);
if (c >= 'A' && c <= 'Z')
return (c - 'A' + 12);
if (c >= 'a' && c <= 'z')
return (c - 'a' + 38);
else
return (-1);
}
int i64c (i)
int i;
{
if (i < 0)
return ('.');
else if (i > 63)
return ('z');
if (i == 0)
return ('.');
if (i == 1)
return ('/');
if (i >= 2 && i <= 11)
return ('0' - 2 + i);
if (i >= 12 && i <= 37)
return ('A' - 12 + i);
if (i >= 38 && i <= 63)
return ('a' - 38 + i);
return ('\0');
}
#ifdef AGING
#ifdef NEED_AL64
#ifdef PASSWD
char *l64a (l)
long l;
{
static char buf[8];
int i = 0;
if (i < 0L)
return ((char *) 0);
do {
buf[i++] = i64c ((int) (l % 64));
buf[i] = '\0';
} while (l /= 64L, l > 0 && i < 6);
return (buf);
}
#endif
long a64l (s)
char *s;
{
int i;
long value;
long shift = 0;
for (i = 0, value = 0L;i < 6 && *s;s++) {
value += (c64i (*s) << shift);
shift += 6;
}
return (value);
}
#endif
#ifndef PASSWD
void expire (last, min, max, incr)
long last;
int min;
int max;
int incr;
{
long clock;
long week;
long expires;
extern char name[];
extern int errno;
(void) time (&clock);
clock /= (24L * 60L * 60L);
if (last == 0L)
expires = 0L;
else
expires = (last + max) * incr;
if (clock >= expires || min == max) {
#ifndef SU
printf ("Your password has expired.");
if (max < min) {
puts (" Contact the system administrator.\n");
exit (1);
}
puts (" Choose a new one.\n");
execl ("/bin/passwd", "-passwd", name, (char *) 0);
puts ("Can't execute /bin/passwd");
exit (errno);
#else
printf ("Your password has expired.\n");
#ifdef SULOG
sulog (0);
#endif
exit (1);
#endif
}
}
void agecheck (last, min, max, incr)
long last;
int min;
int max;
int incr;
{
long clock = time ((long *) 0) / (24L * 3600);
long remain;
if (last == 0)
return;
if ((remain = ((last + max) * incr) - clock) <= WARNAGE)
printf ("Your password will expire in %d %s.\n",
remain, remain == 1 ? "day":"days");
}
#endif
#endif