Repository navigation
Expand file tree
/
Copy pathexpire.c
More file actions
84 lines (66 loc) · 2.46 KB
/
Copy pathexpire.c
File metadata and controls
84 lines (66 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Copyright (c) 1995-1998 by Cisco systems, Inc.
Permission to use, copy, modify, and distribute this software for
any purpose and without fee is hereby granted, provided that this
copyright and permission notice appear on all copies of the
software and supporting documentation, the name of Cisco Systems,
Inc. not be used in advertising or publicity pertaining to
distribution of the program without specific prior permission, and
notice be given in supporting documentation that modification,
copying and distribution is by permission of Cisco Systems, Inc.
Cisco Systems, Inc. makes no representations about the suitability
of this software for any purpose. THIS SOFTWARE IS PROVIDED ``AS
IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "tac_plus.h"
#include "expire.h"
/*
* check a date for expiry. If the field specifies
* a shell return PW_OK
*
* Return PW_OK if not expired
* Return PW_EXPIRING if expiry is coming soon
* Return PW_EXPIRED if already expired
*/
#define SEC_IN_DAY (24*60*60)
#define WARNING_PERIOD 14
static char *monthname[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
static long days_ere_month[] = {0, 31, 59, 90, 120, 151,
181, 212, 243, 273, 304, 334};
int
check_expiration(date)
char *date;
{
long day, month, year, leaps, now, expiration, warning;
char monthstr[10];
int i;
monthstr[0] = '\0';
/* If no date or a shell, let it pass. (Backward compatibility.) */
if (!date || (strlen(date) == 0) || (*date == '/'))
return (PW_OK);
/* Parse date string. Fail it upon error. */
if (sscanf(date, "%s %d %d", monthstr, &day, &year) != 3)
return (PW_EXPIRED);
for(i=0; i < 3; i++) {
monthstr[i] = toupper(monthstr[i]);
}
/* Compute the expiration date in days. */
for (month = 0; month < 12; month++)
if (strncmp(monthstr, monthname[month], 3) == 0)
break;
if (month > 11)
return (PW_EXPIRED);
leaps = (year - 1969) / 4 + (((year % 4) == 0) && (month > 2));
expiration = (((year - 1970) * 365) + days_ere_month[month] + (day - 1) + leaps);
warning = expiration - WARNING_PERIOD;
/* Get the current time (to the day) */
now = time(NULL) / SEC_IN_DAY;
if (now > expiration)
return (PW_EXPIRED);
if (now > warning)
return (PW_EXPIRING);
return (PW_OK);
}