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