]> andersk Git - openssh.git/blob - auth-pam.c
- (djm) Bug #632: Don't call pam_end indirectly from within kbd-int
[openssh.git] / auth-pam.c
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.
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.
18  *
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.
30  */
31
32 /* Based on $FreeBSD: src/crypto/openssh/auth2-pam-freebsd.c,v 1.11 2003/03/31 13:48:18 des Exp $ */
33 #include "includes.h"
34 RCSID("$Id$");
35
36 #ifdef USE_PAM
37 #include <security/pam_appl.h>
38
39 #include "auth.h"
40 #include "auth-pam.h"
41 #include "buffer.h"
42 #include "bufaux.h"
43 #include "canohost.h"
44 #include "log.h"
45 #include "monitor_wrap.h"
46 #include "msg.h"
47 #include "packet.h"
48 #include "readpass.h"
49 #include "servconf.h"
50 #include "ssh2.h"
51 #include "xmalloc.h"
52 #include "auth-options.h"
53
54 extern ServerOptions options;
55
56 #define __unused
57
58 #ifdef USE_POSIX_THREADS
59 #include <pthread.h>
60 /*
61  * Avoid namespace clash when *not* using pthreads for systems *with* 
62  * pthreads, which unconditionally define pthread_t via sys/types.h 
63  * (e.g. Linux)
64  */
65 typedef pthread_t sp_pthread_t; 
66 #else
67 /*
68  * Simulate threads with processes.
69  */
70 typedef pid_t sp_pthread_t;
71
72 static void
73 pthread_exit(void *value __unused)
74 {
75         _exit(0);
76 }
77
78 static int
79 pthread_create(sp_pthread_t *thread, const void *attr __unused,
80     void *(*thread_start)(void *), void *arg)
81 {
82         pid_t pid;
83
84         switch ((pid = fork())) {
85         case -1:
86                 error("fork(): %s", strerror(errno));
87                 return (-1);
88         case 0:
89                 thread_start(arg);
90                 _exit(1);
91         default:
92                 *thread = pid;
93                 return (0);
94         }
95 }
96
97 static int
98 pthread_cancel(sp_pthread_t thread)
99 {
100         return (kill(thread, SIGTERM));
101 }
102
103 static int
104 pthread_join(sp_pthread_t thread, void **value __unused)
105 {
106         int status;
107
108         waitpid(thread, &status, 0);
109         return (status);
110 }
111 #endif
112
113
114 static pam_handle_t *sshpam_handle = NULL;
115 static int sshpam_err = 0;
116 static int sshpam_authenticated = 0;
117 static int sshpam_new_authtok_reqd = 0;
118 static int sshpam_session_open = 0;
119 static int sshpam_cred_established = 0;
120
121 struct pam_ctxt {
122         sp_pthread_t     pam_thread;
123         int              pam_psock;
124         int              pam_csock;
125         int              pam_done;
126 };
127
128 static void sshpam_free_ctx(void *);
129 static struct pam_ctxt *cleanup_ctxt;
130
131 /*
132  * Conversation function for authentication thread.
133  */
134 static int
135 sshpam_thread_conv(int n, const struct pam_message **msg,
136     struct pam_response **resp, void *data)
137 {
138         Buffer buffer;
139         struct pam_ctxt *ctxt;
140         struct pam_response *reply;
141         int i;
142
143         *resp = NULL;
144
145         ctxt = data;
146         if (n <= 0 || n > PAM_MAX_NUM_MSG)
147                 return (PAM_CONV_ERR);
148
149         if ((reply = malloc(n * sizeof(*reply))) == NULL)
150                 return (PAM_CONV_ERR);
151         memset(reply, 0, n * sizeof(*reply));
152
153         buffer_init(&buffer);
154         for (i = 0; i < n; ++i) {
155                 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
156                 case PAM_PROMPT_ECHO_OFF:
157                         buffer_put_cstring(&buffer, 
158                             PAM_MSG_MEMBER(msg, i, msg));
159                         if (ssh_msg_send(ctxt->pam_csock, 
160                             PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
161                                 goto fail;
162                         if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1) 
163                                 goto fail;
164                         if (buffer_get_char(&buffer) != PAM_AUTHTOK)
165                                 goto fail;
166                         reply[i].resp = buffer_get_string(&buffer, NULL);
167                         break;
168                 case PAM_PROMPT_ECHO_ON:
169                         buffer_put_cstring(&buffer, 
170                             PAM_MSG_MEMBER(msg, i, msg));
171                         if (ssh_msg_send(ctxt->pam_csock, 
172                             PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
173                                 goto fail;
174                         if (ssh_msg_recv(ctxt->pam_csock, &buffer) == -1)
175                                 goto fail;
176                         if (buffer_get_char(&buffer) != PAM_AUTHTOK)
177                                 goto fail;
178                         reply[i].resp = buffer_get_string(&buffer, NULL);
179                         break;
180                 case PAM_ERROR_MSG:
181                         buffer_put_cstring(&buffer, 
182                             PAM_MSG_MEMBER(msg, i, msg));
183                         if (ssh_msg_send(ctxt->pam_csock, 
184                             PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
185                                 goto fail;
186                         break;
187                 case PAM_TEXT_INFO:
188                         buffer_put_cstring(&buffer, 
189                             PAM_MSG_MEMBER(msg, i, msg));
190                         if (ssh_msg_send(ctxt->pam_csock, 
191                             PAM_MSG_MEMBER(msg, i, msg_style), &buffer) == -1)
192                                 goto fail;
193                         break;
194                 default:
195                         goto fail;
196                 }
197                 buffer_clear(&buffer);
198         }
199         buffer_free(&buffer);
200         *resp = reply;
201         return (PAM_SUCCESS);
202
203  fail:
204         for(i = 0; i < n; i++) {
205                 if (reply[i].resp != NULL)
206                         xfree(reply[i].resp);
207         }
208         xfree(reply);
209         buffer_free(&buffer);
210         return (PAM_CONV_ERR);
211 }
212
213 /*
214  * Authentication thread.
215  */
216 static void *
217 sshpam_thread(void *ctxtp)
218 {
219         struct pam_ctxt *ctxt = ctxtp;
220         Buffer buffer;
221         struct pam_conv sshpam_conv;
222 #ifndef USE_POSIX_THREADS
223         const char *pam_user;
224
225         pam_get_item(sshpam_handle, PAM_USER, (const void **)&pam_user);
226         setproctitle("%s [pam]", pam_user);
227 #endif
228
229         sshpam_conv.conv = sshpam_thread_conv;
230         sshpam_conv.appdata_ptr = ctxt;
231
232         buffer_init(&buffer);
233         sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
234             (const void *)&sshpam_conv);
235         if (sshpam_err != PAM_SUCCESS)
236                 goto auth_fail;
237         sshpam_err = pam_authenticate(sshpam_handle, 0);
238         if (sshpam_err != PAM_SUCCESS)
239                 goto auth_fail;
240         buffer_put_cstring(&buffer, "OK");
241         /* XXX - can't do much about an error here */
242         ssh_msg_send(ctxt->pam_csock, sshpam_err, &buffer);
243         buffer_free(&buffer);
244         pthread_exit(NULL);
245
246  auth_fail:
247         buffer_put_cstring(&buffer,
248             pam_strerror(sshpam_handle, sshpam_err));
249         /* XXX - can't do much about an error here */
250         ssh_msg_send(ctxt->pam_csock, PAM_AUTH_ERR, &buffer);
251         buffer_free(&buffer);
252         pthread_exit(NULL);
253         
254         return (NULL); /* Avoid warning for non-pthread case */
255 }
256
257 void
258 sshpam_thread_cleanup(void)
259 {
260         struct pam_ctxt *ctxt = cleanup_ctxt;
261
262         if (ctxt != NULL && ctxt->pam_thread != 0) {
263                 pthread_cancel(ctxt->pam_thread);
264                 pthread_join(ctxt->pam_thread, NULL);
265                 close(ctxt->pam_psock);
266                 close(ctxt->pam_csock);
267                 memset(ctxt, 0, sizeof(*ctxt));
268                 cleanup_ctxt = NULL;
269         }
270 }
271
272 static int
273 sshpam_null_conv(int n, const struct pam_message **msg,
274     struct pam_response **resp, void *data)
275 {
276         return (PAM_CONV_ERR);
277 }
278
279 static struct pam_conv null_conv = { sshpam_null_conv, NULL };
280
281 void
282 sshpam_cleanup(void)
283 {
284         debug("PAM: cleanup");
285         if (sshpam_handle == NULL)
286                 return;
287         pam_set_item(sshpam_handle, PAM_CONV, (const void *)&null_conv);
288         if (sshpam_cred_established) {
289                 pam_setcred(sshpam_handle, PAM_DELETE_CRED);
290                 sshpam_cred_established = 0;
291         }
292         if (sshpam_session_open) {
293                 pam_close_session(sshpam_handle, PAM_SILENT);
294                 sshpam_session_open = 0;
295         }
296         sshpam_authenticated = sshpam_new_authtok_reqd = 0;
297         pam_end(sshpam_handle, sshpam_err);
298         sshpam_handle = NULL;
299 }
300
301 static int
302 sshpam_init(const char *user)
303 {
304         extern u_int utmp_len;
305         extern char *__progname;
306         const char *pam_rhost, *pam_user;
307
308         if (sshpam_handle != NULL) {
309                 /* We already have a PAM context; check if the user matches */
310                 sshpam_err = pam_get_item(sshpam_handle,
311                     PAM_USER, (const void **)&pam_user);
312                 if (sshpam_err == PAM_SUCCESS && strcmp(user, pam_user) == 0)
313                         return (0);
314                 pam_end(sshpam_handle, sshpam_err);
315                 sshpam_handle = NULL;
316         }
317         debug("PAM: initializing for \"%s\"", user);
318         sshpam_err =
319             pam_start(SSHD_PAM_SERVICE, user, &null_conv, &sshpam_handle);
320         if (sshpam_err != PAM_SUCCESS) {
321                 pam_end(sshpam_handle, sshpam_err);
322                 sshpam_handle = NULL;
323                 return (-1);
324         }
325         pam_rhost = get_remote_name_or_ip(utmp_len, options.use_dns);
326         debug("PAM: setting PAM_RHOST to \"%s\"", pam_rhost);
327         sshpam_err = pam_set_item(sshpam_handle, PAM_RHOST, pam_rhost);
328         if (sshpam_err != PAM_SUCCESS) {
329                 pam_end(sshpam_handle, sshpam_err);
330                 sshpam_handle = NULL;
331                 return (-1);
332         }
333 #ifdef PAM_TTY_KLUDGE
334         /*
335          * Some silly PAM modules (e.g. pam_time) require a TTY to operate.
336          * sshd doesn't set the tty until too late in the auth process and 
337          * may not even set one (for tty-less connections)
338          */
339         debug("PAM: setting PAM_TTY to \"ssh\"");
340         sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, "ssh");
341         if (sshpam_err != PAM_SUCCESS) {
342                 pam_end(sshpam_handle, sshpam_err);
343                 sshpam_handle = NULL;
344                 return (-1);
345         }
346 #endif
347         return (0);
348 }
349
350 static void *
351 sshpam_init_ctx(Authctxt *authctxt)
352 {
353         struct pam_ctxt *ctxt;
354         int socks[2];
355
356         /* Refuse to start if we don't have PAM enabled */
357         if (!options.use_pam)
358                 return NULL;
359
360         /* Initialize PAM */
361         if (sshpam_init(authctxt->user) == -1) {
362                 error("PAM: initialization failed");
363                 return (NULL);
364         }
365
366         ctxt = xmalloc(sizeof *ctxt);
367         memset(ctxt, 0, sizeof(*ctxt));
368
369         /* Start the authentication thread */
370         if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, socks) == -1) {
371                 error("PAM: failed create sockets: %s", strerror(errno));
372                 xfree(ctxt);
373                 return (NULL);
374         }
375         ctxt->pam_psock = socks[0];
376         ctxt->pam_csock = socks[1];
377         if (pthread_create(&ctxt->pam_thread, NULL, sshpam_thread, ctxt) == -1) {
378                 error("PAM: failed to start authentication thread: %s",
379                     strerror(errno));
380                 close(socks[0]);
381                 close(socks[1]);
382                 xfree(ctxt);
383                 return (NULL);
384         }
385         cleanup_ctxt = ctxt;
386         return (ctxt);
387 }
388
389 static int
390 sshpam_query(void *ctx, char **name, char **info,
391     u_int *num, char ***prompts, u_int **echo_on)
392 {
393         Buffer buffer;
394         struct pam_ctxt *ctxt = ctx;
395         size_t plen;
396         u_char type;
397         char *msg;
398         size_t len;
399
400         buffer_init(&buffer);
401         *name = xstrdup("");
402         *info = xstrdup("");
403         *prompts = xmalloc(sizeof(char *));
404         **prompts = NULL;
405         plen = 0;
406         *echo_on = xmalloc(sizeof(u_int));
407         while (ssh_msg_recv(ctxt->pam_psock, &buffer) == 0) {
408                 type = buffer_get_char(&buffer);
409                 msg = buffer_get_string(&buffer, NULL);
410                 switch (type) {
411                 case PAM_PROMPT_ECHO_ON:
412                 case PAM_PROMPT_ECHO_OFF:
413                         *num = 1;
414                         len = plen + strlen(msg) + 1;
415                         **prompts = xrealloc(**prompts, len);
416                         plen += snprintf(**prompts + plen, len, "%s", msg);
417                         **echo_on = (type == PAM_PROMPT_ECHO_ON);
418                         xfree(msg);
419                         return (0);
420                 case PAM_ERROR_MSG:
421                 case PAM_TEXT_INFO:
422                         /* accumulate messages */
423                         len = plen + strlen(msg) + 2;
424                         **prompts = xrealloc(**prompts, len);
425                         plen += snprintf(**prompts + plen, len, "%s\n", msg);
426                         xfree(msg);
427                         break;
428                 case PAM_SUCCESS:
429                 case PAM_AUTH_ERR:
430                         if (**prompts != NULL) {
431                                 /* drain any accumulated messages */
432 #if 0 /* XXX - not compatible with privsep */
433                                 packet_start(SSH2_MSG_USERAUTH_BANNER);
434                                 packet_put_cstring(**prompts);
435                                 packet_put_cstring("");
436                                 packet_send();
437                                 packet_write_wait();
438 #endif
439                                 xfree(**prompts);
440                                 **prompts = NULL;
441                         }
442                         if (type == PAM_SUCCESS) {
443                                 *num = 0;
444                                 **echo_on = 0;
445                                 ctxt->pam_done = 1;
446                                 xfree(msg);
447                                 return (0);
448                         }
449                         error("PAM: %s", msg);
450                         /* FALLTHROUGH */
451                 default:
452                         *num = 0;
453                         **echo_on = 0;
454                         xfree(msg);
455                         ctxt->pam_done = -1;
456                         return (-1);
457                 }
458         }
459         return (-1);
460 }
461
462 /* XXX - see also comment in auth-chall.c:verify_response */
463 static int
464 sshpam_respond(void *ctx, u_int num, char **resp)
465 {
466         Buffer buffer;
467         struct pam_ctxt *ctxt = ctx;
468
469         debug2("PAM: %s", __func__);
470         switch (ctxt->pam_done) {
471         case 1:
472                 sshpam_authenticated = 1;
473                 return (0);
474         case 0:
475                 break;
476         default:
477                 return (-1);
478         }
479         if (num != 1) {
480                 error("PAM: expected one response, got %u", num);
481                 return (-1);
482         }
483         buffer_init(&buffer);
484         buffer_put_cstring(&buffer, *resp);
485         if (ssh_msg_send(ctxt->pam_psock, PAM_AUTHTOK, &buffer) == -1) {
486                 buffer_free(&buffer);
487                 return (-1);
488         }
489         buffer_free(&buffer);
490         return (1);
491 }
492
493 static void
494 sshpam_free_ctx(void *ctxtp)
495 {
496         struct pam_ctxt *ctxt = ctxtp;
497
498         sshpam_thread_cleanup();
499         xfree(ctxt);
500         /*
501          * We don't call sshpam_cleanup() here because we may need the PAM
502          * handle at a later stage, e.g. when setting up a session.  It's
503          * still on the cleanup list, so pam_end() *will* be called before
504          * the server process terminates.
505          */
506 }
507
508 KbdintDevice sshpam_device = {
509         "pam",
510         sshpam_init_ctx,
511         sshpam_query,
512         sshpam_respond,
513         sshpam_free_ctx
514 };
515
516 KbdintDevice mm_sshpam_device = {
517         "pam",
518         mm_sshpam_init_ctx,
519         mm_sshpam_query,
520         mm_sshpam_respond,
521         mm_sshpam_free_ctx
522 };
523
524 /*
525  * This replaces auth-pam.c
526  */
527 void
528 start_pam(const char *user)
529 {
530         if (!options.use_pam)
531                 fatal("PAM: initialisation requested when UsePAM=no");
532
533         if (sshpam_init(user) == -1)
534                 fatal("PAM: initialisation failed");
535 }
536
537 void
538 finish_pam(void)
539 {
540         sshpam_cleanup();
541 }
542
543 u_int
544 do_pam_account(void)
545 {
546         sshpam_err = pam_acct_mgmt(sshpam_handle, 0);
547         debug3("%s: pam_acct_mgmt = %d", __func__, sshpam_err);
548         
549         if (sshpam_err != PAM_SUCCESS && sshpam_err != PAM_NEW_AUTHTOK_REQD)
550                 return (0);
551
552         if (sshpam_err == PAM_NEW_AUTHTOK_REQD) {
553                 sshpam_new_authtok_reqd = 1;
554
555                 /* Prevent forwardings until password changed */
556                 no_port_forwarding_flag |= 2;
557                 no_agent_forwarding_flag |= 2;
558                 no_x11_forwarding_flag |= 2;
559         }
560
561         return (1);
562 }
563
564 void
565 do_pam_session(void)
566 {
567         sshpam_err = pam_set_item(sshpam_handle, PAM_CONV, 
568             (const void *)&null_conv);
569         if (sshpam_err != PAM_SUCCESS)
570                 fatal("PAM: failed to set PAM_CONV: %s",
571                     pam_strerror(sshpam_handle, sshpam_err));
572         sshpam_err = pam_open_session(sshpam_handle, 0);
573         if (sshpam_err != PAM_SUCCESS)
574                 fatal("PAM: pam_open_session(): %s",
575                     pam_strerror(sshpam_handle, sshpam_err));
576         sshpam_session_open = 1;
577 }
578
579 void
580 do_pam_set_tty(const char *tty)
581 {
582         if (tty != NULL) {
583                 debug("PAM: setting PAM_TTY to \"%s\"", tty);
584                 sshpam_err = pam_set_item(sshpam_handle, PAM_TTY, tty);
585                 if (sshpam_err != PAM_SUCCESS)
586                         fatal("PAM: failed to set PAM_TTY: %s",
587                             pam_strerror(sshpam_handle, sshpam_err));
588         }
589 }
590
591 void
592 do_pam_setcred(int init)
593 {
594         sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
595             (const void *)&null_conv);
596         if (sshpam_err != PAM_SUCCESS)
597                 fatal("PAM: failed to set PAM_CONV: %s",
598                     pam_strerror(sshpam_handle, sshpam_err));
599         if (init) {
600                 debug("PAM: establishing credentials");
601                 sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED);
602         } else {
603                 debug("PAM: reinitializing credentials");
604                 sshpam_err = pam_setcred(sshpam_handle, PAM_REINITIALIZE_CRED);
605         }
606         if (sshpam_err == PAM_SUCCESS) {
607                 sshpam_cred_established = 1;
608                 return;
609         }
610         if (sshpam_authenticated)
611                 fatal("PAM: pam_setcred(): %s",
612                     pam_strerror(sshpam_handle, sshpam_err));
613         else
614                 debug("PAM: pam_setcred(): %s",
615                     pam_strerror(sshpam_handle, sshpam_err));
616 }
617
618 int
619 is_pam_password_change_required(void)
620 {
621         return (sshpam_new_authtok_reqd);
622 }
623
624 static int
625 pam_chauthtok_conv(int n, const struct pam_message **msg,
626     struct pam_response **resp, void *data)
627 {
628         char input[PAM_MAX_MSG_SIZE];
629         struct pam_response *reply;
630         int i;
631
632         *resp = NULL;
633
634         if (n <= 0 || n > PAM_MAX_NUM_MSG)
635                 return (PAM_CONV_ERR);
636
637         if ((reply = malloc(n * sizeof(*reply))) == NULL)
638                 return (PAM_CONV_ERR);
639         memset(reply, 0, n * sizeof(*reply));
640
641         for (i = 0; i < n; ++i) {
642                 switch (PAM_MSG_MEMBER(msg, i, msg_style)) {
643                 case PAM_PROMPT_ECHO_OFF:
644                         reply[i].resp =
645                             read_passphrase(PAM_MSG_MEMBER(msg, i, msg), 
646                             RP_ALLOW_STDIN);
647                         reply[i].resp_retcode = PAM_SUCCESS;
648                         break;
649                 case PAM_PROMPT_ECHO_ON:
650                         fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
651                         fgets(input, sizeof input, stdin);
652                         reply[i].resp = xstrdup(input);
653                         reply[i].resp_retcode = PAM_SUCCESS;
654                         break;
655                 case PAM_ERROR_MSG:
656                 case PAM_TEXT_INFO:
657                         fprintf(stderr, "%s\n", PAM_MSG_MEMBER(msg, i, msg));
658                         reply[i].resp_retcode = PAM_SUCCESS;
659                         break;
660                 default:
661                         goto fail;
662                 }
663         }
664         *resp = reply;
665         return (PAM_SUCCESS);
666
667  fail:
668         for(i = 0; i < n; i++) {
669                 if (reply[i].resp != NULL)
670                         xfree(reply[i].resp);
671         }
672         xfree(reply);
673         return (PAM_CONV_ERR);
674 }
675
676 /*
677  * XXX this should be done in the authentication phase, but ssh1 doesn't
678  * support that
679  */
680 void
681 do_pam_chauthtok(void)
682 {
683         struct pam_conv pam_conv;
684
685         pam_conv.conv = pam_chauthtok_conv;
686         pam_conv.appdata_ptr = NULL;
687
688         if (use_privsep)
689                 fatal("Password expired (unable to change with privsep)");
690         sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
691             (const void *)&pam_conv);
692         if (sshpam_err != PAM_SUCCESS)
693                 fatal("PAM: failed to set PAM_CONV: %s",
694                     pam_strerror(sshpam_handle, sshpam_err));
695         debug("PAM: changing password");
696         sshpam_err = pam_chauthtok(sshpam_handle, PAM_CHANGE_EXPIRED_AUTHTOK);
697         if (sshpam_err != PAM_SUCCESS)
698                 fatal("PAM: pam_chauthtok(): %s",
699                     pam_strerror(sshpam_handle, sshpam_err));
700 }
701
702 /* 
703  * Set a PAM environment string. We need to do this so that the session
704  * modules can handle things like Kerberos/GSI credentials that appear
705  * during the ssh authentication process.
706  */
707
708 int
709 do_pam_putenv(char *name, char *value) 
710 {
711         int ret = 1;
712 #ifdef HAVE_PAM_PUTENV  
713         char *compound;
714         size_t len;
715
716         len = strlen(name) + strlen(value) + 2;
717         compound = xmalloc(len);
718
719         snprintf(compound, len, "%s=%s", name, value);
720         ret = pam_putenv(sshpam_handle, compound);
721         xfree(compound);
722 #endif
723
724         return (ret);
725 }
726
727 void
728 print_pam_messages(void)
729 {
730         /* XXX */
731 }
732
733 char **
734 fetch_pam_environment(void)
735 {
736 #ifdef HAVE_PAM_GETENVLIST
737         debug("PAM: retrieving environment");
738         return (pam_getenvlist(sshpam_handle));
739 #else
740         return (NULL);
741 #endif
742 }
743
744 void
745 free_pam_environment(char **env)
746 {
747         char **envp;
748
749         if (env == NULL)
750                 return;
751
752         for (envp = env; *envp; envp++)
753                 xfree(*envp);
754         xfree(env);
755 }
756
757 #endif /* USE_PAM */
This page took 0.134604 seconds and 5 git commands to generate.