1998-11-18 01:44:37 +00:00
|
|
|
/*-
|
|
|
|
* Copyright 1998 Juniper Networks, Inc.
|
|
|
|
* All rights reserved.
|
2002-03-14 23:27:59 +00:00
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
2002-01-30 19:09:11 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Portions of this software was developed for the FreeBSD Project by
|
|
|
|
* ThinkSec AS and NAI Labs, the Security Research Division of Network
|
|
|
|
* Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
|
|
|
|
* ("CBOSS"), as part of the DARPA CHATS research program.
|
1998-11-18 01:44:37 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2002-01-30 19:09:11 +00:00
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
1998-11-18 01:44:37 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 22:11:06 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
1999-05-08 01:59:27 +00:00
|
|
|
#include <sys/time.h>
|
2002-01-30 19:09:11 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
1999-05-08 01:59:27 +00:00
|
|
|
#include <login_cap.h>
|
2002-01-30 19:09:11 +00:00
|
|
|
#include <netdb.h>
|
1998-11-18 01:44:37 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-05-08 01:59:27 +00:00
|
|
|
#include <stdio.h>
|
2002-02-09 14:12:09 +00:00
|
|
|
#include <syslog.h>
|
1998-11-18 01:44:37 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2002-05-08 00:54:29 +00:00
|
|
|
#include <libutil.h>
|
2001-08-26 17:41:13 +00:00
|
|
|
|
|
|
|
#ifdef YP
|
2002-04-15 22:51:31 +00:00
|
|
|
#include <ypclnt.h>
|
2001-08-26 17:41:13 +00:00
|
|
|
#endif
|
|
|
|
|
1998-11-18 01:44:37 +00:00
|
|
|
#define PAM_SM_AUTH
|
1999-05-08 01:59:27 +00:00
|
|
|
#define PAM_SM_ACCOUNT
|
2001-08-26 17:41:13 +00:00
|
|
|
#define PAM_SM_PASSWORD
|
|
|
|
|
2002-02-05 06:08:26 +00:00
|
|
|
#include <security/pam_appl.h>
|
1998-11-18 01:44:37 +00:00
|
|
|
#include <security/pam_modules.h>
|
2002-02-05 06:08:26 +00:00
|
|
|
#include <security/pam_mod_misc.h>
|
1998-11-18 01:44:37 +00:00
|
|
|
|
2001-08-26 17:41:13 +00:00
|
|
|
#define PASSWORD_HASH "md5"
|
|
|
|
#define DEFAULT_WARN (2L * 7L * 86400L) /* Two weeks */
|
2002-03-14 16:41:36 +00:00
|
|
|
#define SALTSIZE 32
|
2001-07-09 18:20:51 +00:00
|
|
|
|
2002-03-14 16:41:36 +00:00
|
|
|
static void makesalt(char []);
|
|
|
|
|
|
|
|
static char password_hash[] = PASSWORD_HASH;
|
2002-02-03 15:17:57 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
enum {
|
|
|
|
PAM_OPT_AUTH_AS_SELF = PAM_OPT_STD_MAX,
|
|
|
|
PAM_OPT_NULLOK,
|
|
|
|
PAM_OPT_LOCAL_PASS,
|
|
|
|
PAM_OPT_NIS_PASS
|
|
|
|
};
|
2001-07-09 18:20:51 +00:00
|
|
|
|
|
|
|
static struct opttab other_options[] = {
|
|
|
|
{ "auth_as_self", PAM_OPT_AUTH_AS_SELF },
|
|
|
|
{ "nullok", PAM_OPT_NULLOK },
|
2001-08-26 17:41:13 +00:00
|
|
|
{ "local_pass", PAM_OPT_LOCAL_PASS },
|
|
|
|
{ "nis_pass", PAM_OPT_NIS_PASS },
|
2001-07-09 18:20:51 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
1998-11-18 01:44:37 +00:00
|
|
|
|
2001-08-26 17:41:13 +00:00
|
|
|
char *tempname = NULL;
|
|
|
|
|
1999-05-08 01:59:27 +00:00
|
|
|
/*
|
|
|
|
* authentication management
|
|
|
|
*/
|
1998-11-18 01:44:37 +00:00
|
|
|
PAM_EXTERN int
|
2002-04-12 22:27:25 +00:00
|
|
|
pam_sm_authenticate(pam_handle_t *pamh, int flags __unused,
|
|
|
|
int argc, const char *argv[])
|
1998-11-18 01:44:37 +00:00
|
|
|
{
|
2001-08-26 17:41:13 +00:00
|
|
|
login_cap_t *lc;
|
2001-07-09 18:20:51 +00:00
|
|
|
struct options options;
|
1998-11-18 01:44:37 +00:00
|
|
|
struct passwd *pwd;
|
2001-07-09 18:20:51 +00:00
|
|
|
int retval;
|
2002-04-08 11:07:51 +00:00
|
|
|
const char *pass, *user, *realpw, *prompt;
|
1998-11-18 01:44:37 +00:00
|
|
|
|
2001-07-09 18:20:51 +00:00
|
|
|
pam_std_option(&options, other_options, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
|
|
|
|
2002-04-07 21:18:18 +00:00
|
|
|
if (pam_test_option(&options, PAM_OPT_AUTH_AS_SELF, NULL)) {
|
2001-08-26 17:41:13 +00:00
|
|
|
pwd = getpwnam(getlogin());
|
2002-04-07 21:18:18 +00:00
|
|
|
} else {
|
2001-07-09 18:20:51 +00:00
|
|
|
retval = pam_get_user(pamh, &user, NULL);
|
|
|
|
if (retval != PAM_SUCCESS)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
2001-05-24 18:35:52 +00:00
|
|
|
pwd = getpwnam(user);
|
|
|
|
}
|
2001-07-09 18:20:51 +00:00
|
|
|
|
|
|
|
PAM_LOG("Got user: %s", user);
|
|
|
|
|
2001-05-24 18:35:52 +00:00
|
|
|
if (pwd != NULL) {
|
2001-07-09 18:20:51 +00:00
|
|
|
PAM_LOG("Doing real authentication");
|
2002-04-07 21:18:18 +00:00
|
|
|
realpw = pwd->pw_passwd;
|
|
|
|
if (realpw[0] == '\0') {
|
|
|
|
if (!(flags & PAM_DISALLOW_NULL_AUTHTOK) &&
|
|
|
|
pam_test_option(&options, PAM_OPT_NULLOK, NULL))
|
2002-04-12 22:27:25 +00:00
|
|
|
return (PAM_SUCCESS);
|
2002-04-07 21:18:18 +00:00
|
|
|
realpw = "*";
|
2001-06-04 19:16:57 +00:00
|
|
|
}
|
2002-04-07 21:18:18 +00:00
|
|
|
lc = login_getpwclass(pwd);
|
|
|
|
} else {
|
2001-07-09 18:20:51 +00:00
|
|
|
PAM_LOG("Doing dummy authentication");
|
2002-04-07 21:18:18 +00:00
|
|
|
realpw = "*";
|
2002-04-07 20:43:27 +00:00
|
|
|
lc = login_getclass(NULL);
|
1998-11-18 01:44:37 +00:00
|
|
|
}
|
2002-04-07 21:18:18 +00:00
|
|
|
prompt = login_getcapstr(lc, "passwd_prompt", NULL, NULL);
|
|
|
|
retval = pam_get_authtok(pamh, PAM_AUTHTOK, &pass, prompt);
|
|
|
|
login_close(lc);
|
2001-08-26 17:41:13 +00:00
|
|
|
if (retval != PAM_SUCCESS)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
2002-04-07 21:18:18 +00:00
|
|
|
PAM_LOG("Got password");
|
|
|
|
if (strcmp(crypt(pass, realpw), realpw) == 0)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (PAM_SUCCESS);
|
2001-08-26 17:41:13 +00:00
|
|
|
|
2002-04-07 21:18:18 +00:00
|
|
|
PAM_VERBOSE_ERROR("UNIX authentication refused");
|
2002-04-12 22:27:25 +00:00
|
|
|
return (PAM_AUTH_ERR);
|
1998-11-18 01:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PAM_EXTERN int
|
2002-04-12 22:27:25 +00:00
|
|
|
pam_sm_setcred(pam_handle_t *pamh __unused, int flags __unused,
|
|
|
|
int argc __unused, const char *argv[] __unused)
|
1998-11-18 01:44:37 +00:00
|
|
|
{
|
2001-08-26 17:41:13 +00:00
|
|
|
|
2002-04-12 22:27:25 +00:00
|
|
|
return (PAM_SUCCESS);
|
1998-11-18 01:44:37 +00:00
|
|
|
}
|
1999-01-20 21:55:30 +00:00
|
|
|
|
2002-04-12 22:27:25 +00:00
|
|
|
/*
|
1999-05-08 01:59:27 +00:00
|
|
|
* account management
|
|
|
|
*/
|
2001-08-26 17:41:13 +00:00
|
|
|
PAM_EXTERN int
|
2002-04-12 22:27:25 +00:00
|
|
|
pam_sm_acct_mgmt(pam_handle_t *pamh, int flags __unused,
|
|
|
|
int argc, const char *argv[])
|
1999-05-08 01:59:27 +00:00
|
|
|
{
|
2002-01-30 19:09:11 +00:00
|
|
|
struct addrinfo hints, *res;
|
2001-07-09 18:20:51 +00:00
|
|
|
struct options options;
|
2002-01-30 19:09:11 +00:00
|
|
|
struct passwd *pwd;
|
1999-05-08 01:59:27 +00:00
|
|
|
struct timeval tp;
|
2001-07-09 18:20:51 +00:00
|
|
|
login_cap_t *lc;
|
1999-05-08 01:59:27 +00:00
|
|
|
time_t warntime;
|
|
|
|
int retval;
|
2002-01-30 19:09:11 +00:00
|
|
|
const char *rhost, *tty, *user;
|
|
|
|
char rhostip[MAXHOSTNAMELEN];
|
2001-07-09 18:20:51 +00:00
|
|
|
|
|
|
|
pam_std_option(&options, other_options, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
1999-05-08 01:59:27 +00:00
|
|
|
|
2002-04-06 19:30:04 +00:00
|
|
|
retval = pam_get_user(pamh, &user, NULL);
|
2002-01-30 19:09:11 +00:00
|
|
|
if (retval != PAM_SUCCESS)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
1999-05-08 01:59:27 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
if (user == NULL || (pwd = getpwnam(user)) == NULL)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (PAM_SERVICE_ERR);
|
2001-07-09 18:20:51 +00:00
|
|
|
|
|
|
|
PAM_LOG("Got user: %s", user);
|
1999-05-08 01:59:27 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
retval = pam_get_item(pamh, PAM_RHOST, (const void **)&rhost);
|
|
|
|
if (retval != PAM_SUCCESS)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
1999-05-08 01:59:27 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
retval = pam_get_item(pamh, PAM_TTY, (const void **)&tty);
|
|
|
|
if (retval != PAM_SUCCESS)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
2002-01-30 19:09:11 +00:00
|
|
|
|
|
|
|
if (*pwd->pw_passwd == '\0' &&
|
|
|
|
(flags & PAM_DISALLOW_NULL_AUTHTOK) != 0)
|
|
|
|
return (PAM_NEW_AUTHTOK_REQD);
|
2002-04-12 22:27:25 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
lc = login_getpwclass(pwd);
|
|
|
|
if (lc == NULL) {
|
|
|
|
PAM_LOG("Unable to get login class for user %s", user);
|
|
|
|
return (PAM_SERVICE_ERR);
|
|
|
|
}
|
1999-05-08 01:59:27 +00:00
|
|
|
|
2001-07-09 18:20:51 +00:00
|
|
|
PAM_LOG("Got login_cap");
|
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
if (pwd->pw_change || pwd->pw_expire)
|
|
|
|
gettimeofday(&tp, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check pw_expire before pw_change - no point in letting the
|
|
|
|
* user change the password on an expired account.
|
|
|
|
*/
|
2002-04-12 22:27:25 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
if (pwd->pw_expire) {
|
|
|
|
warntime = login_getcaptime(lc, "warnexpire",
|
|
|
|
DEFAULT_WARN, DEFAULT_WARN);
|
|
|
|
if (tp.tv_sec >= pwd->pw_expire) {
|
|
|
|
login_close(lc);
|
2002-04-12 22:27:25 +00:00
|
|
|
return (PAM_ACCT_EXPIRED);
|
2002-01-30 19:09:11 +00:00
|
|
|
} else if (pwd->pw_expire - tp.tv_sec < warntime &&
|
|
|
|
(flags & PAM_SILENT) == 0) {
|
2002-03-05 21:56:25 +00:00
|
|
|
pam_error(pamh, "Warning: your account expires on %s",
|
2002-01-30 19:09:11 +00:00
|
|
|
ctime(&pwd->pw_expire));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = PAM_SUCCESS;
|
|
|
|
if (pwd->pw_change) {
|
|
|
|
warntime = login_getcaptime(lc, "warnpassword",
|
|
|
|
DEFAULT_WARN, DEFAULT_WARN);
|
|
|
|
if (tp.tv_sec >= pwd->pw_change) {
|
1999-05-08 01:59:27 +00:00
|
|
|
retval = PAM_NEW_AUTHTOK_REQD;
|
2002-01-30 19:09:11 +00:00
|
|
|
} else if (pwd->pw_change - tp.tv_sec < warntime &&
|
|
|
|
(flags & PAM_SILENT) == 0) {
|
2002-03-05 21:56:25 +00:00
|
|
|
pam_error(pamh, "Warning: your password expires on %s",
|
2002-01-30 19:09:11 +00:00
|
|
|
ctime(&pwd->pw_change));
|
1999-05-08 01:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
/*
|
|
|
|
* From here on, we must leave retval untouched (unless we
|
|
|
|
* know we're going to fail), because we need to remember
|
|
|
|
* whether we're supposed to return PAM_SUCCESS or
|
|
|
|
* PAM_NEW_AUTHTOK_REQD.
|
|
|
|
*/
|
1999-05-08 01:59:27 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
if (rhost) {
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = AF_UNSPEC;
|
|
|
|
if (getaddrinfo(rhost, NULL, &hints, &res) == 0) {
|
|
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
|
|
|
rhostip, sizeof(rhostip), NULL, 0,
|
|
|
|
NI_NUMERICHOST|NI_WITHSCOPEID);
|
1999-05-08 01:59:27 +00:00
|
|
|
}
|
2002-01-30 19:09:11 +00:00
|
|
|
if (res != NULL)
|
|
|
|
freeaddrinfo(res);
|
1999-05-08 01:59:27 +00:00
|
|
|
}
|
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
/*
|
|
|
|
* Check host / tty / time-of-day restrictions
|
|
|
|
*/
|
2002-04-12 22:27:25 +00:00
|
|
|
|
2002-01-30 19:09:11 +00:00
|
|
|
if (!auth_hostok(lc, rhost, rhostip) ||
|
|
|
|
!auth_ttyok(lc, tty) ||
|
|
|
|
!auth_timeok(lc, time(NULL)))
|
|
|
|
retval = PAM_AUTH_ERR;
|
1999-05-08 01:59:27 +00:00
|
|
|
|
2002-04-12 22:27:25 +00:00
|
|
|
login_close(lc);
|
2001-08-26 17:41:13 +00:00
|
|
|
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
2001-08-26 17:41:13 +00:00
|
|
|
}
|
|
|
|
|
2002-04-12 22:27:25 +00:00
|
|
|
/*
|
2001-08-26 17:41:13 +00:00
|
|
|
* password management
|
|
|
|
*
|
|
|
|
* standard Unix and NIS password changing
|
|
|
|
*/
|
|
|
|
PAM_EXTERN int
|
2002-04-12 22:27:25 +00:00
|
|
|
pam_sm_chauthtok(pam_handle_t *pamh, int flags,
|
|
|
|
int argc, const char *argv[])
|
2001-08-26 17:41:13 +00:00
|
|
|
{
|
2002-04-15 02:34:43 +00:00
|
|
|
#ifdef YP
|
|
|
|
struct ypclnt *ypclnt;
|
|
|
|
const char *yp_domain, *yp_server;
|
|
|
|
#endif
|
2001-08-26 17:41:13 +00:00
|
|
|
struct options options;
|
2002-04-15 02:34:43 +00:00
|
|
|
char salt[SALTSIZE + 1];
|
|
|
|
login_cap_t * lc;
|
2002-05-08 00:54:29 +00:00
|
|
|
struct passwd *pwd, *old_pwd;
|
2002-04-15 02:34:43 +00:00
|
|
|
const char *user, *old_pass, *new_pass;
|
|
|
|
char *encrypted;
|
|
|
|
int pfd, tfd, retval;
|
2001-08-26 17:41:13 +00:00
|
|
|
|
|
|
|
pam_std_option(&options, other_options, argc, argv);
|
|
|
|
|
|
|
|
PAM_LOG("Options processed");
|
|
|
|
|
|
|
|
if (pam_test_option(&options, PAM_OPT_AUTH_AS_SELF, NULL))
|
|
|
|
pwd = getpwnam(getlogin());
|
|
|
|
else {
|
|
|
|
retval = pam_get_user(pamh, &user, NULL);
|
|
|
|
if (retval != PAM_SUCCESS)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
2001-08-26 17:41:13 +00:00
|
|
|
pwd = getpwnam(user);
|
|
|
|
}
|
|
|
|
|
2002-05-08 00:54:29 +00:00
|
|
|
if (pwd == NULL)
|
|
|
|
return (PAM_AUTHTOK_RECOVERY_ERR);
|
|
|
|
|
2001-08-26 17:41:13 +00:00
|
|
|
PAM_LOG("Got user: %s", user);
|
|
|
|
|
|
|
|
if (flags & PAM_PRELIM_CHECK) {
|
|
|
|
|
2002-04-15 03:00:14 +00:00
|
|
|
PAM_LOG("PRELIM round");
|
2001-08-26 17:41:13 +00:00
|
|
|
|
2002-04-26 19:28:17 +00:00
|
|
|
if (getuid() == 0 &&
|
|
|
|
(pwd->pw_fields & _PWF_SOURCE) == _PWF_FILES)
|
|
|
|
/* root doesn't need the old password */
|
|
|
|
return (pam_set_item(pamh, PAM_OLDAUTHTOK, ""));
|
|
|
|
|
2001-08-26 17:41:13 +00:00
|
|
|
if (pwd->pw_passwd[0] == '\0'
|
|
|
|
&& pam_test_option(&options, PAM_OPT_NULLOK, NULL)) {
|
|
|
|
/*
|
|
|
|
* No password case. XXX Are we giving too much away
|
|
|
|
* by not prompting for a password?
|
2002-04-06 19:30:04 +00:00
|
|
|
* XXX check PAM_DISALLOW_NULL_AUTHTOK
|
2001-08-26 17:41:13 +00:00
|
|
|
*/
|
2002-04-15 02:34:43 +00:00
|
|
|
old_pass = "";
|
|
|
|
} else {
|
2002-04-06 19:30:04 +00:00
|
|
|
retval = pam_get_authtok(pamh,
|
2002-04-15 02:34:43 +00:00
|
|
|
PAM_OLDAUTHTOK, &old_pass, NULL);
|
2001-08-26 17:41:13 +00:00
|
|
|
if (retval != PAM_SUCCESS)
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
2002-04-06 19:30:04 +00:00
|
|
|
}
|
|
|
|
PAM_LOG("Got old password");
|
2002-04-15 02:34:43 +00:00
|
|
|
/* always encrypt first */
|
|
|
|
encrypted = crypt(old_pass, pwd->pw_passwd);
|
|
|
|
if ((old_pass[0] == '\0' && pwd->pw_passwd[0] != '\0') ||
|
|
|
|
strcmp(encrypted, pwd->pw_passwd) != 0)
|
|
|
|
return (PAM_PERM_DENIED);
|
2002-04-15 03:00:14 +00:00
|
|
|
}
|
|
|
|
else if (flags & PAM_UPDATE_AUTHTOK) {
|
|
|
|
PAM_LOG("UPDATE round");
|
|
|
|
|
|
|
|
retval = pam_get_authtok(pamh,
|
2002-04-26 19:28:17 +00:00
|
|
|
PAM_OLDAUTHTOK, &old_pass, NULL);
|
2002-04-15 03:00:14 +00:00
|
|
|
if (retval != PAM_SUCCESS)
|
|
|
|
return (retval);
|
|
|
|
PAM_LOG("Got old password");
|
2002-04-06 19:30:04 +00:00
|
|
|
|
2002-04-15 02:34:43 +00:00
|
|
|
/* get new password */
|
2002-04-06 19:30:04 +00:00
|
|
|
for (;;) {
|
|
|
|
retval = pam_get_authtok(pamh,
|
|
|
|
PAM_AUTHTOK, &new_pass, NULL);
|
|
|
|
if (retval != PAM_TRY_AGAIN)
|
|
|
|
break;
|
|
|
|
pam_error(pamh, "Mismatch; try again, EOF to quit.");
|
2001-08-26 17:41:13 +00:00
|
|
|
}
|
2002-04-15 02:34:43 +00:00
|
|
|
PAM_LOG("Got new password");
|
2002-04-26 01:47:48 +00:00
|
|
|
if (retval != PAM_SUCCESS) {
|
2002-04-06 19:30:04 +00:00
|
|
|
PAM_VERBOSE_ERROR("Unable to get new password");
|
2002-04-26 01:47:48 +00:00
|
|
|
return (retval);
|
|
|
|
}
|
2002-04-15 02:34:43 +00:00
|
|
|
|
2002-05-08 00:54:29 +00:00
|
|
|
if ((old_pwd = pw_dup(pwd)) == NULL)
|
|
|
|
return (PAM_BUF_ERR);
|
|
|
|
|
2002-04-15 02:34:43 +00:00
|
|
|
pwd->pw_change = 0;
|
|
|
|
lc = login_getclass(NULL);
|
|
|
|
if (login_setcryptfmt(lc, password_hash, NULL) == NULL)
|
|
|
|
openpam_log(PAM_LOG_ERROR,
|
|
|
|
"can't set password cipher, relying on default");
|
|
|
|
login_close(lc);
|
|
|
|
makesalt(salt);
|
|
|
|
pwd->pw_passwd = crypt(new_pass, salt);
|
2001-08-26 17:41:13 +00:00
|
|
|
#ifdef YP
|
2002-05-08 00:54:29 +00:00
|
|
|
switch (old_pwd->pw_fields & _PWF_SOURCE) {
|
2002-04-15 02:34:43 +00:00
|
|
|
case _PWF_FILES:
|
|
|
|
#endif
|
2002-05-08 00:54:29 +00:00
|
|
|
retval = PAM_SERVICE_ERR;
|
|
|
|
if (pw_init(NULL, NULL))
|
|
|
|
openpam_log(PAM_LOG_ERROR, "pw_init() failed");
|
|
|
|
else if ((pfd = pw_lock()) == -1)
|
|
|
|
openpam_log(PAM_LOG_ERROR, "pw_lock() failed");
|
|
|
|
else if ((tfd = pw_tmp(-1)) == -1)
|
|
|
|
openpam_log(PAM_LOG_ERROR, "pw_tmp() failed");
|
|
|
|
else if (pw_copy(pfd, tfd, pwd, old_pwd) == -1)
|
|
|
|
openpam_log(PAM_LOG_ERROR, "pw_copy() failed");
|
|
|
|
else if (pw_mkdb(pwd->pw_name) == -1)
|
|
|
|
openpam_log(PAM_LOG_ERROR, "pw_mkdb() failed");
|
|
|
|
else
|
|
|
|
retval = PAM_SUCCESS;
|
|
|
|
pw_fini();
|
2002-04-15 02:34:43 +00:00
|
|
|
#ifdef YP
|
|
|
|
break;
|
|
|
|
case _PWF_NIS:
|
|
|
|
yp_domain = yp_server = NULL;
|
|
|
|
(void)pam_get_data(pamh,
|
|
|
|
"yp_domain", (const void **)&yp_domain);
|
|
|
|
(void)pam_get_data(pamh,
|
|
|
|
"yp_server", (const void **)&yp_server);
|
|
|
|
ypclnt = ypclnt_new(yp_domain,
|
|
|
|
"passwd.byname", yp_server);
|
2002-05-08 00:54:29 +00:00
|
|
|
if (ypclnt == NULL) {
|
|
|
|
retval = PAM_BUF_ERR;
|
|
|
|
} else if (ypclnt_connect(ypclnt) == -1 ||
|
2002-04-15 02:34:43 +00:00
|
|
|
ypclnt_passwd(ypclnt, pwd, old_pass) == -1) {
|
|
|
|
openpam_log(PAM_LOG_ERROR, "%s", ypclnt->error);
|
|
|
|
retval = PAM_SERVICE_ERR;
|
2002-05-08 00:54:29 +00:00
|
|
|
} else {
|
|
|
|
retval = PAM_SUCCESS;
|
2001-08-26 17:41:13 +00:00
|
|
|
}
|
2002-04-15 02:34:43 +00:00
|
|
|
ypclnt_free(ypclnt);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
openpam_log(PAM_LOG_ERROR, "unsupported source 0x%x",
|
|
|
|
pwd->pw_fields & _PWF_SOURCE);
|
|
|
|
retval = PAM_SERVICE_ERR;
|
2001-08-26 17:41:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
2002-05-22 23:18:25 +00:00
|
|
|
free(old_pwd);
|
2001-08-26 17:41:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Very bad juju */
|
|
|
|
retval = PAM_ABORT;
|
|
|
|
PAM_LOG("Illegal 'flags'");
|
|
|
|
}
|
|
|
|
|
2002-04-12 22:27:25 +00:00
|
|
|
return (retval);
|
2001-08-26 17:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mostly stolen from passwd(1)'s local_passwd.c - markm */
|
|
|
|
|
|
|
|
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
|
|
|
|
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
|
|
|
static void
|
|
|
|
to64(char *s, long v, int n)
|
|
|
|
{
|
|
|
|
while (--n >= 0) {
|
|
|
|
*s++ = itoa64[v&0x3f];
|
|
|
|
v >>= 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-14 16:41:36 +00:00
|
|
|
/* Salt suitable for traditional DES and MD5 */
|
|
|
|
void
|
|
|
|
makesalt(char salt[SALTSIZE])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* These are not really random numbers, they are just
|
|
|
|
* numbers that change to thwart construction of a
|
|
|
|
* dictionary. This is exposed to the public.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < SALTSIZE; i += 4)
|
|
|
|
to64(&salt[i], arc4random(), 4);
|
|
|
|
salt[SALTSIZE] = '\0';
|
|
|
|
}
|
|
|
|
|
1999-01-20 21:55:30 +00:00
|
|
|
PAM_MODULE_ENTRY("pam_unix");
|