2 * Copyright (c) 2002 Networks Associates Technology, Inc.
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.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
32 /* Based on $FreeBSD: src/crypto/openssh/auth2-pam-freebsd.c,v 1.11 2003/03/31 13:48:18 des Exp $ */
37 #if defined(HAVE_SECURITY_PAM_APPL_H)
38 #include <security/pam_appl.h>
39 #elif defined (HAVE_PAM_PAM_APPL_H)
40 #include <pam/pam_appl.h>
49 #include "monitor_wrap.h"
56 #include "auth-options.h"
58 extern ServerOptions options;
59 extern Buffer loginmsg;
62 #ifdef USE_POSIX_THREADS
65 * Avoid namespace clash when *not* using pthreads for systems *with*
66 * pthreads, which unconditionally define pthread_t via sys/types.h
69 typedef pthread_t sp_pthread_t;
71 typedef pid_t sp_pthread_t;
75 sp_pthread_t pam_thread;
81 static void sshpam_free_ctx(void *);
82 static struct pam_ctxt *cleanup_ctxt;
84 #ifndef USE_POSIX_THREADS
86 * Simulate threads with processes.
89 static int sshpam_thread_status = -1;
90 static mysig_t sshpam_oldsig;
93 sshpam_sigchld_handler(int sig)
95 if (cleanup_ctxt == NULL)
96 return; /* handler called after PAM cleanup, shouldn't happen */
97 if (waitpid(cleanup_ctxt->pam_thread, &sshpam_thread_status, 0) == -1)
98 return; /* couldn't wait for process */
99 if (WIFSIGNALED(sshpam_thread_status) &&
100 WTERMSIG(sshpam_thread_status) == SIGTERM)
101 return; /* terminated by pthread_cancel */
102 if (!WIFEXITED(sshpam_thread_status))
103 fatal("PAM: authentication thread exited unexpectedly");
104 if (WEXITSTATUS(sshpam_thread_status) != 0)
105 fatal("PAM: authentication thread exited uncleanly");
109 pthread_exit(void *value __unused)
115 pthread_create(sp_pthread_t *thread, const void *attr __unused,
116 void *(*thread_start)(void *), void *arg)
120 switch ((pid = fork())) {
122 error("fork(): %s", strerror(errno));
129 sshpam_oldsig = signal(SIGCHLD, sshpam_sigchld_handler);
135 pthread_cancel(sp_pthread_t thread)
137 signal(SIGCHLD, sshpam_oldsig);
138 return (kill(thread, SIGTERM));
142 pthread_join(sp_pthread_t thread, void **value __unused)
146 if (sshpam_thread_status != -1)
147 return (sshpam_thread_status);
148 signal(SIGCHLD, sshpam_oldsig);
149 waitpid(thread, &status, 0);
155 static pam_handle_t *sshpam_handle = NULL;
156 static int sshpam_err = 0;
157 static int sshpam_authenticated = 0;
158 static int sshpam_session_open = 0;
159 static int sshpam_cred_established = 0;
160 static int sshpam_account_status = -1;
161 static char **sshpam_env = NULL;
162 static int *force_pwchange;
164 /* Some PAM implementations don't implement this */
165 #ifndef HAVE_PAM_GETENVLIST
167 pam_getenvlist(pam_handle_t *pamh)
170 * XXX - If necessary, we can still support envrionment passing
171 * for platforms without pam_getenvlist by searching for known
172 * env vars (e.g. KRB5CCNAME) from the PAM environment.
179 pam_password_change_required(int reqd)
181 debug3("%s %d", __func__, reqd);
182 *force_pwchange = reqd;
184 no_port_forwarding_flag |= 2;
185 no_agent_forwarding_flag |= 2;
186 no_x11_forwarding_flag |= 2;
188 no_port_forwarding_flag &= ~2;
189 no_agent_forwarding_flag &= ~2;
190 no_x11_forwarding_flag &= ~2;
194 /* Import regular and PAM environment from subprocess */
196 import_environments(Buffer *b)
202 debug3("PAM: %s entering", __func__);
204 #ifndef USE_POSIX_THREADS
205 /* Import variables set by do_pam_account */
206 sshpam_account_status = buffer_get_int(b);
207 pam_password_change_required(buffer_get_int(b));
209 /* Import environment from subprocess */
210 num_env = buffer_get_int(b);
211 sshpam_env = xmalloc((num_env + 1) * sizeof(*sshpam_env));
212 debug3("PAM: num env strings %d", num_env);
213 for(i = 0; i < num_env; i++)
214 sshpam_env[i] = buffer_get_string(b, NULL);
216 sshpam_env[num_env] = NULL;
218 /* Import PAM environment from subprocess */
219 num_env = buffer_get_int(b);
220 debug("PAM: num PAM env strings %d", num_env);
221 for(i = 0; i < num_env; i++) {
222 env = buffer_get_string(b, NULL);
224 #ifdef HAVE_PAM_PUTENV
225 /* Errors are not fatal here */
226 if ((err = pam_putenv(sshpam_handle, env)) != PAM_SUCCESS) {
227 error("PAM: pam_putenv: %s",
228 pam_strerror(sshpam_handle, sshpam_err));
236 * Conversation function for authentication thread.
239 sshpam_thread_conv(int n, const struct pam_message **msg,
240 struct pam_response **resp, void *data)
243 struct pam_ctxt *ctxt;
244 struct pam_response *reply;
247 debug3("PAM: %s entering, %d messages", __func__, n);
251 if (n <= 0 || n > PAM_MAX_NUM_MSG)
252 return (PAM_CONV_ERR);
254 if ((reply = malloc(n * sizeof(*reply))) == NULL)
255 return (PAM_CONV_ERR);
256 memset(reply, 0, n * sizeof(*reply));
258 buffer_init(&buffer);
259 for (i = 0; i < n; ++i) {
260 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
261 case PAM_PROMPT_ECHO_OFF:
262 buffer_put_cstring(&buffer,
263 PAM_MSG_MEMBER(msg, i, msg));
264 if (ssh_msg_send(ctxt->pam_csock,
265 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
267 if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1)
269 if (buffer_get_char(&buffer) != PAM_AUTHTOK)
271 reply[i].resp = buffer_get_string(&buffer, NULL);
273 case PAM_PROMPT_ECHO_ON:
274 buffer_put_cstring(&buffer,
275 PAM_MSG_MEMBER(msg, i, msg));
276 if (ssh_msg_send(ctxt->pam_csock,
277 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
279 if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1)
281 if (buffer_get_char(&buffer) != PAM_AUTHTOK)
283 reply[i].resp = buffer_get_string(&buffer, NULL);
286 buffer_put_cstring(&buffer,
287 PAM_MSG_MEMBER(msg, i, msg));
288 if (ssh_msg_send(ctxt->pam_csock,
289 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
293 buffer_put_cstring(&buffer,
294 PAM_MSG_MEMBER(msg, i, msg));
295 if (ssh_msg_send(ctxt->pam_csock,
296 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
302 buffer_clear(&buffer);
304 buffer_free(&buffer);
306 return (PAM_SUCCESS);
309 for(i = 0; i < n; i++) {
310 if (reply[i].resp != NULL)
311 xfree(reply[i].resp);
314 buffer_free(&buffer);
315 return (PAM_CONV_ERR);
319 * Authentication thread.
322 sshpam_thread(void *ctxtp)
324 struct pam_ctxt *ctxt = ctxtp;
326 struct pam_conv sshpam_conv;
327 #ifndef USE_POSIX_THREADS
328 extern char **environ;
331 const char *pam_user;
333 pam_get_item(sshpam_handle, PAM_USER, (const void **)&pam_user);
334 setproctitle("%s [pam]", pam_user);
338 sshpam_conv.conv = sshpam_thread_conv;
339 sshpam_conv.appdata_ptr = ctxt;
341 buffer_init(&buffer);
342 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
343 (const void *)&sshpam_conv);
344 if (sshpam_err != PAM_SUCCESS)
346 sshpam_err = pam_authenticate(sshpam_handle, 0);
347 if (sshpam_err != PAM_SUCCESS)
351 if (!do_pam_account())
353 if (*force_pwchange) {
354 sshpam_err = pam_chauthtok(sshpam_handle,
355 PAM_CHANGE_EXPIRED_AUTHTOK);
356 if (sshpam_err != PAM_SUCCESS)
358 pam_password_change_required(0);
362 buffer_put_cstring(&buffer, "OK");
364 #ifndef USE_POSIX_THREADS
365 /* Export variables set by do_pam_account */
366 buffer_put_int(&buffer, sshpam_account_status);
367 buffer_put_int(&buffer, *force_pwchange);
369 /* Export any environment strings set in child */
370 for(i = 0; environ[i] != NULL; i++)
372 buffer_put_int(&buffer, i);
373 for(i = 0; environ[i] != NULL; i++)
374 buffer_put_cstring(&buffer, environ[i]);
376 /* Export any environment strings set by PAM in child */
377 env_from_pam = pam_getenvlist(sshpam_handle);
378 for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++)
380 buffer_put_int(&buffer, i);
381 for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++)
382 buffer_put_cstring(&buffer, env_from_pam[i]);
383 #endif /* USE_POSIX_THREADS */
385 /* XXX - can't do much about an error here */
386 ssh_msg_send(ctxt->pam_csock, sshpam_err, &buffer);
387 buffer_free(&buffer);
391 buffer_put_cstring(&buffer,
392 pam_strerror(sshpam_handle, sshpam_err));
393 /* XXX - can't do much about an error here */
394 ssh_msg_send(ctxt->pam_csock, PAM_AUTH_ERR, &buffer);
395 buffer_free(&buffer);
398 return (NULL); /* Avoid warning for non-pthread case */
402 sshpam_thread_cleanup(void)
404 struct pam_ctxt *ctxt = cleanup_ctxt;
406 debug3("PAM: %s entering", __func__);
407 if (ctxt != NULL && ctxt->pam_thread != 0) {
408 pthread_cancel(ctxt->pam_thread);
409 pthread_join(ctxt->pam_thread, NULL);
410 close(ctxt->pam_psock);
411 close(ctxt->pam_csock);
412 memset(ctxt, 0, sizeof(*ctxt));
418 sshpam_null_conv(int n, const struct pam_message **msg,
419 struct pam_response **resp, void *data)
421 debug3("PAM: %s entering, %d messages", __func__, n);
422 return (PAM_CONV_ERR);
425 static struct pam_conv null_conv = { sshpam_null_conv, NULL };
430 debug("PAM: cleanup");
431 if (sshpam_handle == NULL)
433 pam_set_item(sshpam_handle, PAM_CONV, (const void *)&null_conv);
434 if (sshpam_cred_established) {
435 pam_setcred(sshpam_handle, PAM_DELETE_CRED);
436 sshpam_cred_established = 0;
438 if (sshpam_session_open) {
439 pam_close_session(sshpam_handle, PAM_SILENT);
440 sshpam_session_open = 0;
442 sshpam_authenticated = 0;
443 pam_end(sshpam_handle, sshpam_err);
444 sshpam_handle = NULL;
448 sshpam_init(const char *user)
450 extern u_int utmp_len;
451 extern char *__progname;
452 const char *pam_rhost, *pam_user;
454 if (sshpam_handle != NULL) {
455 /* We already have a PAM context; check if the user matches */
456 sshpam_err = pam_get_item(sshpam_handle,
457 PAM_USER, (const void **)&pam_user);
458 if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0)
460 pam_end(sshpam_handle, sshpam_err);
461 sshpam_handle = NULL;
463 debug("PAM: initializing for \"%s\"", user);
465 pam_start(SSHD_PAM_SERVICE, user, &null_conv, &sshpam_handle);
466 if (sshpam_err != PAM_SUCCESS) {
467 pam_end(sshpam_handle, sshpam_err);
468 sshpam_handle = NULL;
471 pam_rhost = get_remote_name_or_ip(utmp_len, options.use_dns);
472 debug("PAM: setting PAM_RHOST to \"%s\"", pam_rhost);
473 sshpam_err = pam_set_item(sshpam_handle, PAM_RHOST, pam_rhost);
474 if (sshpam_err != PAM_SUCCESS) {
475 pam_end(sshpam_handle, sshpam_err);
476 sshpam_handle = NULL;
479 #ifdef PAM_TTY_KLUDGE
481 * Some silly PAM modules (e.g. pam_time) require a TTY to operate.
482 * sshd doesn't set the tty until too late in the auth process and
483 * may not even set one (for tty-less connections)
485 debug("PAM: setting PAM_TTY to \"ssh\"");
486 sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, "ssh");
487 if (sshpam_err != PAM_SUCCESS) {
488 pam_end(sshpam_handle, sshpam_err);
489 sshpam_handle = NULL;
497 sshpam_init_ctx(Authctxt *authctxt)
499 struct pam_ctxt *ctxt;
502 debug3("PAM: %s entering", __func__);
503 /* Refuse to start if we don't have PAM enabled */
504 if (!options.use_pam)
508 if (sshpam_init(authctxt->user) == -1) {
509 error("PAM: initialization failed");
513 ctxt = xmalloc(sizeof *ctxt);
514 memset(ctxt, 0, sizeof(*ctxt));
516 force_pwchange = &(authctxt->force_pwchange);
518 /* Start the authentication thread */
519 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, socks) == -1) {
520 error("PAM: failed create sockets: %s", strerror(errno));
524 ctxt->pam_psock = socks[0];
525 ctxt->pam_csock = socks[1];
526 if (pthread_create(&ctxt->pam_thread, NULL, sshpam_thread, ctxt) == -1) {
527 error("PAM: failed to start authentication thread: %s",
539 sshpam_query(void *ctx, char **name, char **info,
540 u_int *num, char ***prompts, u_int **echo_on)
543 struct pam_ctxt *ctxt = ctx;
549 debug3("PAM: %s entering", __func__);
550 buffer_init(&buffer);
553 *prompts = xmalloc(sizeof(char *));
556 *echo_on = xmalloc(sizeof(u_int));
557 while (ssh_msg_recv(ctxt->pam_psock, &buffer) == 0) {
558 type = buffer_get_char(&buffer);
559 msg = buffer_get_string(&buffer, NULL);
561 case PAM_PROMPT_ECHO_ON:
562 case PAM_PROMPT_ECHO_OFF:
564 len = plen + strlen(msg) + 1;
565 **prompts = xrealloc(**prompts, len);
566 plen += snprintf(**prompts + plen, len, "%s", msg);
567 **echo_on = (type == PAM_PROMPT_ECHO_ON);
572 /* accumulate messages */
573 len = plen + strlen(msg) + 2;
574 **prompts = xrealloc(**prompts, len);
575 plen += snprintf(**prompts + plen, len, "%s\n", msg);
580 if (**prompts != NULL) {
581 /* drain any accumulated messages */
582 debug("PAM: %s", **prompts);
583 buffer_append(&loginmsg, **prompts,
588 if (type == PAM_SUCCESS) {
589 import_environments(&buffer);
596 error("PAM: %s", msg);
609 /* XXX - see also comment in auth-chall.c:verify_response */
611 sshpam_respond(void *ctx, u_int num, char **resp)
614 struct pam_ctxt *ctxt = ctx;
616 debug2("PAM: %s entering, %d responses", __func__, num);
617 switch (ctxt->pam_done) {
619 sshpam_authenticated = 1;
627 error("PAM: expected one response, got %u", num);
630 buffer_init(&buffer);
631 buffer_put_cstring(&buffer, *resp);
632 if (ssh_msg_send(ctxt->pam_psock, PAM_AUTHTOK, &buffer) == -1) {
633 buffer_free(&buffer);
636 buffer_free(&buffer);
641 sshpam_free_ctx(void *ctxtp)
643 struct pam_ctxt *ctxt = ctxtp;
645 debug3("PAM: %s entering", __func__);
646 sshpam_thread_cleanup();
649 * We don't call sshpam_cleanup() here because we may need the PAM
650 * handle at a later stage, e.g. when setting up a session. It's
651 * still on the cleanup list, so pam_end() *will* be called before
652 * the server process terminates.
656 KbdintDevice sshpam_device = {
664 KbdintDevice mm_sshpam_device = {
673 * This replaces auth-pam.c
676 start_pam(const char *user)
678 if (!options.use_pam)
679 fatal("PAM: initialisation requested when UsePAM=no");
681 if (sshpam_init(user) == -1)
682 fatal("PAM: initialisation failed");
694 if (sshpam_account_status != -1)
695 return (sshpam_account_status);
697 sshpam_err = pam_acct_mgmt(sshpam_handle, 0);
698 debug3("PAM: %s pam_acct_mgmt = %d", __func__, sshpam_err);
700 if (sshpam_err != PAM_SUCCESS && sshpam_err != PAM_NEW_AUTHTOK_REQD) {
701 sshpam_account_status = 0;
702 return (sshpam_account_status);
705 if (sshpam_err == PAM_NEW_AUTHTOK_REQD)
706 pam_password_change_required(1);
708 sshpam_account_status = 1;
709 return (sshpam_account_status);
713 do_pam_set_tty(const char *tty)
716 debug("PAM: setting PAM_TTY to \"%s\"", tty);
717 sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, tty);
718 if (sshpam_err != PAM_SUCCESS)
719 fatal("PAM: failed to set PAM_TTY: %s",
720 pam_strerror(sshpam_handle, sshpam_err));
725 do_pam_setcred(int init)
727 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
728 (const void *)&null_conv);
729 if (sshpam_err != PAM_SUCCESS)
730 fatal("PAM: failed to set PAM_CONV: %s",
731 pam_strerror(sshpam_handle, sshpam_err));
733 debug("PAM: establishing credentials");
734 sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED);
736 debug("PAM: reinitializing credentials");
737 sshpam_err = pam_setcred(sshpam_handle, PAM_REINITIALIZE_CRED);
739 if (sshpam_err == PAM_SUCCESS) {
740 sshpam_cred_established = 1;
743 if (sshpam_authenticated)
744 fatal("PAM: pam_setcred(): %s",
745 pam_strerror(sshpam_handle, sshpam_err));
747 debug("PAM: pam_setcred(): %s",
748 pam_strerror(sshpam_handle, sshpam_err));
752 pam_tty_conv(int n, const struct pam_message **msg,
753 struct pam_response **resp, void *data)
755 char input[PAM_MAX_MSG_SIZE];
756 struct pam_response *reply;
759 debug3("PAM: %s called with %d messages", __func__, n);
763 if (n <= 0 || n > PAM_MAX_NUM_MSG || !isatty(STDIN_FILENO))
764 return (PAM_CONV_ERR);
766 if ((reply = malloc(n * sizeof(*reply))) == NULL)
767 return (PAM_CONV_ERR);
768 memset(reply, 0, n * sizeof(*reply));
770 for (i = 0; i < n; ++i) {
771 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
772 case PAM_PROMPT_ECHO_OFF:
774 read_passphrase(PAM_MSG_MEMBER(msg, i, msg),
776 reply[i].resp_retcode = PAM_SUCCESS;
778 case PAM_PROMPT_ECHO_ON:
779 fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
780 fgets(input, sizeof input, stdin);
781 reply[i].resp = xstrdup(input);
782 reply[i].resp_retcode = PAM_SUCCESS;
786 fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
787 reply[i].resp_retcode = PAM_SUCCESS;
794 return (PAM_SUCCESS);
797 for(i = 0; i < n; i++) {
798 if (reply[i].resp != NULL)
799 xfree(reply[i].resp);
802 return (PAM_CONV_ERR);
805 static struct pam_conv tty_conv = { pam_tty_conv, NULL };
808 * XXX this should be done in the authentication phase, but ssh1 doesn't
812 do_pam_chauthtok(void)
815 fatal("Password expired (unable to change with privsep)");
816 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
817 (const void *)&tty_conv);
818 if (sshpam_err != PAM_SUCCESS)
819 fatal("PAM: failed to set PAM_CONV: %s",
820 pam_strerror(sshpam_handle, sshpam_err));
821 debug("PAM: changing password");
822 sshpam_err = pam_chauthtok(sshpam_handle, PAM_CHANGE_EXPIRED_AUTHTOK);
823 if (sshpam_err != PAM_SUCCESS)
824 fatal("PAM: pam_chauthtok(): %s",
825 pam_strerror(sshpam_handle, sshpam_err));
829 pam_store_conv(int n, const struct pam_message **msg,
830 struct pam_response **resp, void *data)
832 struct pam_response *reply;
836 debug3("PAM: %s called with %d messages", __func__, n);
839 if (n <= 0 || n > PAM_MAX_NUM_MSG)
840 return (PAM_CONV_ERR);
842 if ((reply = malloc(n * sizeof(*reply))) == NULL)
843 return (PAM_CONV_ERR);
844 memset(reply, 0, n * sizeof(*reply));
846 for (i = 0; i < n; ++i) {
847 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
850 len = strlen(PAM_MSG_MEMBER(msg, i, msg));
851 buffer_append(&loginmsg, PAM_MSG_MEMBER(msg, i, msg), len);
852 buffer_append(&loginmsg, "\n", 1 );
853 reply[i].resp_retcode = PAM_SUCCESS;
860 return (PAM_SUCCESS);
863 for(i = 0; i < n; i++) {
864 if (reply[i].resp != NULL)
865 xfree(reply[i].resp);
868 return (PAM_CONV_ERR);
871 static struct pam_conv store_conv = { pam_store_conv, NULL };
876 debug3("PAM: opening session");
877 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
878 (const void *)&store_conv);
879 if (sshpam_err != PAM_SUCCESS)
880 fatal("PAM: failed to set PAM_CONV: %s",
881 pam_strerror(sshpam_handle, sshpam_err));
882 sshpam_err = pam_open_session(sshpam_handle, 0);
883 if (sshpam_err != PAM_SUCCESS)
884 fatal("PAM: pam_open_session(): %s",
885 pam_strerror(sshpam_handle, sshpam_err));
886 sshpam_session_open = 1;
890 * Set a PAM environment string. We need to do this so that the session
891 * modules can handle things like Kerberos/GSI credentials that appear
892 * during the ssh authentication process.
895 do_pam_putenv(char *name, char *value)
898 #ifdef HAVE_PAM_PUTENV
902 len = strlen(name) + strlen(value) + 2;
903 compound = xmalloc(len);
905 snprintf(compound, len, "%s=%s", name, value);
906 ret = pam_putenv(sshpam_handle, compound);
914 fetch_pam_child_environment(void)
920 fetch_pam_environment(void)
922 return (pam_getenvlist(sshpam_handle));
926 free_pam_environment(char **env)
933 for (envp = env; *envp; envp++)