shadow.c revision 55682
1168404Spjd/* 2168404Spjd * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska H�gskolan 3168404Spjd * (Royal Institute of Technology, Stockholm, Sweden). 4168404Spjd * All rights reserved. 5168404Spjd * 6168404Spjd * Redistribution and use in source and binary forms, with or without 7168404Spjd * modification, are permitted provided that the following conditions 8168404Spjd * are met: 9168404Spjd * 10168404Spjd * 1. Redistributions of source code must retain the above copyright 11168404Spjd * notice, this list of conditions and the following disclaimer. 12168404Spjd * 13168404Spjd * 2. Redistributions in binary form must reproduce the above copyright 14168404Spjd * notice, this list of conditions and the following disclaimer in the 15168404Spjd * documentation and/or other materials provided with the distribution. 16168404Spjd * 17168404Spjd * 3. Neither the name of the Institute nor the names of its contributors 18168404Spjd * may be used to endorse or promote products derived from this software 19168404Spjd * without specific prior written permission. 20168404Spjd * 21168404Spjd * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22219089Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23321567Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24296519Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25168404Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26168404Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27219089Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28219089Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29168404Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30168404Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31168404Spjd * SUCH DAMAGE. 32168404Spjd */ 33168404Spjd 34168404Spjd#include "login_locl.h" 35168404Spjd 36168404SpjdRCSID("$Id: shadow.c,v 1.5 1999/12/02 17:04:56 joda Exp $"); 37168404Spjd 38168404Spjd#ifdef HAVE_SHADOW_H 39219089Spjd 40168404Spjd#ifndef _PATH_CHPASS 41219089Spjd#define _PATH_CHPASS "/usr/bin/passwd" 42321610Smav#endif 43168404Spjd 44168404Spjdstatic int 45168404Spjdchange_passwd(const struct passwd *who) 46168404Spjd{ 47168404Spjd int status; 48168404Spjd pid_t pid; 49168404Spjd 50168404Spjd switch (pid = fork()) { 51168404Spjd case -1: 52168404Spjd printf("fork /bin/passwd"); 53168404Spjd exit(1); 54168404Spjd case 0: 55168404Spjd execlp(_PATH_CHPASS, "passwd", who->pw_name, (char *) 0); 56168404Spjd exit(1); 57168404Spjd default: 58168404Spjd waitpid(pid, &status, 0); 59168404Spjd return (status); 60168404Spjd } 61168404Spjd} 62168404Spjd 63168404Spjdvoid 64168404Spjdcheck_shadow(const struct passwd *pw, const struct spwd *sp) 65168404Spjd{ 66168404Spjd long today; 67168404Spjd 68168404Spjd today = time(0)/(24L * 60 * 60); 69168404Spjd 70168404Spjd if (sp == NULL) 71251631Sdelphij return; 72168404Spjd 73251631Sdelphij if (sp->sp_expire > 0) { 74168404Spjd if (today >= sp->sp_expire) { 75267992Shselasky printf("Your account has expired.\n"); 76219089Spjd sleep(1); 77168404Spjd exit(0); 78168404Spjd } else if (sp->sp_expire - today < 14) { 79168404Spjd printf("Your account will expire in %d days.\n", 80168404Spjd (int)(sp->sp_expire - today)); 81168404Spjd } 82168404Spjd } 83168404Spjd 84168404Spjd if (sp->sp_max > 0) { 85168404Spjd if (today >= (sp->sp_lstchg + sp->sp_max)) { 86249921Ssmh printf("Your password has expired. Choose a new one.\n"); 87249921Ssmh change_passwd(pw); 88249921Ssmh } else if (sp->sp_warn > 0 89249921Ssmh && (today > (sp->sp_lstchg + sp->sp_max - sp->sp_warn))) { 90168404Spjd printf("Your password will expire in %d days.\n", 91315441Smav (int)(sp->sp_lstchg + sp->sp_max - today)); 92315441Smav } 93321611Smav } 94321611Smav} 95315441Smav#endif /* HAVE_SHADOW_H */ 96321611Smav