Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2002 Networks Associates Technology, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This software was developed for the FreeBSD Project by ThinkSec AS and |
| 6 | * NAI Labs, the Security Research Division of Network Associates, Inc. |
| 7 | * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the |
| 8 | * DARPA CHATS research program. |
Damien Miller | e69f18c | 2000-06-12 16:38:54 +1000 | [diff] [blame] | 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * 1. Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
Damien Miller | e69f18c | 2000-06-12 16:38:54 +1000 | [diff] [blame] | 18 | * |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | * SUCH DAMAGE. |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 30 | */ |
Damien Miller | 26314f6 | 2004-06-01 11:28:20 +1000 | [diff] [blame] | 31 | /* |
| 32 | * Copyright (c) 2003,2004 Damien Miller <djm@mindrot.org> |
| 33 | * Copyright (c) 2003,2004 Darren Tucker <dtucker@zip.com.au> |
| 34 | * |
| 35 | * Permission to use, copy, modify, and distribute this software for any |
| 36 | * purpose with or without fee is hereby granted, provided that the above |
| 37 | * copyright notice and this permission notice appear in all copies. |
| 38 | * |
| 39 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 40 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 41 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 42 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 43 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 44 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 45 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 46 | */ |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 47 | |
Damien Miller | 25d9342 | 2003-05-18 20:45:47 +1000 | [diff] [blame] | 48 | /* Based on $FreeBSD: src/crypto/openssh/auth2-pam-freebsd.c,v 1.11 2003/03/31 13:48:18 des Exp $ */ |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 49 | #include "includes.h" |
Damien Miller | 6645e7a | 2006-03-15 14:42:54 +1100 | [diff] [blame] | 50 | |
| 51 | #include <sys/types.h> |
| 52 | #include <sys/stat.h> |
| 53 | #include <sys/wait.h> |
| 54 | #include <signal.h> |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 55 | |
| 56 | #ifdef USE_PAM |
Damien Miller | 0f47c53 | 2004-01-02 18:01:30 +1100 | [diff] [blame] | 57 | #if defined(HAVE_SECURITY_PAM_APPL_H) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 58 | #include <security/pam_appl.h> |
Damien Miller | 0f47c53 | 2004-01-02 18:01:30 +1100 | [diff] [blame] | 59 | #elif defined (HAVE_PAM_PAM_APPL_H) |
| 60 | #include <pam/pam_appl.h> |
| 61 | #endif |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 62 | |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 63 | /* OpenGroup RFC86.0 and XSSO specify no "const" on arguments */ |
| 64 | #ifdef PAM_SUN_CODEBASE |
| 65 | # define sshpam_const /* Solaris, HP-UX, AIX */ |
| 66 | #else |
| 67 | # define sshpam_const const /* LinuxPAM, OpenPAM */ |
| 68 | #endif |
| 69 | |
Kevin Steves | e683e76 | 2002-04-04 19:02:28 +0000 | [diff] [blame] | 70 | #include "auth.h" |
Damien Miller | 63dc3e9 | 2001-02-07 12:58:33 +1100 | [diff] [blame] | 71 | #include "auth-pam.h" |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 72 | #include "buffer.h" |
| 73 | #include "bufaux.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 74 | #include "canohost.h" |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 75 | #include "log.h" |
| 76 | #include "monitor_wrap.h" |
| 77 | #include "msg.h" |
| 78 | #include "packet.h" |
Darren Tucker | b6db172 | 2004-05-13 17:29:35 +1000 | [diff] [blame] | 79 | #include "misc.h" |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 80 | #include "servconf.h" |
| 81 | #include "ssh2.h" |
| 82 | #include "xmalloc.h" |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 83 | #include "auth-options.h" |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 84 | |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 85 | extern ServerOptions options; |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 86 | extern Buffer loginmsg; |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 87 | extern int compat20; |
Darren Tucker | 2a9bf4b | 2004-04-18 11:00:26 +1000 | [diff] [blame] | 88 | extern u_int utmp_len; |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 89 | |
Darren Tucker | 328118a | 2005-05-25 16:18:09 +1000 | [diff] [blame] | 90 | /* so we don't silently change behaviour */ |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 91 | #ifdef USE_POSIX_THREADS |
Darren Tucker | 328118a | 2005-05-25 16:18:09 +1000 | [diff] [blame] | 92 | # error "USE_POSIX_THREADS replaced by UNSUPPORTED_POSIX_THREADS_HACK" |
| 93 | #endif |
| 94 | |
| 95 | /* |
| 96 | * Formerly known as USE_POSIX_THREADS, using this is completely unsupported |
| 97 | * and generally a bad idea. Use at own risk and do not expect support if |
| 98 | * this breaks. |
| 99 | */ |
| 100 | #ifdef UNSUPPORTED_POSIX_THREADS_HACK |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 101 | #include <pthread.h> |
| 102 | /* |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 103 | * Avoid namespace clash when *not* using pthreads for systems *with* |
| 104 | * pthreads, which unconditionally define pthread_t via sys/types.h |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 105 | * (e.g. Linux) |
| 106 | */ |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 107 | typedef pthread_t sp_pthread_t; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 108 | #else |
Darren Tucker | 1b27c8f | 2004-01-13 22:35:58 +1100 | [diff] [blame] | 109 | typedef pid_t sp_pthread_t; |
| 110 | #endif |
| 111 | |
| 112 | struct pam_ctxt { |
| 113 | sp_pthread_t pam_thread; |
| 114 | int pam_psock; |
| 115 | int pam_csock; |
| 116 | int pam_done; |
| 117 | }; |
| 118 | |
| 119 | static void sshpam_free_ctx(void *); |
| 120 | static struct pam_ctxt *cleanup_ctxt; |
| 121 | |
Darren Tucker | 328118a | 2005-05-25 16:18:09 +1000 | [diff] [blame] | 122 | #ifndef UNSUPPORTED_POSIX_THREADS_HACK |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 123 | /* |
| 124 | * Simulate threads with processes. |
| 125 | */ |
Kevin Steves | 63007d4 | 2002-07-21 17:57:01 +0000 | [diff] [blame] | 126 | |
Darren Tucker | 749bc95 | 2004-01-14 22:14:04 +1100 | [diff] [blame] | 127 | static int sshpam_thread_status = -1; |
| 128 | static mysig_t sshpam_oldsig; |
| 129 | |
Damien Miller | 94cf4c8 | 2005-07-17 17:04:47 +1000 | [diff] [blame] | 130 | static void |
Darren Tucker | 749bc95 | 2004-01-14 22:14:04 +1100 | [diff] [blame] | 131 | sshpam_sigchld_handler(int sig) |
| 132 | { |
Darren Tucker | b53355e | 2004-05-24 11:55:36 +1000 | [diff] [blame] | 133 | signal(SIGCHLD, SIG_DFL); |
Darren Tucker | 7ae0962 | 2004-01-14 23:07:56 +1100 | [diff] [blame] | 134 | if (cleanup_ctxt == NULL) |
| 135 | return; /* handler called after PAM cleanup, shouldn't happen */ |
Darren Tucker | b53355e | 2004-05-24 11:55:36 +1000 | [diff] [blame] | 136 | if (waitpid(cleanup_ctxt->pam_thread, &sshpam_thread_status, WNOHANG) |
Damien Miller | 37294fb | 2005-07-17 17:18:49 +1000 | [diff] [blame] | 137 | <= 0) { |
Darren Tucker | b53355e | 2004-05-24 11:55:36 +1000 | [diff] [blame] | 138 | /* PAM thread has not exitted, privsep slave must have */ |
| 139 | kill(cleanup_ctxt->pam_thread, SIGTERM); |
| 140 | if (waitpid(cleanup_ctxt->pam_thread, &sshpam_thread_status, 0) |
Darren Tucker | 5d423f4 | 2004-07-11 16:54:08 +1000 | [diff] [blame] | 141 | <= 0) |
Darren Tucker | b53355e | 2004-05-24 11:55:36 +1000 | [diff] [blame] | 142 | return; /* could not wait */ |
| 143 | } |
Darren Tucker | 749bc95 | 2004-01-14 22:14:04 +1100 | [diff] [blame] | 144 | if (WIFSIGNALED(sshpam_thread_status) && |
| 145 | WTERMSIG(sshpam_thread_status) == SIGTERM) |
| 146 | return; /* terminated by pthread_cancel */ |
| 147 | if (!WIFEXITED(sshpam_thread_status)) |
| 148 | fatal("PAM: authentication thread exited unexpectedly"); |
| 149 | if (WEXITSTATUS(sshpam_thread_status) != 0) |
| 150 | fatal("PAM: authentication thread exited uncleanly"); |
| 151 | } |
| 152 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 153 | static void |
| 154 | pthread_exit(void *value __unused) |
| 155 | { |
| 156 | _exit(0); |
| 157 | } |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 158 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 159 | static int |
| 160 | pthread_create(sp_pthread_t *thread, const void *attr __unused, |
| 161 | void *(*thread_start)(void *), void *arg) |
| 162 | { |
| 163 | pid_t pid; |
Darren Tucker | 4f1adad | 2005-07-16 11:33:06 +1000 | [diff] [blame] | 164 | struct pam_ctxt *ctx = arg; |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 165 | |
Darren Tucker | b9b6021 | 2004-03-04 20:03:54 +1100 | [diff] [blame] | 166 | sshpam_thread_status = -1; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 167 | switch ((pid = fork())) { |
| 168 | case -1: |
| 169 | error("fork(): %s", strerror(errno)); |
| 170 | return (-1); |
| 171 | case 0: |
Darren Tucker | 4f1adad | 2005-07-16 11:33:06 +1000 | [diff] [blame] | 172 | close(ctx->pam_psock); |
| 173 | ctx->pam_psock = -1; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 174 | thread_start(arg); |
| 175 | _exit(1); |
| 176 | default: |
| 177 | *thread = pid; |
Darren Tucker | 4f1adad | 2005-07-16 11:33:06 +1000 | [diff] [blame] | 178 | close(ctx->pam_csock); |
| 179 | ctx->pam_csock = -1; |
Darren Tucker | 749bc95 | 2004-01-14 22:14:04 +1100 | [diff] [blame] | 180 | sshpam_oldsig = signal(SIGCHLD, sshpam_sigchld_handler); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 181 | return (0); |
| 182 | } |
| 183 | } |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 184 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 185 | static int |
| 186 | pthread_cancel(sp_pthread_t thread) |
| 187 | { |
Darren Tucker | 7ae0962 | 2004-01-14 23:07:56 +1100 | [diff] [blame] | 188 | signal(SIGCHLD, sshpam_oldsig); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 189 | return (kill(thread, SIGTERM)); |
| 190 | } |
| 191 | |
| 192 | static int |
| 193 | pthread_join(sp_pthread_t thread, void **value __unused) |
| 194 | { |
| 195 | int status; |
| 196 | |
Darren Tucker | 749bc95 | 2004-01-14 22:14:04 +1100 | [diff] [blame] | 197 | if (sshpam_thread_status != -1) |
| 198 | return (sshpam_thread_status); |
| 199 | signal(SIGCHLD, sshpam_oldsig); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 200 | waitpid(thread, &status, 0); |
| 201 | return (status); |
| 202 | } |
| 203 | #endif |
| 204 | |
| 205 | |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 206 | static pam_handle_t *sshpam_handle = NULL; |
| 207 | static int sshpam_err = 0; |
| 208 | static int sshpam_authenticated = 0; |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 209 | static int sshpam_session_open = 0; |
| 210 | static int sshpam_cred_established = 0; |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 211 | static int sshpam_account_status = -1; |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 212 | static char **sshpam_env = NULL; |
Darren Tucker | 17addf0 | 2004-03-30 20:57:57 +1000 | [diff] [blame] | 213 | static Authctxt *sshpam_authctxt = NULL; |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 214 | static const char *sshpam_password = NULL; |
Darren Tucker | 36a3d60 | 2005-01-20 12:43:38 +1100 | [diff] [blame] | 215 | static char badpw[] = "\b\n\r\177INCORRECT"; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 216 | |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 217 | /* Some PAM implementations don't implement this */ |
| 218 | #ifndef HAVE_PAM_GETENVLIST |
| 219 | static char ** |
| 220 | pam_getenvlist(pam_handle_t *pamh) |
| 221 | { |
| 222 | /* |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 223 | * XXX - If necessary, we can still support envrionment passing |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 224 | * for platforms without pam_getenvlist by searching for known |
| 225 | * env vars (e.g. KRB5CCNAME) from the PAM environment. |
| 226 | */ |
| 227 | return NULL; |
| 228 | } |
| 229 | #endif |
| 230 | |
Darren Tucker | 21dd089 | 2004-08-16 23:12:05 +1000 | [diff] [blame] | 231 | /* |
| 232 | * Some platforms, notably Solaris, do not enforce password complexity |
| 233 | * rules during pam_chauthtok() if the real uid of the calling process |
| 234 | * is 0, on the assumption that it's being called by "passwd" run by root. |
| 235 | * This wraps pam_chauthtok and sets/restore the real uid so PAM will do |
| 236 | * the right thing. |
| 237 | */ |
| 238 | #ifdef SSHPAM_CHAUTHTOK_NEEDS_RUID |
| 239 | static int |
| 240 | sshpam_chauthtok_ruid(pam_handle_t *pamh, int flags) |
| 241 | { |
| 242 | int result; |
| 243 | |
| 244 | if (sshpam_authctxt == NULL) |
| 245 | fatal("PAM: sshpam_authctxt not initialized"); |
| 246 | if (setreuid(sshpam_authctxt->pw->pw_uid, -1) == -1) |
| 247 | fatal("%s: setreuid failed: %s", __func__, strerror(errno)); |
| 248 | result = pam_chauthtok(pamh, flags); |
| 249 | if (setreuid(0, -1) == -1) |
| 250 | fatal("%s: setreuid failed: %s", __func__, strerror(errno)); |
| 251 | return result; |
| 252 | } |
| 253 | # define pam_chauthtok(a,b) (sshpam_chauthtok_ruid((a), (b))) |
| 254 | #endif |
| 255 | |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 256 | void |
Darren Tucker | 17db1c4 | 2004-06-19 12:54:38 +1000 | [diff] [blame] | 257 | sshpam_password_change_required(int reqd) |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 258 | { |
Darren Tucker | a8df924 | 2004-01-15 00:15:07 +1100 | [diff] [blame] | 259 | debug3("%s %d", __func__, reqd); |
Darren Tucker | 17addf0 | 2004-03-30 20:57:57 +1000 | [diff] [blame] | 260 | if (sshpam_authctxt == NULL) |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 261 | fatal("%s: PAM authctxt not initialized", __func__); |
Darren Tucker | 17addf0 | 2004-03-30 20:57:57 +1000 | [diff] [blame] | 262 | sshpam_authctxt->force_pwchange = reqd; |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 263 | if (reqd) { |
| 264 | no_port_forwarding_flag |= 2; |
| 265 | no_agent_forwarding_flag |= 2; |
| 266 | no_x11_forwarding_flag |= 2; |
| 267 | } else { |
| 268 | no_port_forwarding_flag &= ~2; |
| 269 | no_agent_forwarding_flag &= ~2; |
| 270 | no_x11_forwarding_flag &= ~2; |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 271 | } |
| 272 | } |
Darren Tucker | 1921ed9 | 2004-02-10 13:23:28 +1100 | [diff] [blame] | 273 | |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 274 | /* Import regular and PAM environment from subprocess */ |
| 275 | static void |
| 276 | import_environments(Buffer *b) |
| 277 | { |
| 278 | char *env; |
| 279 | u_int i, num_env; |
| 280 | int err; |
| 281 | |
Darren Tucker | a8df924 | 2004-01-15 00:15:07 +1100 | [diff] [blame] | 282 | debug3("PAM: %s entering", __func__); |
| 283 | |
Darren Tucker | 328118a | 2005-05-25 16:18:09 +1000 | [diff] [blame] | 284 | #ifndef UNSUPPORTED_POSIX_THREADS_HACK |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 285 | /* Import variables set by do_pam_account */ |
| 286 | sshpam_account_status = buffer_get_int(b); |
Darren Tucker | 17db1c4 | 2004-06-19 12:54:38 +1000 | [diff] [blame] | 287 | sshpam_password_change_required(buffer_get_int(b)); |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 288 | |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 289 | /* Import environment from subprocess */ |
| 290 | num_env = buffer_get_int(b); |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 291 | if (num_env > 1024) |
| 292 | fatal("%s: received %u environment variables, expected <= 1024", |
| 293 | __func__, num_env); |
| 294 | sshpam_env = xcalloc(num_env + 1, sizeof(*sshpam_env)); |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 295 | debug3("PAM: num env strings %d", num_env); |
| 296 | for(i = 0; i < num_env; i++) |
| 297 | sshpam_env[i] = buffer_get_string(b, NULL); |
| 298 | |
| 299 | sshpam_env[num_env] = NULL; |
| 300 | |
| 301 | /* Import PAM environment from subprocess */ |
| 302 | num_env = buffer_get_int(b); |
| 303 | debug("PAM: num PAM env strings %d", num_env); |
| 304 | for(i = 0; i < num_env; i++) { |
| 305 | env = buffer_get_string(b, NULL); |
| 306 | |
Darren Tucker | 8a1624c | 2003-11-18 12:45:35 +1100 | [diff] [blame] | 307 | #ifdef HAVE_PAM_PUTENV |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 308 | /* Errors are not fatal here */ |
| 309 | if ((err = pam_putenv(sshpam_handle, env)) != PAM_SUCCESS) { |
| 310 | error("PAM: pam_putenv: %s", |
| 311 | pam_strerror(sshpam_handle, sshpam_err)); |
| 312 | } |
Darren Tucker | 8a1624c | 2003-11-18 12:45:35 +1100 | [diff] [blame] | 313 | #endif |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 314 | } |
Darren Tucker | 4b385d4 | 2004-03-04 19:54:10 +1100 | [diff] [blame] | 315 | #endif |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 316 | } |
| 317 | |
Damien Miller | 9d5705a | 2000-09-16 16:09:27 +1100 | [diff] [blame] | 318 | /* |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 319 | * Conversation function for authentication thread. |
Damien Miller | 9d5705a | 2000-09-16 16:09:27 +1100 | [diff] [blame] | 320 | */ |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 321 | static int |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 322 | sshpam_thread_conv(int n, sshpam_const struct pam_message **msg, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 323 | struct pam_response **resp, void *data) |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 324 | { |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 325 | Buffer buffer; |
| 326 | struct pam_ctxt *ctxt; |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 327 | struct pam_response *reply; |
Kevin Steves | 38b050a | 2002-07-23 00:44:07 +0000 | [diff] [blame] | 328 | int i; |
| 329 | |
Darren Tucker | ba53b83 | 2004-02-17 20:46:59 +1100 | [diff] [blame] | 330 | debug3("PAM: %s entering, %d messages", __func__, n); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 331 | *resp = NULL; |
| 332 | |
Darren Tucker | 59e0602 | 2004-06-30 20:34:31 +1000 | [diff] [blame] | 333 | if (data == NULL) { |
| 334 | error("PAM: conversation function passed a null context"); |
| 335 | return (PAM_CONV_ERR); |
| 336 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 337 | ctxt = data; |
| 338 | if (n <= 0 || n > PAM_MAX_NUM_MSG) |
| 339 | return (PAM_CONV_ERR); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 340 | |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 341 | if ((reply = calloc(n, sizeof(*reply))) == NULL) |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 342 | return (PAM_CONV_ERR); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 343 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 344 | buffer_init(&buffer); |
| 345 | for (i = 0; i < n; ++i) { |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 346 | switch (PAM_MSG_MEMBER(msg, i, msg_style)) { |
| 347 | case PAM_PROMPT_ECHO_OFF: |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 348 | buffer_put_cstring(&buffer, |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 349 | PAM_MSG_MEMBER(msg, i, msg)); |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 350 | if (ssh_msg_send(ctxt->pam_csock, |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 351 | PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1) |
| 352 | goto fail; |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 353 | if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1) |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 354 | goto fail; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 355 | if (buffer_get_char(&buffer) != PAM_AUTHTOK) |
| 356 | goto fail; |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 357 | reply[i].resp = buffer_get_string(&buffer, NULL); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 358 | break; |
| 359 | case PAM_PROMPT_ECHO_ON: |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 360 | buffer_put_cstring(&buffer, |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 361 | PAM_MSG_MEMBER(msg, i, msg)); |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 362 | if (ssh_msg_send(ctxt->pam_csock, |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 363 | PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1) |
| 364 | goto fail; |
| 365 | if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1) |
| 366 | goto fail; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 367 | if (buffer_get_char(&buffer) != PAM_AUTHTOK) |
| 368 | goto fail; |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 369 | reply[i].resp = buffer_get_string(&buffer, NULL); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 370 | break; |
| 371 | case PAM_ERROR_MSG: |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 372 | buffer_put_cstring(&buffer, |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 373 | PAM_MSG_MEMBER(msg, i, msg)); |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 374 | if (ssh_msg_send(ctxt->pam_csock, |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 375 | PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1) |
| 376 | goto fail; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 377 | break; |
| 378 | case PAM_TEXT_INFO: |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 379 | buffer_put_cstring(&buffer, |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 380 | PAM_MSG_MEMBER(msg, i, msg)); |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 381 | if (ssh_msg_send(ctxt->pam_csock, |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 382 | PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1) |
| 383 | goto fail; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 384 | break; |
| 385 | default: |
| 386 | goto fail; |
| 387 | } |
| 388 | buffer_clear(&buffer); |
Kevin Steves | 38b050a | 2002-07-23 00:44:07 +0000 | [diff] [blame] | 389 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 390 | buffer_free(&buffer); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 391 | *resp = reply; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 392 | return (PAM_SUCCESS); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 393 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 394 | fail: |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 395 | for(i = 0; i < n; i++) { |
| 396 | if (reply[i].resp != NULL) |
| 397 | xfree(reply[i].resp); |
| 398 | } |
| 399 | xfree(reply); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 400 | buffer_free(&buffer); |
| 401 | return (PAM_CONV_ERR); |
Kevin Steves | 38b050a | 2002-07-23 00:44:07 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 404 | /* |
| 405 | * Authentication thread. |
| 406 | */ |
| 407 | static void * |
| 408 | sshpam_thread(void *ctxtp) |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 409 | { |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 410 | struct pam_ctxt *ctxt = ctxtp; |
| 411 | Buffer buffer; |
Damien Miller | f4b6f10 | 2003-09-02 23:12:06 +1000 | [diff] [blame] | 412 | struct pam_conv sshpam_conv; |
Darren Tucker | 1f7e408 | 2004-07-01 14:00:14 +1000 | [diff] [blame] | 413 | int flags = (options.permit_empty_passwd == 0 ? |
| 414 | PAM_DISALLOW_NULL_AUTHTOK : 0); |
Darren Tucker | 328118a | 2005-05-25 16:18:09 +1000 | [diff] [blame] | 415 | #ifndef UNSUPPORTED_POSIX_THREADS_HACK |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 416 | extern char **environ; |
| 417 | char **env_from_pam; |
| 418 | u_int i; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 419 | const char *pam_user; |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 420 | const char **ptr_pam_user = &pam_user; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 421 | |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 422 | pam_get_item(sshpam_handle, PAM_USER, |
| 423 | (sshpam_const void **)ptr_pam_user); |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 424 | environ[0] = NULL; |
Damien Miller | 2d2ed3d | 2004-07-21 20:54:47 +1000 | [diff] [blame] | 425 | |
| 426 | if (sshpam_authctxt != NULL) { |
| 427 | setproctitle("%s [pam]", |
| 428 | sshpam_authctxt->valid ? pam_user : "unknown"); |
| 429 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 430 | #endif |
| 431 | |
Damien Miller | f4b6f10 | 2003-09-02 23:12:06 +1000 | [diff] [blame] | 432 | sshpam_conv.conv = sshpam_thread_conv; |
| 433 | sshpam_conv.appdata_ptr = ctxt; |
| 434 | |
Darren Tucker | 17addf0 | 2004-03-30 20:57:57 +1000 | [diff] [blame] | 435 | if (sshpam_authctxt == NULL) |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 436 | fatal("%s: PAM authctxt not initialized", __func__); |
| 437 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 438 | buffer_init(&buffer); |
| 439 | sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, |
| 440 | (const void *)&sshpam_conv); |
| 441 | if (sshpam_err != PAM_SUCCESS) |
| 442 | goto auth_fail; |
Darren Tucker | 1f7e408 | 2004-07-01 14:00:14 +1000 | [diff] [blame] | 443 | sshpam_err = pam_authenticate(sshpam_handle, flags); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 444 | if (sshpam_err != PAM_SUCCESS) |
| 445 | goto auth_fail; |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 446 | |
Darren Tucker | c376c86 | 2003-12-18 16:08:59 +1100 | [diff] [blame] | 447 | if (compat20) { |
Darren Tucker | 2c77b7f | 2006-05-15 17:22:33 +1000 | [diff] [blame] | 448 | if (!do_pam_account()) { |
| 449 | sshpam_err = PAM_ACCT_EXPIRED; |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 450 | goto auth_fail; |
Darren Tucker | 2c77b7f | 2006-05-15 17:22:33 +1000 | [diff] [blame] | 451 | } |
Darren Tucker | 17addf0 | 2004-03-30 20:57:57 +1000 | [diff] [blame] | 452 | if (sshpam_authctxt->force_pwchange) { |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 453 | sshpam_err = pam_chauthtok(sshpam_handle, |
| 454 | PAM_CHANGE_EXPIRED_AUTHTOK); |
| 455 | if (sshpam_err != PAM_SUCCESS) |
| 456 | goto auth_fail; |
Darren Tucker | 17db1c4 | 2004-06-19 12:54:38 +1000 | [diff] [blame] | 457 | sshpam_password_change_required(0); |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 458 | } |
Darren Tucker | c376c86 | 2003-12-18 16:08:59 +1100 | [diff] [blame] | 459 | } |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 460 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 461 | buffer_put_cstring(&buffer, "OK"); |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 462 | |
Darren Tucker | 328118a | 2005-05-25 16:18:09 +1000 | [diff] [blame] | 463 | #ifndef UNSUPPORTED_POSIX_THREADS_HACK |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 464 | /* Export variables set by do_pam_account */ |
| 465 | buffer_put_int(&buffer, sshpam_account_status); |
Darren Tucker | 17addf0 | 2004-03-30 20:57:57 +1000 | [diff] [blame] | 466 | buffer_put_int(&buffer, sshpam_authctxt->force_pwchange); |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 467 | |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 468 | /* Export any environment strings set in child */ |
| 469 | for(i = 0; environ[i] != NULL; i++) |
| 470 | ; /* Count */ |
| 471 | buffer_put_int(&buffer, i); |
| 472 | for(i = 0; environ[i] != NULL; i++) |
| 473 | buffer_put_cstring(&buffer, environ[i]); |
| 474 | |
| 475 | /* Export any environment strings set by PAM in child */ |
| 476 | env_from_pam = pam_getenvlist(sshpam_handle); |
| 477 | for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++) |
| 478 | ; /* Count */ |
| 479 | buffer_put_int(&buffer, i); |
| 480 | for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++) |
| 481 | buffer_put_cstring(&buffer, env_from_pam[i]); |
Darren Tucker | 328118a | 2005-05-25 16:18:09 +1000 | [diff] [blame] | 482 | #endif /* UNSUPPORTED_POSIX_THREADS_HACK */ |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 483 | |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 484 | /* XXX - can't do much about an error here */ |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 485 | ssh_msg_send(ctxt->pam_csock, sshpam_err, &buffer); |
| 486 | buffer_free(&buffer); |
| 487 | pthread_exit(NULL); |
| 488 | |
| 489 | auth_fail: |
| 490 | buffer_put_cstring(&buffer, |
| 491 | pam_strerror(sshpam_handle, sshpam_err)); |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 492 | /* XXX - can't do much about an error here */ |
Darren Tucker | 2c77b7f | 2006-05-15 17:22:33 +1000 | [diff] [blame] | 493 | if (sshpam_err == PAM_ACCT_EXPIRED) |
| 494 | ssh_msg_send(ctxt->pam_csock, PAM_ACCT_EXPIRED, &buffer); |
| 495 | else |
| 496 | ssh_msg_send(ctxt->pam_csock, PAM_AUTH_ERR, &buffer); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 497 | buffer_free(&buffer); |
| 498 | pthread_exit(NULL); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 499 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 500 | return (NULL); /* Avoid warning for non-pthread case */ |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 501 | } |
| 502 | |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 503 | void |
| 504 | sshpam_thread_cleanup(void) |
Damien Miller | 2f6a0ad | 2000-05-31 11:20:11 +1000 | [diff] [blame] | 505 | { |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 506 | struct pam_ctxt *ctxt = cleanup_ctxt; |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 507 | |
Darren Tucker | a8df924 | 2004-01-15 00:15:07 +1100 | [diff] [blame] | 508 | debug3("PAM: %s entering", __func__); |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 509 | if (ctxt != NULL && ctxt->pam_thread != 0) { |
| 510 | pthread_cancel(ctxt->pam_thread); |
| 511 | pthread_join(ctxt->pam_thread, NULL); |
| 512 | close(ctxt->pam_psock); |
| 513 | close(ctxt->pam_csock); |
| 514 | memset(ctxt, 0, sizeof(*ctxt)); |
| 515 | cleanup_ctxt = NULL; |
| 516 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 517 | } |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 518 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 519 | static int |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 520 | sshpam_null_conv(int n, sshpam_const struct pam_message **msg, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 521 | struct pam_response **resp, void *data) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 522 | { |
Darren Tucker | ba53b83 | 2004-02-17 20:46:59 +1100 | [diff] [blame] | 523 | debug3("PAM: %s entering, %d messages", __func__, n); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 524 | return (PAM_CONV_ERR); |
| 525 | } |
Damien Miller | 63dc3e9 | 2001-02-07 12:58:33 +1100 | [diff] [blame] | 526 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 527 | static struct pam_conv null_conv = { sshpam_null_conv, NULL }; |
| 528 | |
Darren Tucker | 0a7e3c6 | 2004-09-11 22:28:01 +1000 | [diff] [blame] | 529 | static int |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 530 | sshpam_store_conv(int n, sshpam_const struct pam_message **msg, |
Darren Tucker | 0a7e3c6 | 2004-09-11 22:28:01 +1000 | [diff] [blame] | 531 | struct pam_response **resp, void *data) |
| 532 | { |
| 533 | struct pam_response *reply; |
| 534 | int i; |
| 535 | size_t len; |
| 536 | |
| 537 | debug3("PAM: %s called with %d messages", __func__, n); |
| 538 | *resp = NULL; |
| 539 | |
| 540 | if (n <= 0 || n > PAM_MAX_NUM_MSG) |
| 541 | return (PAM_CONV_ERR); |
| 542 | |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 543 | if ((reply = calloc(n, sizeof(*reply))) == NULL) |
Darren Tucker | 0a7e3c6 | 2004-09-11 22:28:01 +1000 | [diff] [blame] | 544 | return (PAM_CONV_ERR); |
Darren Tucker | 0a7e3c6 | 2004-09-11 22:28:01 +1000 | [diff] [blame] | 545 | |
| 546 | for (i = 0; i < n; ++i) { |
| 547 | switch (PAM_MSG_MEMBER(msg, i, msg_style)) { |
| 548 | case PAM_ERROR_MSG: |
| 549 | case PAM_TEXT_INFO: |
| 550 | len = strlen(PAM_MSG_MEMBER(msg, i, msg)); |
| 551 | buffer_append(&loginmsg, PAM_MSG_MEMBER(msg, i, msg), len); |
| 552 | buffer_append(&loginmsg, "\n", 1 ); |
| 553 | reply[i].resp_retcode = PAM_SUCCESS; |
| 554 | break; |
| 555 | default: |
| 556 | goto fail; |
| 557 | } |
| 558 | } |
| 559 | *resp = reply; |
| 560 | return (PAM_SUCCESS); |
| 561 | |
| 562 | fail: |
| 563 | for(i = 0; i < n; i++) { |
| 564 | if (reply[i].resp != NULL) |
| 565 | xfree(reply[i].resp); |
| 566 | } |
| 567 | xfree(reply); |
| 568 | return (PAM_CONV_ERR); |
| 569 | } |
| 570 | |
| 571 | static struct pam_conv store_conv = { sshpam_store_conv, NULL }; |
| 572 | |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 573 | void |
| 574 | sshpam_cleanup(void) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 575 | { |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 576 | debug("PAM: cleanup"); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 577 | if (sshpam_handle == NULL) |
| 578 | return; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 579 | pam_set_item(sshpam_handle, PAM_CONV, (const void *)&null_conv); |
| 580 | if (sshpam_cred_established) { |
| 581 | pam_setcred(sshpam_handle, PAM_DELETE_CRED); |
| 582 | sshpam_cred_established = 0; |
| 583 | } |
| 584 | if (sshpam_session_open) { |
| 585 | pam_close_session(sshpam_handle, PAM_SILENT); |
| 586 | sshpam_session_open = 0; |
| 587 | } |
Darren Tucker | 1921ed9 | 2004-02-10 13:23:28 +1100 | [diff] [blame] | 588 | sshpam_authenticated = 0; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 589 | pam_end(sshpam_handle, sshpam_err); |
| 590 | sshpam_handle = NULL; |
| 591 | } |
| 592 | |
| 593 | static int |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 594 | sshpam_init(Authctxt *authctxt) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 595 | { |
Darren Tucker | 455813b | 2003-09-13 22:12:11 +1000 | [diff] [blame] | 596 | extern char *__progname; |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 597 | const char *pam_rhost, *pam_user, *user = authctxt->user; |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 598 | const char **ptr_pam_user = &pam_user; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 599 | |
| 600 | if (sshpam_handle != NULL) { |
| 601 | /* We already have a PAM context; check if the user matches */ |
| 602 | sshpam_err = pam_get_item(sshpam_handle, |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 603 | PAM_USER, (sshpam_const void **)ptr_pam_user); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 604 | if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0) |
| 605 | return (0); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 606 | pam_end(sshpam_handle, sshpam_err); |
| 607 | sshpam_handle = NULL; |
| 608 | } |
| 609 | debug("PAM: initializing for \"%s\"", user); |
Darren Tucker | c58c2ee | 2003-09-13 22:02:05 +1000 | [diff] [blame] | 610 | sshpam_err = |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 611 | pam_start(SSHD_PAM_SERVICE, user, &store_conv, &sshpam_handle); |
Darren Tucker | 17addf0 | 2004-03-30 20:57:57 +1000 | [diff] [blame] | 612 | sshpam_authctxt = authctxt; |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 613 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 614 | if (sshpam_err != PAM_SUCCESS) { |
| 615 | pam_end(sshpam_handle, sshpam_err); |
| 616 | sshpam_handle = NULL; |
| 617 | return (-1); |
| 618 | } |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 619 | pam_rhost = get_remote_name_or_ip(utmp_len, options.use_dns); |
Damien Miller | 4633720 | 2003-06-02 11:04:39 +1000 | [diff] [blame] | 620 | debug("PAM: setting PAM_RHOST to \"%s\"", pam_rhost); |
Damien Miller | 25d9342 | 2003-05-18 20:45:47 +1000 | [diff] [blame] | 621 | sshpam_err = pam_set_item(sshpam_handle, PAM_RHOST, pam_rhost); |
| 622 | if (sshpam_err != PAM_SUCCESS) { |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 623 | pam_end(sshpam_handle, sshpam_err); |
Damien Miller | 25d9342 | 2003-05-18 20:45:47 +1000 | [diff] [blame] | 624 | sshpam_handle = NULL; |
| 625 | return (-1); |
| 626 | } |
| 627 | #ifdef PAM_TTY_KLUDGE |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 628 | /* |
| 629 | * Some silly PAM modules (e.g. pam_time) require a TTY to operate. |
| 630 | * sshd doesn't set the tty until too late in the auth process and |
Damien Miller | 25d9342 | 2003-05-18 20:45:47 +1000 | [diff] [blame] | 631 | * may not even set one (for tty-less connections) |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 632 | */ |
Damien Miller | 25d9342 | 2003-05-18 20:45:47 +1000 | [diff] [blame] | 633 | debug("PAM: setting PAM_TTY to \"ssh\""); |
| 634 | sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, "ssh"); |
| 635 | if (sshpam_err != PAM_SUCCESS) { |
| 636 | pam_end(sshpam_handle, sshpam_err); |
| 637 | sshpam_handle = NULL; |
| 638 | return (-1); |
| 639 | } |
| 640 | #endif |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 641 | return (0); |
| 642 | } |
| 643 | |
| 644 | static void * |
| 645 | sshpam_init_ctx(Authctxt *authctxt) |
| 646 | { |
| 647 | struct pam_ctxt *ctxt; |
| 648 | int socks[2]; |
| 649 | |
Darren Tucker | a8df924 | 2004-01-15 00:15:07 +1100 | [diff] [blame] | 650 | debug3("PAM: %s entering", __func__); |
Darren Tucker | 2c77b7f | 2006-05-15 17:22:33 +1000 | [diff] [blame] | 651 | /* |
| 652 | * Refuse to start if we don't have PAM enabled or do_pam_account |
| 653 | * has previously failed. |
| 654 | */ |
| 655 | if (!options.use_pam || sshpam_account_status == 0) |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 656 | return NULL; |
| 657 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 658 | /* Initialize PAM */ |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 659 | if (sshpam_init(authctxt) == -1) { |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 660 | error("PAM: initialization failed"); |
| 661 | return (NULL); |
| 662 | } |
| 663 | |
| 664 | ctxt = xmalloc(sizeof *ctxt); |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 665 | memset(ctxt, 0, sizeof(*ctxt)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 666 | |
| 667 | /* Start the authentication thread */ |
| 668 | if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, socks) == -1) { |
| 669 | error("PAM: failed create sockets: %s", strerror(errno)); |
| 670 | xfree(ctxt); |
| 671 | return (NULL); |
| 672 | } |
| 673 | ctxt->pam_psock = socks[0]; |
| 674 | ctxt->pam_csock = socks[1]; |
| 675 | if (pthread_create(&ctxt->pam_thread, NULL, sshpam_thread, ctxt) == -1) { |
| 676 | error("PAM: failed to start authentication thread: %s", |
| 677 | strerror(errno)); |
| 678 | close(socks[0]); |
| 679 | close(socks[1]); |
| 680 | xfree(ctxt); |
| 681 | return (NULL); |
| 682 | } |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 683 | cleanup_ctxt = ctxt; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 684 | return (ctxt); |
| 685 | } |
| 686 | |
| 687 | static int |
| 688 | sshpam_query(void *ctx, char **name, char **info, |
| 689 | u_int *num, char ***prompts, u_int **echo_on) |
| 690 | { |
| 691 | Buffer buffer; |
| 692 | struct pam_ctxt *ctxt = ctx; |
| 693 | size_t plen; |
| 694 | u_char type; |
| 695 | char *msg; |
Damien Miller | daffc6a | 2004-10-16 18:52:44 +1000 | [diff] [blame] | 696 | size_t len, mlen; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 697 | |
Darren Tucker | a8df924 | 2004-01-15 00:15:07 +1100 | [diff] [blame] | 698 | debug3("PAM: %s entering", __func__); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 699 | buffer_init(&buffer); |
| 700 | *name = xstrdup(""); |
| 701 | *info = xstrdup(""); |
| 702 | *prompts = xmalloc(sizeof(char *)); |
| 703 | **prompts = NULL; |
| 704 | plen = 0; |
| 705 | *echo_on = xmalloc(sizeof(u_int)); |
| 706 | while (ssh_msg_recv(ctxt->pam_psock, &buffer) == 0) { |
| 707 | type = buffer_get_char(&buffer); |
| 708 | msg = buffer_get_string(&buffer, NULL); |
Damien Miller | daffc6a | 2004-10-16 18:52:44 +1000 | [diff] [blame] | 709 | mlen = strlen(msg); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 710 | switch (type) { |
| 711 | case PAM_PROMPT_ECHO_ON: |
| 712 | case PAM_PROMPT_ECHO_OFF: |
| 713 | *num = 1; |
Damien Miller | daffc6a | 2004-10-16 18:52:44 +1000 | [diff] [blame] | 714 | len = plen + mlen + 1; |
Damien Miller | 3681209 | 2006-03-26 14:22:47 +1100 | [diff] [blame] | 715 | **prompts = xrealloc(**prompts, 1, len); |
Damien Miller | daffc6a | 2004-10-16 18:52:44 +1000 | [diff] [blame] | 716 | strlcpy(**prompts + plen, msg, len - plen); |
| 717 | plen += mlen; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 718 | **echo_on = (type == PAM_PROMPT_ECHO_ON); |
| 719 | xfree(msg); |
| 720 | return (0); |
| 721 | case PAM_ERROR_MSG: |
| 722 | case PAM_TEXT_INFO: |
| 723 | /* accumulate messages */ |
Damien Miller | daffc6a | 2004-10-16 18:52:44 +1000 | [diff] [blame] | 724 | len = plen + mlen + 2; |
Damien Miller | 3681209 | 2006-03-26 14:22:47 +1100 | [diff] [blame] | 725 | **prompts = xrealloc(**prompts, 1, len); |
Damien Miller | daffc6a | 2004-10-16 18:52:44 +1000 | [diff] [blame] | 726 | strlcpy(**prompts + plen, msg, len - plen); |
| 727 | plen += mlen; |
| 728 | strlcat(**prompts + plen, "\n", len - plen); |
| 729 | plen++; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 730 | xfree(msg); |
| 731 | break; |
Darren Tucker | 2c77b7f | 2006-05-15 17:22:33 +1000 | [diff] [blame] | 732 | case PAM_ACCT_EXPIRED: |
| 733 | sshpam_account_status = 0; |
| 734 | /* FALLTHROUGH */ |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 735 | case PAM_AUTH_ERR: |
Darren Tucker | 2c77b7f | 2006-05-15 17:22:33 +1000 | [diff] [blame] | 736 | debug3("PAM: %s", pam_strerror(sshpam_handle, type)); |
Darren Tucker | 7b1e695 | 2005-09-28 22:33:27 +1000 | [diff] [blame] | 737 | if (**prompts != NULL && strlen(**prompts) != 0) { |
| 738 | *info = **prompts; |
| 739 | **prompts = NULL; |
| 740 | *num = 0; |
| 741 | **echo_on = 0; |
| 742 | ctxt->pam_done = -1; |
Damien Miller | 66f9eb6 | 2006-03-18 23:04:49 +1100 | [diff] [blame] | 743 | xfree(msg); |
Darren Tucker | 7b1e695 | 2005-09-28 22:33:27 +1000 | [diff] [blame] | 744 | return 0; |
| 745 | } |
| 746 | /* FALLTHROUGH */ |
| 747 | case PAM_SUCCESS: |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 748 | if (**prompts != NULL) { |
| 749 | /* drain any accumulated messages */ |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 750 | debug("PAM: %s", **prompts); |
| 751 | buffer_append(&loginmsg, **prompts, |
| 752 | strlen(**prompts)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 753 | xfree(**prompts); |
| 754 | **prompts = NULL; |
| 755 | } |
| 756 | if (type == PAM_SUCCESS) { |
Darren Tucker | d5bfa8f | 2005-01-20 13:29:51 +1100 | [diff] [blame] | 757 | if (!sshpam_authctxt->valid || |
| 758 | (sshpam_authctxt->pw->pw_uid == 0 && |
| 759 | options.permit_root_login != PERMIT_YES)) |
Darren Tucker | 36a3d60 | 2005-01-20 12:43:38 +1100 | [diff] [blame] | 760 | fatal("Internal error: PAM auth " |
| 761 | "succeeded when it should have " |
| 762 | "failed"); |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 763 | import_environments(&buffer); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 764 | *num = 0; |
| 765 | **echo_on = 0; |
| 766 | ctxt->pam_done = 1; |
| 767 | xfree(msg); |
| 768 | return (0); |
| 769 | } |
Darren Tucker | 2a9bf4b | 2004-04-18 11:00:26 +1000 | [diff] [blame] | 770 | error("PAM: %s for %s%.100s from %.100s", msg, |
| 771 | sshpam_authctxt->valid ? "" : "illegal user ", |
| 772 | sshpam_authctxt->user, |
| 773 | get_remote_name_or_ip(utmp_len, options.use_dns)); |
Darren Tucker | 439ce0d | 2003-10-09 14:20:15 +1000 | [diff] [blame] | 774 | /* FALLTHROUGH */ |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 775 | default: |
| 776 | *num = 0; |
| 777 | **echo_on = 0; |
| 778 | xfree(msg); |
| 779 | ctxt->pam_done = -1; |
| 780 | return (-1); |
| 781 | } |
| 782 | } |
| 783 | return (-1); |
| 784 | } |
| 785 | |
| 786 | /* XXX - see also comment in auth-chall.c:verify_response */ |
| 787 | static int |
| 788 | sshpam_respond(void *ctx, u_int num, char **resp) |
| 789 | { |
| 790 | Buffer buffer; |
| 791 | struct pam_ctxt *ctxt = ctx; |
| 792 | |
Darren Tucker | 1d4ebbf | 2006-01-29 16:46:13 +1100 | [diff] [blame] | 793 | debug2("PAM: %s entering, %u responses", __func__, num); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 794 | switch (ctxt->pam_done) { |
| 795 | case 1: |
| 796 | sshpam_authenticated = 1; |
| 797 | return (0); |
| 798 | case 0: |
| 799 | break; |
| 800 | default: |
| 801 | return (-1); |
| 802 | } |
| 803 | if (num != 1) { |
| 804 | error("PAM: expected one response, got %u", num); |
| 805 | return (-1); |
| 806 | } |
| 807 | buffer_init(&buffer); |
Darren Tucker | d5bfa8f | 2005-01-20 13:29:51 +1100 | [diff] [blame] | 808 | if (sshpam_authctxt->valid && |
| 809 | (sshpam_authctxt->pw->pw_uid != 0 || |
Damien Miller | 37294fb | 2005-07-17 17:18:49 +1000 | [diff] [blame] | 810 | options.permit_root_login == PERMIT_YES)) |
Darren Tucker | 36a3d60 | 2005-01-20 12:43:38 +1100 | [diff] [blame] | 811 | buffer_put_cstring(&buffer, *resp); |
| 812 | else |
| 813 | buffer_put_cstring(&buffer, badpw); |
Damien Miller | 9bdba70 | 2003-11-17 21:27:55 +1100 | [diff] [blame] | 814 | if (ssh_msg_send(ctxt->pam_psock, PAM_AUTHTOK, &buffer) == -1) { |
| 815 | buffer_free(&buffer); |
| 816 | return (-1); |
| 817 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 818 | buffer_free(&buffer); |
| 819 | return (1); |
| 820 | } |
| 821 | |
| 822 | static void |
| 823 | sshpam_free_ctx(void *ctxtp) |
| 824 | { |
| 825 | struct pam_ctxt *ctxt = ctxtp; |
| 826 | |
Darren Tucker | a8df924 | 2004-01-15 00:15:07 +1100 | [diff] [blame] | 827 | debug3("PAM: %s entering", __func__); |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 828 | sshpam_thread_cleanup(); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 829 | xfree(ctxt); |
| 830 | /* |
| 831 | * We don't call sshpam_cleanup() here because we may need the PAM |
| 832 | * handle at a later stage, e.g. when setting up a session. It's |
| 833 | * still on the cleanup list, so pam_end() *will* be called before |
| 834 | * the server process terminates. |
| 835 | */ |
| 836 | } |
| 837 | |
| 838 | KbdintDevice sshpam_device = { |
| 839 | "pam", |
| 840 | sshpam_init_ctx, |
| 841 | sshpam_query, |
| 842 | sshpam_respond, |
| 843 | sshpam_free_ctx |
| 844 | }; |
| 845 | |
| 846 | KbdintDevice mm_sshpam_device = { |
| 847 | "pam", |
| 848 | mm_sshpam_init_ctx, |
| 849 | mm_sshpam_query, |
| 850 | mm_sshpam_respond, |
| 851 | mm_sshpam_free_ctx |
| 852 | }; |
| 853 | |
| 854 | /* |
| 855 | * This replaces auth-pam.c |
| 856 | */ |
| 857 | void |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 858 | start_pam(Authctxt *authctxt) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 859 | { |
Damien Miller | 9d507da | 2003-05-14 15:31:12 +1000 | [diff] [blame] | 860 | if (!options.use_pam) |
| 861 | fatal("PAM: initialisation requested when UsePAM=no"); |
| 862 | |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 863 | if (sshpam_init(authctxt) == -1) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 864 | fatal("PAM: initialisation failed"); |
| 865 | } |
| 866 | |
| 867 | void |
| 868 | finish_pam(void) |
| 869 | { |
Darren Tucker | 8846a07 | 2003-10-07 11:30:15 +1000 | [diff] [blame] | 870 | sshpam_cleanup(); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 871 | } |
| 872 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 873 | u_int |
| 874 | do_pam_account(void) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 875 | { |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 876 | debug("%s: called", __func__); |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 877 | if (sshpam_account_status != -1) |
| 878 | return (sshpam_account_status); |
| 879 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 880 | sshpam_err = pam_acct_mgmt(sshpam_handle, 0); |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 881 | debug3("PAM: %s pam_acct_mgmt = %d (%s)", __func__, sshpam_err, |
| 882 | pam_strerror(sshpam_handle, sshpam_err)); |
Damien Miller | 94cf4c8 | 2005-07-17 17:04:47 +1000 | [diff] [blame] | 883 | |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 884 | if (sshpam_err != PAM_SUCCESS && sshpam_err != PAM_NEW_AUTHTOK_REQD) { |
| 885 | sshpam_account_status = 0; |
| 886 | return (sshpam_account_status); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 887 | } |
| 888 | |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 889 | if (sshpam_err == PAM_NEW_AUTHTOK_REQD) |
Darren Tucker | 17db1c4 | 2004-06-19 12:54:38 +1000 | [diff] [blame] | 890 | sshpam_password_change_required(1); |
Darren Tucker | 07705c7 | 2003-12-18 15:34:31 +1100 | [diff] [blame] | 891 | |
| 892 | sshpam_account_status = 1; |
| 893 | return (sshpam_account_status); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | void |
Damien Miller | 341c6e6 | 2003-09-02 23:18:52 +1000 | [diff] [blame] | 897 | do_pam_set_tty(const char *tty) |
| 898 | { |
Darren Tucker | f38db7f | 2003-08-08 13:43:37 +1000 | [diff] [blame] | 899 | if (tty != NULL) { |
| 900 | debug("PAM: setting PAM_TTY to \"%s\"", tty); |
| 901 | sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, tty); |
| 902 | if (sshpam_err != PAM_SUCCESS) |
| 903 | fatal("PAM: failed to set PAM_TTY: %s", |
| 904 | pam_strerror(sshpam_handle, sshpam_err)); |
| 905 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | void |
| 909 | do_pam_setcred(int init) |
| 910 | { |
| 911 | sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 912 | (const void *)&store_conv); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 913 | if (sshpam_err != PAM_SUCCESS) |
| 914 | fatal("PAM: failed to set PAM_CONV: %s", |
| 915 | pam_strerror(sshpam_handle, sshpam_err)); |
| 916 | if (init) { |
| 917 | debug("PAM: establishing credentials"); |
| 918 | sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED); |
| 919 | } else { |
| 920 | debug("PAM: reinitializing credentials"); |
| 921 | sshpam_err = pam_setcred(sshpam_handle, PAM_REINITIALIZE_CRED); |
| 922 | } |
| 923 | if (sshpam_err == PAM_SUCCESS) { |
| 924 | sshpam_cred_established = 1; |
| 925 | return; |
| 926 | } |
| 927 | if (sshpam_authenticated) |
| 928 | fatal("PAM: pam_setcred(): %s", |
| 929 | pam_strerror(sshpam_handle, sshpam_err)); |
| 930 | else |
| 931 | debug("PAM: pam_setcred(): %s", |
| 932 | pam_strerror(sshpam_handle, sshpam_err)); |
| 933 | } |
| 934 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 935 | static int |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 936 | sshpam_tty_conv(int n, sshpam_const struct pam_message **msg, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 937 | struct pam_response **resp, void *data) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 938 | { |
| 939 | char input[PAM_MAX_MSG_SIZE]; |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 940 | struct pam_response *reply; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 941 | int i; |
| 942 | |
Darren Tucker | ba53b83 | 2004-02-17 20:46:59 +1100 | [diff] [blame] | 943 | debug3("PAM: %s called with %d messages", __func__, n); |
| 944 | |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 945 | *resp = NULL; |
| 946 | |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 947 | if (n <= 0 || n > PAM_MAX_NUM_MSG || !isatty(STDIN_FILENO)) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 948 | return (PAM_CONV_ERR); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 949 | |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 950 | if ((reply = calloc(n, sizeof(*reply))) == NULL) |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 951 | return (PAM_CONV_ERR); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 952 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 953 | for (i = 0; i < n; ++i) { |
| 954 | switch (PAM_MSG_MEMBER(msg, i, msg_style)) { |
| 955 | case PAM_PROMPT_ECHO_OFF: |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 956 | reply[i].resp = |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 957 | read_passphrase(PAM_MSG_MEMBER(msg, i, msg), |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 958 | RP_ALLOW_STDIN); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 959 | reply[i].resp_retcode = PAM_SUCCESS; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 960 | break; |
| 961 | case PAM_PROMPT_ECHO_ON: |
Darren Tucker | 0947ddf | 2003-11-13 11:21:31 +1100 | [diff] [blame] | 962 | fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 963 | fgets(input, sizeof input, stdin); |
Damien Miller | a6fb77f | 2004-07-19 09:39:11 +1000 | [diff] [blame] | 964 | if ((reply[i].resp = strdup(input)) == NULL) |
| 965 | goto fail; |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 966 | reply[i].resp_retcode = PAM_SUCCESS; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 967 | break; |
| 968 | case PAM_ERROR_MSG: |
| 969 | case PAM_TEXT_INFO: |
Darren Tucker | 0947ddf | 2003-11-13 11:21:31 +1100 | [diff] [blame] | 970 | fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg)); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 971 | reply[i].resp_retcode = PAM_SUCCESS; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 972 | break; |
| 973 | default: |
| 974 | goto fail; |
| 975 | } |
| 976 | } |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 977 | *resp = reply; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 978 | return (PAM_SUCCESS); |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 979 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 980 | fail: |
Damien Miller | 5c3a558 | 2003-09-23 22:12:38 +1000 | [diff] [blame] | 981 | for(i = 0; i < n; i++) { |
| 982 | if (reply[i].resp != NULL) |
| 983 | xfree(reply[i].resp); |
| 984 | } |
| 985 | xfree(reply); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 986 | return (PAM_CONV_ERR); |
| 987 | } |
| 988 | |
Darren Tucker | 94befab | 2004-06-03 14:53:12 +1000 | [diff] [blame] | 989 | static struct pam_conv tty_conv = { sshpam_tty_conv, NULL }; |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 990 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 991 | /* |
| 992 | * XXX this should be done in the authentication phase, but ssh1 doesn't |
| 993 | * support that |
| 994 | */ |
| 995 | void |
| 996 | do_pam_chauthtok(void) |
| 997 | { |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 998 | if (use_privsep) |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 999 | fatal("Password expired (unable to change with privsep)"); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1000 | sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 1001 | (const void *)&tty_conv); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1002 | if (sshpam_err != PAM_SUCCESS) |
| 1003 | fatal("PAM: failed to set PAM_CONV: %s", |
| 1004 | pam_strerror(sshpam_handle, sshpam_err)); |
| 1005 | debug("PAM: changing password"); |
| 1006 | sshpam_err = pam_chauthtok(sshpam_handle, PAM_CHANGE_EXPIRED_AUTHTOK); |
| 1007 | if (sshpam_err != PAM_SUCCESS) |
| 1008 | fatal("PAM: pam_chauthtok(): %s", |
| 1009 | pam_strerror(sshpam_handle, sshpam_err)); |
| 1010 | } |
| 1011 | |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 1012 | void |
| 1013 | do_pam_session(void) |
| 1014 | { |
Darren Tucker | 1921ed9 | 2004-02-10 13:23:28 +1100 | [diff] [blame] | 1015 | debug3("PAM: opening session"); |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 1016 | sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, |
Darren Tucker | 5cf8ef7 | 2004-02-17 23:20:07 +1100 | [diff] [blame] | 1017 | (const void *)&store_conv); |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 1018 | if (sshpam_err != PAM_SUCCESS) |
| 1019 | fatal("PAM: failed to set PAM_CONV: %s", |
| 1020 | pam_strerror(sshpam_handle, sshpam_err)); |
| 1021 | sshpam_err = pam_open_session(sshpam_handle, 0); |
Darren Tucker | 69687f4 | 2004-09-11 22:17:26 +1000 | [diff] [blame] | 1022 | if (sshpam_err == PAM_SUCCESS) |
| 1023 | sshpam_session_open = 1; |
| 1024 | else { |
| 1025 | sshpam_session_open = 0; |
| 1026 | disable_forwarding(); |
| 1027 | error("PAM: pam_open_session(): %s", |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 1028 | pam_strerror(sshpam_handle, sshpam_err)); |
Darren Tucker | 69687f4 | 2004-09-11 22:17:26 +1000 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | } |
| 1032 | |
| 1033 | int |
| 1034 | is_pam_session_open(void) |
| 1035 | { |
| 1036 | return sshpam_session_open; |
Darren Tucker | 18df00c | 2003-11-18 12:42:07 +1100 | [diff] [blame] | 1037 | } |
| 1038 | |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 1039 | /* |
Darren Tucker | 49aaf4a | 2003-08-26 11:58:16 +1000 | [diff] [blame] | 1040 | * Set a PAM environment string. We need to do this so that the session |
| 1041 | * modules can handle things like Kerberos/GSI credentials that appear |
| 1042 | * during the ssh authentication process. |
| 1043 | */ |
Darren Tucker | 49aaf4a | 2003-08-26 11:58:16 +1000 | [diff] [blame] | 1044 | int |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 1045 | do_pam_putenv(char *name, char *value) |
Darren Tucker | 49aaf4a | 2003-08-26 11:58:16 +1000 | [diff] [blame] | 1046 | { |
Darren Tucker | 49aaf4a | 2003-08-26 11:58:16 +1000 | [diff] [blame] | 1047 | int ret = 1; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1048 | #ifdef HAVE_PAM_PUTENV |
Damien Miller | f272809 | 2003-09-17 07:24:25 +1000 | [diff] [blame] | 1049 | char *compound; |
| 1050 | size_t len; |
| 1051 | |
| 1052 | len = strlen(name) + strlen(value) + 2; |
| 1053 | compound = xmalloc(len); |
| 1054 | |
| 1055 | snprintf(compound, len, "%s=%s", name, value); |
| 1056 | ret = pam_putenv(sshpam_handle, compound); |
| 1057 | xfree(compound); |
Darren Tucker | 49aaf4a | 2003-08-26 11:58:16 +1000 | [diff] [blame] | 1058 | #endif |
Damien Miller | f272809 | 2003-09-17 07:24:25 +1000 | [diff] [blame] | 1059 | |
Darren Tucker | 49aaf4a | 2003-08-26 11:58:16 +1000 | [diff] [blame] | 1060 | return (ret); |
| 1061 | } |
| 1062 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1063 | char ** |
Damien Miller | c756e9b | 2003-11-17 21:41:42 +1100 | [diff] [blame] | 1064 | fetch_pam_child_environment(void) |
| 1065 | { |
| 1066 | return sshpam_env; |
| 1067 | } |
| 1068 | |
| 1069 | char ** |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1070 | fetch_pam_environment(void) |
| 1071 | { |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1072 | return (pam_getenvlist(sshpam_handle)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | void |
| 1076 | free_pam_environment(char **env) |
| 1077 | { |
| 1078 | char **envp; |
| 1079 | |
Damien Miller | e27c6cc | 2003-05-16 18:21:01 +1000 | [diff] [blame] | 1080 | if (env == NULL) |
| 1081 | return; |
| 1082 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 1083 | for (envp = env; *envp; envp++) |
| 1084 | xfree(*envp); |
| 1085 | xfree(env); |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 1086 | } |
| 1087 | |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1088 | /* |
| 1089 | * "Blind" conversation function for password authentication. Assumes that |
| 1090 | * echo-off prompts are for the password and stores messages for later |
| 1091 | * display. |
| 1092 | */ |
| 1093 | static int |
Darren Tucker | f08bdb5 | 2005-05-26 19:59:48 +1000 | [diff] [blame] | 1094 | sshpam_passwd_conv(int n, sshpam_const struct pam_message **msg, |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1095 | struct pam_response **resp, void *data) |
| 1096 | { |
| 1097 | struct pam_response *reply; |
| 1098 | int i; |
| 1099 | size_t len; |
| 1100 | |
| 1101 | debug3("PAM: %s called with %d messages", __func__, n); |
| 1102 | |
| 1103 | *resp = NULL; |
| 1104 | |
| 1105 | if (n <= 0 || n > PAM_MAX_NUM_MSG) |
| 1106 | return (PAM_CONV_ERR); |
| 1107 | |
| 1108 | if ((reply = malloc(n * sizeof(*reply))) == NULL) |
| 1109 | return (PAM_CONV_ERR); |
| 1110 | memset(reply, 0, n * sizeof(*reply)); |
| 1111 | |
| 1112 | for (i = 0; i < n; ++i) { |
| 1113 | switch (PAM_MSG_MEMBER(msg, i, msg_style)) { |
| 1114 | case PAM_PROMPT_ECHO_OFF: |
| 1115 | if (sshpam_password == NULL) |
| 1116 | goto fail; |
Damien Miller | a6fb77f | 2004-07-19 09:39:11 +1000 | [diff] [blame] | 1117 | if ((reply[i].resp = strdup(sshpam_password)) == NULL) |
| 1118 | goto fail; |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1119 | reply[i].resp_retcode = PAM_SUCCESS; |
| 1120 | break; |
| 1121 | case PAM_ERROR_MSG: |
| 1122 | case PAM_TEXT_INFO: |
| 1123 | len = strlen(PAM_MSG_MEMBER(msg, i, msg)); |
| 1124 | if (len > 0) { |
| 1125 | buffer_append(&loginmsg, |
| 1126 | PAM_MSG_MEMBER(msg, i, msg), len); |
| 1127 | buffer_append(&loginmsg, "\n", 1); |
| 1128 | } |
Damien Miller | a6fb77f | 2004-07-19 09:39:11 +1000 | [diff] [blame] | 1129 | if ((reply[i].resp = strdup("")) == NULL) |
| 1130 | goto fail; |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1131 | reply[i].resp_retcode = PAM_SUCCESS; |
| 1132 | break; |
| 1133 | default: |
| 1134 | goto fail; |
| 1135 | } |
| 1136 | } |
| 1137 | *resp = reply; |
| 1138 | return (PAM_SUCCESS); |
| 1139 | |
Damien Miller | 94cf4c8 | 2005-07-17 17:04:47 +1000 | [diff] [blame] | 1140 | fail: |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1141 | for(i = 0; i < n; i++) { |
| 1142 | if (reply[i].resp != NULL) |
| 1143 | xfree(reply[i].resp); |
| 1144 | } |
| 1145 | xfree(reply); |
| 1146 | return (PAM_CONV_ERR); |
| 1147 | } |
| 1148 | |
| 1149 | static struct pam_conv passwd_conv = { sshpam_passwd_conv, NULL }; |
| 1150 | |
| 1151 | /* |
| 1152 | * Attempt password authentication via PAM |
| 1153 | */ |
| 1154 | int |
| 1155 | sshpam_auth_passwd(Authctxt *authctxt, const char *password) |
| 1156 | { |
| 1157 | int flags = (options.permit_empty_passwd == 0 ? |
| 1158 | PAM_DISALLOW_NULL_AUTHTOK : 0); |
| 1159 | |
| 1160 | if (!options.use_pam || sshpam_handle == NULL) |
| 1161 | fatal("PAM: %s called when PAM disabled or failed to " |
| 1162 | "initialise.", __func__); |
| 1163 | |
| 1164 | sshpam_password = password; |
| 1165 | sshpam_authctxt = authctxt; |
| 1166 | |
Darren Tucker | e061b15 | 2004-05-30 22:04:56 +1000 | [diff] [blame] | 1167 | /* |
| 1168 | * If the user logging in is invalid, or is root but is not permitted |
| 1169 | * by PermitRootLogin, use an invalid password to prevent leaking |
| 1170 | * information via timing (eg if the PAM config has a delay on fail). |
| 1171 | */ |
Darren Tucker | d5bfa8f | 2005-01-20 13:29:51 +1100 | [diff] [blame] | 1172 | if (!authctxt->valid || (authctxt->pw->pw_uid == 0 && |
Damien Miller | 37294fb | 2005-07-17 17:18:49 +1000 | [diff] [blame] | 1173 | options.permit_root_login != PERMIT_YES)) |
Darren Tucker | e061b15 | 2004-05-30 22:04:56 +1000 | [diff] [blame] | 1174 | sshpam_password = badpw; |
| 1175 | |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1176 | sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, |
| 1177 | (const void *)&passwd_conv); |
| 1178 | if (sshpam_err != PAM_SUCCESS) |
| 1179 | fatal("PAM: %s: failed to set PAM_CONV: %s", __func__, |
| 1180 | pam_strerror(sshpam_handle, sshpam_err)); |
| 1181 | |
| 1182 | sshpam_err = pam_authenticate(sshpam_handle, flags); |
| 1183 | sshpam_password = NULL; |
Darren Tucker | d5bfa8f | 2005-01-20 13:29:51 +1100 | [diff] [blame] | 1184 | if (sshpam_err == PAM_SUCCESS && authctxt->valid) { |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1185 | debug("PAM: password authentication accepted for %.100s", |
| 1186 | authctxt->user); |
Damien Miller | 37294fb | 2005-07-17 17:18:49 +1000 | [diff] [blame] | 1187 | return 1; |
Darren Tucker | 450a158 | 2004-05-30 20:43:59 +1000 | [diff] [blame] | 1188 | } else { |
| 1189 | debug("PAM: password authentication failed for %.100s: %s", |
| 1190 | authctxt->valid ? authctxt->user : "an illegal user", |
| 1191 | pam_strerror(sshpam_handle, sshpam_err)); |
| 1192 | return 0; |
| 1193 | } |
| 1194 | } |
Damien Miller | e72b7af | 1999-12-30 15:08:44 +1100 | [diff] [blame] | 1195 | #endif /* USE_PAM */ |