2004-02-10 02:01:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 Darren Tucker. 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
2004-02-11 07:48:52 +00:00
|
|
|
#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE)
|
2004-02-10 02:01:14 +00:00
|
|
|
#include <shadow.h>
|
2006-09-01 05:38:36 +00:00
|
|
|
#include <stdarg.h>
|
2006-07-24 04:51:00 +00:00
|
|
|
#include <string.h>
|
2007-04-29 02:10:57 +00:00
|
|
|
#include <time.h>
|
2004-02-10 02:01:14 +00:00
|
|
|
|
2006-08-05 04:07:20 +00:00
|
|
|
#include "hostfile.h"
|
2004-02-10 02:01:14 +00:00
|
|
|
#include "auth.h"
|
2018-07-10 09:39:52 +00:00
|
|
|
#include "sshbuf.h"
|
|
|
|
#include "ssherr.h"
|
2004-02-10 02:01:14 +00:00
|
|
|
#include "log.h"
|
|
|
|
|
2005-02-16 03:20:06 +00:00
|
|
|
#ifdef DAY
|
|
|
|
# undef DAY
|
|
|
|
#endif
|
2004-02-10 02:01:14 +00:00
|
|
|
#define DAY (24L * 60 * 60) /* 1 day in seconds */
|
|
|
|
|
2018-07-10 09:39:52 +00:00
|
|
|
extern struct sshbuf *loginmsg;
|
2004-02-10 02:01:14 +00:00
|
|
|
|
2004-02-21 22:43:15 +00:00
|
|
|
/*
|
|
|
|
* For the account and password expiration functions, we assume the expiry
|
|
|
|
* occurs the day after the day specified.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if specified account is expired. Returns 1 if account is expired,
|
|
|
|
* 0 otherwise.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
auth_shadow_acctexpired(struct spwd *spw)
|
|
|
|
{
|
|
|
|
time_t today;
|
2023-02-27 06:28:59 +00:00
|
|
|
long long daysleft;
|
2018-07-10 09:39:52 +00:00
|
|
|
int r;
|
2004-02-21 22:43:15 +00:00
|
|
|
|
|
|
|
today = time(NULL) / DAY;
|
2004-02-21 23:22:05 +00:00
|
|
|
daysleft = spw->sp_expire - today;
|
2023-02-27 06:28:59 +00:00
|
|
|
debug3("%s: today %lld sp_expire %lld days left %lld", __func__,
|
|
|
|
(long long)today, (long long)spw->sp_expire, daysleft);
|
2004-02-21 22:43:15 +00:00
|
|
|
|
2004-02-21 23:22:05 +00:00
|
|
|
if (spw->sp_expire == -1) {
|
|
|
|
debug3("account expiration disabled");
|
|
|
|
} else if (daysleft < 0) {
|
2004-02-21 22:43:15 +00:00
|
|
|
logit("Account %.100s has expired", spw->sp_namp);
|
|
|
|
return 1;
|
2004-02-21 23:22:05 +00:00
|
|
|
} else if (daysleft <= spw->sp_warn) {
|
2023-02-27 06:28:59 +00:00
|
|
|
debug3("account will expire in %lld days", daysleft);
|
2018-07-10 09:39:52 +00:00
|
|
|
if ((r = sshbuf_putf(loginmsg,
|
2023-02-27 06:28:59 +00:00
|
|
|
"Your account will expire in %lld day%s.\n", daysleft,
|
2018-07-10 09:39:52 +00:00
|
|
|
daysleft == 1 ? "" : "s")) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
2004-02-21 22:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-02-10 02:01:14 +00:00
|
|
|
/*
|
|
|
|
* Checks password expiry for platforms that use shadow passwd files.
|
|
|
|
* Returns: 1 = password expired, 0 = password not expired
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
auth_shadow_pwexpired(Authctxt *ctxt)
|
|
|
|
{
|
|
|
|
struct spwd *spw = NULL;
|
|
|
|
const char *user = ctxt->pw->pw_name;
|
|
|
|
time_t today;
|
2018-07-10 09:39:52 +00:00
|
|
|
int r, daysleft, disabled = 0;
|
2004-02-10 02:01:14 +00:00
|
|
|
|
2004-02-21 23:22:05 +00:00
|
|
|
if ((spw = getspnam((char *)user)) == NULL) {
|
2004-02-10 02:01:14 +00:00
|
|
|
error("Could not get shadow information for %.100s", user);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
today = time(NULL) / DAY;
|
2023-02-27 10:04:22 +00:00
|
|
|
debug3_f("today %lld sp_lstchg %lld sp_max %lld", (long long)today,
|
|
|
|
(long long)spw->sp_lstchg, (long long)spw->sp_max);
|
2004-02-10 02:01:14 +00:00
|
|
|
|
|
|
|
#if defined(__hpux) && !defined(HAVE_SECUREWARE)
|
2004-02-21 23:22:05 +00:00
|
|
|
if (iscomsec()) {
|
|
|
|
struct pr_passwd *pr;
|
2005-07-17 07:04:47 +00:00
|
|
|
|
2004-02-21 23:22:05 +00:00
|
|
|
pr = getprpwnam((char *)user);
|
|
|
|
|
|
|
|
/* Test for Trusted Mode expiry disabled */
|
|
|
|
if (pr != NULL && pr->ufld.fd_min == 0 &&
|
|
|
|
pr->ufld.fd_lifetime == 0 && pr->ufld.fd_expire == 0 &&
|
|
|
|
pr->ufld.fd_pw_expire_warning == 0 &&
|
|
|
|
pr->ufld.fd_schange != 0)
|
|
|
|
disabled = 1;
|
|
|
|
}
|
2004-02-10 02:01:14 +00:00
|
|
|
#endif
|
|
|
|
|
2004-02-21 23:22:05 +00:00
|
|
|
/* TODO: check sp_inact */
|
|
|
|
daysleft = spw->sp_lstchg + spw->sp_max - today;
|
|
|
|
if (disabled) {
|
|
|
|
debug3("password expiration disabled");
|
|
|
|
} else if (spw->sp_lstchg == 0) {
|
2004-02-10 02:01:14 +00:00
|
|
|
logit("User %.100s password has expired (root forced)", user);
|
|
|
|
return 1;
|
2004-02-21 23:22:05 +00:00
|
|
|
} else if (spw->sp_max == -1) {
|
|
|
|
debug3("password expiration disabled");
|
|
|
|
} else if (daysleft < 0) {
|
2004-02-10 02:01:14 +00:00
|
|
|
logit("User %.100s password has expired (password aged)", user);
|
|
|
|
return 1;
|
2004-02-21 23:22:05 +00:00
|
|
|
} else if (daysleft <= spw->sp_warn) {
|
|
|
|
debug3("password will expire in %d days", daysleft);
|
2018-07-10 09:39:52 +00:00
|
|
|
if ((r = sshbuf_putf(loginmsg,
|
2004-02-21 23:22:05 +00:00
|
|
|
"Your password will expire in %d day%s.\n", daysleft,
|
2018-07-10 09:39:52 +00:00
|
|
|
daysleft == 1 ? "" : "s")) != 0)
|
|
|
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
2004-02-10 02:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-02-11 07:48:52 +00:00
|
|
|
#endif /* USE_SHADOW && HAS_SHADOW_EXPIRE */
|