blob: e68718a7eb910e368aedee4d842fd0588ced6650 [file] [log] [blame]
Damien Millerb38eff82000-04-01 11:09:21 +10001/*
2 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
3 * All rights reserved
4 */
Damien Millerefb4afe2000-04-12 18:45:05 +10005/*
6 * SSH2 support by Markus Friedl.
7 * Copyright (c) 2000 Markus Friedl. All rights reserved.
8 */
Damien Millerb38eff82000-04-01 11:09:21 +10009
10#include "includes.h"
Damien Miller182ee6e2000-07-12 09:45:27 +100011RCSID("$OpenBSD: session.c,v 1.23 2000/07/11 08:11:33 deraadt Exp $");
Damien Millerb38eff82000-04-01 11:09:21 +100012
13#include "xmalloc.h"
14#include "ssh.h"
15#include "pty.h"
16#include "packet.h"
17#include "buffer.h"
18#include "cipher.h"
19#include "mpaux.h"
20#include "servconf.h"
21#include "uidswap.h"
22#include "compat.h"
23#include "channels.h"
24#include "nchan.h"
25
Damien Millerefb4afe2000-04-12 18:45:05 +100026#include "bufaux.h"
27#include "ssh2.h"
28#include "auth.h"
Damien Millerf6d9e222000-06-18 14:50:44 +100029#include "auth-options.h"
Damien Millerefb4afe2000-04-12 18:45:05 +100030
Damien Miller91606b12000-06-28 08:22:29 +100031#ifdef WITH_IRIX_PROJECT
32#include <proj.h>
33#endif /* WITH_IRIX_PROJECT */
34
Damien Miller37023962000-07-11 17:31:38 +100035#if defined(HAVE_USERSEC_H)
36#include <usersec.h>
37#endif
38
Damien Millerb8c656e2000-06-28 15:22:41 +100039#ifdef HAVE_OSF_SIA
40# include <sia.h>
41# include <siad.h>
42#endif
43
Damien Millerd17b8d52000-08-09 14:42:28 +100044/* AIX limits */
45#if defined(HAVE_GETUSERATTR) && !defined(S_UFSIZE_HARD) && defined(S_UFSIZE)
Damien Miller0da2eaa2000-08-15 11:32:59 +100046# define S_UFSIZE_HARD S_UFSIZE "_hard"
47# define S_UCPU_HARD S_UCPU "_hard"
48# define S_UDATA_HARD S_UDATA "_hard"
49# define S_USTACK_HARD S_USTACK "_hard"
50# define S_URSS_HARD S_URSS "_hard"
51# define S_UCORE_HARD S_UCORE "_hard"
52# define S_UNOFILE_HARD S_UNOFILE "_hard"
Damien Millerd17b8d52000-08-09 14:42:28 +100053#endif
54
Damien Millerb38eff82000-04-01 11:09:21 +100055/* types */
56
57#define TTYSZ 64
58typedef struct Session Session;
59struct Session {
60 int used;
61 int self;
Damien Millerbd483e72000-04-30 10:00:53 +100062 int extended;
Damien Millerb38eff82000-04-01 11:09:21 +100063 struct passwd *pw;
64 pid_t pid;
65 /* tty */
66 char *term;
67 int ptyfd, ttyfd, ptymaster;
68 int row, col, xpixel, ypixel;
69 char tty[TTYSZ];
70 /* X11 */
71 char *display;
72 int screen;
73 char *auth_proto;
74 char *auth_data;
Damien Millerbd483e72000-04-30 10:00:53 +100075 int single_connection;
Damien Millerb38eff82000-04-01 11:09:21 +100076 /* proto 2 */
77 int chanid;
78};
79
80/* func */
81
82Session *session_new(void);
83void session_set_fds(Session *s, int fdin, int fdout, int fderr);
84void session_pty_cleanup(Session *s);
Damien Millere247cc42000-05-07 12:03:14 +100085void session_proctitle(Session *s);
Damien Millerb38eff82000-04-01 11:09:21 +100086void do_exec_pty(Session *s, const char *command, struct passwd * pw);
87void do_exec_no_pty(Session *s, const char *command, struct passwd * pw);
88
89void
90do_child(const char *command, struct passwd * pw, const char *term,
91 const char *display, const char *auth_proto,
92 const char *auth_data, const char *ttyname);
93
94/* import */
95extern ServerOptions options;
Damien Miller06d84b72000-04-21 16:13:07 +100096#ifdef HAVE___PROGNAME
Damien Millerb38eff82000-04-01 11:09:21 +100097extern char *__progname;
Damien Miller06d84b72000-04-21 16:13:07 +100098#else /* HAVE___PROGNAME */
Damien Miller70fb6712000-05-01 20:59:50 +100099static const char *__progname = "sshd";
Damien Miller06d84b72000-04-21 16:13:07 +1000100#endif /* HAVE___PROGNAME */
101
Damien Millerb38eff82000-04-01 11:09:21 +1000102extern int log_stderr;
103extern int debug_flag;
104
Damien Miller37023962000-07-11 17:31:38 +1000105extern int startup_pipe;
106
Damien Millerb38eff82000-04-01 11:09:21 +1000107/* Local Xauthority file. */
108static char *xauthfile;
109
110/* data */
111#define MAX_SESSIONS 10
112Session sessions[MAX_SESSIONS];
Damien Millerd2c208a2000-05-17 22:00:02 +1000113#ifdef WITH_AIXAUTHENTICATE
114/* AIX's lastlogin message, set in auth1.c */
115char *aixloginmsg;
116#endif /* WITH_AIXAUTHENTICATE */
Damien Millerb38eff82000-04-01 11:09:21 +1000117
Damien Millerb38eff82000-04-01 11:09:21 +1000118/*
119 * Remove local Xauthority file.
120 */
121void
122xauthfile_cleanup_proc(void *ignore)
123{
124 debug("xauthfile_cleanup_proc called");
125
126 if (xauthfile != NULL) {
127 char *p;
128 unlink(xauthfile);
129 p = strrchr(xauthfile, '/');
130 if (p != NULL) {
131 *p = '\0';
132 rmdir(xauthfile);
133 }
134 xfree(xauthfile);
135 xauthfile = NULL;
136 }
137}
138
139/*
140 * Function to perform cleanup if we get aborted abnormally (e.g., due to a
141 * dropped connection).
142 */
Damien Miller4af51302000-04-16 11:18:38 +1000143void
Damien Millerb38eff82000-04-01 11:09:21 +1000144pty_cleanup_proc(void *session)
145{
146 Session *s=session;
147 if (s == NULL)
148 fatal("pty_cleanup_proc: no session");
149 debug("pty_cleanup_proc: %s", s->tty);
150
151 if (s->pid != 0) {
152 /* Record that the user has logged out. */
153 record_logout(s->pid, s->tty);
154 }
155
156 /* Release the pseudo-tty. */
157 pty_release(s->tty);
158}
159
160/*
161 * Prepares for an interactive session. This is called after the user has
162 * been successfully authenticated. During this message exchange, pseudo
163 * terminals are allocated, X11, TCP/IP, and authentication agent forwardings
164 * are requested, etc.
165 */
Damien Miller4af51302000-04-16 11:18:38 +1000166void
Damien Millerb38eff82000-04-01 11:09:21 +1000167do_authenticated(struct passwd * pw)
168{
169 Session *s;
170 int type;
171 int compression_level = 0, enable_compression_after_reply = 0;
172 int have_pty = 0;
173 char *command;
174 int n_bytes;
175 int plen;
176 unsigned int proto_len, data_len, dlen;
177
178 /*
179 * Cancel the alarm we set to limit the time taken for
180 * authentication.
181 */
182 alarm(0);
Damien Miller182ee6e2000-07-12 09:45:27 +1000183 if (startup_pipe != -1) {
Damien Miller4d97ba22000-07-11 18:15:50 +1000184 close(startup_pipe);
Damien Miller182ee6e2000-07-12 09:45:27 +1000185 startup_pipe = -1;
186 }
Damien Millerb38eff82000-04-01 11:09:21 +1000187
188 /*
189 * Inform the channel mechanism that we are the server side and that
190 * the client may request to connect to any port at all. (The user
191 * could do it anyway, and we wouldn\'t know what is permitted except
192 * by the client telling us, so we can equally well trust the client
193 * not to request anything bogus.)
194 */
195 if (!no_port_forwarding_flag)
196 channel_permit_all_opens();
197
198 s = session_new();
Damien Millerbd483e72000-04-30 10:00:53 +1000199 s->pw = pw;
Damien Millerb38eff82000-04-01 11:09:21 +1000200
201 /*
202 * We stay in this loop until the client requests to execute a shell
203 * or a command.
204 */
205 for (;;) {
206 int success = 0;
207
208 /* Get a packet from the client. */
209 type = packet_read(&plen);
210
211 /* Process the packet. */
212 switch (type) {
213 case SSH_CMSG_REQUEST_COMPRESSION:
214 packet_integrity_check(plen, 4, type);
215 compression_level = packet_get_int();
216 if (compression_level < 1 || compression_level > 9) {
217 packet_send_debug("Received illegal compression level %d.",
218 compression_level);
219 break;
220 }
221 /* Enable compression after we have responded with SUCCESS. */
222 enable_compression_after_reply = 1;
223 success = 1;
224 break;
225
226 case SSH_CMSG_REQUEST_PTY:
227 if (no_pty_flag) {
228 debug("Allocating a pty not permitted for this authentication.");
229 break;
230 }
231 if (have_pty)
232 packet_disconnect("Protocol error: you already have a pty.");
233
234 debug("Allocating pty.");
235
236 /* Allocate a pty and open it. */
237 if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty,
238 sizeof(s->tty))) {
239 error("Failed to allocate pty.");
240 break;
241 }
242 fatal_add_cleanup(pty_cleanup_proc, (void *)s);
243 pty_setowner(pw, s->tty);
244
245 /* Get TERM from the packet. Note that the value may be of arbitrary length. */
246 s->term = packet_get_string(&dlen);
247 packet_integrity_check(dlen, strlen(s->term), type);
248 /* packet_integrity_check(plen, 4 + dlen + 4*4 + n_bytes, type); */
249 /* Remaining bytes */
250 n_bytes = plen - (4 + dlen + 4 * 4);
251
252 if (strcmp(s->term, "") == 0) {
253 xfree(s->term);
254 s->term = NULL;
255 }
256 /* Get window size from the packet. */
257 s->row = packet_get_int();
258 s->col = packet_get_int();
259 s->xpixel = packet_get_int();
260 s->ypixel = packet_get_int();
261 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
262
263 /* Get tty modes from the packet. */
264 tty_parse_modes(s->ttyfd, &n_bytes);
265 packet_integrity_check(plen, 4 + dlen + 4 * 4 + n_bytes, type);
266
Damien Millere247cc42000-05-07 12:03:14 +1000267 session_proctitle(s);
268
Damien Millerb38eff82000-04-01 11:09:21 +1000269 /* Indicate that we now have a pty. */
270 success = 1;
271 have_pty = 1;
272 break;
273
274 case SSH_CMSG_X11_REQUEST_FORWARDING:
275 if (!options.x11_forwarding) {
276 packet_send_debug("X11 forwarding disabled in server configuration file.");
277 break;
278 }
Damien Miller0c043c12000-06-07 21:22:38 +1000279 if (!options.xauth_location) {
280 packet_send_debug("No xauth program; cannot forward with spoofing.");
281 break;
282 }
Damien Millerb38eff82000-04-01 11:09:21 +1000283 if (no_x11_forwarding_flag) {
284 packet_send_debug("X11 forwarding not permitted for this authentication.");
285 break;
286 }
287 debug("Received request for X11 forwarding with auth spoofing.");
288 if (s->display != NULL)
289 packet_disconnect("Protocol error: X11 display already set.");
290
291 s->auth_proto = packet_get_string(&proto_len);
292 s->auth_data = packet_get_string(&data_len);
293 packet_integrity_check(plen, 4 + proto_len + 4 + data_len + 4, type);
294
295 if (packet_get_protocol_flags() & SSH_PROTOFLAG_SCREEN_NUMBER)
296 s->screen = packet_get_int();
297 else
298 s->screen = 0;
299 s->display = x11_create_display_inet(s->screen, options.x11_display_offset);
300
301 if (s->display == NULL)
302 break;
303
304 /* Setup to always have a local .Xauthority. */
305 xauthfile = xmalloc(MAXPATHLEN);
306 strlcpy(xauthfile, "/tmp/ssh-XXXXXXXX", MAXPATHLEN);
307 temporarily_use_uid(pw->pw_uid);
308 if (mkdtemp(xauthfile) == NULL) {
309 restore_uid();
310 error("private X11 dir: mkdtemp %s failed: %s",
311 xauthfile, strerror(errno));
312 xfree(xauthfile);
313 xauthfile = NULL;
Damien Millerbd483e72000-04-30 10:00:53 +1000314 /* XXXX remove listening channels */
Damien Millerb38eff82000-04-01 11:09:21 +1000315 break;
316 }
317 strlcat(xauthfile, "/cookies", MAXPATHLEN);
318 open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600);
319 restore_uid();
320 fatal_add_cleanup(xauthfile_cleanup_proc, NULL);
321 success = 1;
322 break;
Damien Millerb38eff82000-04-01 11:09:21 +1000323
324 case SSH_CMSG_AGENT_REQUEST_FORWARDING:
325 if (no_agent_forwarding_flag || compat13) {
326 debug("Authentication agent forwarding not permitted for this authentication.");
327 break;
328 }
329 debug("Received authentication agent forwarding request.");
Damien Miller0c043c12000-06-07 21:22:38 +1000330 success = auth_input_request_forwarding(pw);
Damien Millerb38eff82000-04-01 11:09:21 +1000331 break;
332
333 case SSH_CMSG_PORT_FORWARD_REQUEST:
334 if (no_port_forwarding_flag) {
335 debug("Port forwarding not permitted for this authentication.");
336 break;
337 }
338 debug("Received TCP/IP port forwarding request.");
Damien Millere247cc42000-05-07 12:03:14 +1000339 channel_input_port_forward_request(pw->pw_uid == 0, options.gateway_ports);
Damien Millerb38eff82000-04-01 11:09:21 +1000340 success = 1;
341 break;
342
343 case SSH_CMSG_MAX_PACKET_SIZE:
344 if (packet_set_maxsize(packet_get_int()) > 0)
345 success = 1;
346 break;
347
348 case SSH_CMSG_EXEC_SHELL:
349 case SSH_CMSG_EXEC_CMD:
350 /* Set interactive/non-interactive mode. */
351 packet_set_interactive(have_pty || s->display != NULL,
352 options.keepalives);
353
354 if (type == SSH_CMSG_EXEC_CMD) {
355 command = packet_get_string(&dlen);
356 debug("Exec command '%.500s'", command);
357 packet_integrity_check(plen, 4 + dlen, type);
358 } else {
359 command = NULL;
360 packet_integrity_check(plen, 0, type);
361 }
362 if (forced_command != NULL) {
363 command = forced_command;
364 debug("Forced command '%.500s'", forced_command);
365 }
366 if (have_pty)
367 do_exec_pty(s, command, pw);
368 else
369 do_exec_no_pty(s, command, pw);
370
371 if (command != NULL)
372 xfree(command);
373 /* Cleanup user's local Xauthority file. */
374 if (xauthfile)
375 xauthfile_cleanup_proc(NULL);
376 return;
377
378 default:
379 /*
380 * Any unknown messages in this phase are ignored,
381 * and a failure message is returned.
382 */
383 log("Unknown packet type received after authentication: %d", type);
384 }
385 packet_start(success ? SSH_SMSG_SUCCESS : SSH_SMSG_FAILURE);
386 packet_send();
387 packet_write_wait();
388
389 /* Enable compression now that we have replied if appropriate. */
390 if (enable_compression_after_reply) {
391 enable_compression_after_reply = 0;
392 packet_start_compression(compression_level);
393 }
394 }
395}
396
397/*
398 * This is called to fork and execute a command when we have no tty. This
399 * will call do_child from the child, and server_loop from the parent after
400 * setting up file descriptors and such.
401 */
Damien Miller4af51302000-04-16 11:18:38 +1000402void
Damien Millerb38eff82000-04-01 11:09:21 +1000403do_exec_no_pty(Session *s, const char *command, struct passwd * pw)
404{
405 int pid;
406
407#ifdef USE_PIPES
408 int pin[2], pout[2], perr[2];
409 /* Allocate pipes for communicating with the program. */
410 if (pipe(pin) < 0 || pipe(pout) < 0 || pipe(perr) < 0)
411 packet_disconnect("Could not create pipes: %.100s",
412 strerror(errno));
413#else /* USE_PIPES */
414 int inout[2], err[2];
415 /* Uses socket pairs to communicate with the program. */
416 if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) < 0 ||
417 socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0)
418 packet_disconnect("Could not create socket pairs: %.100s",
419 strerror(errno));
420#endif /* USE_PIPES */
421 if (s == NULL)
422 fatal("do_exec_no_pty: no session");
423
Damien Millere247cc42000-05-07 12:03:14 +1000424 session_proctitle(s);
Damien Millerb38eff82000-04-01 11:09:21 +1000425
426#ifdef USE_PAM
427 do_pam_setcred();
428#endif /* USE_PAM */
429
430 /* Fork the child. */
431 if ((pid = fork()) == 0) {
432 /* Child. Reinitialize the log since the pid has changed. */
433 log_init(__progname, options.log_level, options.log_facility, log_stderr);
434
435 /*
436 * Create a new session and process group since the 4.4BSD
437 * setlogin() affects the entire process group.
438 */
439 if (setsid() < 0)
440 error("setsid failed: %.100s", strerror(errno));
441
442#ifdef USE_PIPES
443 /*
444 * Redirect stdin. We close the parent side of the socket
445 * pair, and make the child side the standard input.
446 */
447 close(pin[1]);
448 if (dup2(pin[0], 0) < 0)
449 perror("dup2 stdin");
450 close(pin[0]);
451
452 /* Redirect stdout. */
453 close(pout[0]);
454 if (dup2(pout[1], 1) < 0)
455 perror("dup2 stdout");
456 close(pout[1]);
457
458 /* Redirect stderr. */
459 close(perr[0]);
460 if (dup2(perr[1], 2) < 0)
461 perror("dup2 stderr");
462 close(perr[1]);
463#else /* USE_PIPES */
464 /*
465 * Redirect stdin, stdout, and stderr. Stdin and stdout will
466 * use the same socket, as some programs (particularly rdist)
467 * seem to depend on it.
468 */
469 close(inout[1]);
470 close(err[1]);
471 if (dup2(inout[0], 0) < 0) /* stdin */
472 perror("dup2 stdin");
473 if (dup2(inout[0], 1) < 0) /* stdout. Note: same socket as stdin. */
474 perror("dup2 stdout");
475 if (dup2(err[0], 2) < 0) /* stderr */
476 perror("dup2 stderr");
477#endif /* USE_PIPES */
478
479 /* Do processing for the child (exec command etc). */
480 do_child(command, pw, NULL, s->display, s->auth_proto, s->auth_data, NULL);
481 /* NOTREACHED */
482 }
483 if (pid < 0)
484 packet_disconnect("fork failed: %.100s", strerror(errno));
485 s->pid = pid;
486#ifdef USE_PIPES
487 /* We are the parent. Close the child sides of the pipes. */
488 close(pin[0]);
489 close(pout[1]);
490 close(perr[1]);
491
Damien Millerefb4afe2000-04-12 18:45:05 +1000492 if (compat20) {
Damien Millerbd483e72000-04-30 10:00:53 +1000493 session_set_fds(s, pin[1], pout[0], s->extended ? perr[0] : -1);
Damien Millerefb4afe2000-04-12 18:45:05 +1000494 } else {
495 /* Enter the interactive session. */
496 server_loop(pid, pin[1], pout[0], perr[0]);
497 /* server_loop has closed pin[1], pout[1], and perr[1]. */
498 }
Damien Millerb38eff82000-04-01 11:09:21 +1000499#else /* USE_PIPES */
500 /* We are the parent. Close the child sides of the socket pairs. */
501 close(inout[0]);
502 close(err[0]);
503
504 /*
505 * Enter the interactive session. Note: server_loop must be able to
506 * handle the case that fdin and fdout are the same.
507 */
Damien Millerefb4afe2000-04-12 18:45:05 +1000508 if (compat20) {
Damien Millerbd483e72000-04-30 10:00:53 +1000509 session_set_fds(s, inout[1], inout[1], s->extended ? err[1] : -1);
Damien Millerefb4afe2000-04-12 18:45:05 +1000510 } else {
511 server_loop(pid, inout[1], inout[1], err[1]);
512 /* server_loop has closed inout[1] and err[1]. */
513 }
Damien Millerb38eff82000-04-01 11:09:21 +1000514#endif /* USE_PIPES */
515}
516
517/*
518 * This is called to fork and execute a command when we have a tty. This
519 * will call do_child from the child, and server_loop from the parent after
520 * setting up file descriptors, controlling tty, updating wtmp, utmp,
521 * lastlog, and other such operations.
522 */
Damien Miller4af51302000-04-16 11:18:38 +1000523void
Damien Millerb38eff82000-04-01 11:09:21 +1000524do_exec_pty(Session *s, const char *command, struct passwd * pw)
525{
526 FILE *f;
527 char buf[100], *time_string;
528 char line[256];
529 const char *hostname;
530 int fdout, ptyfd, ttyfd, ptymaster;
531 int quiet_login;
532 pid_t pid;
533 socklen_t fromlen;
534 struct sockaddr_storage from;
535 struct stat st;
536 time_t last_login_time;
537
538 if (s == NULL)
539 fatal("do_exec_pty: no session");
540 ptyfd = s->ptyfd;
541 ttyfd = s->ttyfd;
542
543 /* Get remote host name. */
544 hostname = get_canonical_hostname();
545
546 /*
547 * Get the time when the user last logged in. Buf will be set to
548 * contain the hostname the last login was from.
549 */
550 if (!options.use_login) {
551 last_login_time = get_last_login_time(pw->pw_uid, pw->pw_name,
552 buf, sizeof(buf));
553 }
Damien Millerb38eff82000-04-01 11:09:21 +1000554
555#ifdef USE_PAM
556 do_pam_session(pw->pw_name, s->tty);
557 do_pam_setcred();
558#endif /* USE_PAM */
559
560 /* Fork the child. */
561 if ((pid = fork()) == 0) {
562 pid = getpid();
563
564 /* Child. Reinitialize the log because the pid has
565 changed. */
566 log_init(__progname, options.log_level, options.log_facility, log_stderr);
567
568 /* Close the master side of the pseudo tty. */
569 close(ptyfd);
570
571 /* Make the pseudo tty our controlling tty. */
572 pty_make_controlling_tty(&ttyfd, s->tty);
573
574 /* Redirect stdin from the pseudo tty. */
575 if (dup2(ttyfd, fileno(stdin)) < 0)
576 error("dup2 stdin failed: %.100s", strerror(errno));
577
578 /* Redirect stdout to the pseudo tty. */
579 if (dup2(ttyfd, fileno(stdout)) < 0)
580 error("dup2 stdin failed: %.100s", strerror(errno));
581
582 /* Redirect stderr to the pseudo tty. */
583 if (dup2(ttyfd, fileno(stderr)) < 0)
584 error("dup2 stdin failed: %.100s", strerror(errno));
585
586 /* Close the extra descriptor for the pseudo tty. */
587 close(ttyfd);
588
Damien Millere247cc42000-05-07 12:03:14 +1000589/* XXXX ? move to do_child() ??*/
Damien Millerb38eff82000-04-01 11:09:21 +1000590 /*
591 * Get IP address of client. This is needed because we want
592 * to record where the user logged in from. If the
593 * connection is not a socket, let the ip address be 0.0.0.0.
594 */
595 memset(&from, 0, sizeof(from));
596 if (packet_connection_is_on_socket()) {
597 fromlen = sizeof(from);
598 if (getpeername(packet_get_connection_in(),
599 (struct sockaddr *) & from, &fromlen) < 0) {
600 debug("getpeername: %.100s", strerror(errno));
601 fatal_cleanup();
602 }
603 }
604 /* Record that there was a login on that terminal. */
Damien Miller348c9b72000-08-15 10:01:22 +1000605 if (!options.use_login || command != NULL)
606 record_login(pid, s->tty, pw->pw_name, pw->pw_uid,
607 hostname, (struct sockaddr *)&from);
Damien Millerb38eff82000-04-01 11:09:21 +1000608
609 /* Check if .hushlogin exists. */
610 snprintf(line, sizeof line, "%.200s/.hushlogin", pw->pw_dir);
611 quiet_login = stat(line, &st) >= 0;
612
613#ifdef USE_PAM
614 if (!quiet_login)
615 print_pam_messages();
616#endif /* USE_PAM */
617
618 /*
619 * If the user has logged in before, display the time of last
620 * login. However, don't display anything extra if a command
621 * has been specified (so that ssh can be used to execute
622 * commands on a remote machine without users knowing they
623 * are going to another machine). Login(1) will do this for
624 * us as well, so check if login(1) is used
625 */
626 if (command == NULL && last_login_time != 0 && !quiet_login &&
627 !options.use_login) {
628 /* Convert the date to a string. */
629 time_string = ctime(&last_login_time);
630 /* Remove the trailing newline. */
631 if (strchr(time_string, '\n'))
632 *strchr(time_string, '\n') = 0;
633 /* Display the last login time. Host if displayed
634 if known. */
635 if (strcmp(buf, "") == 0)
636 printf("Last login: %s\r\n", time_string);
637 else
638 printf("Last login: %s from %s\r\n", time_string, buf);
639 }
640 /*
641 * Print /etc/motd unless a command was specified or printing
642 * it was disabled in server options or login(1) will be
643 * used. Note that some machines appear to print it in
644 * /etc/profile or similar.
645 */
646 if (command == NULL && options.print_motd && !quiet_login &&
647 !options.use_login) {
648 /* Print /etc/motd if it exists. */
649 f = fopen("/etc/motd", "r");
650 if (f) {
651 while (fgets(line, sizeof(line), f))
652 fputs(line, stdout);
653 fclose(f);
654 }
655 }
Damien Millerd2c208a2000-05-17 22:00:02 +1000656#if defined(WITH_AIXAUTHENTICATE)
657 /*
658 * AIX handles the lastlog info differently. Display it here.
659 */
660 if (command == NULL && aixloginmsg && *aixloginmsg &&
661 !quiet_login && !options.use_login) {
662 printf("%s\n", aixloginmsg);
663 }
664#endif
Damien Millerb38eff82000-04-01 11:09:21 +1000665 /* Do common processing for the child, such as execing the command. */
Damien Millerb1715dc2000-05-30 13:44:51 +1000666 do_child(command, pw, s->term, s->display, s->auth_proto,
667 s->auth_data, s->tty);
Damien Millerb38eff82000-04-01 11:09:21 +1000668 /* NOTREACHED */
669 }
670 if (pid < 0)
671 packet_disconnect("fork failed: %.100s", strerror(errno));
672 s->pid = pid;
673
674 /* Parent. Close the slave side of the pseudo tty. */
675 close(ttyfd);
676
677 /*
678 * Create another descriptor of the pty master side for use as the
679 * standard input. We could use the original descriptor, but this
680 * simplifies code in server_loop. The descriptor is bidirectional.
681 */
682 fdout = dup(ptyfd);
683 if (fdout < 0)
684 packet_disconnect("dup #1 failed: %.100s", strerror(errno));
685
686 /* we keep a reference to the pty master */
687 ptymaster = dup(ptyfd);
688 if (ptymaster < 0)
689 packet_disconnect("dup #2 failed: %.100s", strerror(errno));
690 s->ptymaster = ptymaster;
691
692 /* Enter interactive session. */
Damien Millerefb4afe2000-04-12 18:45:05 +1000693 if (compat20) {
694 session_set_fds(s, ptyfd, fdout, -1);
695 } else {
696 server_loop(pid, ptyfd, fdout, -1);
697 /* server_loop _has_ closed ptyfd and fdout. */
698 session_pty_cleanup(s);
699 }
Damien Millerb38eff82000-04-01 11:09:21 +1000700}
701
702/*
703 * Sets the value of the given variable in the environment. If the variable
704 * already exists, its value is overriden.
705 */
Damien Miller4af51302000-04-16 11:18:38 +1000706void
Damien Millerb38eff82000-04-01 11:09:21 +1000707child_set_env(char ***envp, unsigned int *envsizep, const char *name,
708 const char *value)
709{
710 unsigned int i, namelen;
711 char **env;
712
713 /*
714 * Find the slot where the value should be stored. If the variable
715 * already exists, we reuse the slot; otherwise we append a new slot
716 * at the end of the array, expanding if necessary.
717 */
718 env = *envp;
719 namelen = strlen(name);
720 for (i = 0; env[i]; i++)
721 if (strncmp(env[i], name, namelen) == 0 && env[i][namelen] == '=')
722 break;
723 if (env[i]) {
724 /* Reuse the slot. */
725 xfree(env[i]);
726 } else {
727 /* New variable. Expand if necessary. */
728 if (i >= (*envsizep) - 1) {
729 (*envsizep) += 50;
730 env = (*envp) = xrealloc(env, (*envsizep) * sizeof(char *));
731 }
732 /* Need to set the NULL pointer at end of array beyond the new slot. */
733 env[i + 1] = NULL;
734 }
735
736 /* Allocate space and format the variable in the appropriate slot. */
737 env[i] = xmalloc(strlen(name) + 1 + strlen(value) + 1);
738 snprintf(env[i], strlen(name) + 1 + strlen(value) + 1, "%s=%s", name, value);
739}
740
741/*
742 * Reads environment variables from the given file and adds/overrides them
743 * into the environment. If the file does not exist, this does nothing.
744 * Otherwise, it must consist of empty lines, comments (line starts with '#')
745 * and assignments of the form name=value. No other forms are allowed.
746 */
Damien Miller4af51302000-04-16 11:18:38 +1000747void
Damien Millerb38eff82000-04-01 11:09:21 +1000748read_environment_file(char ***env, unsigned int *envsize,
749 const char *filename)
750{
751 FILE *f;
752 char buf[4096];
753 char *cp, *value;
754
755 f = fopen(filename, "r");
756 if (!f)
757 return;
758
759 while (fgets(buf, sizeof(buf), f)) {
760 for (cp = buf; *cp == ' ' || *cp == '\t'; cp++)
761 ;
762 if (!*cp || *cp == '#' || *cp == '\n')
763 continue;
764 if (strchr(cp, '\n'))
765 *strchr(cp, '\n') = '\0';
766 value = strchr(cp, '=');
767 if (value == NULL) {
768 fprintf(stderr, "Bad line in %.100s: %.200s\n", filename, buf);
769 continue;
770 }
Damien Millerb1715dc2000-05-30 13:44:51 +1000771 /*
772 * Replace the equals sign by nul, and advance value to
773 * the value string.
774 */
Damien Millerb38eff82000-04-01 11:09:21 +1000775 *value = '\0';
776 value++;
777 child_set_env(env, envsize, cp, value);
778 }
779 fclose(f);
780}
781
782#ifdef USE_PAM
783/*
784 * Sets any environment variables which have been specified by PAM
785 */
786void do_pam_environment(char ***env, int *envsize)
787{
788 char *equals, var_name[512], var_val[512];
789 char **pam_env;
790 int i;
791
792 if ((pam_env = fetch_pam_environment()) == NULL)
793 return;
794
795 for(i = 0; pam_env[i] != NULL; i++) {
796 if ((equals = strstr(pam_env[i], "=")) == NULL)
797 continue;
798
799 if (strlen(pam_env[i]) < (sizeof(var_name) - 1)) {
800 memset(var_name, '\0', sizeof(var_name));
801 memset(var_val, '\0', sizeof(var_val));
802
803 strncpy(var_name, pam_env[i], equals - pam_env[i]);
804 strcpy(var_val, equals + 1);
805
806 debug("PAM environment: %s=%s", var_name, var_val);
807
808 child_set_env(env, envsize, var_name, var_val);
809 }
810 }
811}
812#endif /* USE_PAM */
813
Damien Miller5fc85652000-07-09 23:53:07 +1000814#if defined(HAVE_GETUSERATTR)
815/*
816 * AIX-specific login initialisation
817 */
818void set_limit(char *user, char *soft, char *hard, int resource, int mult)
819{
820 struct rlimit rlim;
Damien Miller65964d62000-07-11 09:16:22 +1000821 int slim, hlim;
Damien Miller5fc85652000-07-09 23:53:07 +1000822
823 getrlimit(resource, &rlim);
824
Damien Miller65964d62000-07-11 09:16:22 +1000825 slim = 0;
826 if (getuserattr(user, soft, &slim, SEC_INT) != -1) {
827 if (slim < 0) {
828 rlim.rlim_cur = RLIM_INFINITY;
829 } else if (slim != 0) {
830 /* See the wackiness below */
831 if (rlim.rlim_cur == slim * mult)
832 slim = 0;
833 else
834 rlim.rlim_cur = slim * mult;
835 }
836 }
Damien Miller5fc85652000-07-09 23:53:07 +1000837
Damien Miller65964d62000-07-11 09:16:22 +1000838 hlim = 0;
839 if (getuserattr(user, hard, &hlim, SEC_INT) != -1) {
840 if (hlim < 0) {
841 rlim.rlim_max = RLIM_INFINITY;
842 } else if (hlim != 0) {
843 rlim.rlim_max = hlim * mult;
844 }
845 }
Damien Miller5fc85652000-07-09 23:53:07 +1000846
Damien Miller65964d62000-07-11 09:16:22 +1000847 /*
848 * XXX For cpu and fsize the soft limit is set to the hard limit
849 * if the hard limit is left at its default value and the soft limit
850 * is changed from its default value, either by requesting it
851 * (slim == 0) or by setting it to the current default. At least
852 * that's how rlogind does it. If you're confused you're not alone.
853 * Bug or feature? AIX 4.3.1.2
854 */
855 if ((!strcmp(soft, "fsize") || !strcmp(soft, "cpu"))
856 && hlim == 0 && slim != 0)
857 rlim.rlim_max = rlim.rlim_cur;
858 /* A specified hard limit limits the soft limit */
859 else if (hlim > 0 && rlim.rlim_cur > rlim.rlim_max)
860 rlim.rlim_cur = rlim.rlim_max;
861 /* A soft limit can increase a hard limit */
862 else if (rlim.rlim_cur > rlim.rlim_max)
Damien Miller5fc85652000-07-09 23:53:07 +1000863 rlim.rlim_max = rlim.rlim_cur;
864
865 if (setrlimit(resource, &rlim) != 0)
Damien Miller65964d62000-07-11 09:16:22 +1000866 error("setrlimit(%.10s) failed: %.100s", soft, strerror(errno));
Damien Miller5fc85652000-07-09 23:53:07 +1000867}
868
869void set_limits_from_userattr(char *user)
870{
871 int mask;
872 char buf[16];
873
874 set_limit(user, S_UFSIZE, S_UFSIZE_HARD, RLIMIT_FSIZE, 512);
875 set_limit(user, S_UCPU, S_UCPU_HARD, RLIMIT_CPU, 1);
876 set_limit(user, S_UDATA, S_UDATA_HARD, RLIMIT_DATA, 512);
877 set_limit(user, S_USTACK, S_USTACK_HARD, RLIMIT_STACK, 512);
878 set_limit(user, S_URSS, S_URSS_HARD, RLIMIT_RSS, 512);
879 set_limit(user, S_UCORE, S_UCORE_HARD, RLIMIT_CORE, 512);
880#if defined(S_UNOFILE)
881 set_limit(user, S_UNOFILE, S_UNOFILE_HARD, RLIMIT_NOFILE, 1);
882#endif
883
884 if (getuserattr(user, S_UMASK, &mask, SEC_INT) != -1) {
885 /* Convert decimal to octal */
886 (void) snprintf(buf, sizeof(buf), "%d", mask);
887 if (sscanf(buf, "%o", &mask) == 1)
888 umask(mask);
889 }
890}
891#endif /* defined(HAVE_GETUSERATTR) */
892
Damien Millerb38eff82000-04-01 11:09:21 +1000893/*
894 * Performs common processing for the child, such as setting up the
895 * environment, closing extra file descriptors, setting the user and group
896 * ids, and executing the command or shell.
897 */
Damien Miller4af51302000-04-16 11:18:38 +1000898void
Damien Millerb38eff82000-04-01 11:09:21 +1000899do_child(const char *command, struct passwd * pw, const char *term,
900 const char *display, const char *auth_proto,
901 const char *auth_data, const char *ttyname)
902{
903 const char *shell, *cp = NULL;
904 char buf[256];
Damien Miller0c043c12000-06-07 21:22:38 +1000905 char cmd[1024];
Damien Millerb38eff82000-04-01 11:09:21 +1000906 FILE *f;
907 unsigned int envsize, i;
908 char **env;
909 extern char **environ;
910 struct stat st;
911 char *argv[10];
Damien Miller91606b12000-06-28 08:22:29 +1000912#ifdef WITH_IRIX_PROJECT
913 prid_t projid;
914#endif /* WITH_IRIX_PROJECT */
Damien Millerb38eff82000-04-01 11:09:21 +1000915
Damien Millerd3a18572000-06-07 19:55:44 +1000916 /* login(1) is only called if we execute the login shell */
917 if (options.use_login && command != NULL)
918 options.use_login = 0;
919
Damien Millerb38eff82000-04-01 11:09:21 +1000920#ifndef USE_PAM /* pam_nologin handles this */
921 f = fopen("/etc/nologin", "r");
922 if (f) {
923 /* /etc/nologin exists. Print its contents and exit. */
924 while (fgets(buf, sizeof(buf), f))
925 fputs(buf, stderr);
926 fclose(f);
927 if (pw->pw_uid != 0)
928 exit(254);
929 }
930#endif /* USE_PAM */
931
Damien Millerb8c656e2000-06-28 15:22:41 +1000932#ifndef HAVE_OSF_SIA
Damien Millerb38eff82000-04-01 11:09:21 +1000933 /* Set login name in the kernel. */
934 if (setlogin(pw->pw_name) < 0)
935 error("setlogin failed: %s", strerror(errno));
Damien Millerb8c656e2000-06-28 15:22:41 +1000936#endif
Damien Millerb38eff82000-04-01 11:09:21 +1000937
938 /* Set uid, gid, and groups. */
939 /* Login(1) does this as well, and it needs uid 0 for the "-h"
940 switch, so we let login(1) to this for us. */
941 if (!options.use_login) {
Damien Millerb8c656e2000-06-28 15:22:41 +1000942#ifdef HAVE_OSF_SIA
943 extern char **saved_argv;
944 extern int saved_argc;
945 char *host = get_canonical_hostname ();
946
947 if (sia_become_user(NULL, saved_argc, saved_argv, host,
948 pw->pw_name, ttyname, 0, NULL, NULL, SIA_BEU_SETLUID) !=
949 SIASUCCESS) {
950 perror("sia_become_user");
951 exit(1);
952 }
953 if (setreuid(geteuid(), geteuid()) < 0) {
954 perror("setreuid");
955 exit(1);
956 }
957#else /* HAVE_OSF_SIA */
Damien Millerb38eff82000-04-01 11:09:21 +1000958 if (getuid() == 0 || geteuid() == 0) {
Damien Miller5fc85652000-07-09 23:53:07 +1000959#if defined(HAVE_GETUSERATTR)
960 set_limits_from_userattr(pw->pw_name);
961#endif /* defined(HAVE_GETUSERATTR) */
962
Damien Millerb38eff82000-04-01 11:09:21 +1000963 if (setgid(pw->pw_gid) < 0) {
964 perror("setgid");
965 exit(1);
966 }
967 /* Initialize the group list. */
968 if (initgroups(pw->pw_name, pw->pw_gid) < 0) {
969 perror("initgroups");
970 exit(1);
971 }
972 endgrent();
973
Damien Miller91606b12000-06-28 08:22:29 +1000974#ifdef WITH_IRIX_ARRAY
975 /* initialize array session */
976 if (newarraysess() != 0)
977 fatal("Failed to set up new array session: %.100s",
978 strerror(errno));
979#endif /* WITH_IRIX_ARRAY */
980
981#ifdef WITH_IRIX_PROJECT
982 /* initialize irix project info */
983 if ((projid = getdfltprojuser(pw->pw_name)) == -1) {
984 debug("Failed to get project id, using projid 0");
985 projid = 0;
986 }
987
988 if (setprid(projid))
989 fatal("Failed to initialize project %d for %s: %.100s",
990 (int)projid, pw->pw_name, strerror(errno));
991#endif /* WITH_IRIX_PROJECT */
992
Damien Millerb38eff82000-04-01 11:09:21 +1000993 /* Permanently switch to the desired uid. */
994 permanently_set_uid(pw->pw_uid);
995 }
996 if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
997 fatal("Failed to set uids to %d.", (int) pw->pw_uid);
Damien Millerb8c656e2000-06-28 15:22:41 +1000998#endif /* HAVE_OSF_SIA */
Damien Millerb38eff82000-04-01 11:09:21 +1000999 }
1000 /*
1001 * Get the shell from the password data. An empty shell field is
1002 * legal, and means /bin/sh.
1003 */
1004 shell = (pw->pw_shell[0] == '\0') ? _PATH_BSHELL : pw->pw_shell;
1005
1006#ifdef AFS
1007 /* Try to get AFS tokens for the local cell. */
1008 if (k_hasafs()) {
1009 char cell[64];
1010
1011 if (k_afs_cell_of_file(pw->pw_dir, cell, sizeof(cell)) == 0)
1012 krb_afslog(cell, 0);
1013
1014 krb_afslog(0, 0);
1015 }
1016#endif /* AFS */
1017
1018 /* Initialize the environment. */
1019 envsize = 100;
1020 env = xmalloc(envsize * sizeof(char *));
1021 env[0] = NULL;
1022
1023 if (!options.use_login) {
1024 /* Set basic environment. */
1025 child_set_env(&env, &envsize, "USER", pw->pw_name);
1026 child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
1027 child_set_env(&env, &envsize, "HOME", pw->pw_dir);
1028 child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
1029
1030 snprintf(buf, sizeof buf, "%.200s/%.50s",
1031 _PATH_MAILDIR, pw->pw_name);
1032 child_set_env(&env, &envsize, "MAIL", buf);
1033
1034 /* Normal systems set SHELL by default. */
1035 child_set_env(&env, &envsize, "SHELL", shell);
1036 }
1037 if (getenv("TZ"))
1038 child_set_env(&env, &envsize, "TZ", getenv("TZ"));
1039
1040 /* Set custom environment options from RSA authentication. */
1041 while (custom_environment) {
1042 struct envstring *ce = custom_environment;
1043 char *s = ce->s;
1044 int i;
1045 for (i = 0; s[i] != '=' && s[i]; i++);
1046 if (s[i] == '=') {
1047 s[i] = 0;
1048 child_set_env(&env, &envsize, s, s + i + 1);
1049 }
1050 custom_environment = ce->next;
1051 xfree(ce->s);
1052 xfree(ce);
1053 }
1054
1055 snprintf(buf, sizeof buf, "%.50s %d %d",
1056 get_remote_ipaddr(), get_remote_port(), get_local_port());
1057 child_set_env(&env, &envsize, "SSH_CLIENT", buf);
1058
1059 if (ttyname)
1060 child_set_env(&env, &envsize, "SSH_TTY", ttyname);
1061 if (term)
1062 child_set_env(&env, &envsize, "TERM", term);
1063 if (display)
1064 child_set_env(&env, &envsize, "DISPLAY", display);
1065
1066#ifdef _AIX
1067 {
1068 char *authstate,*krb5cc;
1069
1070 if ((authstate = getenv("AUTHSTATE")) != NULL)
1071 child_set_env(&env,&envsize,"AUTHSTATE",authstate);
1072
1073 if ((krb5cc = getenv("KRB5CCNAME")) != NULL)
1074 child_set_env(&env,&envsize,"KRB5CCNAME",krb5cc);
1075 }
1076#endif
1077
1078#ifdef KRB4
1079 {
1080 extern char *ticket;
1081
1082 if (ticket)
1083 child_set_env(&env, &envsize, "KRBTKFILE", ticket);
1084 }
1085#endif /* KRB4 */
1086
1087#ifdef USE_PAM
1088 /* Pull in any environment variables that may have been set by PAM. */
1089 do_pam_environment(&env, &envsize);
1090#endif /* USE_PAM */
1091
1092 read_environment_file(&env,&envsize,"/etc/environment");
1093
1094 if (xauthfile)
1095 child_set_env(&env, &envsize, "XAUTHORITY", xauthfile);
1096 if (auth_get_socket_name() != NULL)
1097 child_set_env(&env, &envsize, SSH_AUTHSOCKET_ENV_NAME,
1098 auth_get_socket_name());
1099
1100 /* read $HOME/.ssh/environment. */
1101 if (!options.use_login) {
Damien Millerb1715dc2000-05-30 13:44:51 +10001102 snprintf(buf, sizeof buf, "%.200s/.ssh/environment",
1103 pw->pw_dir);
Damien Millerb38eff82000-04-01 11:09:21 +10001104 read_environment_file(&env, &envsize, buf);
1105 }
1106 if (debug_flag) {
1107 /* dump the environment */
1108 fprintf(stderr, "Environment:\n");
1109 for (i = 0; env[i]; i++)
1110 fprintf(stderr, " %.200s\n", env[i]);
1111 }
1112 /*
1113 * Close the connection descriptors; note that this is the child, and
1114 * the server will still have the socket open, and it is important
1115 * that we do not shutdown it. Note that the descriptors cannot be
1116 * closed before building the environment, as we call
1117 * get_remote_ipaddr there.
1118 */
1119 if (packet_get_connection_in() == packet_get_connection_out())
1120 close(packet_get_connection_in());
1121 else {
1122 close(packet_get_connection_in());
1123 close(packet_get_connection_out());
1124 }
1125 /*
1126 * Close all descriptors related to channels. They will still remain
1127 * open in the parent.
1128 */
1129 /* XXX better use close-on-exec? -markus */
1130 channel_close_all();
1131
1132 /*
1133 * Close any extra file descriptors. Note that there may still be
1134 * descriptors left by system functions. They will be closed later.
1135 */
1136 endpwent();
1137
1138 /*
1139 * Close any extra open file descriptors so that we don\'t have them
1140 * hanging around in clients. Note that we want to do this after
1141 * initgroups, because at least on Solaris 2.3 it leaves file
1142 * descriptors open.
1143 */
1144 for (i = 3; i < 64; i++)
1145 close(i);
1146
1147 /* Change current directory to the user\'s home directory. */
1148 if (chdir(pw->pw_dir) < 0)
1149 fprintf(stderr, "Could not chdir to home directory %s: %s\n",
1150 pw->pw_dir, strerror(errno));
1151
1152 /*
1153 * Must take new environment into use so that .ssh/rc, /etc/sshrc and
1154 * xauth are run in the proper environment.
1155 */
1156 environ = env;
1157
1158 /*
1159 * Run $HOME/.ssh/rc, /etc/sshrc, or xauth (whichever is found first
1160 * in this order).
1161 */
1162 if (!options.use_login) {
1163 if (stat(SSH_USER_RC, &st) >= 0) {
1164 if (debug_flag)
Damien Miller7b413d22000-07-01 13:24:21 +10001165 fprintf(stderr, "Running "_PATH_BSHELL" %s\n", SSH_USER_RC);
Damien Millerb38eff82000-04-01 11:09:21 +10001166
Damien Miller7b413d22000-07-01 13:24:21 +10001167 f = popen(_PATH_BSHELL " " SSH_USER_RC, "w");
Damien Millerb38eff82000-04-01 11:09:21 +10001168 if (f) {
1169 if (auth_proto != NULL && auth_data != NULL)
1170 fprintf(f, "%s %s\n", auth_proto, auth_data);
1171 pclose(f);
1172 } else
1173 fprintf(stderr, "Could not run %s\n", SSH_USER_RC);
1174 } else if (stat(SSH_SYSTEM_RC, &st) >= 0) {
1175 if (debug_flag)
Damien Miller7b413d22000-07-01 13:24:21 +10001176 fprintf(stderr, "Running "_PATH_BSHELL" %s\n", SSH_SYSTEM_RC);
Damien Millerb38eff82000-04-01 11:09:21 +10001177
Damien Miller7b413d22000-07-01 13:24:21 +10001178 f = popen(_PATH_BSHELL " " SSH_SYSTEM_RC, "w");
Damien Millerb38eff82000-04-01 11:09:21 +10001179 if (f) {
1180 if (auth_proto != NULL && auth_data != NULL)
1181 fprintf(f, "%s %s\n", auth_proto, auth_data);
1182 pclose(f);
1183 } else
1184 fprintf(stderr, "Could not run %s\n", SSH_SYSTEM_RC);
Damien Miller0c043c12000-06-07 21:22:38 +10001185 } else if (options.xauth_location != NULL) {
Damien Millerb38eff82000-04-01 11:09:21 +10001186 /* Add authority data to .Xauthority if appropriate. */
1187 if (auth_proto != NULL && auth_data != NULL) {
Damien Millerd999ae22000-05-20 12:49:31 +10001188 char *screen = strchr(display, ':');
1189 if (debug_flag) {
Damien Millerb1715dc2000-05-30 13:44:51 +10001190 fprintf(stderr,
1191 "Running %.100s add %.100s %.100s %.100s\n",
Damien Miller0c043c12000-06-07 21:22:38 +10001192 options.xauth_location, display,
1193 auth_proto, auth_data);
Damien Millerd999ae22000-05-20 12:49:31 +10001194 if (screen != NULL)
Damien Millerb1715dc2000-05-30 13:44:51 +10001195 fprintf(stderr,
1196 "Adding %.*s/unix%s %s %s\n",
1197 screen-display, display,
1198 screen, auth_proto, auth_data);
Damien Millerd999ae22000-05-20 12:49:31 +10001199 }
Damien Miller0c043c12000-06-07 21:22:38 +10001200 snprintf(cmd, sizeof cmd, "%s -q -",
1201 options.xauth_location);
1202 f = popen(cmd, "w");
Damien Millerb38eff82000-04-01 11:09:21 +10001203 if (f) {
Damien Millerb1715dc2000-05-30 13:44:51 +10001204 fprintf(f, "add %s %s %s\n", display,
1205 auth_proto, auth_data);
Damien Millerd999ae22000-05-20 12:49:31 +10001206 if (screen != NULL)
1207 fprintf(f, "add %.*s/unix%s %s %s\n",
Damien Millerb1715dc2000-05-30 13:44:51 +10001208 screen-display, display,
1209 screen, auth_proto, auth_data);
Damien Millerb38eff82000-04-01 11:09:21 +10001210 pclose(f);
Damien Miller0c043c12000-06-07 21:22:38 +10001211 } else {
1212 fprintf(stderr, "Could not run %s\n",
1213 cmd);
1214 }
Damien Millerb38eff82000-04-01 11:09:21 +10001215 }
1216 }
Damien Millerb38eff82000-04-01 11:09:21 +10001217 /* Get the last component of the shell name. */
1218 cp = strrchr(shell, '/');
1219 if (cp)
1220 cp++;
1221 else
1222 cp = shell;
1223 }
1224 /*
1225 * If we have no command, execute the shell. In this case, the shell
1226 * name to be passed in argv[0] is preceded by '-' to indicate that
1227 * this is a login shell.
1228 */
1229 if (!command) {
1230 if (!options.use_login) {
1231 char buf[256];
1232
1233 /*
1234 * Check for mail if we have a tty and it was enabled
1235 * in server options.
1236 */
1237 if (ttyname && options.check_mail) {
1238 char *mailbox;
1239 struct stat mailstat;
1240 mailbox = getenv("MAIL");
1241 if (mailbox != NULL) {
Damien Millerb1715dc2000-05-30 13:44:51 +10001242 if (stat(mailbox, &mailstat) != 0 ||
1243 mailstat.st_size == 0)
Damien Millerb38eff82000-04-01 11:09:21 +10001244 printf("No mail.\n");
1245 else if (mailstat.st_mtime < mailstat.st_atime)
1246 printf("You have mail.\n");
1247 else
1248 printf("You have new mail.\n");
1249 }
1250 }
1251 /* Start the shell. Set initial character to '-'. */
1252 buf[0] = '-';
1253 strncpy(buf + 1, cp, sizeof(buf) - 1);
1254 buf[sizeof(buf) - 1] = 0;
1255
1256 /* Execute the shell. */
1257 argv[0] = buf;
1258 argv[1] = NULL;
1259 execve(shell, argv, env);
1260
1261 /* Executing the shell failed. */
1262 perror(shell);
1263 exit(1);
1264
1265 } else {
1266 /* Launch login(1). */
1267
Damien Miller7b413d22000-07-01 13:24:21 +10001268 execl(LOGIN_PROGRAM, "login", "-h", get_remote_ipaddr(),
Damien Millerb38eff82000-04-01 11:09:21 +10001269 "-p", "-f", "--", pw->pw_name, NULL);
1270
1271 /* Login couldn't be executed, die. */
1272
1273 perror("login");
1274 exit(1);
1275 }
1276 }
1277 /*
1278 * Execute the command using the user's shell. This uses the -c
1279 * option to execute the command.
1280 */
1281 argv[0] = (char *) cp;
1282 argv[1] = "-c";
1283 argv[2] = (char *) command;
1284 argv[3] = NULL;
1285 execve(shell, argv, env);
1286 perror(shell);
1287 exit(1);
1288}
1289
1290Session *
1291session_new(void)
1292{
1293 int i;
1294 static int did_init = 0;
1295 if (!did_init) {
1296 debug("session_new: init");
1297 for(i = 0; i < MAX_SESSIONS; i++) {
1298 sessions[i].used = 0;
1299 sessions[i].self = i;
1300 }
1301 did_init = 1;
1302 }
1303 for(i = 0; i < MAX_SESSIONS; i++) {
1304 Session *s = &sessions[i];
1305 if (! s->used) {
1306 s->pid = 0;
Damien Millerbd483e72000-04-30 10:00:53 +10001307 s->extended = 0;
Damien Millerb38eff82000-04-01 11:09:21 +10001308 s->chanid = -1;
1309 s->ptyfd = -1;
1310 s->ttyfd = -1;
1311 s->term = NULL;
1312 s->pw = NULL;
1313 s->display = NULL;
1314 s->screen = 0;
1315 s->auth_data = NULL;
1316 s->auth_proto = NULL;
1317 s->used = 1;
Damien Millerbd483e72000-04-30 10:00:53 +10001318 s->pw = NULL;
Damien Millerb38eff82000-04-01 11:09:21 +10001319 debug("session_new: session %d", i);
1320 return s;
1321 }
1322 }
1323 return NULL;
1324}
1325
1326void
1327session_dump(void)
1328{
1329 int i;
1330 for(i = 0; i < MAX_SESSIONS; i++) {
1331 Session *s = &sessions[i];
1332 debug("dump: used %d session %d %p channel %d pid %d",
1333 s->used,
1334 s->self,
1335 s,
1336 s->chanid,
1337 s->pid);
1338 }
1339}
1340
Damien Millerefb4afe2000-04-12 18:45:05 +10001341int
1342session_open(int chanid)
1343{
1344 Session *s = session_new();
1345 debug("session_open: channel %d", chanid);
1346 if (s == NULL) {
1347 error("no more sessions");
1348 return 0;
1349 }
Damien Millerefb4afe2000-04-12 18:45:05 +10001350 s->pw = auth_get_user();
1351 if (s->pw == NULL)
Damien Millerbd483e72000-04-30 10:00:53 +10001352 fatal("no user for session %i", s->self);
1353 debug("session_open: session %d: link with channel %d", s->self, chanid);
1354 s->chanid = chanid;
Damien Millerefb4afe2000-04-12 18:45:05 +10001355 return 1;
1356}
1357
1358Session *
1359session_by_channel(int id)
1360{
1361 int i;
1362 for(i = 0; i < MAX_SESSIONS; i++) {
1363 Session *s = &sessions[i];
1364 if (s->used && s->chanid == id) {
1365 debug("session_by_channel: session %d channel %d", i, id);
1366 return s;
1367 }
1368 }
1369 debug("session_by_channel: unknown channel %d", id);
1370 session_dump();
1371 return NULL;
1372}
1373
1374Session *
1375session_by_pid(pid_t pid)
1376{
1377 int i;
1378 debug("session_by_pid: pid %d", pid);
1379 for(i = 0; i < MAX_SESSIONS; i++) {
1380 Session *s = &sessions[i];
1381 if (s->used && s->pid == pid)
1382 return s;
1383 }
1384 error("session_by_pid: unknown pid %d", pid);
1385 session_dump();
1386 return NULL;
1387}
1388
1389int
1390session_window_change_req(Session *s)
1391{
1392 s->col = packet_get_int();
1393 s->row = packet_get_int();
1394 s->xpixel = packet_get_int();
1395 s->ypixel = packet_get_int();
Damien Miller4af51302000-04-16 11:18:38 +10001396 packet_done();
Damien Millerefb4afe2000-04-12 18:45:05 +10001397 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
1398 return 1;
1399}
1400
1401int
1402session_pty_req(Session *s)
1403{
1404 unsigned int len;
Damien Miller4af51302000-04-16 11:18:38 +10001405 char *term_modes; /* encoded terminal modes */
Damien Millerefb4afe2000-04-12 18:45:05 +10001406
Damien Millerf6d9e222000-06-18 14:50:44 +10001407 if (no_pty_flag)
1408 return 0;
Damien Millerefb4afe2000-04-12 18:45:05 +10001409 if (s->ttyfd != -1)
Damien Miller4af51302000-04-16 11:18:38 +10001410 return 0;
Damien Millerefb4afe2000-04-12 18:45:05 +10001411 s->term = packet_get_string(&len);
1412 s->col = packet_get_int();
1413 s->row = packet_get_int();
1414 s->xpixel = packet_get_int();
1415 s->ypixel = packet_get_int();
Damien Miller4af51302000-04-16 11:18:38 +10001416 term_modes = packet_get_string(&len);
1417 packet_done();
Damien Millerefb4afe2000-04-12 18:45:05 +10001418
1419 if (strcmp(s->term, "") == 0) {
1420 xfree(s->term);
1421 s->term = NULL;
1422 }
1423 /* Allocate a pty and open it. */
1424 if (!pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty))) {
1425 xfree(s->term);
1426 s->term = NULL;
1427 s->ptyfd = -1;
1428 s->ttyfd = -1;
1429 error("session_pty_req: session %d alloc failed", s->self);
Damien Miller4af51302000-04-16 11:18:38 +10001430 xfree(term_modes);
1431 return 0;
Damien Millerefb4afe2000-04-12 18:45:05 +10001432 }
1433 debug("session_pty_req: session %d alloc %s", s->self, s->tty);
1434 /*
1435 * Add a cleanup function to clear the utmp entry and record logout
1436 * time in case we call fatal() (e.g., the connection gets closed).
1437 */
1438 fatal_add_cleanup(pty_cleanup_proc, (void *)s);
1439 pty_setowner(s->pw, s->tty);
1440 /* Get window size from the packet. */
1441 pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
1442
Damien Millere247cc42000-05-07 12:03:14 +10001443 session_proctitle(s);
1444
Damien Miller5f056372000-04-16 12:31:48 +10001445 /* XXX parse and set terminal modes */
1446 xfree(term_modes);
Damien Millerefb4afe2000-04-12 18:45:05 +10001447 return 1;
1448}
1449
Damien Millerbd483e72000-04-30 10:00:53 +10001450int
1451session_subsystem_req(Session *s)
1452{
1453 unsigned int len;
1454 int success = 0;
1455 char *subsys = packet_get_string(&len);
Damien Millerf6d9e222000-06-18 14:50:44 +10001456 int i;
Damien Millerbd483e72000-04-30 10:00:53 +10001457
1458 packet_done();
1459 log("subsystem request for %s", subsys);
1460
Damien Millerf6d9e222000-06-18 14:50:44 +10001461 for (i = 0; i < options.num_subsystems; i++) {
1462 if(strcmp(subsys, options.subsystem_name[i]) == 0) {
1463 debug("subsystem: exec() %s", options.subsystem_command[i]);
1464 do_exec_no_pty(s, options.subsystem_command[i], s->pw);
1465 success = 1;
1466 }
1467 }
1468
1469 if (!success)
1470 log("subsystem request for %s failed, subsystem not found", subsys);
1471
Damien Millerbd483e72000-04-30 10:00:53 +10001472 xfree(subsys);
1473 return success;
1474}
1475
1476int
1477session_x11_req(Session *s)
1478{
Damien Miller37023962000-07-11 17:31:38 +10001479 if (no_x11_forwarding_flag) {
Damien Millerf6d9e222000-06-18 14:50:44 +10001480 debug("X11 forwarding disabled in user configuration file.");
1481 return 0;
1482 }
Damien Millerbd483e72000-04-30 10:00:53 +10001483 if (!options.x11_forwarding) {
1484 debug("X11 forwarding disabled in server configuration file.");
1485 return 0;
1486 }
1487 if (xauthfile != NULL) {
1488 debug("X11 fwd already started.");
1489 return 0;
1490 }
1491
1492 debug("Received request for X11 forwarding with auth spoofing.");
1493 if (s->display != NULL)
1494 packet_disconnect("Protocol error: X11 display already set.");
1495
1496 s->single_connection = packet_get_char();
1497 s->auth_proto = packet_get_string(NULL);
1498 s->auth_data = packet_get_string(NULL);
1499 s->screen = packet_get_int();
1500 packet_done();
1501
1502 s->display = x11_create_display_inet(s->screen, options.x11_display_offset);
1503 if (s->display == NULL) {
1504 xfree(s->auth_proto);
1505 xfree(s->auth_data);
1506 return 0;
1507 }
1508 xauthfile = xmalloc(MAXPATHLEN);
1509 strlcpy(xauthfile, "/tmp/ssh-XXXXXXXX", MAXPATHLEN);
1510 temporarily_use_uid(s->pw->pw_uid);
1511 if (mkdtemp(xauthfile) == NULL) {
1512 restore_uid();
1513 error("private X11 dir: mkdtemp %s failed: %s",
1514 xauthfile, strerror(errno));
1515 xfree(xauthfile);
1516 xauthfile = NULL;
1517 xfree(s->auth_proto);
1518 xfree(s->auth_data);
1519 /* XXXX remove listening channels */
1520 return 0;
1521 }
1522 strlcat(xauthfile, "/cookies", MAXPATHLEN);
1523 open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600);
1524 restore_uid();
1525 fatal_add_cleanup(xauthfile_cleanup_proc, s);
1526 return 1;
1527}
1528
Damien Millerf6d9e222000-06-18 14:50:44 +10001529int
1530session_shell_req(Session *s)
1531{
1532 /* if forced_command == NULL, the shell is execed */
1533 char *shell = forced_command;
1534 packet_done();
1535 s->extended = 1;
1536 if (s->ttyfd == -1)
1537 do_exec_no_pty(s, shell, s->pw);
1538 else
1539 do_exec_pty(s, shell, s->pw);
1540 return 1;
1541}
1542
1543int
1544session_exec_req(Session *s)
1545{
1546 unsigned int len;
1547 char *command = packet_get_string(&len);
1548 packet_done();
1549 if (forced_command) {
1550 xfree(command);
1551 command = forced_command;
1552 debug("Forced command '%.500s'", forced_command);
1553 }
1554 s->extended = 1;
1555 if (s->ttyfd == -1)
1556 do_exec_no_pty(s, command, s->pw);
1557 else
1558 do_exec_pty(s, command, s->pw);
1559 if (forced_command == NULL)
1560 xfree(command);
1561 return 1;
1562}
1563
Damien Millerefb4afe2000-04-12 18:45:05 +10001564void
1565session_input_channel_req(int id, void *arg)
1566{
1567 unsigned int len;
1568 int reply;
1569 int success = 0;
1570 char *rtype;
1571 Session *s;
1572 Channel *c;
1573
1574 rtype = packet_get_string(&len);
1575 reply = packet_get_char();
1576
1577 s = session_by_channel(id);
1578 if (s == NULL)
1579 fatal("session_input_channel_req: channel %d: no session", id);
1580 c = channel_lookup(id);
1581 if (c == NULL)
1582 fatal("session_input_channel_req: channel %d: bad channel", id);
1583
1584 debug("session_input_channel_req: session %d channel %d request %s reply %d",
1585 s->self, id, rtype, reply);
1586
1587 /*
1588 * a session is in LARVAL state until a shell
1589 * or programm is executed
1590 */
1591 if (c->type == SSH_CHANNEL_LARVAL) {
1592 if (strcmp(rtype, "shell") == 0) {
Damien Millerf6d9e222000-06-18 14:50:44 +10001593 success = session_shell_req(s);
Damien Millerefb4afe2000-04-12 18:45:05 +10001594 } else if (strcmp(rtype, "exec") == 0) {
Damien Millerf6d9e222000-06-18 14:50:44 +10001595 success = session_exec_req(s);
Damien Millerefb4afe2000-04-12 18:45:05 +10001596 } else if (strcmp(rtype, "pty-req") == 0) {
Damien Miller5f056372000-04-16 12:31:48 +10001597 success = session_pty_req(s);
Damien Millerbd483e72000-04-30 10:00:53 +10001598 } else if (strcmp(rtype, "x11-req") == 0) {
1599 success = session_x11_req(s);
1600 } else if (strcmp(rtype, "subsystem") == 0) {
1601 success = session_subsystem_req(s);
Damien Millerefb4afe2000-04-12 18:45:05 +10001602 }
1603 }
1604 if (strcmp(rtype, "window-change") == 0) {
1605 success = session_window_change_req(s);
1606 }
1607
1608 if (reply) {
1609 packet_start(success ?
1610 SSH2_MSG_CHANNEL_SUCCESS : SSH2_MSG_CHANNEL_FAILURE);
1611 packet_put_int(c->remote_id);
1612 packet_send();
1613 }
1614 xfree(rtype);
1615}
1616
1617void
1618session_set_fds(Session *s, int fdin, int fdout, int fderr)
1619{
1620 if (!compat20)
1621 fatal("session_set_fds: called for proto != 2.0");
1622 /*
1623 * now that have a child and a pipe to the child,
1624 * we can activate our channel and register the fd's
1625 */
1626 if (s->chanid == -1)
1627 fatal("no channel for session %d", s->self);
1628 channel_set_fds(s->chanid,
1629 fdout, fdin, fderr,
1630 fderr == -1 ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ);
1631}
1632
Damien Millerb38eff82000-04-01 11:09:21 +10001633void
1634session_pty_cleanup(Session *s)
1635{
1636 if (s == NULL || s->ttyfd == -1)
1637 return;
1638
1639 debug("session_pty_cleanup: session %i release %s", s->self, s->tty);
1640
1641 /* Cancel the cleanup function. */
1642 fatal_remove_cleanup(pty_cleanup_proc, (void *)s);
1643
1644 /* Record that the user has logged out. */
1645 record_logout(s->pid, s->tty);
1646
1647 /* Release the pseudo-tty. */
1648 pty_release(s->tty);
1649
1650 /*
1651 * Close the server side of the socket pairs. We must do this after
1652 * the pty cleanup, so that another process doesn't get this pty
1653 * while we're still cleaning up.
1654 */
1655 if (close(s->ptymaster) < 0)
1656 error("close(s->ptymaster): %s", strerror(errno));
1657}
Damien Millerefb4afe2000-04-12 18:45:05 +10001658
1659void
1660session_exit_message(Session *s, int status)
1661{
1662 Channel *c;
1663 if (s == NULL)
1664 fatal("session_close: no session");
1665 c = channel_lookup(s->chanid);
1666 if (c == NULL)
1667 fatal("session_close: session %d: no channel %d",
1668 s->self, s->chanid);
1669 debug("session_exit_message: session %d channel %d pid %d",
1670 s->self, s->chanid, s->pid);
1671
1672 if (WIFEXITED(status)) {
1673 channel_request_start(s->chanid,
1674 "exit-status", 0);
1675 packet_put_int(WEXITSTATUS(status));
1676 packet_send();
1677 } else if (WIFSIGNALED(status)) {
1678 channel_request_start(s->chanid,
1679 "exit-signal", 0);
1680 packet_put_int(WTERMSIG(status));
Damien Millerf3c6cf12000-05-17 22:08:29 +10001681#ifdef WCOREDUMP
Damien Millerefb4afe2000-04-12 18:45:05 +10001682 packet_put_char(WCOREDUMP(status));
Damien Millerf3c6cf12000-05-17 22:08:29 +10001683#else /* WCOREDUMP */
1684 packet_put_char(0);
1685#endif /* WCOREDUMP */
Damien Millerefb4afe2000-04-12 18:45:05 +10001686 packet_put_cstring("");
1687 packet_put_cstring("");
1688 packet_send();
1689 } else {
1690 /* Some weird exit cause. Just exit. */
1691 packet_disconnect("wait returned status %04x.", status);
1692 }
1693
1694 /* disconnect channel */
1695 debug("session_exit_message: release channel %d", s->chanid);
1696 channel_cancel_cleanup(s->chanid);
Damien Miller166fca82000-04-20 07:42:21 +10001697 /*
1698 * emulate a write failure with 'chan_write_failed', nobody will be
1699 * interested in data we write.
1700 * Note that we must not call 'chan_read_failed', since there could
1701 * be some more data waiting in the pipe.
1702 */
Damien Millerbd483e72000-04-30 10:00:53 +10001703 if (c->ostate != CHAN_OUTPUT_CLOSED)
1704 chan_write_failed(c);
Damien Millerefb4afe2000-04-12 18:45:05 +10001705 s->chanid = -1;
1706}
1707
1708void
1709session_free(Session *s)
1710{
1711 debug("session_free: session %d pid %d", s->self, s->pid);
1712 if (s->term)
1713 xfree(s->term);
1714 if (s->display)
1715 xfree(s->display);
1716 if (s->auth_data)
1717 xfree(s->auth_data);
1718 if (s->auth_proto)
1719 xfree(s->auth_proto);
1720 s->used = 0;
1721}
1722
1723void
1724session_close(Session *s)
1725{
1726 session_pty_cleanup(s);
1727 session_free(s);
Damien Millere247cc42000-05-07 12:03:14 +10001728 session_proctitle(s);
Damien Millerefb4afe2000-04-12 18:45:05 +10001729}
1730
1731void
1732session_close_by_pid(pid_t pid, int status)
1733{
1734 Session *s = session_by_pid(pid);
1735 if (s == NULL) {
1736 debug("session_close_by_pid: no session for pid %d", s->pid);
1737 return;
1738 }
1739 if (s->chanid != -1)
1740 session_exit_message(s, status);
1741 session_close(s);
1742}
1743
1744/*
1745 * this is called when a channel dies before
1746 * the session 'child' itself dies
1747 */
1748void
1749session_close_by_channel(int id, void *arg)
1750{
1751 Session *s = session_by_channel(id);
1752 if (s == NULL) {
1753 debug("session_close_by_channel: no session for channel %d", id);
1754 return;
1755 }
1756 /* disconnect channel */
1757 channel_cancel_cleanup(s->chanid);
1758 s->chanid = -1;
1759
1760 debug("session_close_by_channel: channel %d kill %d", id, s->pid);
1761 if (s->pid == 0) {
1762 /* close session immediately */
1763 session_close(s);
1764 } else {
1765 /* notify child, delay session cleanup */
Damien Miller099f5052000-06-22 20:57:11 +10001766 if (s->pid <= 1)
Damien Miller7a445bb2000-06-26 13:12:37 +10001767 fatal("session_close_by_channel: Unsafe s->pid = %d", s->pid);
1768 if (kill(s->pid, (s->ttyfd == -1) ? SIGTERM : SIGHUP) < 0)
Damien Millerefb4afe2000-04-12 18:45:05 +10001769 error("session_close_by_channel: kill %d: %s",
1770 s->pid, strerror(errno));
1771 }
1772}
1773
Damien Millere247cc42000-05-07 12:03:14 +10001774char *
1775session_tty_list(void)
1776{
1777 static char buf[1024];
1778 int i;
1779 buf[0] = '\0';
1780 for(i = 0; i < MAX_SESSIONS; i++) {
1781 Session *s = &sessions[i];
1782 if (s->used && s->ttyfd != -1) {
1783 if (buf[0] != '\0')
1784 strlcat(buf, ",", sizeof buf);
1785 strlcat(buf, strrchr(s->tty, '/') + 1, sizeof buf);
1786 }
1787 }
1788 if (buf[0] == '\0')
1789 strlcpy(buf, "notty", sizeof buf);
1790 return buf;
1791}
1792
1793void
1794session_proctitle(Session *s)
1795{
1796 if (s->pw == NULL)
1797 error("no user for session %d", s->self);
1798 else
1799 setproctitle("%s@%s", s->pw->pw_name, session_tty_list());
1800}
1801
Damien Millerefb4afe2000-04-12 18:45:05 +10001802void
1803do_authenticated2(void)
1804{
1805 /*
1806 * Cancel the alarm we set to limit the time taken for
1807 * authentication.
1808 */
1809 alarm(0);
Damien Miller182ee6e2000-07-12 09:45:27 +10001810 if (startup_pipe != -1) {
Damien Miller4d97ba22000-07-11 18:15:50 +10001811 close(startup_pipe);
Damien Miller182ee6e2000-07-12 09:45:27 +10001812 startup_pipe = -1;
1813 }
Damien Millerefb4afe2000-04-12 18:45:05 +10001814 server_loop2();
Damien Miller1b26ab22000-04-30 10:12:49 +10001815 if (xauthfile)
1816 xauthfile_cleanup_proc(NULL);
Damien Millerefb4afe2000-04-12 18:45:05 +10001817}