imapext-2007

view src/osdep/unix/ckp_psx.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line source
1 /* ========================================================================
2 * Copyright 1988-2006 University of Washington
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
14 /*
15 * Program: POSIX check password
16 *
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
22 * Seattle, WA 98195
23 * Internet: MRC@CAC.Washington.EDU
24 *
25 * Date: 1 August 1988
26 * Last Edited: 30 August 2006
27 */
29 /* Check password
30 * Accepts: login passwd struct
31 * password string
32 * argument count
33 * argument vector
34 * Returns: passwd struct if password validated, NIL otherwise
35 */
37 struct passwd *checkpw (struct passwd *pw,char *pass,int argc,char *argv[])
38 {
39 char tmp[MAILTMPLEN];
40 struct spwd *sp = NIL;
41 time_t left;
42 time_t now = time (0);
43 struct tm *t = gmtime (&now);
44 int zone = t->tm_hour * 60 + t->tm_min;
45 int julian = t->tm_yday;
46 t = localtime (&now); /* get local time now */
47 /* minus UTC minutes since midnight */
48 zone = t->tm_hour * 60 + t->tm_min - zone;
49 /* julian can be one of:
50 * 36x local time is December 31, UTC is January 1, offset -24 hours
51 * 1 local time is 1 day ahead of UTC, offset +24 hours
52 * 0 local time is same day as UTC, no offset
53 * -1 local time is 1 day behind UTC, offset -24 hours
54 * -36x local time is January 1, UTC is December 31, offset +24 hours
55 */
56 if (julian = t->tm_yday -julian)
57 zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60;
58 /* days since 1/1/1970 local time */
59 now = ((now /60) + zone) / (60*24);
60 /* non-shadow authentication */
61 if (!pw->pw_passwd || !pw->pw_passwd[0] || !pw->pw_passwd[1] ||
62 strcmp (pw->pw_passwd,(char *) crypt (pass,pw->pw_passwd))) {
63 /* As far as I've been able to determine, here is how the expiration
64 * fields in the shadow authentication data work:
65 * lstchg last password change date if non-negative. If zero, the
66 * user can not log in without changing password.
67 * max number of days a password is valid if positive
68 * warn number of days of password expiration warning
69 * expire date account expires if positive
70 * inact number of days an accout can be inactive (not checked!)
71 * The expiration day is the *last* day that the password or account
72 * is valid.
73 */
74 /* shadow authentication */
75 if ((sp = getspnam (pw->pw_name)) && sp->sp_lstchg &&
76 ((sp->sp_lstchg < 0) || (sp->sp_max <= 0) ||
77 ((sp->sp_lstchg + sp->sp_max) >= now)) &&
78 ((sp->sp_expire <= 0) || (sp->sp_expire >= now)) &&
79 sp->sp_pwdp && sp->sp_pwdp[0] && sp->sp_pwdp[1] &&
80 !strcmp (sp->sp_pwdp,(char *) crypt (pass,sp->sp_pwdp))) {
81 if ((sp->sp_lstchg > 0) && (sp->sp_max > 0) &&
82 ((left = (sp->sp_lstchg + sp->sp_max) - now) <= sp->sp_warn)) {
83 if (left) {
84 sprintf (tmp,"[ALERT] Password expires in %ld day(s)",(long) left);
85 mm_notify (NIL,tmp,NIL);
86 }
87 else mm_notify (NIL,"[ALERT] Password expires today!",WARN);
88 }
89 if ((sp->sp_expire > 0) && ((left = sp->sp_expire - now) < 28)) {
90 if (left) {
91 sprintf (tmp,"[ALERT] Account expires in %ld day(s)",(long) left);
92 mm_notify (NIL,tmp,NIL);
93 }
94 else mm_notify (NIL,"[ALERT] Account expires today!",WARN);
95 }
96 endspent (); /* don't need shadow password data any more */
97 }
98 else pw = NIL; /* password failed */
99 }
100 return pw;
101 }

UW-IMAP'd extensions by yuuji