-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnagios_check_pwd_exp.c
68 lines (60 loc) · 1.73 KB
/
nagios_check_pwd_exp.c
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
/**************************************************************************
* Nagios Plugin to Check User Password Expiration stat.
* Created by hewei.chn#gmail.com 20130228
* Version v0.1
* Usage: ./a.out to check all users.
* ./a.out user_a user_b user_and_so_on to check a list of users.
* Return:
* "User_expire:OK" With retcode 0 OR
* "User_expire:CRITICAL"
* "userA:daysToExpire"
* "userB:-daysHasExpire" ... With retcode 2
***************************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <shadow.h>
#include <time.h>
struct spwd * get_user_spwd(int argc, char ** argv)
{
static cur_index = 1;
struct spwd * ptr = NULL;
if (argc == 1) {
return getspent();
} else {
while(cur_index < argc && !(ptr = getspnam(argv[cur_index++]))){/*Nothing but continue;*/};
return ptr;
}
}
int main(int argc, char ** argv)
{
struct spwd * user = NULL;
time_t secs = time(NULL);
long int today = secs/(24*60*60);
int head_flag = 0;
//printf("Today is %d\n", today);
while (user = get_user_spwd(argc, argv)) {
/* printf("Username:%s,Password:%s,sp_lstchg:%d,sp_min:%d,sp_max:%d,sp_warn:%d,sp_inact,%d,sp_expire:%d,sp_flag:%d\n",
user->sp_namp,
user->sp_pwdp,
user->sp_lstchg,
user->sp_min,
user->sp_max,
user->sp_warn,
user->sp_inact,
user->sp_expire,
user->sp_flag);
*/
if (user->sp_expire > 0 && user->sp_expire - today <= user->sp_warn) {
if (!head_flag) {
printf("User_expire: CRITICAL\n");
head_flag = 1;
}
printf("%s:%d\n",user->sp_namp, user->sp_expire - today);
}
}
if (head_flag)
return 2;
else
printf("User_expire: OK\n");
return 0;
}