2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 1998, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2001 - 2006, Tomasz Kłoczko
|
2009-04-23 23:03:21 +05:30
|
|
|
* Copyright (c) 2008 - 2009, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2008-04-27 06:10:09 +05:30
|
|
|
* 3. The name of the copyright holders or contributors may not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2008-04-27 06:10:09 +05:30
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "exitcodes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifndef PASSWD_PROGRAM
|
|
|
|
#define PASSWD_PROGRAM "/bin/passwd"
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* expire - force password change if password expired
|
|
|
|
*
|
|
|
|
* expire() calls /bin/passwd to change the user's password
|
|
|
|
* if it has expired.
|
|
|
|
*/
|
2009-04-23 23:03:21 +05:30
|
|
|
int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:15:23 +05:30
|
|
|
int status;
|
2008-06-14 00:54:27 +05:30
|
|
|
pid_t child;
|
|
|
|
pid_t pid;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
if (NULL == sp) {
|
2009-04-06 03:59:42 +05:30
|
|
|
return 0;
|
2008-06-14 00:54:27 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* See if the user's password has expired, and if so
|
|
|
|
* force them to change their password.
|
|
|
|
*/
|
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
status = isexpired (pw, sp);
|
|
|
|
switch (status) {
|
2007-10-07 17:15:23 +05:30
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
2008-06-14 00:54:27 +05:30
|
|
|
(void) fputs (_("Your password has expired."), stdout);
|
2007-10-07 17:15:23 +05:30
|
|
|
break;
|
|
|
|
case 2:
|
2008-06-14 00:54:27 +05:30
|
|
|
(void) fputs (_("Your password is inactive."), stdout);
|
2007-10-07 17:15:23 +05:30
|
|
|
break;
|
|
|
|
case 3:
|
2008-06-14 00:54:27 +05:30
|
|
|
(void) fputs (_("Your login has expired."), stdout);
|
2007-10-07 17:15:23 +05:30
|
|
|
break;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting the maximum valid period to less than the minimum
|
|
|
|
* valid period means that the minimum period will never
|
|
|
|
* occur while the password is valid, so the user can never
|
|
|
|
* change that password.
|
|
|
|
*/
|
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
if ((status > 1) || (sp->sp_max < sp->sp_min)) {
|
|
|
|
(void) puts (_(" Contact the system administrator."));
|
2009-04-23 16:44:18 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-14 00:54:27 +05:30
|
|
|
(void) puts (_(" Choose a new password."));
|
|
|
|
(void) fflush (stdout);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Close all the files so that unauthorized access won't
|
|
|
|
* occur. This needs to be done anyway because those files
|
|
|
|
* might become stale after "passwd" is executed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
endspent ();
|
|
|
|
endpwent ();
|
2007-10-07 17:15:40 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:02 +05:30
|
|
|
endsgent ();
|
2007-10-07 17:15:40 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
endgrent ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute the /bin/passwd command. The exit status will be
|
|
|
|
* examined to see what the result is. If there are any
|
|
|
|
* errors the routine will exit. This forces the user to
|
|
|
|
* change their password before being able to use the account.
|
|
|
|
*/
|
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
pid = fork ();
|
|
|
|
if (0 == pid) {
|
2007-10-07 17:14:02 +05:30
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the UID to be that of the user. This causes
|
|
|
|
* passwd to work just like it would had they executed
|
|
|
|
* it from the command line while logged in.
|
|
|
|
*/
|
2009-04-06 03:59:42 +05:30
|
|
|
#if defined(HAVE_INITGROUPS) && ! defined(USE_PAM)
|
|
|
|
if (setup_uid_gid (pw, false) != 0)
|
|
|
|
#else
|
|
|
|
if (setup_uid_gid (pw) != 0)
|
|
|
|
#endif
|
|
|
|
{
|
2007-10-07 17:15:23 +05:30
|
|
|
_exit (126);
|
2008-06-14 00:54:27 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 16:44:18 +05:30
|
|
|
(void) execl (PASSWD_PROGRAM, PASSWD_PROGRAM, pw->pw_name, (char *) 0);
|
2007-10-07 17:14:02 +05:30
|
|
|
err = errno;
|
2007-10-07 17:15:23 +05:30
|
|
|
perror ("Can't execute " PASSWD_PROGRAM);
|
2008-06-14 00:54:27 +05:30
|
|
|
_exit ((ENOENT == err) ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
|
|
|
|
} else if ((pid_t) -1 == pid) {
|
2007-10-07 17:15:23 +05:30
|
|
|
perror ("fork");
|
2009-04-23 16:44:18 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
while (((child = wait (&status)) != pid) && (child != (pid_t)-1));
|
|
|
|
|
|
|
|
if ((child == pid) && (0 == status)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 1;
|
2008-06-14 00:54:27 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 16:44:18 +05:30
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
/*@notreached@*/}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* agecheck - see if warning is needed for password expiration
|
|
|
|
*
|
|
|
|
* agecheck sees how many days until the user's password is going
|
|
|
|
* to expire and warns the user of the pending password expiration.
|
|
|
|
*/
|
|
|
|
|
* libmisc/utmp.c, libmisc/age.c, libmisc/shell.c, lib/groupio.c,
lib/groupio.h, lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c,
lib/pwio.c, lib/commonio.c, lib/shadowio.h, lib/pwio.h,
lib/commonio.h, lib/prototypes.h: Added splint annotations.
2009-04-23 02:51:14 +05:30
|
|
|
void agecheck (/*@null@*/const struct spwd *sp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-06-14 00:54:27 +05:30
|
|
|
long now = (long) time ((time_t *) 0) / SCALE;
|
2007-10-07 17:15:23 +05:30
|
|
|
long remain;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
if (NULL == sp) {
|
2009-04-06 03:59:42 +05:30
|
|
|
return;
|
2008-06-14 00:54:27 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The last, max, and warn fields must be supported or the
|
|
|
|
* warning period cannot be calculated.
|
|
|
|
*/
|
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
if ( (-1 == sp->sp_lstchg)
|
|
|
|
|| (-1 == sp->sp_max)
|
|
|
|
|| (-1 == sp->sp_warn)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return;
|
2008-06-14 00:54:27 +05:30
|
|
|
}
|
2009-04-06 02:52:53 +05:30
|
|
|
|
|
|
|
if (0 == sp->sp_lstchg) {
|
|
|
|
(void) puts (_("You must change your password."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-14 00:54:27 +05:30
|
|
|
remain = sp->sp_lstchg + sp->sp_max - now;
|
|
|
|
if (remain <= sp->sp_warn) {
|
2007-10-07 17:15:23 +05:30
|
|
|
remain /= DAY / SCALE;
|
2008-06-14 00:54:27 +05:30
|
|
|
if (remain > 1) {
|
|
|
|
(void) printf (_("Your password will expire in %ld days.\n"),
|
|
|
|
remain);
|
|
|
|
} else if (1 == remain) {
|
|
|
|
(void) puts (_("Your password will expire tomorrow."));
|
|
|
|
} else if (remain == 0) {
|
|
|
|
(void) puts (_("Your password will expire today."));
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2008-06-14 00:54:27 +05:30
|
|
|
|