File: isexpired.c

package info (click to toggle)
netstd 3.07-7slink.3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 6,312 kB
  • ctags: 9,027
  • sloc: ansic: 72,107; cpp: 6,144; makefile: 1,650; yacc: 1,614; sh: 1,164; perl: 308; awk: 46
file content (45 lines) | stat: -rw-r--r-- 892 bytes parent folder | download | duplicates (4)
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
#ifdef USE_SHADOW

#include <shadow.h>
#include <time.h>
#include "isexpired.h"

/*
 * Check password aging info when using shadow passwords.  Returns:
 *  3 - after account expiration date
 *  2 - expired password not changed for too long
 *  1 - password expired, must be changed
 *  0 - success, or no shadow password information at all
 *
 * Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>,
 * public domain.
 */
int
isexpired(const struct spwd *sp)
{
	long now, change;

	if (!sp)
		return 0;

	now = ((unsigned long) time((time_t *) 0)) / (24L * 3600L);

	if (sp->sp_expire > 0 && now >= sp->sp_expire)
		return 3;

	if (sp->sp_lstchg > 0 && sp->sp_max > 0) {
		change = sp->sp_lstchg + sp->sp_max;

		if (sp->sp_inact >= 0 && now >= change + sp->sp_inact)
			return 2;

		if (now >= change)
			return 1;
	}

	if (sp->sp_lstchg == 0)
		return 1;

	return 0;
}
#endif