2003-05-10 17:28:02 +08:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
2000-06-12 14:38:54 +08: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.
|
|
|
|
*
|
2003-05-10 17:28:02 +08: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.
|
1999-12-30 12:08:44 +08:00
|
|
|
*/
|
2004-06-01 09:28:20 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2003,2004 Damien Miller <djm@mindrot.org>
|
|
|
|
* Copyright (c) 2003,2004 Darren Tucker <dtucker@zip.com.au>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-18 18:45:47 +08:00
|
|
|
/* Based on $FreeBSD: src/crypto/openssh/auth2-pam-freebsd.c,v 1.11 2003/03/31 13:48:18 des Exp $ */
|
1999-12-30 12:08:44 +08:00
|
|
|
#include "includes.h"
|
2004-09-11 20:17:26 +08:00
|
|
|
RCSID("$Id: auth-pam.c,v 1.115 2004/09/11 12:17:26 dtucker Exp $");
|
1999-12-30 12:08:44 +08:00
|
|
|
|
|
|
|
#ifdef USE_PAM
|
2004-01-02 15:01:30 +08:00
|
|
|
#if defined(HAVE_SECURITY_PAM_APPL_H)
|
2003-05-10 17:28:02 +08:00
|
|
|
#include <security/pam_appl.h>
|
2004-01-02 15:01:30 +08:00
|
|
|
#elif defined (HAVE_PAM_PAM_APPL_H)
|
|
|
|
#include <pam/pam_appl.h>
|
|
|
|
#endif
|
2003-05-10 17:28:02 +08:00
|
|
|
|
2002-04-05 03:02:28 +08:00
|
|
|
#include "auth.h"
|
2001-02-07 09:58:33 +08:00
|
|
|
#include "auth-pam.h"
|
2003-05-10 17:28:02 +08:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "bufaux.h"
|
2001-01-22 13:34:40 +08:00
|
|
|
#include "canohost.h"
|
2003-05-10 17:28:02 +08:00
|
|
|
#include "log.h"
|
|
|
|
#include "monitor_wrap.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "packet.h"
|
2004-05-13 15:29:35 +08:00
|
|
|
#include "misc.h"
|
2003-05-10 17:28:02 +08:00
|
|
|
#include "servconf.h"
|
|
|
|
#include "ssh2.h"
|
|
|
|
#include "xmalloc.h"
|
2003-08-25 11:08:49 +08:00
|
|
|
#include "auth-options.h"
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-14 13:11:48 +08:00
|
|
|
extern ServerOptions options;
|
2003-11-18 09:42:07 +08:00
|
|
|
extern Buffer loginmsg;
|
2003-12-18 12:34:31 +08:00
|
|
|
extern int compat20;
|
2004-04-18 09:00:26 +08:00
|
|
|
extern u_int utmp_len;
|
2003-05-14 13:11:48 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
#ifdef USE_POSIX_THREADS
|
|
|
|
#include <pthread.h>
|
|
|
|
/*
|
2003-11-21 20:48:55 +08:00
|
|
|
* Avoid namespace clash when *not* using pthreads for systems *with*
|
|
|
|
* pthreads, which unconditionally define pthread_t via sys/types.h
|
2003-05-10 17:28:02 +08:00
|
|
|
* (e.g. Linux)
|
|
|
|
*/
|
2003-11-21 20:48:55 +08:00
|
|
|
typedef pthread_t sp_pthread_t;
|
2003-05-10 17:28:02 +08:00
|
|
|
#else
|
2004-01-13 19:35:58 +08:00
|
|
|
typedef pid_t sp_pthread_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct pam_ctxt {
|
|
|
|
sp_pthread_t pam_thread;
|
|
|
|
int pam_psock;
|
|
|
|
int pam_csock;
|
|
|
|
int pam_done;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sshpam_free_ctx(void *);
|
|
|
|
static struct pam_ctxt *cleanup_ctxt;
|
|
|
|
|
|
|
|
#ifndef USE_POSIX_THREADS
|
2003-05-10 17:28:02 +08:00
|
|
|
/*
|
|
|
|
* Simulate threads with processes.
|
|
|
|
*/
|
2000-05-31 09:20:11 +08:00
|
|
|
|
2004-01-14 19:14:04 +08:00
|
|
|
static int sshpam_thread_status = -1;
|
|
|
|
static mysig_t sshpam_oldsig;
|
|
|
|
|
|
|
|
static void
|
|
|
|
sshpam_sigchld_handler(int sig)
|
|
|
|
{
|
2004-05-24 09:55:36 +08:00
|
|
|
signal(SIGCHLD, SIG_DFL);
|
2004-01-14 20:07:56 +08:00
|
|
|
if (cleanup_ctxt == NULL)
|
|
|
|
return; /* handler called after PAM cleanup, shouldn't happen */
|
2004-05-24 09:55:36 +08:00
|
|
|
if (waitpid(cleanup_ctxt->pam_thread, &sshpam_thread_status, WNOHANG)
|
2004-07-11 14:54:08 +08:00
|
|
|
<= 0) {
|
2004-05-24 09:55:36 +08:00
|
|
|
/* PAM thread has not exitted, privsep slave must have */
|
|
|
|
kill(cleanup_ctxt->pam_thread, SIGTERM);
|
|
|
|
if (waitpid(cleanup_ctxt->pam_thread, &sshpam_thread_status, 0)
|
2004-07-11 14:54:08 +08:00
|
|
|
<= 0)
|
2004-05-24 09:55:36 +08:00
|
|
|
return; /* could not wait */
|
|
|
|
}
|
2004-01-14 19:14:04 +08:00
|
|
|
if (WIFSIGNALED(sshpam_thread_status) &&
|
|
|
|
WTERMSIG(sshpam_thread_status) == SIGTERM)
|
|
|
|
return; /* terminated by pthread_cancel */
|
|
|
|
if (!WIFEXITED(sshpam_thread_status))
|
|
|
|
fatal("PAM: authentication thread exited unexpectedly");
|
|
|
|
if (WEXITSTATUS(sshpam_thread_status) != 0)
|
|
|
|
fatal("PAM: authentication thread exited uncleanly");
|
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static void
|
|
|
|
pthread_exit(void *value __unused)
|
|
|
|
{
|
|
|
|
_exit(0);
|
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
|
|
|
pthread_create(sp_pthread_t *thread, const void *attr __unused,
|
|
|
|
void *(*thread_start)(void *), void *arg)
|
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
|
2004-03-04 17:03:54 +08:00
|
|
|
sshpam_thread_status = -1;
|
2003-05-10 17:28:02 +08:00
|
|
|
switch ((pid = fork())) {
|
|
|
|
case -1:
|
|
|
|
error("fork(): %s", strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
case 0:
|
|
|
|
thread_start(arg);
|
|
|
|
_exit(1);
|
|
|
|
default:
|
|
|
|
*thread = pid;
|
2004-01-14 19:14:04 +08:00
|
|
|
sshpam_oldsig = signal(SIGCHLD, sshpam_sigchld_handler);
|
2003-05-10 17:28:02 +08:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
|
|
|
pthread_cancel(sp_pthread_t thread)
|
2000-12-03 08:51:51 +08:00
|
|
|
{
|
2004-01-14 20:07:56 +08:00
|
|
|
signal(SIGCHLD, sshpam_oldsig);
|
2003-05-10 17:28:02 +08:00
|
|
|
return (kill(thread, SIGTERM));
|
2000-12-03 08:51:51 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
|
|
|
pthread_join(sp_pthread_t thread, void **value __unused)
|
2000-12-03 08:51:51 +08:00
|
|
|
{
|
2003-05-10 17:28:02 +08:00
|
|
|
int status;
|
|
|
|
|
2004-01-14 19:14:04 +08:00
|
|
|
if (sshpam_thread_status != -1)
|
|
|
|
return (sshpam_thread_status);
|
|
|
|
signal(SIGCHLD, sshpam_oldsig);
|
2003-05-10 17:28:02 +08:00
|
|
|
waitpid(thread, &status, 0);
|
|
|
|
return (status);
|
2000-12-03 08:51:51 +08:00
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-09-23 20:12:38 +08:00
|
|
|
static pam_handle_t *sshpam_handle = NULL;
|
|
|
|
static int sshpam_err = 0;
|
|
|
|
static int sshpam_authenticated = 0;
|
|
|
|
static int sshpam_session_open = 0;
|
|
|
|
static int sshpam_cred_established = 0;
|
2003-12-18 12:34:31 +08:00
|
|
|
static int sshpam_account_status = -1;
|
2003-11-17 18:41:42 +08:00
|
|
|
static char **sshpam_env = NULL;
|
2004-03-30 18:57:57 +08:00
|
|
|
static Authctxt *sshpam_authctxt = NULL;
|
2004-05-30 18:43:59 +08:00
|
|
|
static const char *sshpam_password = NULL;
|
2003-05-10 17:28:02 +08:00
|
|
|
|
2003-11-17 18:41:42 +08:00
|
|
|
/* Some PAM implementations don't implement this */
|
|
|
|
#ifndef HAVE_PAM_GETENVLIST
|
|
|
|
static char **
|
|
|
|
pam_getenvlist(pam_handle_t *pamh)
|
|
|
|
{
|
|
|
|
/*
|
2003-11-21 20:48:55 +08:00
|
|
|
* XXX - If necessary, we can still support envrionment passing
|
2003-11-17 18:41:42 +08:00
|
|
|
* for platforms without pam_getenvlist by searching for known
|
|
|
|
* env vars (e.g. KRB5CCNAME) from the PAM environment.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-08-16 21:12:05 +08:00
|
|
|
/*
|
|
|
|
* Some platforms, notably Solaris, do not enforce password complexity
|
|
|
|
* rules during pam_chauthtok() if the real uid of the calling process
|
|
|
|
* is 0, on the assumption that it's being called by "passwd" run by root.
|
|
|
|
* This wraps pam_chauthtok and sets/restore the real uid so PAM will do
|
|
|
|
* the right thing.
|
|
|
|
*/
|
|
|
|
#ifdef SSHPAM_CHAUTHTOK_NEEDS_RUID
|
|
|
|
static int
|
|
|
|
sshpam_chauthtok_ruid(pam_handle_t *pamh, int flags)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (sshpam_authctxt == NULL)
|
|
|
|
fatal("PAM: sshpam_authctxt not initialized");
|
|
|
|
if (setreuid(sshpam_authctxt->pw->pw_uid, -1) == -1)
|
|
|
|
fatal("%s: setreuid failed: %s", __func__, strerror(errno));
|
|
|
|
result = pam_chauthtok(pamh, flags);
|
|
|
|
if (setreuid(0, -1) == -1)
|
|
|
|
fatal("%s: setreuid failed: %s", __func__, strerror(errno));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
# define pam_chauthtok(a,b) (sshpam_chauthtok_ruid((a), (b)))
|
|
|
|
#endif
|
|
|
|
|
2003-12-18 12:34:31 +08:00
|
|
|
void
|
2004-06-19 10:54:38 +08:00
|
|
|
sshpam_password_change_required(int reqd)
|
2003-12-18 12:34:31 +08:00
|
|
|
{
|
2004-01-14 21:15:07 +08:00
|
|
|
debug3("%s %d", __func__, reqd);
|
2004-03-30 18:57:57 +08:00
|
|
|
if (sshpam_authctxt == NULL)
|
2004-03-08 20:04:06 +08:00
|
|
|
fatal("%s: PAM authctxt not initialized", __func__);
|
2004-03-30 18:57:57 +08:00
|
|
|
sshpam_authctxt->force_pwchange = reqd;
|
2003-12-18 12:34:31 +08:00
|
|
|
if (reqd) {
|
|
|
|
no_port_forwarding_flag |= 2;
|
|
|
|
no_agent_forwarding_flag |= 2;
|
|
|
|
no_x11_forwarding_flag |= 2;
|
|
|
|
} else {
|
|
|
|
no_port_forwarding_flag &= ~2;
|
|
|
|
no_agent_forwarding_flag &= ~2;
|
|
|
|
no_x11_forwarding_flag &= ~2;
|
|
|
|
}
|
|
|
|
}
|
2004-02-10 10:23:28 +08:00
|
|
|
|
2003-11-17 18:41:42 +08:00
|
|
|
/* Import regular and PAM environment from subprocess */
|
|
|
|
static void
|
|
|
|
import_environments(Buffer *b)
|
|
|
|
{
|
|
|
|
char *env;
|
|
|
|
u_int i, num_env;
|
|
|
|
int err;
|
|
|
|
|
2004-01-14 21:15:07 +08:00
|
|
|
debug3("PAM: %s entering", __func__);
|
|
|
|
|
2004-03-04 16:54:10 +08:00
|
|
|
#ifndef USE_POSIX_THREADS
|
2003-12-18 12:34:31 +08:00
|
|
|
/* Import variables set by do_pam_account */
|
|
|
|
sshpam_account_status = buffer_get_int(b);
|
2004-06-19 10:54:38 +08:00
|
|
|
sshpam_password_change_required(buffer_get_int(b));
|
2003-12-18 12:34:31 +08:00
|
|
|
|
2003-11-17 18:41:42 +08:00
|
|
|
/* Import environment from subprocess */
|
|
|
|
num_env = buffer_get_int(b);
|
|
|
|
sshpam_env = xmalloc((num_env + 1) * sizeof(*sshpam_env));
|
|
|
|
debug3("PAM: num env strings %d", num_env);
|
|
|
|
for(i = 0; i < num_env; i++)
|
|
|
|
sshpam_env[i] = buffer_get_string(b, NULL);
|
|
|
|
|
|
|
|
sshpam_env[num_env] = NULL;
|
|
|
|
|
|
|
|
/* Import PAM environment from subprocess */
|
|
|
|
num_env = buffer_get_int(b);
|
|
|
|
debug("PAM: num PAM env strings %d", num_env);
|
|
|
|
for(i = 0; i < num_env; i++) {
|
|
|
|
env = buffer_get_string(b, NULL);
|
|
|
|
|
2003-11-18 09:45:35 +08:00
|
|
|
#ifdef HAVE_PAM_PUTENV
|
2003-11-17 18:41:42 +08:00
|
|
|
/* Errors are not fatal here */
|
|
|
|
if ((err = pam_putenv(sshpam_handle, env)) != PAM_SUCCESS) {
|
|
|
|
error("PAM: pam_putenv: %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
}
|
2003-11-18 09:45:35 +08:00
|
|
|
#endif
|
2003-11-17 18:41:42 +08:00
|
|
|
}
|
2004-03-04 16:54:10 +08:00
|
|
|
#endif
|
2003-11-17 18:41:42 +08:00
|
|
|
}
|
|
|
|
|
2000-09-16 13:09:27 +08:00
|
|
|
/*
|
2003-05-10 17:28:02 +08:00
|
|
|
* Conversation function for authentication thread.
|
2000-09-16 13:09:27 +08:00
|
|
|
*/
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
2004-07-01 10:38:14 +08:00
|
|
|
sshpam_thread_conv(int n, struct pam_message **msg,
|
2003-08-25 11:08:49 +08:00
|
|
|
struct pam_response **resp, void *data)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-05-10 17:28:02 +08:00
|
|
|
Buffer buffer;
|
|
|
|
struct pam_ctxt *ctxt;
|
2003-09-23 20:12:38 +08:00
|
|
|
struct pam_response *reply;
|
2003-05-10 17:28:02 +08:00
|
|
|
int i;
|
|
|
|
|
2004-02-17 17:46:59 +08:00
|
|
|
debug3("PAM: %s entering, %d messages", __func__, n);
|
2003-09-23 20:12:38 +08:00
|
|
|
*resp = NULL;
|
|
|
|
|
2004-06-30 18:34:31 +08:00
|
|
|
if (data == NULL) {
|
|
|
|
error("PAM: conversation function passed a null context");
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
ctxt = data;
|
|
|
|
if (n <= 0 || n > PAM_MAX_NUM_MSG)
|
|
|
|
return (PAM_CONV_ERR);
|
2003-09-23 20:12:38 +08:00
|
|
|
|
|
|
|
if ((reply = malloc(n * sizeof(*reply))) == NULL)
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
memset(reply, 0, n * sizeof(*reply));
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_init(&buffer);
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
|
|
|
|
case PAM_PROMPT_ECHO_OFF:
|
2003-11-21 20:48:55 +08:00
|
|
|
buffer_put_cstring(&buffer,
|
2003-09-23 20:12:38 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg));
|
2003-11-21 20:48:55 +08:00
|
|
|
if (ssh_msg_send(ctxt->pam_csock,
|
2003-11-17 18:27:55 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
|
|
|
|
goto fail;
|
2003-11-21 20:48:55 +08:00
|
|
|
if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1)
|
2003-11-17 18:27:55 +08:00
|
|
|
goto fail;
|
2003-05-10 17:28:02 +08:00
|
|
|
if (buffer_get_char(&buffer) != PAM_AUTHTOK)
|
|
|
|
goto fail;
|
2003-09-23 20:12:38 +08:00
|
|
|
reply[i].resp = buffer_get_string(&buffer, NULL);
|
2003-05-10 17:28:02 +08:00
|
|
|
break;
|
|
|
|
case PAM_PROMPT_ECHO_ON:
|
2003-11-21 20:48:55 +08:00
|
|
|
buffer_put_cstring(&buffer,
|
2003-09-23 20:12:38 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg));
|
2003-11-21 20:48:55 +08:00
|
|
|
if (ssh_msg_send(ctxt->pam_csock,
|
2003-11-17 18:27:55 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
|
|
|
|
goto fail;
|
|
|
|
if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1)
|
|
|
|
goto fail;
|
2003-05-10 17:28:02 +08:00
|
|
|
if (buffer_get_char(&buffer) != PAM_AUTHTOK)
|
|
|
|
goto fail;
|
2003-09-23 20:12:38 +08:00
|
|
|
reply[i].resp = buffer_get_string(&buffer, NULL);
|
2003-05-10 17:28:02 +08:00
|
|
|
break;
|
|
|
|
case PAM_ERROR_MSG:
|
2003-11-21 20:48:55 +08:00
|
|
|
buffer_put_cstring(&buffer,
|
2003-09-23 20:12:38 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg));
|
2003-11-21 20:48:55 +08:00
|
|
|
if (ssh_msg_send(ctxt->pam_csock,
|
2003-11-17 18:27:55 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
|
|
|
|
goto fail;
|
2003-05-10 17:28:02 +08:00
|
|
|
break;
|
|
|
|
case PAM_TEXT_INFO:
|
2003-11-21 20:48:55 +08:00
|
|
|
buffer_put_cstring(&buffer,
|
2003-09-23 20:12:38 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg));
|
2003-11-21 20:48:55 +08:00
|
|
|
if (ssh_msg_send(ctxt->pam_csock,
|
2003-11-17 18:27:55 +08:00
|
|
|
PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
|
|
|
|
goto fail;
|
2003-05-10 17:28:02 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_clear(&buffer);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_free(&buffer);
|
2003-09-23 20:12:38 +08:00
|
|
|
*resp = reply;
|
2003-05-10 17:28:02 +08:00
|
|
|
return (PAM_SUCCESS);
|
2003-09-23 20:12:38 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
fail:
|
2003-09-23 20:12:38 +08:00
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
if (reply[i].resp != NULL)
|
|
|
|
xfree(reply[i].resp);
|
|
|
|
}
|
|
|
|
xfree(reply);
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_free(&buffer);
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
/*
|
|
|
|
* Authentication thread.
|
|
|
|
*/
|
|
|
|
static void *
|
|
|
|
sshpam_thread(void *ctxtp)
|
|
|
|
{
|
|
|
|
struct pam_ctxt *ctxt = ctxtp;
|
|
|
|
Buffer buffer;
|
2003-09-02 21:12:06 +08:00
|
|
|
struct pam_conv sshpam_conv;
|
2004-07-01 12:00:14 +08:00
|
|
|
int flags = (options.permit_empty_passwd == 0 ?
|
|
|
|
PAM_DISALLOW_NULL_AUTHTOK : 0);
|
2003-05-10 17:28:02 +08:00
|
|
|
#ifndef USE_POSIX_THREADS
|
2003-11-17 18:41:42 +08:00
|
|
|
extern char **environ;
|
|
|
|
char **env_from_pam;
|
|
|
|
u_int i;
|
2003-05-10 17:28:02 +08:00
|
|
|
const char *pam_user;
|
|
|
|
|
2004-07-01 10:38:14 +08:00
|
|
|
pam_get_item(sshpam_handle, PAM_USER, (void **)&pam_user);
|
2003-11-17 18:41:42 +08:00
|
|
|
environ[0] = NULL;
|
2004-07-21 18:54:47 +08:00
|
|
|
|
|
|
|
if (sshpam_authctxt != NULL) {
|
|
|
|
setproctitle("%s [pam]",
|
|
|
|
sshpam_authctxt->valid ? pam_user : "unknown");
|
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
#endif
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-09-02 21:12:06 +08:00
|
|
|
sshpam_conv.conv = sshpam_thread_conv;
|
|
|
|
sshpam_conv.appdata_ptr = ctxt;
|
|
|
|
|
2004-03-30 18:57:57 +08:00
|
|
|
if (sshpam_authctxt == NULL)
|
2004-03-08 20:04:06 +08:00
|
|
|
fatal("%s: PAM authctxt not initialized", __func__);
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_init(&buffer);
|
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
|
|
|
|
(const void *)&sshpam_conv);
|
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
goto auth_fail;
|
2004-07-01 12:00:14 +08:00
|
|
|
sshpam_err = pam_authenticate(sshpam_handle, flags);
|
2003-05-10 17:28:02 +08:00
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
goto auth_fail;
|
2003-12-18 12:34:31 +08:00
|
|
|
|
2003-12-18 13:08:59 +08:00
|
|
|
if (compat20) {
|
2003-12-18 12:34:31 +08:00
|
|
|
if (!do_pam_account())
|
|
|
|
goto auth_fail;
|
2004-03-30 18:57:57 +08:00
|
|
|
if (sshpam_authctxt->force_pwchange) {
|
2003-12-18 12:34:31 +08:00
|
|
|
sshpam_err = pam_chauthtok(sshpam_handle,
|
|
|
|
PAM_CHANGE_EXPIRED_AUTHTOK);
|
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
goto auth_fail;
|
2004-06-19 10:54:38 +08:00
|
|
|
sshpam_password_change_required(0);
|
2003-12-18 12:34:31 +08:00
|
|
|
}
|
2003-12-18 13:08:59 +08:00
|
|
|
}
|
2003-12-18 12:34:31 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_put_cstring(&buffer, "OK");
|
2003-11-17 18:41:42 +08:00
|
|
|
|
|
|
|
#ifndef USE_POSIX_THREADS
|
2003-12-18 12:34:31 +08:00
|
|
|
/* Export variables set by do_pam_account */
|
|
|
|
buffer_put_int(&buffer, sshpam_account_status);
|
2004-03-30 18:57:57 +08:00
|
|
|
buffer_put_int(&buffer, sshpam_authctxt->force_pwchange);
|
2003-12-18 12:34:31 +08:00
|
|
|
|
2003-11-17 18:41:42 +08:00
|
|
|
/* Export any environment strings set in child */
|
|
|
|
for(i = 0; environ[i] != NULL; i++)
|
|
|
|
; /* Count */
|
|
|
|
buffer_put_int(&buffer, i);
|
|
|
|
for(i = 0; environ[i] != NULL; i++)
|
|
|
|
buffer_put_cstring(&buffer, environ[i]);
|
|
|
|
|
|
|
|
/* Export any environment strings set by PAM in child */
|
|
|
|
env_from_pam = pam_getenvlist(sshpam_handle);
|
|
|
|
for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++)
|
|
|
|
; /* Count */
|
|
|
|
buffer_put_int(&buffer, i);
|
|
|
|
for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++)
|
|
|
|
buffer_put_cstring(&buffer, env_from_pam[i]);
|
|
|
|
#endif /* USE_POSIX_THREADS */
|
|
|
|
|
2003-11-17 18:27:55 +08:00
|
|
|
/* XXX - can't do much about an error here */
|
2003-05-10 17:28:02 +08:00
|
|
|
ssh_msg_send(ctxt->pam_csock, sshpam_err, &buffer);
|
|
|
|
buffer_free(&buffer);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
|
|
|
|
auth_fail:
|
|
|
|
buffer_put_cstring(&buffer,
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
2003-11-17 18:27:55 +08:00
|
|
|
/* XXX - can't do much about an error here */
|
2003-05-10 17:28:02 +08:00
|
|
|
ssh_msg_send(ctxt->pam_csock, PAM_AUTH_ERR, &buffer);
|
|
|
|
buffer_free(&buffer);
|
|
|
|
pthread_exit(NULL);
|
2003-11-21 20:56:47 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
return (NULL); /* Avoid warning for non-pthread case */
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-10-07 09:30:15 +08:00
|
|
|
void
|
|
|
|
sshpam_thread_cleanup(void)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-10-07 09:30:15 +08:00
|
|
|
struct pam_ctxt *ctxt = cleanup_ctxt;
|
|
|
|
|
2004-01-14 21:15:07 +08:00
|
|
|
debug3("PAM: %s entering", __func__);
|
2003-10-07 09:30:15 +08:00
|
|
|
if (ctxt != NULL && ctxt->pam_thread != 0) {
|
|
|
|
pthread_cancel(ctxt->pam_thread);
|
|
|
|
pthread_join(ctxt->pam_thread, NULL);
|
|
|
|
close(ctxt->pam_psock);
|
|
|
|
close(ctxt->pam_csock);
|
|
|
|
memset(ctxt, 0, sizeof(*ctxt));
|
|
|
|
cleanup_ctxt = NULL;
|
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
2004-07-01 10:38:14 +08:00
|
|
|
sshpam_null_conv(int n, struct pam_message **msg,
|
2003-08-25 11:08:49 +08:00
|
|
|
struct pam_response **resp, void *data)
|
2003-05-10 17:28:02 +08:00
|
|
|
{
|
2004-02-17 17:46:59 +08:00
|
|
|
debug3("PAM: %s entering, %d messages", __func__, n);
|
2003-05-10 17:28:02 +08:00
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static struct pam_conv null_conv = { sshpam_null_conv, NULL };
|
|
|
|
|
2003-10-07 09:30:15 +08:00
|
|
|
void
|
|
|
|
sshpam_cleanup(void)
|
2003-05-10 17:28:02 +08:00
|
|
|
{
|
|
|
|
debug("PAM: cleanup");
|
2003-09-23 20:12:38 +08:00
|
|
|
if (sshpam_handle == NULL)
|
|
|
|
return;
|
2003-05-10 17:28:02 +08:00
|
|
|
pam_set_item(sshpam_handle, PAM_CONV, (const void *)&null_conv);
|
|
|
|
if (sshpam_cred_established) {
|
|
|
|
pam_setcred(sshpam_handle, PAM_DELETE_CRED);
|
|
|
|
sshpam_cred_established = 0;
|
|
|
|
}
|
|
|
|
if (sshpam_session_open) {
|
|
|
|
pam_close_session(sshpam_handle, PAM_SILENT);
|
|
|
|
sshpam_session_open = 0;
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
2004-02-10 10:23:28 +08:00
|
|
|
sshpam_authenticated = 0;
|
2003-05-10 17:28:02 +08:00
|
|
|
pam_end(sshpam_handle, sshpam_err);
|
|
|
|
sshpam_handle = NULL;
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
2004-03-08 20:04:06 +08:00
|
|
|
sshpam_init(Authctxt *authctxt)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-09-13 20:12:11 +08:00
|
|
|
extern char *__progname;
|
2004-03-08 20:04:06 +08:00
|
|
|
const char *pam_rhost, *pam_user, *user = authctxt->user;
|
2003-05-10 17:28:02 +08:00
|
|
|
|
|
|
|
if (sshpam_handle != NULL) {
|
|
|
|
/* We already have a PAM context; check if the user matches */
|
|
|
|
sshpam_err = pam_get_item(sshpam_handle,
|
2004-07-01 10:38:14 +08:00
|
|
|
PAM_USER, (void **)&pam_user);
|
2003-05-10 17:28:02 +08:00
|
|
|
if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0)
|
|
|
|
return (0);
|
|
|
|
pam_end(sshpam_handle, sshpam_err);
|
|
|
|
sshpam_handle = NULL;
|
|
|
|
}
|
|
|
|
debug("PAM: initializing for \"%s\"", user);
|
2003-09-13 20:02:05 +08:00
|
|
|
sshpam_err =
|
|
|
|
pam_start(SSHD_PAM_SERVICE, user, &null_conv, &sshpam_handle);
|
2004-03-30 18:57:57 +08:00
|
|
|
sshpam_authctxt = authctxt;
|
2004-03-08 20:04:06 +08:00
|
|
|
|
2003-05-18 18:45:47 +08:00
|
|
|
if (sshpam_err != PAM_SUCCESS) {
|
|
|
|
pam_end(sshpam_handle, sshpam_err);
|
|
|
|
sshpam_handle = NULL;
|
2003-05-10 17:28:02 +08:00
|
|
|
return (-1);
|
2003-05-18 18:45:47 +08:00
|
|
|
}
|
2003-06-03 08:25:48 +08:00
|
|
|
pam_rhost = get_remote_name_or_ip(utmp_len, options.use_dns);
|
2003-06-02 09:04:39 +08:00
|
|
|
debug("PAM: setting PAM_RHOST to \"%s\"", pam_rhost);
|
2003-05-10 17:28:02 +08:00
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_RHOST, pam_rhost);
|
2003-05-18 18:45:47 +08:00
|
|
|
if (sshpam_err != PAM_SUCCESS) {
|
2003-08-25 11:08:49 +08:00
|
|
|
pam_end(sshpam_handle, sshpam_err);
|
2003-05-18 18:45:47 +08:00
|
|
|
sshpam_handle = NULL;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
#ifdef PAM_TTY_KLUDGE
|
2003-11-21 20:48:55 +08:00
|
|
|
/*
|
|
|
|
* Some silly PAM modules (e.g. pam_time) require a TTY to operate.
|
|
|
|
* sshd doesn't set the tty until too late in the auth process and
|
2003-05-18 18:45:47 +08:00
|
|
|
* may not even set one (for tty-less connections)
|
2003-11-21 20:48:55 +08:00
|
|
|
*/
|
2003-05-18 18:45:47 +08:00
|
|
|
debug("PAM: setting PAM_TTY to \"ssh\"");
|
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, "ssh");
|
2003-05-10 17:28:02 +08:00
|
|
|
if (sshpam_err != PAM_SUCCESS) {
|
|
|
|
pam_end(sshpam_handle, sshpam_err);
|
|
|
|
sshpam_handle = NULL;
|
|
|
|
return (-1);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
2003-05-18 18:45:47 +08:00
|
|
|
#endif
|
2003-05-10 17:28:02 +08:00
|
|
|
return (0);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static void *
|
|
|
|
sshpam_init_ctx(Authctxt *authctxt)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-05-10 17:28:02 +08:00
|
|
|
struct pam_ctxt *ctxt;
|
|
|
|
int socks[2];
|
2001-02-05 20:42:17 +08:00
|
|
|
|
2004-01-14 21:15:07 +08:00
|
|
|
debug3("PAM: %s entering", __func__);
|
2003-05-14 13:11:48 +08:00
|
|
|
/* Refuse to start if we don't have PAM enabled */
|
|
|
|
if (!options.use_pam)
|
|
|
|
return NULL;
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
/* Initialize PAM */
|
2004-03-08 20:04:06 +08:00
|
|
|
if (sshpam_init(authctxt) == -1) {
|
2003-05-10 17:28:02 +08:00
|
|
|
error("PAM: initialization failed");
|
|
|
|
return (NULL);
|
|
|
|
}
|
2001-02-07 09:58:33 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
ctxt = xmalloc(sizeof *ctxt);
|
2003-10-07 09:30:15 +08:00
|
|
|
memset(ctxt, 0, sizeof(*ctxt));
|
2003-05-10 17:28:02 +08:00
|
|
|
|
|
|
|
/* Start the authentication thread */
|
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, socks) == -1) {
|
|
|
|
error("PAM: failed create sockets: %s", strerror(errno));
|
|
|
|
xfree(ctxt);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
ctxt->pam_psock = socks[0];
|
|
|
|
ctxt->pam_csock = socks[1];
|
|
|
|
if (pthread_create(&ctxt->pam_thread, NULL, sshpam_thread, ctxt) == -1) {
|
|
|
|
error("PAM: failed to start authentication thread: %s",
|
|
|
|
strerror(errno));
|
|
|
|
close(socks[0]);
|
|
|
|
close(socks[1]);
|
|
|
|
xfree(ctxt);
|
|
|
|
return (NULL);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
2003-10-07 09:30:15 +08:00
|
|
|
cleanup_ctxt = ctxt;
|
2003-05-10 17:28:02 +08:00
|
|
|
return (ctxt);
|
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
|
|
|
sshpam_query(void *ctx, char **name, char **info,
|
|
|
|
u_int *num, char ***prompts, u_int **echo_on)
|
|
|
|
{
|
|
|
|
Buffer buffer;
|
|
|
|
struct pam_ctxt *ctxt = ctx;
|
|
|
|
size_t plen;
|
|
|
|
u_char type;
|
|
|
|
char *msg;
|
2003-07-30 12:53:11 +08:00
|
|
|
size_t len;
|
2003-05-10 17:28:02 +08:00
|
|
|
|
2004-01-14 21:15:07 +08:00
|
|
|
debug3("PAM: %s entering", __func__);
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_init(&buffer);
|
|
|
|
*name = xstrdup("");
|
|
|
|
*info = xstrdup("");
|
|
|
|
*prompts = xmalloc(sizeof(char *));
|
|
|
|
**prompts = NULL;
|
|
|
|
plen = 0;
|
|
|
|
*echo_on = xmalloc(sizeof(u_int));
|
|
|
|
while (ssh_msg_recv(ctxt->pam_psock, &buffer) == 0) {
|
|
|
|
type = buffer_get_char(&buffer);
|
|
|
|
msg = buffer_get_string(&buffer, NULL);
|
|
|
|
switch (type) {
|
|
|
|
case PAM_PROMPT_ECHO_ON:
|
|
|
|
case PAM_PROMPT_ECHO_OFF:
|
|
|
|
*num = 1;
|
2003-07-30 12:53:11 +08:00
|
|
|
len = plen + strlen(msg) + 1;
|
|
|
|
**prompts = xrealloc(**prompts, len);
|
|
|
|
plen += snprintf(**prompts + plen, len, "%s", msg);
|
2003-05-10 17:28:02 +08:00
|
|
|
**echo_on = (type == PAM_PROMPT_ECHO_ON);
|
|
|
|
xfree(msg);
|
|
|
|
return (0);
|
|
|
|
case PAM_ERROR_MSG:
|
|
|
|
case PAM_TEXT_INFO:
|
|
|
|
/* accumulate messages */
|
2003-11-13 16:52:31 +08:00
|
|
|
len = plen + strlen(msg) + 2;
|
2003-07-30 12:53:11 +08:00
|
|
|
**prompts = xrealloc(**prompts, len);
|
2003-11-13 16:52:31 +08:00
|
|
|
plen += snprintf(**prompts + plen, len, "%s\n", msg);
|
2003-05-10 17:28:02 +08:00
|
|
|
xfree(msg);
|
2000-05-31 09:20:11 +08:00
|
|
|
break;
|
2003-05-10 17:28:02 +08:00
|
|
|
case PAM_SUCCESS:
|
|
|
|
case PAM_AUTH_ERR:
|
|
|
|
if (**prompts != NULL) {
|
|
|
|
/* drain any accumulated messages */
|
2003-11-18 09:42:07 +08:00
|
|
|
debug("PAM: %s", **prompts);
|
|
|
|
buffer_append(&loginmsg, **prompts,
|
|
|
|
strlen(**prompts));
|
2003-05-10 17:28:02 +08:00
|
|
|
xfree(**prompts);
|
|
|
|
**prompts = NULL;
|
|
|
|
}
|
|
|
|
if (type == PAM_SUCCESS) {
|
2003-11-17 18:41:42 +08:00
|
|
|
import_environments(&buffer);
|
2003-05-10 17:28:02 +08:00
|
|
|
*num = 0;
|
|
|
|
**echo_on = 0;
|
|
|
|
ctxt->pam_done = 1;
|
|
|
|
xfree(msg);
|
|
|
|
return (0);
|
|
|
|
}
|
2004-04-18 09:00:26 +08:00
|
|
|
error("PAM: %s for %s%.100s from %.100s", msg,
|
|
|
|
sshpam_authctxt->valid ? "" : "illegal user ",
|
|
|
|
sshpam_authctxt->user,
|
|
|
|
get_remote_name_or_ip(utmp_len, options.use_dns));
|
2003-10-09 12:20:15 +08:00
|
|
|
/* FALLTHROUGH */
|
2000-05-31 09:20:11 +08:00
|
|
|
default:
|
2003-05-10 17:28:02 +08:00
|
|
|
*num = 0;
|
|
|
|
**echo_on = 0;
|
|
|
|
xfree(msg);
|
|
|
|
ctxt->pam_done = -1;
|
|
|
|
return (-1);
|
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
return (-1);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
/* XXX - see also comment in auth-chall.c:verify_response */
|
|
|
|
static int
|
|
|
|
sshpam_respond(void *ctx, u_int num, char **resp)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-05-10 17:28:02 +08:00
|
|
|
Buffer buffer;
|
|
|
|
struct pam_ctxt *ctxt = ctx;
|
|
|
|
|
2004-01-14 21:15:07 +08:00
|
|
|
debug2("PAM: %s entering, %d responses", __func__, num);
|
2003-05-10 17:28:02 +08:00
|
|
|
switch (ctxt->pam_done) {
|
|
|
|
case 1:
|
|
|
|
sshpam_authenticated = 1;
|
|
|
|
return (0);
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (-1);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
if (num != 1) {
|
|
|
|
error("PAM: expected one response, got %u", num);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
buffer_init(&buffer);
|
|
|
|
buffer_put_cstring(&buffer, *resp);
|
2003-11-17 18:27:55 +08:00
|
|
|
if (ssh_msg_send(ctxt->pam_psock, PAM_AUTHTOK, &buffer) == -1) {
|
|
|
|
buffer_free(&buffer);
|
|
|
|
return (-1);
|
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
buffer_free(&buffer);
|
|
|
|
return (1);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static void
|
|
|
|
sshpam_free_ctx(void *ctxtp)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-05-10 17:28:02 +08:00
|
|
|
struct pam_ctxt *ctxt = ctxtp;
|
2002-05-08 10:27:55 +08:00
|
|
|
|
2004-01-14 21:15:07 +08:00
|
|
|
debug3("PAM: %s entering", __func__);
|
2003-10-07 09:30:15 +08:00
|
|
|
sshpam_thread_cleanup();
|
2003-05-10 17:28:02 +08:00
|
|
|
xfree(ctxt);
|
|
|
|
/*
|
|
|
|
* We don't call sshpam_cleanup() here because we may need the PAM
|
|
|
|
* handle at a later stage, e.g. when setting up a session. It's
|
|
|
|
* still on the cleanup list, so pam_end() *will* be called before
|
|
|
|
* the server process terminates.
|
|
|
|
*/
|
2000-09-16 13:09:27 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
KbdintDevice sshpam_device = {
|
|
|
|
"pam",
|
|
|
|
sshpam_init_ctx,
|
|
|
|
sshpam_query,
|
|
|
|
sshpam_respond,
|
|
|
|
sshpam_free_ctx
|
|
|
|
};
|
|
|
|
|
|
|
|
KbdintDevice mm_sshpam_device = {
|
|
|
|
"pam",
|
|
|
|
mm_sshpam_init_ctx,
|
|
|
|
mm_sshpam_query,
|
|
|
|
mm_sshpam_respond,
|
|
|
|
mm_sshpam_free_ctx
|
|
|
|
};
|
2000-10-14 21:36:13 +08:00
|
|
|
|
2001-02-05 20:42:17 +08:00
|
|
|
/*
|
2003-05-10 17:28:02 +08:00
|
|
|
* This replaces auth-pam.c
|
2000-09-16 13:09:27 +08:00
|
|
|
*/
|
2003-05-10 17:28:02 +08:00
|
|
|
void
|
2004-03-08 20:04:06 +08:00
|
|
|
start_pam(Authctxt *authctxt)
|
2000-09-16 13:09:27 +08:00
|
|
|
{
|
2003-05-14 13:31:12 +08:00
|
|
|
if (!options.use_pam)
|
|
|
|
fatal("PAM: initialisation requested when UsePAM=no");
|
|
|
|
|
2004-03-08 20:04:06 +08:00
|
|
|
if (sshpam_init(authctxt) == -1)
|
2003-05-10 17:28:02 +08:00
|
|
|
fatal("PAM: initialisation failed");
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
void
|
|
|
|
finish_pam(void)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-10-07 09:30:15 +08:00
|
|
|
sshpam_cleanup();
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-08-25 11:08:49 +08:00
|
|
|
u_int
|
|
|
|
do_pam_account(void)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-12-18 12:34:31 +08:00
|
|
|
if (sshpam_account_status != -1)
|
|
|
|
return (sshpam_account_status);
|
|
|
|
|
2003-08-25 11:08:49 +08:00
|
|
|
sshpam_err = pam_acct_mgmt(sshpam_handle, 0);
|
2004-01-14 21:15:07 +08:00
|
|
|
debug3("PAM: %s pam_acct_mgmt = %d", __func__, sshpam_err);
|
2003-12-18 12:34:31 +08:00
|
|
|
|
|
|
|
if (sshpam_err != PAM_SUCCESS && sshpam_err != PAM_NEW_AUTHTOK_REQD) {
|
|
|
|
sshpam_account_status = 0;
|
|
|
|
return (sshpam_account_status);
|
2003-08-25 11:08:49 +08:00
|
|
|
}
|
|
|
|
|
2003-12-18 12:34:31 +08:00
|
|
|
if (sshpam_err == PAM_NEW_AUTHTOK_REQD)
|
2004-06-19 10:54:38 +08:00
|
|
|
sshpam_password_change_required(1);
|
2003-12-18 12:34:31 +08:00
|
|
|
|
|
|
|
sshpam_account_status = 1;
|
|
|
|
return (sshpam_account_status);
|
2003-05-10 17:28:02 +08:00
|
|
|
}
|
2001-04-24 01:28:28 +08:00
|
|
|
|
2003-09-02 21:18:52 +08:00
|
|
|
void
|
|
|
|
do_pam_set_tty(const char *tty)
|
|
|
|
{
|
2003-08-08 11:43:37 +08:00
|
|
|
if (tty != NULL) {
|
|
|
|
debug("PAM: setting PAM_TTY to \"%s\"", tty);
|
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, tty);
|
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
fatal("PAM: failed to set PAM_TTY: %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
}
|
2003-05-10 17:28:02 +08:00
|
|
|
}
|
2000-06-18 12:07:04 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
void
|
|
|
|
do_pam_setcred(int init)
|
|
|
|
{
|
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
|
|
|
|
(const void *)&null_conv);
|
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
fatal("PAM: failed to set PAM_CONV: %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
if (init) {
|
|
|
|
debug("PAM: establishing credentials");
|
|
|
|
sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED);
|
|
|
|
} else {
|
|
|
|
debug("PAM: reinitializing credentials");
|
|
|
|
sshpam_err = pam_setcred(sshpam_handle, PAM_REINITIALIZE_CRED);
|
|
|
|
}
|
|
|
|
if (sshpam_err == PAM_SUCCESS) {
|
|
|
|
sshpam_cred_established = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sshpam_authenticated)
|
|
|
|
fatal("PAM: pam_setcred(): %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
else
|
|
|
|
debug("PAM: pam_setcred(): %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
static int
|
2004-07-01 10:38:14 +08:00
|
|
|
sshpam_tty_conv(int n, struct pam_message **msg,
|
2003-08-25 11:08:49 +08:00
|
|
|
struct pam_response **resp, void *data)
|
2002-07-23 08:44:07 +08:00
|
|
|
{
|
2003-05-10 17:28:02 +08:00
|
|
|
char input[PAM_MAX_MSG_SIZE];
|
2003-09-23 20:12:38 +08:00
|
|
|
struct pam_response *reply;
|
2002-07-23 08:44:07 +08:00
|
|
|
int i;
|
|
|
|
|
2004-02-17 17:46:59 +08:00
|
|
|
debug3("PAM: %s called with %d messages", __func__, n);
|
|
|
|
|
2003-09-23 20:12:38 +08:00
|
|
|
*resp = NULL;
|
|
|
|
|
2003-11-18 09:42:07 +08:00
|
|
|
if (n <= 0 || n > PAM_MAX_NUM_MSG || !isatty(STDIN_FILENO))
|
2003-05-10 17:28:02 +08:00
|
|
|
return (PAM_CONV_ERR);
|
2003-09-23 20:12:38 +08:00
|
|
|
|
|
|
|
if ((reply = malloc(n * sizeof(*reply))) == NULL)
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
memset(reply, 0, n * sizeof(*reply));
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
|
|
|
|
case PAM_PROMPT_ECHO_OFF:
|
2003-09-23 20:12:38 +08:00
|
|
|
reply[i].resp =
|
2003-11-21 20:48:55 +08:00
|
|
|
read_passphrase(PAM_MSG_MEMBER(msg, i, msg),
|
2003-05-10 17:28:02 +08:00
|
|
|
RP_ALLOW_STDIN);
|
2003-09-23 20:12:38 +08:00
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
2003-05-10 17:28:02 +08:00
|
|
|
break;
|
|
|
|
case PAM_PROMPT_ECHO_ON:
|
2003-11-13 08:21:31 +08:00
|
|
|
fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
|
2003-05-10 17:28:02 +08:00
|
|
|
fgets(input, sizeof input, stdin);
|
2004-07-19 07:39:11 +08:00
|
|
|
if ((reply[i].resp = strdup(input)) == NULL)
|
|
|
|
goto fail;
|
2003-09-23 20:12:38 +08:00
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
2003-05-10 17:28:02 +08:00
|
|
|
break;
|
|
|
|
case PAM_ERROR_MSG:
|
|
|
|
case PAM_TEXT_INFO:
|
2003-11-13 08:21:31 +08:00
|
|
|
fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
|
2003-09-23 20:12:38 +08:00
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
2003-05-10 17:28:02 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2002-07-23 08:44:07 +08:00
|
|
|
}
|
2003-09-23 20:12:38 +08:00
|
|
|
*resp = reply;
|
2003-05-10 17:28:02 +08:00
|
|
|
return (PAM_SUCCESS);
|
2003-09-23 20:12:38 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
fail:
|
2003-09-23 20:12:38 +08:00
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
if (reply[i].resp != NULL)
|
|
|
|
xfree(reply[i].resp);
|
|
|
|
}
|
|
|
|
xfree(reply);
|
2003-05-10 17:28:02 +08:00
|
|
|
return (PAM_CONV_ERR);
|
2002-07-23 08:44:07 +08:00
|
|
|
}
|
|
|
|
|
2004-06-03 12:53:12 +08:00
|
|
|
static struct pam_conv tty_conv = { sshpam_tty_conv, NULL };
|
2003-11-18 09:42:07 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
/*
|
|
|
|
* XXX this should be done in the authentication phase, but ssh1 doesn't
|
|
|
|
* support that
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
do_pam_chauthtok(void)
|
1999-12-30 12:08:44 +08:00
|
|
|
{
|
2003-05-10 17:28:02 +08:00
|
|
|
if (use_privsep)
|
2003-08-25 11:08:49 +08:00
|
|
|
fatal("Password expired (unable to change with privsep)");
|
2003-05-10 17:28:02 +08:00
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
|
2003-11-18 09:42:07 +08:00
|
|
|
(const void *)&tty_conv);
|
2003-05-10 17:28:02 +08:00
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
fatal("PAM: failed to set PAM_CONV: %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
debug("PAM: changing password");
|
|
|
|
sshpam_err = pam_chauthtok(sshpam_handle, PAM_CHANGE_EXPIRED_AUTHTOK);
|
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
fatal("PAM: pam_chauthtok(): %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
2000-05-31 09:20:11 +08:00
|
|
|
}
|
|
|
|
|
2004-02-17 20:20:07 +08:00
|
|
|
static int
|
2004-07-01 10:38:14 +08:00
|
|
|
sshpam_store_conv(int n, struct pam_message **msg,
|
2004-02-17 20:20:07 +08:00
|
|
|
struct pam_response **resp, void *data)
|
|
|
|
{
|
|
|
|
struct pam_response *reply;
|
|
|
|
int i;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
debug3("PAM: %s called with %d messages", __func__, n);
|
|
|
|
*resp = NULL;
|
|
|
|
|
|
|
|
if (n <= 0 || n > PAM_MAX_NUM_MSG)
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
|
|
|
|
if ((reply = malloc(n * sizeof(*reply))) == NULL)
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
memset(reply, 0, n * sizeof(*reply));
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
|
|
|
|
case PAM_ERROR_MSG:
|
|
|
|
case PAM_TEXT_INFO:
|
|
|
|
len = strlen(PAM_MSG_MEMBER(msg, i, msg));
|
|
|
|
buffer_append(&loginmsg, PAM_MSG_MEMBER(msg, i, msg), len);
|
|
|
|
buffer_append(&loginmsg, "\n", 1 );
|
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*resp = reply;
|
|
|
|
return (PAM_SUCCESS);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
if (reply[i].resp != NULL)
|
|
|
|
xfree(reply[i].resp);
|
|
|
|
}
|
|
|
|
xfree(reply);
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
}
|
|
|
|
|
2004-06-03 12:53:12 +08:00
|
|
|
static struct pam_conv store_conv = { sshpam_store_conv, NULL };
|
2004-02-17 20:20:07 +08:00
|
|
|
|
2003-11-18 09:42:07 +08:00
|
|
|
void
|
|
|
|
do_pam_session(void)
|
|
|
|
{
|
2004-02-10 10:23:28 +08:00
|
|
|
debug3("PAM: opening session");
|
2003-11-21 20:48:55 +08:00
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
|
2004-02-17 20:20:07 +08:00
|
|
|
(const void *)&store_conv);
|
2003-11-18 09:42:07 +08:00
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
fatal("PAM: failed to set PAM_CONV: %s",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
sshpam_err = pam_open_session(sshpam_handle, 0);
|
2004-09-11 20:17:26 +08:00
|
|
|
if (sshpam_err == PAM_SUCCESS)
|
|
|
|
sshpam_session_open = 1;
|
|
|
|
else {
|
|
|
|
sshpam_session_open = 0;
|
|
|
|
disable_forwarding();
|
|
|
|
error("PAM: pam_open_session(): %s",
|
2003-11-18 09:42:07 +08:00
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
2004-09-11 20:17:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
is_pam_session_open(void)
|
|
|
|
{
|
|
|
|
return sshpam_session_open;
|
2003-11-18 09:42:07 +08:00
|
|
|
}
|
|
|
|
|
2003-11-21 20:48:55 +08:00
|
|
|
/*
|
2003-08-26 09:58:16 +08:00
|
|
|
* Set a PAM environment string. We need to do this so that the session
|
|
|
|
* modules can handle things like Kerberos/GSI credentials that appear
|
|
|
|
* during the ssh authentication process.
|
|
|
|
*/
|
|
|
|
int
|
2003-11-21 20:48:55 +08:00
|
|
|
do_pam_putenv(char *name, char *value)
|
2003-08-26 09:58:16 +08:00
|
|
|
{
|
|
|
|
int ret = 1;
|
2003-11-21 20:56:47 +08:00
|
|
|
#ifdef HAVE_PAM_PUTENV
|
2003-09-17 05:24:25 +08:00
|
|
|
char *compound;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(name) + strlen(value) + 2;
|
|
|
|
compound = xmalloc(len);
|
|
|
|
|
|
|
|
snprintf(compound, len, "%s=%s", name, value);
|
|
|
|
ret = pam_putenv(sshpam_handle, compound);
|
|
|
|
xfree(compound);
|
2003-08-26 09:58:16 +08:00
|
|
|
#endif
|
2003-09-17 05:24:25 +08:00
|
|
|
|
2003-08-26 09:58:16 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2003-11-17 18:41:42 +08:00
|
|
|
char **
|
|
|
|
fetch_pam_child_environment(void)
|
|
|
|
{
|
|
|
|
return sshpam_env;
|
|
|
|
}
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
char **
|
|
|
|
fetch_pam_environment(void)
|
|
|
|
{
|
|
|
|
return (pam_getenvlist(sshpam_handle));
|
|
|
|
}
|
2001-02-07 09:58:33 +08:00
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
void
|
|
|
|
free_pam_environment(char **env)
|
|
|
|
{
|
|
|
|
char **envp;
|
2000-05-31 09:20:11 +08:00
|
|
|
|
2003-05-16 16:21:01 +08:00
|
|
|
if (env == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-05-10 17:28:02 +08:00
|
|
|
for (envp = env; *envp; envp++)
|
|
|
|
xfree(*envp);
|
|
|
|
xfree(env);
|
1999-12-30 12:08:44 +08:00
|
|
|
}
|
|
|
|
|
2004-05-30 18:43:59 +08:00
|
|
|
/*
|
|
|
|
* "Blind" conversation function for password authentication. Assumes that
|
|
|
|
* echo-off prompts are for the password and stores messages for later
|
|
|
|
* display.
|
|
|
|
*/
|
|
|
|
static int
|
2004-07-01 10:38:14 +08:00
|
|
|
sshpam_passwd_conv(int n, struct pam_message **msg,
|
2004-05-30 18:43:59 +08:00
|
|
|
struct pam_response **resp, void *data)
|
|
|
|
{
|
|
|
|
struct pam_response *reply;
|
|
|
|
int i;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
debug3("PAM: %s called with %d messages", __func__, n);
|
|
|
|
|
|
|
|
*resp = NULL;
|
|
|
|
|
|
|
|
if (n <= 0 || n > PAM_MAX_NUM_MSG)
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
|
|
|
|
if ((reply = malloc(n * sizeof(*reply))) == NULL)
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
memset(reply, 0, n * sizeof(*reply));
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
|
|
|
|
case PAM_PROMPT_ECHO_OFF:
|
|
|
|
if (sshpam_password == NULL)
|
|
|
|
goto fail;
|
2004-07-19 07:39:11 +08:00
|
|
|
if ((reply[i].resp = strdup(sshpam_password)) == NULL)
|
|
|
|
goto fail;
|
2004-05-30 18:43:59 +08:00
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
|
|
|
break;
|
|
|
|
case PAM_ERROR_MSG:
|
|
|
|
case PAM_TEXT_INFO:
|
|
|
|
len = strlen(PAM_MSG_MEMBER(msg, i, msg));
|
|
|
|
if (len > 0) {
|
|
|
|
buffer_append(&loginmsg,
|
|
|
|
PAM_MSG_MEMBER(msg, i, msg), len);
|
|
|
|
buffer_append(&loginmsg, "\n", 1);
|
|
|
|
}
|
2004-07-19 07:39:11 +08:00
|
|
|
if ((reply[i].resp = strdup("")) == NULL)
|
|
|
|
goto fail;
|
2004-05-30 18:43:59 +08:00
|
|
|
reply[i].resp_retcode = PAM_SUCCESS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*resp = reply;
|
|
|
|
return (PAM_SUCCESS);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
if (reply[i].resp != NULL)
|
|
|
|
xfree(reply[i].resp);
|
|
|
|
}
|
|
|
|
xfree(reply);
|
|
|
|
return (PAM_CONV_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pam_conv passwd_conv = { sshpam_passwd_conv, NULL };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt password authentication via PAM
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sshpam_auth_passwd(Authctxt *authctxt, const char *password)
|
|
|
|
{
|
|
|
|
int flags = (options.permit_empty_passwd == 0 ?
|
|
|
|
PAM_DISALLOW_NULL_AUTHTOK : 0);
|
2004-05-30 20:04:56 +08:00
|
|
|
static char badpw[] = "\b\n\r\177INCORRECT";
|
2004-05-30 18:43:59 +08:00
|
|
|
|
|
|
|
if (!options.use_pam || sshpam_handle == NULL)
|
|
|
|
fatal("PAM: %s called when PAM disabled or failed to "
|
|
|
|
"initialise.", __func__);
|
|
|
|
|
|
|
|
sshpam_password = password;
|
|
|
|
sshpam_authctxt = authctxt;
|
|
|
|
|
2004-05-30 20:04:56 +08:00
|
|
|
/*
|
|
|
|
* If the user logging in is invalid, or is root but is not permitted
|
|
|
|
* by PermitRootLogin, use an invalid password to prevent leaking
|
|
|
|
* information via timing (eg if the PAM config has a delay on fail).
|
|
|
|
*/
|
|
|
|
if (!authctxt->valid || (authctxt->pw->pw_uid == 0 &&
|
|
|
|
options.permit_root_login != PERMIT_YES))
|
|
|
|
sshpam_password = badpw;
|
|
|
|
|
2004-05-30 18:43:59 +08:00
|
|
|
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
|
|
|
|
(const void *)&passwd_conv);
|
|
|
|
if (sshpam_err != PAM_SUCCESS)
|
|
|
|
fatal("PAM: %s: failed to set PAM_CONV: %s", __func__,
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
|
|
|
|
sshpam_err = pam_authenticate(sshpam_handle, flags);
|
|
|
|
sshpam_password = NULL;
|
|
|
|
if (sshpam_err == PAM_SUCCESS && authctxt->valid) {
|
|
|
|
debug("PAM: password authentication accepted for %.100s",
|
|
|
|
authctxt->user);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
debug("PAM: password authentication failed for %.100s: %s",
|
|
|
|
authctxt->valid ? authctxt->user : "an illegal user",
|
|
|
|
pam_strerror(sshpam_handle, sshpam_err));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
1999-12-30 12:08:44 +08:00
|
|
|
#endif /* USE_PAM */
|