d9898ee8 |
1 | /* |
2 | ** Copyright 1998 - 2005 Double Precision, Inc. See COPYING for |
3 | ** distribution information. |
4 | */ |
5 | |
6 | #if HAVE_CONFIG_H |
7 | #include "courier_auth_config.h" |
8 | #endif |
9 | #include <time.h> |
10 | #include <stdio.h> |
11 | #include <stdlib.h> |
12 | #include <string.h> |
13 | #include <errno.h> |
14 | #include <pwd.h> |
15 | #if HAVE_UNISTD_H |
16 | #include <unistd.h> |
17 | #endif |
18 | #if HAVE_SHADOW_H |
19 | #include <shadow.h> |
20 | #endif |
21 | |
22 | |
23 | #include "auth.h" |
24 | #include "courierauthdebug.h" |
25 | |
d9898ee8 |
26 | |
27 | int auth_shadow_pre(const char *userid, const char *service, |
28 | int (*callback)(struct authinfo *, void *), |
29 | void *arg) |
30 | { |
31 | struct authinfo auth; |
32 | struct passwd *pw; |
33 | struct spwd *spw; |
34 | long today; |
35 | |
36 | memset(&auth, 0, sizeof(auth)); |
37 | |
38 | if ((pw=getpwnam(userid)) == NULL) |
39 | { |
40 | if (errno == ENOMEM) return 1; |
41 | return -1; |
42 | } |
43 | |
44 | if ((spw=getspnam(userid)) == NULL) |
45 | { |
46 | if (errno == ENOMEM) return 1; |
47 | return -1; |
48 | } |
49 | |
50 | today = (long)time(NULL)/(24L*60*60); |
51 | |
52 | if ((spw->sp_expire > 0) && (today > spw->sp_expire)) |
53 | { |
54 | DPRINTF("authshadow: %s - account expired", userid); |
55 | return -1; /* account expired */ |
56 | } |
57 | |
58 | if ((spw->sp_lstchg != -1) && (spw->sp_max != -1) && |
59 | ((spw->sp_lstchg + spw->sp_max) < today)) |
60 | { |
61 | DPRINTF("authshadow: %s - password expired", userid); |
62 | return -1; /* password expired */ |
63 | } |
64 | |
65 | auth.sysusername=userid; |
66 | auth.sysgroupid=pw->pw_gid; |
67 | auth.homedir=pw->pw_dir; |
68 | auth.address=userid; |
69 | auth.fullname=pw->pw_gecos; |
70 | auth.passwd=spw->sp_pwdp; |
71 | |
72 | courier_authdebug_authinfo("DEBUG: authshadow: ", &auth, 0, pw->pw_passwd); |
73 | return ((*callback)(&auth, arg)); |
74 | } |