]> andersk Git - openssh.git/blob - session.c
- markus@cvs.openbsd.org 2003/08/22 10:56:09
[openssh.git] / session.c
1 /*
2  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3  *                    All rights reserved
4  *
5  * As far as I am concerned, the code I have written for this software
6  * can be used freely for any purpose.  Any derived versions of this
7  * software must be clearly marked as such, and if the derived work is
8  * incompatible with the protocol description in the RFC file, it must be
9  * called by a name other than "ssh" or "Secure Shell".
10  *
11  * SSH2 support by Markus Friedl.
12  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include "includes.h"
36 RCSID("$OpenBSD: session.c,v 1.161 2003/08/22 10:56:09 markus Exp $");
37
38 #include "ssh.h"
39 #include "ssh1.h"
40 #include "ssh2.h"
41 #include "xmalloc.h"
42 #include "sshpty.h"
43 #include "packet.h"
44 #include "buffer.h"
45 #include "mpaux.h"
46 #include "uidswap.h"
47 #include "compat.h"
48 #include "channels.h"
49 #include "bufaux.h"
50 #include "auth.h"
51 #include "auth-options.h"
52 #include "pathnames.h"
53 #include "log.h"
54 #include "servconf.h"
55 #include "sshlogin.h"
56 #include "serverloop.h"
57 #include "canohost.h"
58 #include "session.h"
59 #include "monitor_wrap.h"
60
61 #ifdef GSSAPI
62 #include "ssh-gss.h"
63 #endif
64
65 /* func */
66
67 Session *session_new(void);
68 void    session_set_fds(Session *, int, int, int);
69 void    session_pty_cleanup(void *);
70 void    session_proctitle(Session *);
71 int     session_setup_x11fwd(Session *);
72 void    do_exec_pty(Session *, const char *);
73 void    do_exec_no_pty(Session *, const char *);
74 void    do_exec(Session *, const char *);
75 void    do_login(Session *, const char *);
76 #ifdef LOGIN_NEEDS_UTMPX
77 static void     do_pre_login(Session *s);
78 #endif
79 void    do_child(Session *, const char *);
80 void    do_motd(void);
81 int     check_quietlogin(Session *, const char *);
82
83 static void do_authenticated1(Authctxt *);
84 static void do_authenticated2(Authctxt *);
85
86 static int session_pty_req(Session *);
87
88 /* import */
89 extern ServerOptions options;
90 extern char *__progname;
91 extern int log_stderr;
92 extern int debug_flag;
93 extern u_int utmp_len;
94 extern int startup_pipe;
95 extern void destroy_sensitive_data(void);
96 extern Buffer loginmsg;
97
98 /* original command from peer. */
99 const char *original_command = NULL;
100
101 /* data */
102 #define MAX_SESSIONS 10
103 Session sessions[MAX_SESSIONS];
104
105 #ifdef HAVE_LOGIN_CAP
106 login_cap_t *lc;
107 #endif
108
109 /* Name and directory of socket for authentication agent forwarding. */
110 static char *auth_sock_name = NULL;
111 static char *auth_sock_dir = NULL;
112
113 /* removes the agent forwarding socket */
114
115 static void
116 auth_sock_cleanup_proc(void *_pw)
117 {
118         struct passwd *pw = _pw;
119
120         if (auth_sock_name != NULL) {
121                 temporarily_use_uid(pw);
122                 unlink(auth_sock_name);
123                 rmdir(auth_sock_dir);
124                 auth_sock_name = NULL;
125                 restore_uid();
126         }
127 }
128
129 static int
130 auth_input_request_forwarding(struct passwd * pw)
131 {
132         Channel *nc;
133         int sock;
134         struct sockaddr_un sunaddr;
135
136         if (auth_sock_name != NULL) {
137                 error("authentication forwarding requested twice.");
138                 return 0;
139         }
140
141         /* Temporarily drop privileged uid for mkdir/bind. */
142         temporarily_use_uid(pw);
143
144         /* Allocate a buffer for the socket name, and format the name. */
145         auth_sock_name = xmalloc(MAXPATHLEN);
146         auth_sock_dir = xmalloc(MAXPATHLEN);
147         strlcpy(auth_sock_dir, "/tmp/ssh-XXXXXXXX", MAXPATHLEN);
148
149         /* Create private directory for socket */
150         if (mkdtemp(auth_sock_dir) == NULL) {
151                 packet_send_debug("Agent forwarding disabled: "
152                     "mkdtemp() failed: %.100s", strerror(errno));
153                 restore_uid();
154                 xfree(auth_sock_name);
155                 xfree(auth_sock_dir);
156                 auth_sock_name = NULL;
157                 auth_sock_dir = NULL;
158                 return 0;
159         }
160         snprintf(auth_sock_name, MAXPATHLEN, "%s/agent.%ld",
161                  auth_sock_dir, (long) getpid());
162
163         /* delete agent socket on fatal() */
164         fatal_add_cleanup(auth_sock_cleanup_proc, pw);
165
166         /* Create the socket. */
167         sock = socket(AF_UNIX, SOCK_STREAM, 0);
168         if (sock < 0)
169                 packet_disconnect("socket: %.100s", strerror(errno));
170
171         /* Bind it to the name. */
172         memset(&sunaddr, 0, sizeof(sunaddr));
173         sunaddr.sun_family = AF_UNIX;
174         strlcpy(sunaddr.sun_path, auth_sock_name, sizeof(sunaddr.sun_path));
175
176         if (bind(sock, (struct sockaddr *) & sunaddr, sizeof(sunaddr)) < 0)
177                 packet_disconnect("bind: %.100s", strerror(errno));
178
179         /* Restore the privileged uid. */
180         restore_uid();
181
182         /* Start listening on the socket. */
183         if (listen(sock, 5) < 0)
184                 packet_disconnect("listen: %.100s", strerror(errno));
185
186         /* Allocate a channel for the authentication agent socket. */
187         nc = channel_new("auth socket",
188             SSH_CHANNEL_AUTH_SOCKET, sock, sock, -1,
189             CHAN_X11_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT,
190             0, "auth socket", 1);
191         strlcpy(nc->path, auth_sock_name, sizeof(nc->path));
192         return 1;
193 }
194
195
196 void
197 do_authenticated(Authctxt *authctxt)
198 {
199         setproctitle("%s", authctxt->pw->pw_name);
200
201         /*
202          * Cancel the alarm we set to limit the time taken for
203          * authentication.
204          */
205         alarm(0);
206         if (startup_pipe != -1) {
207                 close(startup_pipe);
208                 startup_pipe = -1;
209         }
210
211         /* setup the channel layer */
212         if (!no_port_forwarding_flag && options.allow_tcp_forwarding)
213                 channel_permit_all_opens();
214
215         if (compat20)
216                 do_authenticated2(authctxt);
217         else
218                 do_authenticated1(authctxt);
219
220         /* remove agent socket */
221         if (auth_sock_name != NULL)
222                 auth_sock_cleanup_proc(authctxt->pw);
223 #ifdef KRB5
224         if (options.kerberos_ticket_cleanup)
225                 krb5_cleanup_proc(authctxt);
226 #endif
227 }
228
229 /*
230  * Prepares for an interactive session.  This is called after the user has
231  * been successfully authenticated.  During this message exchange, pseudo
232  * terminals are allocated, X11, TCP/IP, and authentication agent forwardings
233  * are requested, etc.
234  */
235 static void
236 do_authenticated1(Authctxt *authctxt)
237 {
238         Session *s;
239         char *command;
240         int success, type, screen_flag;
241         int enable_compression_after_reply = 0;
242         u_int proto_len, data_len, dlen, compression_level = 0;
243
244         s = session_new();
245         s->authctxt = authctxt;
246         s->pw = authctxt->pw;
247
248         /*
249          * We stay in this loop until the client requests to execute a shell
250          * or a command.
251          */
252         for (;;) {
253                 success = 0;
254
255                 /* Get a packet from the client. */
256                 type = packet_read();
257
258                 /* Process the packet. */
259                 switch (type) {
260                 case SSH_CMSG_REQUEST_COMPRESSION:
261                         compression_level = packet_get_int();
262                         packet_check_eom();
263                         if (compression_level < 1 || compression_level > 9) {
264                                 packet_send_debug("Received illegal compression level %d.",
265                                     compression_level);
266                                 break;
267                         }
268                         if (!options.compression) {
269                                 debug2("compression disabled");
270                                 break;
271                         }
272                         /* Enable compression after we have responded with SUCCESS. */
273                         enable_compression_after_reply = 1;
274                         success = 1;
275                         break;
276
277                 case SSH_CMSG_REQUEST_PTY:
278                         success = session_pty_req(s);
279                         break;
280
281                 case SSH_CMSG_X11_REQUEST_FORWARDING:
282                         s->auth_proto = packet_get_string(&proto_len);
283                         s->auth_data = packet_get_string(&data_len);
284
285                         screen_flag = packet_get_protocol_flags() &
286                             SSH_PROTOFLAG_SCREEN_NUMBER;
287                         debug2("SSH_PROTOFLAG_SCREEN_NUMBER: %d", screen_flag);
288
289                         if (packet_remaining() == 4) {
290                                 if (!screen_flag)
291                                         debug2("Buggy client: "
292                                             "X11 screen flag missing");
293                                 s->screen = packet_get_int();
294                         } else {
295                                 s->screen = 0;
296                         }
297                         packet_check_eom();
298                         success = session_setup_x11fwd(s);
299                         if (!success) {
300                                 xfree(s->auth_proto);
301                                 xfree(s->auth_data);
302                                 s->auth_proto = NULL;
303                                 s->auth_data = NULL;
304                         }
305                         break;
306
307                 case SSH_CMSG_AGENT_REQUEST_FORWARDING:
308                         if (no_agent_forwarding_flag || compat13) {
309                                 debug("Authentication agent forwarding not permitted for this authentication.");
310                                 break;
311                         }
312                         debug("Received authentication agent forwarding request.");
313                         success = auth_input_request_forwarding(s->pw);
314                         break;
315
316                 case SSH_CMSG_PORT_FORWARD_REQUEST:
317                         if (no_port_forwarding_flag) {
318                                 debug("Port forwarding not permitted for this authentication.");
319                                 break;
320                         }
321                         if (!options.allow_tcp_forwarding) {
322                                 debug("Port forwarding not permitted.");
323                                 break;
324                         }
325                         debug("Received TCP/IP port forwarding request.");
326                         channel_input_port_forward_request(s->pw->pw_uid == 0, options.gateway_ports);
327                         success = 1;
328                         break;
329
330                 case SSH_CMSG_MAX_PACKET_SIZE:
331                         if (packet_set_maxsize(packet_get_int()) > 0)
332                                 success = 1;
333                         break;
334
335 #ifdef KRB5
336                 case SSH_CMSG_HAVE_KERBEROS_TGT:
337                         if (!options.kerberos_tgt_passing) {
338                                 verbose("Kerberos TGT passing disabled.");
339                         } else {
340                                 char *kdata = packet_get_string(&dlen);
341                                 packet_check_eom();
342
343                                 /* XXX - 0x41, used for AFS */
344                                 if (kdata[0] != 0x41) {
345                                         krb5_data tgt;
346                                         tgt.data = kdata;
347                                         tgt.length = dlen;
348
349                                         if (auth_krb5_tgt(s->authctxt, &tgt))
350                                                 success = 1;
351                                         else
352                                                 verbose("Kerberos v5 TGT refused for %.100s", s->authctxt->user);
353                                 }
354                                 xfree(kdata);
355                         }
356                         break;
357 #endif
358
359                 case SSH_CMSG_EXEC_SHELL:
360                 case SSH_CMSG_EXEC_CMD:
361                         if (type == SSH_CMSG_EXEC_CMD) {
362                                 command = packet_get_string(&dlen);
363                                 debug("Exec command '%.500s'", command);
364                                 do_exec(s, command);
365                                 xfree(command);
366                         } else {
367                                 do_exec(s, NULL);
368                         }
369                         packet_check_eom();
370                         session_close(s);
371                         return;
372
373                 default:
374                         /*
375                          * Any unknown messages in this phase are ignored,
376                          * and a failure message is returned.
377                          */
378                         logit("Unknown packet type received after authentication: %d", type);
379                 }
380                 packet_start(success ? SSH_SMSG_SUCCESS : SSH_SMSG_FAILURE);
381                 packet_send();
382                 packet_write_wait();
383
384                 /* Enable compression now that we have replied if appropriate. */
385                 if (enable_compression_after_reply) {
386                         enable_compression_after_reply = 0;
387                         packet_start_compression(compression_level);
388                 }
389         }
390 }
391
392 /*
393  * This is called to fork and execute a command when we have no tty.  This
394  * will call do_child from the child, and server_loop from the parent after
395  * setting up file descriptors and such.
396  */
397 void
398 do_exec_no_pty(Session *s, const char *command)
399 {
400         pid_t pid;
401
402 #ifdef USE_PIPES
403         int pin[2], pout[2], perr[2];
404         /* Allocate pipes for communicating with the program. */
405         if (pipe(pin) < 0 || pipe(pout) < 0 || pipe(perr) < 0)
406                 packet_disconnect("Could not create pipes: %.100s",
407                                   strerror(errno));
408 #else /* USE_PIPES */
409         int inout[2], err[2];
410         /* Uses socket pairs to communicate with the program. */
411         if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) < 0 ||
412             socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0)
413                 packet_disconnect("Could not create socket pairs: %.100s",
414                                   strerror(errno));
415 #endif /* USE_PIPES */
416         if (s == NULL)
417                 fatal("do_exec_no_pty: no session");
418
419         session_proctitle(s);
420
421 #if defined(USE_PAM)
422         if (options.use_pam) {
423                 do_pam_session(s->pw->pw_name, NULL);
424                 do_pam_setcred(1);
425                 if (is_pam_password_change_required())
426                         packet_disconnect("Password change required but no "
427                             "TTY available");
428         }
429 #endif /* USE_PAM */
430
431 #ifdef GSSAPI
432         temporarily_use_uid(s->pw);
433         ssh_gssapi_storecreds();
434         restore_uid();
435 #endif
436
437         /* Fork the child. */
438         if ((pid = fork()) == 0) {
439                 fatal_remove_all_cleanups();
440
441                 /* Child.  Reinitialize the log since the pid has changed. */
442                 log_init(__progname, options.log_level, options.log_facility, log_stderr);
443
444                 /*
445                  * Create a new session and process group since the 4.4BSD
446                  * setlogin() affects the entire process group.
447                  */
448                 if (setsid() < 0)
449                         error("setsid failed: %.100s", strerror(errno));
450
451 #ifdef USE_PIPES
452                 /*
453                  * Redirect stdin.  We close the parent side of the socket
454                  * pair, and make the child side the standard input.
455                  */
456                 close(pin[1]);
457                 if (dup2(pin[0], 0) < 0)
458                         perror("dup2 stdin");
459                 close(pin[0]);
460
461                 /* Redirect stdout. */
462                 close(pout[0]);
463                 if (dup2(pout[1], 1) < 0)
464                         perror("dup2 stdout");
465                 close(pout[1]);
466
467                 /* Redirect stderr. */
468                 close(perr[0]);
469                 if (dup2(perr[1], 2) < 0)
470                         perror("dup2 stderr");
471                 close(perr[1]);
472 #else /* USE_PIPES */
473                 /*
474                  * Redirect stdin, stdout, and stderr.  Stdin and stdout will
475                  * use the same socket, as some programs (particularly rdist)
476                  * seem to depend on it.
477                  */
478                 close(inout[1]);
479                 close(err[1]);
480                 if (dup2(inout[0], 0) < 0)      /* stdin */
481                         perror("dup2 stdin");
482                 if (dup2(inout[0], 1) < 0)      /* stdout.  Note: same socket as stdin. */
483                         perror("dup2 stdout");
484                 if (dup2(err[0], 2) < 0)        /* stderr */
485                         perror("dup2 stderr");
486 #endif /* USE_PIPES */
487
488 #ifdef _UNICOS
489                 cray_init_job(s->pw); /* set up cray jid and tmpdir */
490 #endif
491
492                 /* Do processing for the child (exec command etc). */
493                 do_child(s, command);
494                 /* NOTREACHED */
495         }
496 #ifdef _UNICOS
497         signal(WJSIGNAL, cray_job_termination_handler);
498 #endif /* _UNICOS */
499 #ifdef HAVE_CYGWIN
500         if (is_winnt)
501                 cygwin_set_impersonation_token(INVALID_HANDLE_VALUE);
502 #endif
503         if (pid < 0)
504                 packet_disconnect("fork failed: %.100s", strerror(errno));
505         s->pid = pid;
506         /* Set interactive/non-interactive mode. */
507         packet_set_interactive(s->display != NULL);
508 #ifdef USE_PIPES
509         /* We are the parent.  Close the child sides of the pipes. */
510         close(pin[0]);
511         close(pout[1]);
512         close(perr[1]);
513
514         if (compat20) {
515                 session_set_fds(s, pin[1], pout[0], s->is_subsystem ? -1 : perr[0]);
516         } else {
517                 /* Enter the interactive session. */
518                 server_loop(pid, pin[1], pout[0], perr[0]);
519                 /* server_loop has closed pin[1], pout[0], and perr[0]. */
520         }
521 #else /* USE_PIPES */
522         /* We are the parent.  Close the child sides of the socket pairs. */
523         close(inout[0]);
524         close(err[0]);
525
526         /*
527          * Enter the interactive session.  Note: server_loop must be able to
528          * handle the case that fdin and fdout are the same.
529          */
530         if (compat20) {
531                 session_set_fds(s, inout[1], inout[1], s->is_subsystem ? -1 : err[1]);
532         } else {
533                 server_loop(pid, inout[1], inout[1], err[1]);
534                 /* server_loop has closed inout[1] and err[1]. */
535         }
536 #endif /* USE_PIPES */
537 }
538
539 /*
540  * This is called to fork and execute a command when we have a tty.  This
541  * will call do_child from the child, and server_loop from the parent after
542  * setting up file descriptors, controlling tty, updating wtmp, utmp,
543  * lastlog, and other such operations.
544  */
545 void
546 do_exec_pty(Session *s, const char *command)
547 {
548         int fdout, ptyfd, ttyfd, ptymaster;
549         pid_t pid;
550
551         if (s == NULL)
552                 fatal("do_exec_pty: no session");
553         ptyfd = s->ptyfd;
554         ttyfd = s->ttyfd;
555
556 #if defined(USE_PAM)
557         if (options.use_pam) {
558                 do_pam_session(s->pw->pw_name, s->tty);
559                 do_pam_setcred(1);
560         }
561 #endif
562
563 #ifdef GSSAPI
564         temporarily_use_uid(s->pw);
565         ssh_gssapi_storecreds();
566         restore_uid();
567 #endif
568
569         /* Fork the child. */
570         if ((pid = fork()) == 0) {
571                 fatal_remove_all_cleanups();
572
573                 /* Child.  Reinitialize the log because the pid has changed. */
574                 log_init(__progname, options.log_level, options.log_facility, log_stderr);
575                 /* Close the master side of the pseudo tty. */
576                 close(ptyfd);
577
578                 /* Make the pseudo tty our controlling tty. */
579                 pty_make_controlling_tty(&ttyfd, s->tty);
580
581                 /* Redirect stdin/stdout/stderr from the pseudo tty. */
582                 if (dup2(ttyfd, 0) < 0)
583                         error("dup2 stdin: %s", strerror(errno));
584                 if (dup2(ttyfd, 1) < 0)
585                         error("dup2 stdout: %s", strerror(errno));
586                 if (dup2(ttyfd, 2) < 0)
587                         error("dup2 stderr: %s", strerror(errno));
588
589                 /* Close the extra descriptor for the pseudo tty. */
590                 close(ttyfd);
591
592                 /* record login, etc. similar to login(1) */
593 #ifndef HAVE_OSF_SIA
594                 if (!(options.use_login && command == NULL)) {
595 #ifdef _UNICOS
596                         cray_init_job(s->pw); /* set up cray jid and tmpdir */
597 #endif /* _UNICOS */
598                         do_login(s, command);
599                 }
600 # ifdef LOGIN_NEEDS_UTMPX
601                 else
602                         do_pre_login(s);
603 # endif
604 #endif
605
606                 /* Do common processing for the child, such as execing the command. */
607                 do_child(s, command);
608                 /* NOTREACHED */
609         }
610 #ifdef _UNICOS
611         signal(WJSIGNAL, cray_job_termination_handler);
612 #endif /* _UNICOS */
613 #ifdef HAVE_CYGWIN
614         if (is_winnt)
615                 cygwin_set_impersonation_token(INVALID_HANDLE_VALUE);
616 #endif
617         if (pid < 0)
618                 packet_disconnect("fork failed: %.100s", strerror(errno));
619         s->pid = pid;
620
621         /* Parent.  Close the slave side of the pseudo tty. */
622         close(ttyfd);
623
624         /*
625          * Create another descriptor of the pty master side for use as the
626          * standard input.  We could use the original descriptor, but this
627          * simplifies code in server_loop.  The descriptor is bidirectional.
628          */
629         fdout = dup(ptyfd);
630         if (fdout < 0)
631                 packet_disconnect("dup #1 failed: %.100s", strerror(errno));
632
633         /* we keep a reference to the pty master */
634         ptymaster = dup(ptyfd);
635         if (ptymaster < 0)
636                 packet_disconnect("dup #2 failed: %.100s", strerror(errno));
637         s->ptymaster = ptymaster;
638
639         /* Enter interactive session. */
640         packet_set_interactive(1);
641         if (compat20) {
642                 session_set_fds(s, ptyfd, fdout, -1);
643         } else {
644                 server_loop(pid, ptyfd, fdout, -1);
645                 /* server_loop _has_ closed ptyfd and fdout. */
646         }
647 }
648
649 #ifdef LOGIN_NEEDS_UTMPX
650 static void
651 do_pre_login(Session *s)
652 {
653         socklen_t fromlen;
654         struct sockaddr_storage from;
655         pid_t pid = getpid();
656
657         /*
658          * Get IP address of client. If the connection is not a socket, let
659          * the address be 0.0.0.0.
660          */
661         memset(&from, 0, sizeof(from));
662         fromlen = sizeof(from);
663         if (packet_connection_is_on_socket()) {
664                 if (getpeername(packet_get_connection_in(),
665                     (struct sockaddr *) & from, &fromlen) < 0) {
666                         debug("getpeername: %.100s", strerror(errno));
667                         fatal_cleanup();
668                 }
669         }
670
671         record_utmp_only(pid, s->tty, s->pw->pw_name,
672             get_remote_name_or_ip(utmp_len, options.use_dns),
673             (struct sockaddr *)&from, fromlen);
674 }
675 #endif
676
677 /*
678  * This is called to fork and execute a command.  If another command is
679  * to be forced, execute that instead.
680  */
681 void
682 do_exec(Session *s, const char *command)
683 {
684         if (forced_command) {
685                 original_command = command;
686                 command = forced_command;
687                 debug("Forced command '%.900s'", command);
688         }
689
690         if (s->ttyfd != -1)
691                 do_exec_pty(s, command);
692         else
693                 do_exec_no_pty(s, command);
694
695         original_command = NULL;
696 }
697
698
699 /* administrative, login(1)-like work */
700 void
701 do_login(Session *s, const char *command)
702 {
703         char *time_string;
704         socklen_t fromlen;
705         struct sockaddr_storage from;
706         struct passwd * pw = s->pw;
707         pid_t pid = getpid();
708
709         /*
710          * Get IP address of client. If the connection is not a socket, let
711          * the address be 0.0.0.0.
712          */
713         memset(&from, 0, sizeof(from));
714         fromlen = sizeof(from);
715         if (packet_connection_is_on_socket()) {
716                 if (getpeername(packet_get_connection_in(),
717                     (struct sockaddr *) & from, &fromlen) < 0) {
718                         debug("getpeername: %.100s", strerror(errno));
719                         fatal_cleanup();
720                 }
721         }
722
723         /* Record that there was a login on that tty from the remote host. */
724         if (!use_privsep)
725                 record_login(pid, s->tty, pw->pw_name, pw->pw_uid,
726                     get_remote_name_or_ip(utmp_len,
727                     options.use_dns),
728                     (struct sockaddr *)&from, fromlen);
729
730 #ifdef USE_PAM
731         /*
732          * If password change is needed, do it now.
733          * This needs to occur before the ~/.hushlogin check.
734          */
735         if (options.use_pam && is_pam_password_change_required()) {
736                 print_pam_messages();
737                 do_pam_chauthtok();
738                 /* XXX - signal [net] parent to enable forwardings */
739         }
740 #endif
741
742         if (check_quietlogin(s, command))
743                 return;
744
745 #ifdef USE_PAM
746         if (options.use_pam && !is_pam_password_change_required())
747                 print_pam_messages();
748 #endif /* USE_PAM */
749
750         /* display post-login message */
751         if (buffer_len(&loginmsg) > 0) {
752                 buffer_append(&loginmsg, "\0", 1);
753                 printf("%s\n", (char *)buffer_ptr(&loginmsg));
754         }
755         buffer_free(&loginmsg);
756
757 #ifndef NO_SSH_LASTLOG
758         if (options.print_lastlog && s->last_login_time != 0) {
759                 time_string = ctime(&s->last_login_time);
760                 if (strchr(time_string, '\n'))
761                         *strchr(time_string, '\n') = 0;
762                 if (strcmp(s->hostname, "") == 0)
763                         printf("Last login: %s\r\n", time_string);
764                 else
765                         printf("Last login: %s from %s\r\n", time_string,
766                             s->hostname);
767         }
768 #endif /* NO_SSH_LASTLOG */
769
770         do_motd();
771 }
772
773 /*
774  * Display the message of the day.
775  */
776 void
777 do_motd(void)
778 {
779         FILE *f;
780         char buf[256];
781
782         if (options.print_motd) {
783 #ifdef HAVE_LOGIN_CAP
784                 f = fopen(login_getcapstr(lc, "welcome", "/etc/motd",
785                     "/etc/motd"), "r");
786 #else
787                 f = fopen("/etc/motd", "r");
788 #endif
789                 if (f) {
790                         while (fgets(buf, sizeof(buf), f))
791                                 fputs(buf, stdout);
792                         fclose(f);
793                 }
794         }
795 }
796
797
798 /*
799  * Check for quiet login, either .hushlogin or command given.
800  */
801 int
802 check_quietlogin(Session *s, const char *command)
803 {
804         char buf[256];
805         struct passwd *pw = s->pw;
806         struct stat st;
807
808         /* Return 1 if .hushlogin exists or a command given. */
809         if (command != NULL)
810                 return 1;
811         snprintf(buf, sizeof(buf), "%.200s/.hushlogin", pw->pw_dir);
812 #ifdef HAVE_LOGIN_CAP
813         if (login_getcapbool(lc, "hushlogin", 0) || stat(buf, &st) >= 0)
814                 return 1;
815 #else
816         if (stat(buf, &st) >= 0)
817                 return 1;
818 #endif
819         return 0;
820 }
821
822 /*
823  * Sets the value of the given variable in the environment.  If the variable
824  * already exists, its value is overriden.
825  */
826 void
827 child_set_env(char ***envp, u_int *envsizep, const char *name,
828         const char *value)
829 {
830         u_int i, namelen;
831         char **env;
832
833         /*
834          * Find the slot where the value should be stored.  If the variable
835          * already exists, we reuse the slot; otherwise we append a new slot
836          * at the end of the array, expanding if necessary.
837          */
838         env = *envp;
839         namelen = strlen(name);
840         for (i = 0; env[i]; i++)
841                 if (strncmp(env[i], name, namelen) == 0 && env[i][namelen] == '=')
842                         break;
843         if (env[i]) {
844                 /* Reuse the slot. */
845                 xfree(env[i]);
846         } else {
847                 /* New variable.  Expand if necessary. */
848                 if (i >= (*envsizep) - 1) {
849                         if (*envsizep >= 1000)
850                                 fatal("child_set_env: too many env vars,"
851                                     " skipping: %.100s", name);
852                         (*envsizep) += 50;
853                         env = (*envp) = xrealloc(env, (*envsizep) * sizeof(char *));
854                 }
855                 /* Need to set the NULL pointer at end of array beyond the new slot. */
856                 env[i + 1] = NULL;
857         }
858
859         /* Allocate space and format the variable in the appropriate slot. */
860         env[i] = xmalloc(strlen(name) + 1 + strlen(value) + 1);
861         snprintf(env[i], strlen(name) + 1 + strlen(value) + 1, "%s=%s", name, value);
862 }
863
864 /*
865  * Reads environment variables from the given file and adds/overrides them
866  * into the environment.  If the file does not exist, this does nothing.
867  * Otherwise, it must consist of empty lines, comments (line starts with '#')
868  * and assignments of the form name=value.  No other forms are allowed.
869  */
870 static void
871 read_environment_file(char ***env, u_int *envsize,
872         const char *filename)
873 {
874         FILE *f;
875         char buf[4096];
876         char *cp, *value;
877         u_int lineno = 0;
878
879         f = fopen(filename, "r");
880         if (!f)
881                 return;
882
883         while (fgets(buf, sizeof(buf), f)) {
884                 if (++lineno > 1000)
885                         fatal("Too many lines in environment file %s", filename);
886                 for (cp = buf; *cp == ' ' || *cp == '\t'; cp++)
887                         ;
888                 if (!*cp || *cp == '#' || *cp == '\n')
889                         continue;
890                 if (strchr(cp, '\n'))
891                         *strchr(cp, '\n') = '\0';
892                 value = strchr(cp, '=');
893                 if (value == NULL) {
894                         fprintf(stderr, "Bad line %u in %.100s\n", lineno,
895                             filename);
896                         continue;
897                 }
898                 /*
899                  * Replace the equals sign by nul, and advance value to
900                  * the value string.
901                  */
902                 *value = '\0';
903                 value++;
904                 child_set_env(env, envsize, cp, value);
905         }
906         fclose(f);
907 }
908
909 void copy_environment(char **source, char ***env, u_int *envsize)
910 {
911         char *var_name, *var_val;
912         int i;
913
914         if (source == NULL)
915                 return;
916
917         for(i = 0; source[i] != NULL; i++) {
918                 var_name = xstrdup(source[i]);
919                 if ((var_val = strstr(var_name, "=")) == NULL) {
920                         xfree(var_name);
921                         continue;
922                 }
923                 *var_val++ = '\0';
924
925                 debug3("Copy environment: %s=%s", var_name, var_val);
926                 child_set_env(env, envsize, var_name, var_val);
927                 
928                 xfree(var_name);
929         }
930 }
931
932 static char **
933 do_setup_env(Session *s, const char *shell)
934 {
935         char buf[256];
936         u_int i, envsize;
937         char **env, *laddr;
938         struct passwd *pw = s->pw;
939
940         /* Initialize the environment. */
941         envsize = 100;
942         env = xmalloc(envsize * sizeof(char *));
943         env[0] = NULL;
944
945 #ifdef HAVE_CYGWIN
946         /*
947          * The Windows environment contains some setting which are
948          * important for a running system. They must not be dropped.
949          */
950         copy_environment(environ, &env, &envsize);
951 #endif
952
953 #ifdef GSSAPI
954         /* Allow any GSSAPI methods that we've used to alter 
955          * the childs environment as they see fit
956          */
957         ssh_gssapi_do_child(&env, &envsize);
958 #endif
959
960         if (!options.use_login) {
961                 /* Set basic environment. */
962                 child_set_env(&env, &envsize, "USER", pw->pw_name);
963                 child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
964 #ifdef _AIX
965                 child_set_env(&env, &envsize, "LOGIN", pw->pw_name);
966 #endif
967                 child_set_env(&env, &envsize, "HOME", pw->pw_dir);
968 #ifdef HAVE_LOGIN_CAP
969                 if (setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH) < 0)
970                         child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
971                 else
972                         child_set_env(&env, &envsize, "PATH", getenv("PATH"));
973 #else /* HAVE_LOGIN_CAP */
974 # ifndef HAVE_CYGWIN
975                 /*
976                  * There's no standard path on Windows. The path contains
977                  * important components pointing to the system directories,
978                  * needed for loading shared libraries. So the path better
979                  * remains intact here.
980                  */
981 #  ifdef SUPERUSER_PATH
982                 child_set_env(&env, &envsize, "PATH", 
983                     s->pw->pw_uid == 0 ? SUPERUSER_PATH : _PATH_STDPATH);
984 #  else 
985                 child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
986 #  endif /* SUPERUSER_PATH */
987 # endif /* HAVE_CYGWIN */
988 #endif /* HAVE_LOGIN_CAP */
989
990                 snprintf(buf, sizeof buf, "%.200s/%.50s",
991                          _PATH_MAILDIR, pw->pw_name);
992                 child_set_env(&env, &envsize, "MAIL", buf);
993
994                 /* Normal systems set SHELL by default. */
995                 child_set_env(&env, &envsize, "SHELL", shell);
996         }
997         if (getenv("TZ"))
998                 child_set_env(&env, &envsize, "TZ", getenv("TZ"));
999
1000         /* Set custom environment options from RSA authentication. */
1001         if (!options.use_login) {
1002                 while (custom_environment) {
1003                         struct envstring *ce = custom_environment;
1004                         char *str = ce->s;
1005
1006                         for (i = 0; str[i] != '=' && str[i]; i++)
1007                                 ;
1008                         if (str[i] == '=') {
1009                                 str[i] = 0;
1010                                 child_set_env(&env, &envsize, str, str + i + 1);
1011                         }
1012                         custom_environment = ce->next;
1013                         xfree(ce->s);
1014                         xfree(ce);
1015                 }
1016         }
1017
1018         /* SSH_CLIENT deprecated */
1019         snprintf(buf, sizeof buf, "%.50s %d %d",
1020             get_remote_ipaddr(), get_remote_port(), get_local_port());
1021         child_set_env(&env, &envsize, "SSH_CLIENT", buf);
1022
1023         laddr = get_local_ipaddr(packet_get_connection_in());
1024         snprintf(buf, sizeof buf, "%.50s %d %.50s %d",
1025             get_remote_ipaddr(), get_remote_port(), laddr, get_local_port());
1026         xfree(laddr);
1027         child_set_env(&env, &envsize, "SSH_CONNECTION", buf);
1028
1029         if (s->ttyfd != -1)
1030                 child_set_env(&env, &envsize, "SSH_TTY", s->tty);
1031         if (s->term)
1032                 child_set_env(&env, &envsize, "TERM", s->term);
1033         if (s->display)
1034                 child_set_env(&env, &envsize, "DISPLAY", s->display);
1035         if (original_command)
1036                 child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND",
1037                     original_command);
1038
1039 #ifdef _UNICOS
1040         if (cray_tmpdir[0] != '\0')
1041                 child_set_env(&env, &envsize, "TMPDIR", cray_tmpdir);
1042 #endif /* _UNICOS */
1043
1044 #ifdef _AIX
1045         {
1046                 char *cp;
1047
1048                 if ((cp = getenv("AUTHSTATE")) != NULL)
1049                         child_set_env(&env, &envsize, "AUTHSTATE", cp);
1050                 if ((cp = getenv("KRB5CCNAME")) != NULL)
1051                         child_set_env(&env, &envsize, "KRB5CCNAME", cp);
1052                 read_environment_file(&env, &envsize, "/etc/environment");
1053         }
1054 #endif
1055 #ifdef KRB5
1056         if (s->authctxt->krb5_ticket_file)
1057                 child_set_env(&env, &envsize, "KRB5CCNAME",
1058                     s->authctxt->krb5_ticket_file);
1059 #endif
1060 #ifdef USE_PAM
1061         /*
1062          * Pull in any environment variables that may have
1063          * been set by PAM.
1064          */
1065         if (options.use_pam) {
1066                 char **p = fetch_pam_environment();
1067
1068                 copy_environment(p, &env, &envsize);
1069                 free_pam_environment(p);
1070         }
1071 #endif /* USE_PAM */
1072
1073         if (auth_sock_name != NULL)
1074                 child_set_env(&env, &envsize, SSH_AUTHSOCKET_ENV_NAME,
1075                     auth_sock_name);
1076
1077         /* read $HOME/.ssh/environment. */
1078         if (options.permit_user_env && !options.use_login) {
1079                 snprintf(buf, sizeof buf, "%.200s/.ssh/environment",
1080                     strcmp(pw->pw_dir, "/") ? pw->pw_dir : "");
1081                 read_environment_file(&env, &envsize, buf);
1082         }
1083         if (debug_flag) {
1084                 /* dump the environment */
1085                 fprintf(stderr, "Environment:\n");
1086                 for (i = 0; env[i]; i++)
1087                         fprintf(stderr, "  %.200s\n", env[i]);
1088         }
1089         return env;
1090 }
1091
1092 /*
1093  * Run $HOME/.ssh/rc, /etc/ssh/sshrc, or xauth (whichever is found
1094  * first in this order).
1095  */
1096 static void
1097 do_rc_files(Session *s, const char *shell)
1098 {
1099         FILE *f = NULL;
1100         char cmd[1024];
1101         int do_xauth;
1102         struct stat st;
1103
1104         do_xauth =
1105             s->display != NULL && s->auth_proto != NULL && s->auth_data != NULL;
1106
1107         /* ignore _PATH_SSH_USER_RC for subsystems */
1108         if (!s->is_subsystem && (stat(_PATH_SSH_USER_RC, &st) >= 0)) {
1109                 snprintf(cmd, sizeof cmd, "%s -c '%s %s'",
1110                     shell, _PATH_BSHELL, _PATH_SSH_USER_RC);
1111                 if (debug_flag)
1112                         fprintf(stderr, "Running %s\n", cmd);
1113                 f = popen(cmd, "w");
1114                 if (f) {
1115                         if (do_xauth)
1116                                 fprintf(f, "%s %s\n", s->auth_proto,
1117                                     s->auth_data);
1118                         pclose(f);
1119                 } else
1120                         fprintf(stderr, "Could not run %s\n",
1121                             _PATH_SSH_USER_RC);
1122         } else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) {
1123                 if (debug_flag)
1124                         fprintf(stderr, "Running %s %s\n", _PATH_BSHELL,
1125                             _PATH_SSH_SYSTEM_RC);
1126                 f = popen(_PATH_BSHELL " " _PATH_SSH_SYSTEM_RC, "w");
1127                 if (f) {
1128                         if (do_xauth)
1129                                 fprintf(f, "%s %s\n", s->auth_proto,
1130                                     s->auth_data);
1131                         pclose(f);
1132                 } else
1133                         fprintf(stderr, "Could not run %s\n",
1134                             _PATH_SSH_SYSTEM_RC);
1135         } else if (do_xauth && options.xauth_location != NULL) {
1136                 /* Add authority data to .Xauthority if appropriate. */
1137                 if (debug_flag) {
1138                         fprintf(stderr,
1139                             "Running %.500s remove %.100s\n",
1140                             options.xauth_location, s->auth_display);
1141                         fprintf(stderr,
1142                             "%.500s add %.100s %.100s %.100s\n",
1143                             options.xauth_location, s->auth_display,
1144                             s->auth_proto, s->auth_data);
1145                 }
1146                 snprintf(cmd, sizeof cmd, "%s -q -",
1147                     options.xauth_location);
1148                 f = popen(cmd, "w");
1149                 if (f) {
1150                         fprintf(f, "remove %s\n",
1151                             s->auth_display);
1152                         fprintf(f, "add %s %s %s\n",
1153                             s->auth_display, s->auth_proto,
1154                             s->auth_data);
1155                         pclose(f);
1156                 } else {
1157                         fprintf(stderr, "Could not run %s\n",
1158                             cmd);
1159                 }
1160         }
1161 }
1162
1163 static void
1164 do_nologin(struct passwd *pw)
1165 {
1166         FILE *f = NULL;
1167         char buf[1024];
1168
1169 #ifdef HAVE_LOGIN_CAP
1170         if (!login_getcapbool(lc, "ignorenologin", 0) && pw->pw_uid)
1171                 f = fopen(login_getcapstr(lc, "nologin", _PATH_NOLOGIN,
1172                     _PATH_NOLOGIN), "r");
1173 #else
1174         if (pw->pw_uid)
1175                 f = fopen(_PATH_NOLOGIN, "r");
1176 #endif
1177         if (f) {
1178                 /* /etc/nologin exists.  Print its contents and exit. */
1179                 logit("User %.100s not allowed because %s exists",
1180                     pw->pw_name, _PATH_NOLOGIN);
1181                 while (fgets(buf, sizeof(buf), f))
1182                         fputs(buf, stderr);
1183                 fclose(f);
1184                 fflush(NULL);
1185                 exit(254);
1186         }
1187 }
1188
1189 /* Set login name, uid, gid, and groups. */
1190 void
1191 do_setusercontext(struct passwd *pw)
1192 {
1193 #ifndef HAVE_CYGWIN
1194         if (getuid() == 0 || geteuid() == 0)
1195 #endif /* HAVE_CYGWIN */
1196         {
1197
1198 #ifdef HAVE_SETPCRED
1199                 if (setpcred(pw->pw_name, (char **)NULL) == -1)
1200                         fatal("Failed to set process credentials");
1201 #endif /* HAVE_SETPCRED */
1202 #ifdef HAVE_LOGIN_CAP
1203 # ifdef __bsdi__
1204                 setpgid(0, 0);
1205 # endif
1206                 if (setusercontext(lc, pw, pw->pw_uid,
1207                     (LOGIN_SETALL & ~LOGIN_SETPATH)) < 0) {
1208                         perror("unable to set user context");
1209                         exit(1);
1210                 }
1211 #else
1212 # if defined(HAVE_GETLUID) && defined(HAVE_SETLUID)
1213                 /* Sets login uid for accounting */
1214                 if (getluid() == -1 && setluid(pw->pw_uid) == -1)
1215                         error("setluid: %s", strerror(errno));
1216 # endif /* defined(HAVE_GETLUID) && defined(HAVE_SETLUID) */
1217
1218                 if (setlogin(pw->pw_name) < 0)
1219                         error("setlogin failed: %s", strerror(errno));
1220                 if (setgid(pw->pw_gid) < 0) {
1221                         perror("setgid");
1222                         exit(1);
1223                 }
1224                 /* Initialize the group list. */
1225                 if (initgroups(pw->pw_name, pw->pw_gid) < 0) {
1226                         perror("initgroups");
1227                         exit(1);
1228                 }
1229                 endgrent();
1230 # ifdef USE_PAM
1231                 /*
1232                  * PAM credentials may take the form of supplementary groups. 
1233                  * These will have been wiped by the above initgroups() call.
1234                  * Reestablish them here.
1235                  */
1236                 if (options.use_pam)
1237                         do_pam_setcred(0);
1238 # endif /* USE_PAM */
1239 # if defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY)
1240                 irix_setusercontext(pw);
1241 #  endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */
1242 # ifdef _AIX
1243                 aix_usrinfo(pw);
1244 # endif /* _AIX */
1245                 /* Permanently switch to the desired uid. */
1246                 permanently_set_uid(pw);
1247 #endif
1248         }
1249
1250 #ifdef HAVE_CYGWIN
1251         if (is_winnt)
1252 #endif
1253         if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
1254                 fatal("Failed to set uids to %u.", (u_int) pw->pw_uid);
1255 }
1256
1257 static void
1258 launch_login(struct passwd *pw, const char *hostname)
1259 {
1260         /* Launch login(1). */
1261
1262         execl(LOGIN_PROGRAM, "login", "-h", hostname,
1263 #ifdef xxxLOGIN_NEEDS_TERM
1264                     (s->term ? s->term : "unknown"),
1265 #endif /* LOGIN_NEEDS_TERM */
1266 #ifdef LOGIN_NO_ENDOPT
1267             "-p", "-f", pw->pw_name, (char *)NULL);
1268 #else
1269             "-p", "-f", "--", pw->pw_name, (char *)NULL);
1270 #endif
1271
1272         /* Login couldn't be executed, die. */
1273
1274         perror("login");
1275         exit(1);
1276 }
1277
1278 /*
1279  * Performs common processing for the child, such as setting up the
1280  * environment, closing extra file descriptors, setting the user and group
1281  * ids, and executing the command or shell.
1282  */
1283 void
1284 do_child(Session *s, const char *command)
1285 {
1286         extern char **environ;
1287         char **env;
1288         char *argv[10];
1289         const char *shell, *shell0, *hostname = NULL;
1290         struct passwd *pw = s->pw;
1291         u_int i;
1292
1293         /* remove hostkey from the child's memory */
1294         destroy_sensitive_data();
1295
1296         /* login(1) is only called if we execute the login shell */
1297         if (options.use_login && command != NULL)
1298                 options.use_login = 0;
1299
1300 #ifdef _UNICOS
1301         cray_setup(pw->pw_uid, pw->pw_name, command);
1302 #endif /* _UNICOS */
1303
1304         /*
1305          * Login(1) does this as well, and it needs uid 0 for the "-h"
1306          * switch, so we let login(1) to this for us.
1307          */
1308         if (!options.use_login) {
1309 #ifdef HAVE_OSF_SIA
1310                 session_setup_sia(pw, s->ttyfd == -1 ? NULL : s->tty);
1311                 if (!check_quietlogin(s, command))
1312                         do_motd();
1313 #else /* HAVE_OSF_SIA */
1314                 do_nologin(pw);
1315                 do_setusercontext(pw);
1316 #endif /* HAVE_OSF_SIA */
1317         }
1318
1319         /*
1320          * Get the shell from the password data.  An empty shell field is
1321          * legal, and means /bin/sh.
1322          */
1323         shell = (pw->pw_shell[0] == '\0') ? _PATH_BSHELL : pw->pw_shell;
1324
1325         /*
1326          * Make sure $SHELL points to the shell from the password file,
1327          * even if shell is overridden from login.conf
1328          */
1329         env = do_setup_env(s, shell);
1330
1331 #ifdef HAVE_LOGIN_CAP
1332         shell = login_getcapstr(lc, "shell", (char *)shell, (char *)shell);
1333 #endif
1334
1335         /* we have to stash the hostname before we close our socket. */
1336         if (options.use_login)
1337                 hostname = get_remote_name_or_ip(utmp_len,
1338                     options.use_dns);
1339         /*
1340          * Close the connection descriptors; note that this is the child, and
1341          * the server will still have the socket open, and it is important
1342          * that we do not shutdown it.  Note that the descriptors cannot be
1343          * closed before building the environment, as we call
1344          * get_remote_ipaddr there.
1345          */
1346         if (packet_get_connection_in() == packet_get_connection_out())
1347                 close(packet_get_connection_in());
1348         else {
1349                 close(packet_get_connection_in());
1350                 close(packet_get_connection_out());
1351         }
1352         /*
1353          * Close all descriptors related to channels.  They will still remain
1354          * open in the parent.
1355          */
1356         /* XXX better use close-on-exec? -markus */
1357         channel_close_all();
1358
1359         /*
1360          * Close any extra file descriptors.  Note that there may still be
1361          * descriptors left by system functions.  They will be closed later.
1362          */
1363         endpwent();
1364
1365         /*
1366          * Close any extra open file descriptors so that we don\'t have them
1367          * hanging around in clients.  Note that we want to do this after
1368          * initgroups, because at least on Solaris 2.3 it leaves file
1369          * descriptors open.
1370          */
1371         for (i = 3; i < 64; i++)
1372                 close(i);
1373
1374         /*
1375          * Must take new environment into use so that .ssh/rc,
1376          * /etc/ssh/sshrc and xauth are run in the proper environment.
1377          */
1378         environ = env;
1379
1380         /* Change current directory to the user\'s home directory. */
1381         if (chdir(pw->pw_dir) < 0) {
1382                 fprintf(stderr, "Could not chdir to home directory %s: %s\n",
1383                     pw->pw_dir, strerror(errno));
1384 #ifdef HAVE_LOGIN_CAP
1385                 if (login_getcapbool(lc, "requirehome", 0))
1386                         exit(1);
1387 #endif
1388         }
1389
1390         if (!options.use_login)
1391                 do_rc_files(s, shell);
1392
1393         /* restore SIGPIPE for child */
1394         signal(SIGPIPE,  SIG_DFL);
1395
1396         if (options.use_login) {
1397                 launch_login(pw, hostname);
1398                 /* NEVERREACHED */
1399         }
1400
1401         /* Get the last component of the shell name. */
1402         if ((shell0 = strrchr(shell, '/')) != NULL)
1403                 shell0++;
1404         else
1405                 shell0 = shell;
1406
1407         /*
1408          * If we have no command, execute the shell.  In this case, the shell
1409          * name to be passed in argv[0] is preceded by '-' to indicate that
1410          * this is a login shell.
1411          */
1412         if (!command) {
1413                 char argv0[256];
1414
1415                 /* Start the shell.  Set initial character to '-'. */
1416                 argv0[0] = '-';
1417
1418                 if (strlcpy(argv0 + 1, shell0, sizeof(argv0) - 1)
1419                     >= sizeof(argv0) - 1) {
1420                         errno = EINVAL;
1421                         perror(shell);
1422                         exit(1);
1423                 }
1424
1425                 /* Execute the shell. */
1426                 argv[0] = argv0;
1427                 argv[1] = NULL;
1428                 execve(shell, argv, env);
1429
1430                 /* Executing the shell failed. */
1431                 perror(shell);
1432                 exit(1);
1433         }
1434         /*
1435          * Execute the command using the user's shell.  This uses the -c
1436          * option to execute the command.
1437          */
1438         argv[0] = (char *) shell0;
1439         argv[1] = "-c";
1440         argv[2] = (char *) command;
1441         argv[3] = NULL;
1442         execve(shell, argv, env);
1443         perror(shell);
1444         exit(1);
1445 }
1446
1447 Session *
1448 session_new(void)
1449 {
1450         int i;
1451         static int did_init = 0;
1452         if (!did_init) {
1453                 debug("session_new: init");
1454                 for (i = 0; i < MAX_SESSIONS; i++) {
1455                         sessions[i].used = 0;
1456                 }
1457                 did_init = 1;
1458         }
1459         for (i = 0; i < MAX_SESSIONS; i++) {
1460                 Session *s = &sessions[i];
1461                 if (! s->used) {
1462                         memset(s, 0, sizeof(*s));
1463                         s->chanid = -1;
1464                         s->ptyfd = -1;
1465                         s->ttyfd = -1;
1466                         s->used = 1;
1467                         s->self = i;
1468                         debug("session_new: session %d", i);
1469                         return s;
1470                 }
1471         }
1472         return NULL;
1473 }
1474
1475 static void
1476 session_dump(void)
1477 {
1478         int i;
1479         for (i = 0; i < MAX_SESSIONS; i++) {
1480                 Session *s = &sessions[i];
1481                 debug("dump: used %d session %d %p channel %d pid %ld",
1482                     s->used,
1483                     s->self,
1484                     s,
1485                     s->chanid,
1486                     (long)s->pid);
1487         }
1488 }
1489
1490 int
1491 session_open(Authctxt *authctxt, int chanid)
1492 {
1493         Session *s = session_new();
1494         debug("session_open: channel %d", chanid);
1495         if (s == NULL) {
1496                 error("no more sessions");
1497                 return 0;
1498         }
1499         s->authctxt = authctxt;
1500         s->pw = authctxt->pw;
1501         if (s->pw == NULL)
1502                 fatal("no user for session %d", s->self);
1503         debug("session_open: session %d: link with channel %d", s->self, chanid);
1504         s->chanid = chanid;
1505         return 1;
1506 }
1507
1508 Session *
1509 session_by_tty(char *tty)
1510 {
1511         int i;
1512         for (i = 0; i < MAX_SESSIONS; i++) {
1513                 Session *s = &sessions[i];
1514                 if (s->used && s->ttyfd != -1 && strcmp(s->tty, tty) == 0) {
1515                         debug("session_by_tty: session %d tty %s", i, tty);
1516                         return s;
1517                 }
1518         }
1519         debug("session_by_tty: unknown tty %.100s", tty);
1520         session_dump();
1521         return NULL;
1522 }
1523
1524 static Session *
1525 session_by_channel(int id)
1526 {
1527         int i;
1528         for (i = 0; i < MAX_SESSIONS; i++) {
1529                 Session *s = &sessions[i];
1530                 if (s->used && s->chanid == id) {
1531                         debug("session_by_channel: session %d channel %d", i, id);
1532                         return s;
1533                 }
1534         }
1535         debug("session_by_channel: unknown channel %d", id);
1536         session_dump();
1537         return NULL;
1538 }
1539
1540 static Session *
1541 session_by_pid(pid_t pid)
1542 {
1543         int i;
1544         debug("session_by_pid: pid %ld", (long)pid);
1545         for (i = 0; i < MAX_SESSIONS; i++) {
1546                 Session *s = &sessions[i];
1547                 if (s->used && s->pid == pid)
1548                         return s;
1549         }
1550         error("session_by_pid: unknown pid %ld", (long)pid);
1551         session_dump();
1552         return NULL;
1553 }
1554
1555 static int
1556 session_window_change_req(Session *s)
1557 {
1558         s->col = packet_get_int();
1559         s->row = packet_get_int();
1560         s->xpixel = packet_get_int();
1561         s->ypixel = packet_get_int();
1562         packet_check_eom();
1563         pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
1564         return 1;
1565 }
1566
1567 static int
1568 session_pty_req(Session *s)
1569 {
1570         u_int len;
1571         int n_bytes;
1572
1573         if (no_pty_flag) {
1574                 debug("Allocating a pty not permitted for this authentication.");
1575                 return 0;
1576         }
1577         if (s->ttyfd != -1) {
1578                 packet_disconnect("Protocol error: you already have a pty.");
1579                 return 0;
1580         }
1581         /* Get the time and hostname when the user last logged in. */
1582         if (options.print_lastlog) {
1583                 s->hostname[0] = '\0';
1584                 s->last_login_time = get_last_login_time(s->pw->pw_uid,
1585                     s->pw->pw_name, s->hostname, sizeof(s->hostname));
1586         }
1587
1588         s->term = packet_get_string(&len);
1589
1590         if (compat20) {
1591                 s->col = packet_get_int();
1592                 s->row = packet_get_int();
1593         } else {
1594                 s->row = packet_get_int();
1595                 s->col = packet_get_int();
1596         }
1597         s->xpixel = packet_get_int();
1598         s->ypixel = packet_get_int();
1599
1600         if (strcmp(s->term, "") == 0) {
1601                 xfree(s->term);
1602                 s->term = NULL;
1603         }
1604
1605         /* Allocate a pty and open it. */
1606         debug("Allocating pty.");
1607         if (!PRIVSEP(pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty)))) {
1608                 if (s->term)
1609                         xfree(s->term);
1610                 s->term = NULL;
1611                 s->ptyfd = -1;
1612                 s->ttyfd = -1;
1613                 error("session_pty_req: session %d alloc failed", s->self);
1614                 return 0;
1615         }
1616         debug("session_pty_req: session %d alloc %s", s->self, s->tty);
1617
1618         /* for SSH1 the tty modes length is not given */
1619         if (!compat20)
1620                 n_bytes = packet_remaining();
1621         tty_parse_modes(s->ttyfd, &n_bytes);
1622
1623         /*
1624          * Add a cleanup function to clear the utmp entry and record logout
1625          * time in case we call fatal() (e.g., the connection gets closed).
1626          */
1627         fatal_add_cleanup(session_pty_cleanup, (void *)s);
1628         if (!use_privsep)
1629                 pty_setowner(s->pw, s->tty);
1630
1631         /* Set window size from the packet. */
1632         pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
1633
1634         packet_check_eom();
1635         session_proctitle(s);
1636         return 1;
1637 }
1638
1639 static int
1640 session_subsystem_req(Session *s)
1641 {
1642         struct stat st;
1643         u_int len;
1644         int success = 0;
1645         char *cmd, *subsys = packet_get_string(&len);
1646         int i;
1647
1648         packet_check_eom();
1649         logit("subsystem request for %.100s", subsys);
1650
1651         for (i = 0; i < options.num_subsystems; i++) {
1652                 if (strcmp(subsys, options.subsystem_name[i]) == 0) {
1653                         cmd = options.subsystem_command[i];
1654                         if (stat(cmd, &st) < 0) {
1655                                 error("subsystem: cannot stat %s: %s", cmd,
1656                                     strerror(errno));
1657                                 break;
1658                         }
1659                         debug("subsystem: exec() %s", cmd);
1660                         s->is_subsystem = 1;
1661                         do_exec(s, cmd);
1662                         success = 1;
1663                         break;
1664                 }
1665         }
1666
1667         if (!success)
1668                 logit("subsystem request for %.100s failed, subsystem not found",
1669                     subsys);
1670
1671         xfree(subsys);
1672         return success;
1673 }
1674
1675 static int
1676 session_x11_req(Session *s)
1677 {
1678         int success;
1679
1680         s->single_connection = packet_get_char();
1681         s->auth_proto = packet_get_string(NULL);
1682         s->auth_data = packet_get_string(NULL);
1683         s->screen = packet_get_int();
1684         packet_check_eom();
1685
1686         success = session_setup_x11fwd(s);
1687         if (!success) {
1688                 xfree(s->auth_proto);
1689                 xfree(s->auth_data);
1690                 s->auth_proto = NULL;
1691                 s->auth_data = NULL;
1692         }
1693         return success;
1694 }
1695
1696 static int
1697 session_shell_req(Session *s)
1698 {
1699         packet_check_eom();
1700         do_exec(s, NULL);
1701         return 1;
1702 }
1703
1704 static int
1705 session_exec_req(Session *s)
1706 {
1707         u_int len;
1708         char *command = packet_get_string(&len);
1709         packet_check_eom();
1710         do_exec(s, command);
1711         xfree(command);
1712         return 1;
1713 }
1714
1715 static int
1716 session_break_req(Session *s)
1717 {
1718         u_int break_length;
1719
1720         break_length = packet_get_int();        /* ignored */
1721         packet_check_eom();
1722
1723         if (s->ttyfd == -1 ||
1724             tcsendbreak(s->ttyfd, 0) < 0)
1725                 return 0;
1726         return 1;
1727 }
1728
1729 static int
1730 session_auth_agent_req(Session *s)
1731 {
1732         static int called = 0;
1733         packet_check_eom();
1734         if (no_agent_forwarding_flag) {
1735                 debug("session_auth_agent_req: no_agent_forwarding_flag");
1736                 return 0;
1737         }
1738         if (called) {
1739                 return 0;
1740         } else {
1741                 called = 1;
1742                 return auth_input_request_forwarding(s->pw);
1743         }
1744 }
1745
1746 int
1747 session_input_channel_req(Channel *c, const char *rtype)
1748 {
1749         int success = 0;
1750         Session *s;
1751
1752         if ((s = session_by_channel(c->self)) == NULL) {
1753                 logit("session_input_channel_req: no session %d req %.100s",
1754                     c->self, rtype);
1755                 return 0;
1756         }
1757         debug("session_input_channel_req: session %d req %s", s->self, rtype);
1758
1759         /*
1760          * a session is in LARVAL state until a shell, a command
1761          * or a subsystem is executed
1762          */
1763         if (c->type == SSH_CHANNEL_LARVAL) {
1764                 if (strcmp(rtype, "shell") == 0) {
1765                         success = session_shell_req(s);
1766                 } else if (strcmp(rtype, "exec") == 0) {
1767                         success = session_exec_req(s);
1768                 } else if (strcmp(rtype, "pty-req") == 0) {
1769                         success =  session_pty_req(s);
1770                 } else if (strcmp(rtype, "x11-req") == 0) {
1771                         success = session_x11_req(s);
1772                 } else if (strcmp(rtype, "auth-agent-req@openssh.com") == 0) {
1773                         success = session_auth_agent_req(s);
1774                 } else if (strcmp(rtype, "subsystem") == 0) {
1775                         success = session_subsystem_req(s);
1776                 } else if (strcmp(rtype, "break") == 0) {
1777                         success = session_break_req(s);
1778                 }
1779         }
1780         if (strcmp(rtype, "window-change") == 0) {
1781                 success = session_window_change_req(s);
1782         }
1783         return success;
1784 }
1785
1786 void
1787 session_set_fds(Session *s, int fdin, int fdout, int fderr)
1788 {
1789         if (!compat20)
1790                 fatal("session_set_fds: called for proto != 2.0");
1791         /*
1792          * now that have a child and a pipe to the child,
1793          * we can activate our channel and register the fd's
1794          */
1795         if (s->chanid == -1)
1796                 fatal("no channel for session %d", s->self);
1797         channel_set_fds(s->chanid,
1798             fdout, fdin, fderr,
1799             fderr == -1 ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ,
1800             1,
1801             CHAN_SES_WINDOW_DEFAULT);
1802 }
1803
1804 /*
1805  * Function to perform pty cleanup. Also called if we get aborted abnormally
1806  * (e.g., due to a dropped connection).
1807  */
1808 void
1809 session_pty_cleanup2(void *session)
1810 {
1811         Session *s = session;
1812
1813         if (s == NULL) {
1814                 error("session_pty_cleanup: no session");
1815                 return;
1816         }
1817         if (s->ttyfd == -1)
1818                 return;
1819
1820         debug("session_pty_cleanup: session %d release %s", s->self, s->tty);
1821
1822         /* Record that the user has logged out. */
1823         if (s->pid != 0)
1824                 record_logout(s->pid, s->tty, s->pw->pw_name);
1825
1826         /* Release the pseudo-tty. */
1827         if (getuid() == 0)
1828                 pty_release(s->tty);
1829
1830         /*
1831          * Close the server side of the socket pairs.  We must do this after
1832          * the pty cleanup, so that another process doesn't get this pty
1833          * while we're still cleaning up.
1834          */
1835         if (close(s->ptymaster) < 0)
1836                 error("close(s->ptymaster/%d): %s", s->ptymaster, strerror(errno));
1837
1838         /* unlink pty from session */
1839         s->ttyfd = -1;
1840 }
1841
1842 void
1843 session_pty_cleanup(void *session)
1844 {
1845         PRIVSEP(session_pty_cleanup2(session));
1846 }
1847
1848 static char *
1849 sig2name(int sig)
1850 {
1851 #define SSH_SIG(x) if (sig == SIG ## x) return #x
1852         SSH_SIG(ABRT);
1853         SSH_SIG(ALRM);
1854         SSH_SIG(FPE);
1855         SSH_SIG(HUP);
1856         SSH_SIG(ILL);
1857         SSH_SIG(INT);
1858         SSH_SIG(KILL);
1859         SSH_SIG(PIPE);
1860         SSH_SIG(QUIT);
1861         SSH_SIG(SEGV);
1862         SSH_SIG(TERM);
1863         SSH_SIG(USR1);
1864         SSH_SIG(USR2);
1865 #undef  SSH_SIG
1866         return "SIG@openssh.com";
1867 }
1868
1869 static void
1870 session_exit_message(Session *s, int status)
1871 {
1872         Channel *c;
1873
1874         if ((c = channel_lookup(s->chanid)) == NULL)
1875                 fatal("session_exit_message: session %d: no channel %d",
1876                     s->self, s->chanid);
1877         debug("session_exit_message: session %d channel %d pid %ld",
1878             s->self, s->chanid, (long)s->pid);
1879
1880         if (WIFEXITED(status)) {
1881                 channel_request_start(s->chanid, "exit-status", 0);
1882                 packet_put_int(WEXITSTATUS(status));
1883                 packet_send();
1884         } else if (WIFSIGNALED(status)) {
1885                 channel_request_start(s->chanid, "exit-signal", 0);
1886                 packet_put_cstring(sig2name(WTERMSIG(status)));
1887 #ifdef WCOREDUMP
1888                 packet_put_char(WCOREDUMP(status));
1889 #else /* WCOREDUMP */
1890                 packet_put_char(0);
1891 #endif /* WCOREDUMP */
1892                 packet_put_cstring("");
1893                 packet_put_cstring("");
1894                 packet_send();
1895         } else {
1896                 /* Some weird exit cause.  Just exit. */
1897                 packet_disconnect("wait returned status %04x.", status);
1898         }
1899
1900         /* disconnect channel */
1901         debug("session_exit_message: release channel %d", s->chanid);
1902         channel_cancel_cleanup(s->chanid);
1903         /*
1904          * emulate a write failure with 'chan_write_failed', nobody will be
1905          * interested in data we write.
1906          * Note that we must not call 'chan_read_failed', since there could
1907          * be some more data waiting in the pipe.
1908          */
1909         if (c->ostate != CHAN_OUTPUT_CLOSED)
1910                 chan_write_failed(c);
1911         s->chanid = -1;
1912 }
1913
1914 void
1915 session_close(Session *s)
1916 {
1917         debug("session_close: session %d pid %ld", s->self, (long)s->pid);
1918         if (s->ttyfd != -1) {
1919                 fatal_remove_cleanup(session_pty_cleanup, (void *)s);
1920                 session_pty_cleanup(s);
1921         }
1922         if (s->term)
1923                 xfree(s->term);
1924         if (s->display)
1925                 xfree(s->display);
1926         if (s->auth_display)
1927                 xfree(s->auth_display);
1928         if (s->auth_data)
1929                 xfree(s->auth_data);
1930         if (s->auth_proto)
1931                 xfree(s->auth_proto);
1932         s->used = 0;
1933         session_proctitle(s);
1934 }
1935
1936 void
1937 session_close_by_pid(pid_t pid, int status)
1938 {
1939         Session *s = session_by_pid(pid);
1940         if (s == NULL) {
1941                 debug("session_close_by_pid: no session for pid %ld",
1942                     (long)pid);
1943                 return;
1944         }
1945         if (s->chanid != -1)
1946                 session_exit_message(s, status);
1947         session_close(s);
1948 }
1949
1950 /*
1951  * this is called when a channel dies before
1952  * the session 'child' itself dies
1953  */
1954 void
1955 session_close_by_channel(int id, void *arg)
1956 {
1957         Session *s = session_by_channel(id);
1958         if (s == NULL) {
1959                 debug("session_close_by_channel: no session for id %d", id);
1960                 return;
1961         }
1962         debug("session_close_by_channel: channel %d child %ld",
1963             id, (long)s->pid);
1964         if (s->pid != 0) {
1965                 debug("session_close_by_channel: channel %d: has child", id);
1966                 /*
1967                  * delay detach of session, but release pty, since
1968                  * the fd's to the child are already closed
1969                  */
1970                 if (s->ttyfd != -1) {
1971                         fatal_remove_cleanup(session_pty_cleanup, (void *)s);
1972                         session_pty_cleanup(s);
1973                 }
1974                 return;
1975         }
1976         /* detach by removing callback */
1977         channel_cancel_cleanup(s->chanid);
1978         s->chanid = -1;
1979         session_close(s);
1980 }
1981
1982 void
1983 session_destroy_all(void (*closefunc)(Session *))
1984 {
1985         int i;
1986         for (i = 0; i < MAX_SESSIONS; i++) {
1987                 Session *s = &sessions[i];
1988                 if (s->used) {
1989                         if (closefunc != NULL)
1990                                 closefunc(s);
1991                         else
1992                                 session_close(s);
1993                 }
1994         }
1995 }
1996
1997 static char *
1998 session_tty_list(void)
1999 {
2000         static char buf[1024];
2001         int i;
2002         char *cp;
2003
2004         buf[0] = '\0';
2005         for (i = 0; i < MAX_SESSIONS; i++) {
2006                 Session *s = &sessions[i];
2007                 if (s->used && s->ttyfd != -1) {
2008                         
2009                         if (strncmp(s->tty, "/dev/", 5) != 0) {
2010                                 cp = strrchr(s->tty, '/');
2011                                 cp = (cp == NULL) ? s->tty : cp + 1;
2012                         } else
2013                                 cp = s->tty + 5;
2014                         
2015                         if (buf[0] != '\0')
2016                                 strlcat(buf, ",", sizeof buf);
2017                         strlcat(buf, cp, sizeof buf);
2018                 }
2019         }
2020         if (buf[0] == '\0')
2021                 strlcpy(buf, "notty", sizeof buf);
2022         return buf;
2023 }
2024
2025 void
2026 session_proctitle(Session *s)
2027 {
2028         if (s->pw == NULL)
2029                 error("no user for session %d", s->self);
2030         else
2031                 setproctitle("%s@%s", s->pw->pw_name, session_tty_list());
2032 }
2033
2034 int
2035 session_setup_x11fwd(Session *s)
2036 {
2037         struct stat st;
2038         char display[512], auth_display[512];
2039         char hostname[MAXHOSTNAMELEN];
2040
2041         if (no_x11_forwarding_flag) {
2042                 packet_send_debug("X11 forwarding disabled in user configuration file.");
2043                 return 0;
2044         }
2045         if (!options.x11_forwarding) {
2046                 debug("X11 forwarding disabled in server configuration file.");
2047                 return 0;
2048         }
2049         if (!options.xauth_location ||
2050             (stat(options.xauth_location, &st) == -1)) {
2051                 packet_send_debug("No xauth program; cannot forward with spoofing.");
2052                 return 0;
2053         }
2054         if (options.use_login) {
2055                 packet_send_debug("X11 forwarding disabled; "
2056                     "not compatible with UseLogin=yes.");
2057                 return 0;
2058         }
2059         if (s->display != NULL) {
2060                 debug("X11 display already set.");
2061                 return 0;
2062         }
2063         if (x11_create_display_inet(options.x11_display_offset,
2064             options.x11_use_localhost, s->single_connection,
2065             &s->display_number) == -1) {
2066                 debug("x11_create_display_inet failed.");
2067                 return 0;
2068         }
2069
2070         /* Set up a suitable value for the DISPLAY variable. */
2071         if (gethostname(hostname, sizeof(hostname)) < 0)
2072                 fatal("gethostname: %.100s", strerror(errno));
2073         /*
2074          * auth_display must be used as the displayname when the
2075          * authorization entry is added with xauth(1).  This will be
2076          * different than the DISPLAY string for localhost displays.
2077          */
2078         if (options.x11_use_localhost) {
2079                 snprintf(display, sizeof display, "localhost:%u.%u",
2080                     s->display_number, s->screen);
2081                 snprintf(auth_display, sizeof auth_display, "unix:%u.%u",
2082                     s->display_number, s->screen);
2083                 s->display = xstrdup(display);
2084                 s->auth_display = xstrdup(auth_display);
2085         } else {
2086 #ifdef IPADDR_IN_DISPLAY
2087                 struct hostent *he;
2088                 struct in_addr my_addr;
2089
2090                 he = gethostbyname(hostname);
2091                 if (he == NULL) {
2092                         error("Can't get IP address for X11 DISPLAY.");
2093                         packet_send_debug("Can't get IP address for X11 DISPLAY.");
2094                         return 0;
2095                 }
2096                 memcpy(&my_addr, he->h_addr_list[0], sizeof(struct in_addr));
2097                 snprintf(display, sizeof display, "%.50s:%u.%u", inet_ntoa(my_addr),
2098                     s->display_number, s->screen);
2099 #else
2100                 snprintf(display, sizeof display, "%.400s:%u.%u", hostname,
2101                     s->display_number, s->screen);
2102 #endif
2103                 s->display = xstrdup(display);
2104                 s->auth_display = xstrdup(display);
2105         }
2106
2107         return 1;
2108 }
2109
2110 static void
2111 do_authenticated2(Authctxt *authctxt)
2112 {
2113         server_loop2(authctxt);
2114 #if defined(GSSAPI)
2115         if (options.gss_cleanup_creds)
2116                 ssh_gssapi_cleanup_creds(NULL);
2117 #endif
2118 }
This page took 0.311213 seconds and 5 git commands to generate.