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 sshpam_thread_status = -1;
121 switch ((pid = fork())) {
123 error("fork(): %s", strerror(errno));
130 sshpam_oldsig = signal(SIGCHLD, sshpam_sigchld_handler);
136 pthread_cancel(sp_pthread_t thread)
138 signal(SIGCHLD, sshpam_oldsig);
139 return (kill(thread, SIGTERM));
143 pthread_join(sp_pthread_t thread, void **value __unused)
147 if (sshpam_thread_status != -1)
148 return (sshpam_thread_status);
149 signal(SIGCHLD, sshpam_oldsig);
150 waitpid(thread, &status, 0);
156 static pam_handle_t *sshpam_handle = NULL;
157 static int sshpam_err = 0;
158 static int sshpam_authenticated = 0;
159 static int sshpam_session_open = 0;
160 static int sshpam_cred_established = 0;
161 static int sshpam_account_status = -1;
162 static char **sshpam_env = NULL;
163 static Authctxt *sshpam_authctxt = NULL;
165 /* Some PAM implementations don't implement this */
166 #ifndef HAVE_PAM_GETENVLIST
168 pam_getenvlist(pam_handle_t *pamh)
171 * XXX - If necessary, we can still support envrionment passing
172 * for platforms without pam_getenvlist by searching for known
173 * env vars (e.g. KRB5CCNAME) from the PAM environment.
180 pam_password_change_required(int reqd)
182 debug3("%s %d", __func__, reqd);
183 if (sshpam_authctxt == NULL)
184 fatal("%s: PAM authctxt not initialized", __func__);
185 sshpam_authctxt->force_pwchange = reqd;
187 no_port_forwarding_flag |= 2;
188 no_agent_forwarding_flag |= 2;
189 no_x11_forwarding_flag |= 2;
191 no_port_forwarding_flag &= ~2;
192 no_agent_forwarding_flag &= ~2;
193 no_x11_forwarding_flag &= ~2;
197 /* Import regular and PAM environment from subprocess */
199 import_environments(Buffer *b)
205 debug3("PAM: %s entering", __func__);
207 #ifndef USE_POSIX_THREADS
208 /* Import variables set by do_pam_account */
209 sshpam_account_status = buffer_get_int(b);
210 pam_password_change_required(buffer_get_int(b));
212 /* Import environment from subprocess */
213 num_env = buffer_get_int(b);
214 sshpam_env = xmalloc((num_env + 1) * sizeof(*sshpam_env));
215 debug3("PAM: num env strings %d", num_env);
216 for(i = 0; i < num_env; i++)
217 sshpam_env[i] = buffer_get_string(b, NULL);
219 sshpam_env[num_env] = NULL;
221 /* Import PAM environment from subprocess */
222 num_env = buffer_get_int(b);
223 debug("PAM: num PAM env strings %d", num_env);
224 for(i = 0; i < num_env; i++) {
225 env = buffer_get_string(b, NULL);
227 #ifdef HAVE_PAM_PUTENV
228 /* Errors are not fatal here */
229 if ((err = pam_putenv(sshpam_handle, env)) != PAM_SUCCESS) {
230 error("PAM: pam_putenv: %s",
231 pam_strerror(sshpam_handle, sshpam_err));
239 * Conversation function for authentication thread.
242 sshpam_thread_conv(int n, const struct pam_message **msg,
243 struct pam_response **resp, void *data)
246 struct pam_ctxt *ctxt;
247 struct pam_response *reply;
250 debug3("PAM: %s entering, %d messages", __func__, n);
254 if (n <= 0 || n > PAM_MAX_NUM_MSG)
255 return (PAM_CONV_ERR);
257 if ((reply = malloc(n * sizeof(*reply))) == NULL)
258 return (PAM_CONV_ERR);
259 memset(reply, 0, n * sizeof(*reply));
261 buffer_init(&buffer);
262 for (i = 0; i < n; ++i) {
263 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
264 case PAM_PROMPT_ECHO_OFF:
265 buffer_put_cstring(&buffer,
266 PAM_MSG_MEMBER(msg, i, msg));
267 if (ssh_msg_send(ctxt->pam_csock,
268 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
270 if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1)
272 if (buffer_get_char(&buffer) != PAM_AUTHTOK)
274 reply[i].resp = buffer_get_string(&buffer, NULL);
276 case PAM_PROMPT_ECHO_ON:
277 buffer_put_cstring(&buffer,
278 PAM_MSG_MEMBER(msg, i, msg));
279 if (ssh_msg_send(ctxt->pam_csock,
280 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
282 if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1)
284 if (buffer_get_char(&buffer) != PAM_AUTHTOK)
286 reply[i].resp = buffer_get_string(&buffer, NULL);
289 buffer_put_cstring(&buffer,
290 PAM_MSG_MEMBER(msg, i, msg));
291 if (ssh_msg_send(ctxt->pam_csock,
292 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
296 buffer_put_cstring(&buffer,
297 PAM_MSG_MEMBER(msg, i, msg));
298 if (ssh_msg_send(ctxt->pam_csock,
299 PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
305 buffer_clear(&buffer);
307 buffer_free(&buffer);
309 return (PAM_SUCCESS);
312 for(i = 0; i < n; i++) {
313 if (reply[i].resp != NULL)
314 xfree(reply[i].resp);
317 buffer_free(&buffer);
318 return (PAM_CONV_ERR);
322 * Authentication thread.
325 sshpam_thread(void *ctxtp)
327 struct pam_ctxt *ctxt = ctxtp;
329 struct pam_conv sshpam_conv;
330 #ifndef USE_POSIX_THREADS
331 extern char **environ;
334 const char *pam_user;
336 pam_get_item(sshpam_handle, PAM_USER, (const void **)&pam_user);
337 setproctitle("%s [pam]", pam_user);
341 sshpam_conv.conv = sshpam_thread_conv;
342 sshpam_conv.appdata_ptr = ctxt;
344 if (sshpam_authctxt == NULL)
345 fatal("%s: PAM authctxt not initialized", __func__);
347 buffer_init(&buffer);
348 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
349 (const void *)&sshpam_conv);
350 if (sshpam_err != PAM_SUCCESS)
352 sshpam_err = pam_authenticate(sshpam_handle, 0);
353 if (sshpam_err != PAM_SUCCESS)
357 if (!do_pam_account())
359 if (sshpam_authctxt->force_pwchange) {
360 sshpam_err = pam_chauthtok(sshpam_handle,
361 PAM_CHANGE_EXPIRED_AUTHTOK);
362 if (sshpam_err != PAM_SUCCESS)
364 pam_password_change_required(0);
368 buffer_put_cstring(&buffer, "OK");
370 #ifndef USE_POSIX_THREADS
371 /* Export variables set by do_pam_account */
372 buffer_put_int(&buffer, sshpam_account_status);
373 buffer_put_int(&buffer, sshpam_authctxt->force_pwchange);
375 /* Export any environment strings set in child */
376 for(i = 0; environ[i] != NULL; i++)
378 buffer_put_int(&buffer, i);
379 for(i = 0; environ[i] != NULL; i++)
380 buffer_put_cstring(&buffer, environ[i]);
382 /* Export any environment strings set by PAM in child */
383 env_from_pam = pam_getenvlist(sshpam_handle);
384 for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++)
386 buffer_put_int(&buffer, i);
387 for(i = 0; env_from_pam != NULL && env_from_pam[i] != NULL; i++)
388 buffer_put_cstring(&buffer, env_from_pam[i]);
389 #endif /* USE_POSIX_THREADS */
391 /* XXX - can't do much about an error here */
392 ssh_msg_send(ctxt->pam_csock, sshpam_err, &buffer);
393 buffer_free(&buffer);
397 buffer_put_cstring(&buffer,
398 pam_strerror(sshpam_handle, sshpam_err));
399 /* XXX - can't do much about an error here */
400 ssh_msg_send(ctxt->pam_csock, PAM_AUTH_ERR, &buffer);
401 buffer_free(&buffer);
404 return (NULL); /* Avoid warning for non-pthread case */
408 sshpam_thread_cleanup(void)
410 struct pam_ctxt *ctxt = cleanup_ctxt;
412 debug3("PAM: %s entering", __func__);
413 if (ctxt != NULL && ctxt->pam_thread != 0) {
414 pthread_cancel(ctxt->pam_thread);
415 pthread_join(ctxt->pam_thread, NULL);
416 close(ctxt->pam_psock);
417 close(ctxt->pam_csock);
418 memset(ctxt, 0, sizeof(*ctxt));
424 sshpam_null_conv(int n, const struct pam_message **msg,
425 struct pam_response **resp, void *data)
427 debug3("PAM: %s entering, %d messages", __func__, n);
428 return (PAM_CONV_ERR);
431 static struct pam_conv null_conv = { sshpam_null_conv, NULL };
436 debug("PAM: cleanup");
437 if (sshpam_handle == NULL)
439 pam_set_item(sshpam_handle, PAM_CONV, (const void *)&null_conv);
440 if (sshpam_cred_established) {
441 pam_setcred(sshpam_handle, PAM_DELETE_CRED);
442 sshpam_cred_established = 0;
444 if (sshpam_session_open) {
445 pam_close_session(sshpam_handle, PAM_SILENT);
446 sshpam_session_open = 0;
448 sshpam_authenticated = 0;
449 pam_end(sshpam_handle, sshpam_err);
450 sshpam_handle = NULL;
454 sshpam_init(Authctxt *authctxt)
456 extern u_int utmp_len;
457 extern char *__progname;
458 const char *pam_rhost, *pam_user, *user = authctxt->user;
460 if (sshpam_handle != NULL) {
461 /* We already have a PAM context; check if the user matches */
462 sshpam_err = pam_get_item(sshpam_handle,
463 PAM_USER, (const void **)&pam_user);
464 if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0)
466 pam_end(sshpam_handle, sshpam_err);
467 sshpam_handle = NULL;
469 debug("PAM: initializing for \"%s\"", user);
471 pam_start(SSHD_PAM_SERVICE, user, &null_conv, &sshpam_handle);
472 sshpam_authctxt = authctxt;
474 if (sshpam_err != PAM_SUCCESS) {
475 pam_end(sshpam_handle, sshpam_err);
476 sshpam_handle = NULL;
479 pam_rhost = get_remote_name_or_ip(utmp_len, options.use_dns);
480 debug("PAM: setting PAM_RHOST to \"%s\"", pam_rhost);
481 sshpam_err = pam_set_item(sshpam_handle, PAM_RHOST, pam_rhost);
482 if (sshpam_err != PAM_SUCCESS) {
483 pam_end(sshpam_handle, sshpam_err);
484 sshpam_handle = NULL;
487 #ifdef PAM_TTY_KLUDGE
489 * Some silly PAM modules (e.g. pam_time) require a TTY to operate.
490 * sshd doesn't set the tty until too late in the auth process and
491 * may not even set one (for tty-less connections)
493 debug("PAM: setting PAM_TTY to \"ssh\"");
494 sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, "ssh");
495 if (sshpam_err != PAM_SUCCESS) {
496 pam_end(sshpam_handle, sshpam_err);
497 sshpam_handle = NULL;
505 sshpam_init_ctx(Authctxt *authctxt)
507 struct pam_ctxt *ctxt;
510 debug3("PAM: %s entering", __func__);
511 /* Refuse to start if we don't have PAM enabled */
512 if (!options.use_pam)
516 if (sshpam_init(authctxt) == -1) {
517 error("PAM: initialization failed");
521 ctxt = xmalloc(sizeof *ctxt);
522 memset(ctxt, 0, sizeof(*ctxt));
524 /* Start the authentication thread */
525 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, socks) == -1) {
526 error("PAM: failed create sockets: %s", strerror(errno));
530 ctxt->pam_psock = socks[0];
531 ctxt->pam_csock = socks[1];
532 if (pthread_create(&ctxt->pam_thread, NULL, sshpam_thread, ctxt) == -1) {
533 error("PAM: failed to start authentication thread: %s",
545 sshpam_query(void *ctx, char **name, char **info,
546 u_int *num, char ***prompts, u_int **echo_on)
549 struct pam_ctxt *ctxt = ctx;
555 debug3("PAM: %s entering", __func__);
556 buffer_init(&buffer);
559 *prompts = xmalloc(sizeof(char *));
562 *echo_on = xmalloc(sizeof(u_int));
563 while (ssh_msg_recv(ctxt->pam_psock, &buffer) == 0) {
564 type = buffer_get_char(&buffer);
565 msg = buffer_get_string(&buffer, NULL);
567 case PAM_PROMPT_ECHO_ON:
568 case PAM_PROMPT_ECHO_OFF:
570 len = plen + strlen(msg) + 1;
571 **prompts = xrealloc(**prompts, len);
572 plen += snprintf(**prompts + plen, len, "%s", msg);
573 **echo_on = (type == PAM_PROMPT_ECHO_ON);
578 /* accumulate messages */
579 len = plen + strlen(msg) + 2;
580 **prompts = xrealloc(**prompts, len);
581 plen += snprintf(**prompts + plen, len, "%s\n", msg);
586 if (**prompts != NULL) {
587 /* drain any accumulated messages */
588 debug("PAM: %s", **prompts);
589 buffer_append(&loginmsg, **prompts,
594 if (type == PAM_SUCCESS) {
595 import_environments(&buffer);
602 error("PAM: %s", msg);
615 /* XXX - see also comment in auth-chall.c:verify_response */
617 sshpam_respond(void *ctx, u_int num, char **resp)
620 struct pam_ctxt *ctxt = ctx;
622 debug2("PAM: %s entering, %d responses", __func__, num);
623 switch (ctxt->pam_done) {
625 sshpam_authenticated = 1;
633 error("PAM: expected one response, got %u", num);
636 buffer_init(&buffer);
637 buffer_put_cstring(&buffer, *resp);
638 if (ssh_msg_send(ctxt->pam_psock, PAM_AUTHTOK, &buffer) == -1) {
639 buffer_free(&buffer);
642 buffer_free(&buffer);
647 sshpam_free_ctx(void *ctxtp)
649 struct pam_ctxt *ctxt = ctxtp;
651 debug3("PAM: %s entering", __func__);
652 sshpam_thread_cleanup();
655 * We don't call sshpam_cleanup() here because we may need the PAM
656 * handle at a later stage, e.g. when setting up a session. It's
657 * still on the cleanup list, so pam_end() *will* be called before
658 * the server process terminates.
662 KbdintDevice sshpam_device = {
670 KbdintDevice mm_sshpam_device = {
679 * This replaces auth-pam.c
682 start_pam(Authctxt *authctxt)
684 if (!options.use_pam)
685 fatal("PAM: initialisation requested when UsePAM=no");
687 if (sshpam_init(authctxt) == -1)
688 fatal("PAM: initialisation failed");
700 if (sshpam_account_status != -1)
701 return (sshpam_account_status);
703 sshpam_err = pam_acct_mgmt(sshpam_handle, 0);
704 debug3("PAM: %s pam_acct_mgmt = %d", __func__, sshpam_err);
706 if (sshpam_err != PAM_SUCCESS && sshpam_err != PAM_NEW_AUTHTOK_REQD) {
707 sshpam_account_status = 0;
708 return (sshpam_account_status);
711 if (sshpam_err == PAM_NEW_AUTHTOK_REQD)
712 pam_password_change_required(1);
714 sshpam_account_status = 1;
715 return (sshpam_account_status);
719 do_pam_set_tty(const char *tty)
722 debug("PAM: setting PAM_TTY to \"%s\"", tty);
723 sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, tty);
724 if (sshpam_err != PAM_SUCCESS)
725 fatal("PAM: failed to set PAM_TTY: %s",
726 pam_strerror(sshpam_handle, sshpam_err));
731 do_pam_setcred(int init)
733 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
734 (const void *)&null_conv);
735 if (sshpam_err != PAM_SUCCESS)
736 fatal("PAM: failed to set PAM_CONV: %s",
737 pam_strerror(sshpam_handle, sshpam_err));
739 debug("PAM: establishing credentials");
740 sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED);
742 debug("PAM: reinitializing credentials");
743 sshpam_err = pam_setcred(sshpam_handle, PAM_REINITIALIZE_CRED);
745 if (sshpam_err == PAM_SUCCESS) {
746 sshpam_cred_established = 1;
749 if (sshpam_authenticated)
750 fatal("PAM: pam_setcred(): %s",
751 pam_strerror(sshpam_handle, sshpam_err));
753 debug("PAM: pam_setcred(): %s",
754 pam_strerror(sshpam_handle, sshpam_err));
758 pam_tty_conv(int n, const struct pam_message **msg,
759 struct pam_response **resp, void *data)
761 char input[PAM_MAX_MSG_SIZE];
762 struct pam_response *reply;
765 debug3("PAM: %s called with %d messages", __func__, n);
769 if (n <= 0 || n > PAM_MAX_NUM_MSG || !isatty(STDIN_FILENO))
770 return (PAM_CONV_ERR);
772 if ((reply = malloc(n * sizeof(*reply))) == NULL)
773 return (PAM_CONV_ERR);
774 memset(reply, 0, n * sizeof(*reply));
776 for (i = 0; i < n; ++i) {
777 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
778 case PAM_PROMPT_ECHO_OFF:
780 read_passphrase(PAM_MSG_MEMBER(msg, i, msg),
782 reply[i].resp_retcode = PAM_SUCCESS;
784 case PAM_PROMPT_ECHO_ON:
785 fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
786 fgets(input, sizeof input, stdin);
787 reply[i].resp = xstrdup(input);
788 reply[i].resp_retcode = PAM_SUCCESS;
792 fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
793 reply[i].resp_retcode = PAM_SUCCESS;
800 return (PAM_SUCCESS);
803 for(i = 0; i < n; i++) {
804 if (reply[i].resp != NULL)
805 xfree(reply[i].resp);
808 return (PAM_CONV_ERR);
811 static struct pam_conv tty_conv = { pam_tty_conv, NULL };
814 * XXX this should be done in the authentication phase, but ssh1 doesn't
818 do_pam_chauthtok(void)
821 fatal("Password expired (unable to change with privsep)");
822 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
823 (const void *)&tty_conv);
824 if (sshpam_err != PAM_SUCCESS)
825 fatal("PAM: failed to set PAM_CONV: %s",
826 pam_strerror(sshpam_handle, sshpam_err));
827 debug("PAM: changing password");
828 sshpam_err = pam_chauthtok(sshpam_handle, PAM_CHANGE_EXPIRED_AUTHTOK);
829 if (sshpam_err != PAM_SUCCESS)
830 fatal("PAM: pam_chauthtok(): %s",
831 pam_strerror(sshpam_handle, sshpam_err));
835 pam_store_conv(int n, const struct pam_message **msg,
836 struct pam_response **resp, void *data)
838 struct pam_response *reply;
842 debug3("PAM: %s called with %d messages", __func__, n);
845 if (n <= 0 || n > PAM_MAX_NUM_MSG)
846 return (PAM_CONV_ERR);
848 if ((reply = malloc(n * sizeof(*reply))) == NULL)
849 return (PAM_CONV_ERR);
850 memset(reply, 0, n * sizeof(*reply));
852 for (i = 0; i < n; ++i) {
853 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
856 len = strlen(PAM_MSG_MEMBER(msg, i, msg));
857 buffer_append(&loginmsg, PAM_MSG_MEMBER(msg, i, msg), len);
858 buffer_append(&loginmsg, "\n", 1 );
859 reply[i].resp_retcode = PAM_SUCCESS;
866 return (PAM_SUCCESS);
869 for(i = 0; i < n; i++) {
870 if (reply[i].resp != NULL)
871 xfree(reply[i].resp);
874 return (PAM_CONV_ERR);
877 static struct pam_conv store_conv = { pam_store_conv, NULL };
882 debug3("PAM: opening session");
883 sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
884 (const void *)&store_conv);
885 if (sshpam_err != PAM_SUCCESS)
886 fatal("PAM: failed to set PAM_CONV: %s",
887 pam_strerror(sshpam_handle, sshpam_err));
888 sshpam_err = pam_open_session(sshpam_handle, 0);
889 if (sshpam_err != PAM_SUCCESS)
890 fatal("PAM: pam_open_session(): %s",
891 pam_strerror(sshpam_handle, sshpam_err));
892 sshpam_session_open = 1;
896 * Set a PAM environment string. We need to do this so that the session
897 * modules can handle things like Kerberos/GSI credentials that appear
898 * during the ssh authentication process.
901 do_pam_putenv(char *name, char *value)
904 #ifdef HAVE_PAM_PUTENV
908 len = strlen(name) + strlen(value) + 2;
909 compound = xmalloc(len);
911 snprintf(compound, len, "%s=%s", name, value);
912 ret = pam_putenv(sshpam_handle, compound);
920 fetch_pam_child_environment(void)
926 fetch_pam_environment(void)
928 return (pam_getenvlist(sshpam_handle));
932 free_pam_environment(char **env)
939 for (envp = env; *envp; envp++)