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