imapext-2007

diff src/osdep/unix/ckp_sv4.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/osdep/unix/ckp_sv4.c	Mon Sep 14 15:17:45 2009 +0900
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* ========================================================================
     1.5 + * Copyright 1988-2006 University of Washington
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *     http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * 
    1.14 + * ========================================================================
    1.15 + */
    1.16 +
    1.17 +/*
    1.18 + * Program:	SVR4 check password
    1.19 + *
    1.20 + * Author:	Mark Crispin
    1.21 + *		Networks and Distributed Computing
    1.22 + *		Computing & Communications
    1.23 + *		University of Washington
    1.24 + *		Administration Building, AG-44
    1.25 + *		Seattle, WA  98195
    1.26 + *		Internet: MRC@CAC.Washington.EDU
    1.27 + *
    1.28 + * Date:	1 August 1988
    1.29 + * Last Edited:	30 August 2006
    1.30 + */
    1.31 +
    1.32 +/* Check password
    1.33 + * Accepts: login passwd struct
    1.34 + *	    password string
    1.35 + *	    argument count
    1.36 + *	    argument vector
    1.37 + * Returns: passwd struct if password validated, NIL otherwise
    1.38 + */
    1.39 +
    1.40 +struct passwd *checkpw (struct passwd *pw,char *pass,int argc,char *argv[])
    1.41 +{
    1.42 +  char tmp[MAILTMPLEN];
    1.43 +  struct spwd *sp = NIL;
    1.44 +  time_t left;
    1.45 +  time_t now = time (0);
    1.46 +  struct tm *t = gmtime (&now);
    1.47 +  int zone = t->tm_hour * 60 + t->tm_min;
    1.48 +  int julian = t->tm_yday;
    1.49 +  t = localtime (&now);		/* get local time now */
    1.50 +				/* minus UTC minutes since midnight */
    1.51 +  zone = t->tm_hour * 60 + t->tm_min - zone;
    1.52 +  /* julian can be one of:
    1.53 +   *  36x  local time is December 31, UTC is January 1, offset -24 hours
    1.54 +   *    1  local time is 1 day ahead of UTC, offset +24 hours
    1.55 +   *    0  local time is same day as UTC, no offset
    1.56 +   *   -1  local time is 1 day behind UTC, offset -24 hours
    1.57 +   * -36x  local time is January 1, UTC is December 31, offset +24 hours
    1.58 +   */
    1.59 +  if (julian = t->tm_yday -julian)
    1.60 +    zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60;
    1.61 +				/* days since 1/1/1970 local time */
    1.62 +  now = ((now /60) + zone) / (60*24);
    1.63 +				/* non-shadow authentication */
    1.64 +  if (!pw->pw_passwd || !pw->pw_passwd[0] || !pw->pw_passwd[1] ||
    1.65 +      strcmp (pw->pw_passwd,(char *) crypt (pass,pw->pw_passwd))) {
    1.66 +    /* As far as I've been able to determine, here is how the expiration
    1.67 +     * fields in the shadow authentication data work:
    1.68 +     *  lstchg	last password change date if non-negative.  If zero, the
    1.69 +     *		user can not log in without changing password.
    1.70 +     *  max	number of days a password is valid if positive
    1.71 +     *  warn	number of days of password expiration warning
    1.72 +     * The expiration day is the *last* day that the password is valid.
    1.73 +     */
    1.74 +				/* shadow authentication */
    1.75 +    if ((sp = getspnam (pw->pw_name)) && sp->sp_lstchg &&
    1.76 +	((sp->sp_lstchg < 0) || (sp->sp_max <= 0) ||
    1.77 +	 ((sp->sp_lstchg + sp->sp_max) >= now)) &&
    1.78 +	sp->sp_pwdp && sp->sp_pwdp[0] && sp->sp_pwdp[1] &&
    1.79 +	!strcmp (sp->sp_pwdp,(char *) crypt (pass,sp->sp_pwdp))) {
    1.80 +      if ((sp->sp_lstchg > 0) && (sp->sp_max > 0) &&
    1.81 +	  ((left = (sp->sp_lstchg + sp->sp_max) - now) <= sp->sp_warn)) {
    1.82 +	if (left) {
    1.83 +	  sprintf (tmp,"[ALERT] Password expires in %ld day(s)",(long) left);
    1.84 +	  mm_notify (NIL,tmp,NIL);
    1.85 +	}
    1.86 +	else mm_notify (NIL,"[ALERT] Password expires today!",WARN);
    1.87 +      }
    1.88 +      endspent ();		/* don't need shadow password data any more */
    1.89 +    }
    1.90 +    else pw = NIL;		/* password failed */
    1.91 +  }
    1.92 +  return pw;
    1.93 +}

UW-IMAP'd extensions by yuuji