annotate svr-chansession.c @ 1900:6110afb6f581

Add release.sh --testrel, github action This makes github actions create a tarball sha256sum for comparison. The release.sh script now works in a git repository too.
author Matt Johnston <matt@ucc.asn.au>
date Thu, 24 Mar 2022 12:22:07 +0800
parents 2839daa507b3
children 284c3837891c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * All rights reserved.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * all copies or substantial portions of the Software.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * SOFTWARE. */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #include "includes.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 #include "packet.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #include "buffer.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "session.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #include "dbutil.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 #include "channel.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 #include "chansession.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 #include "sshpty.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 #include "termcodes.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 #include "ssh.h"
858
220f55d540ae rename random.h to dbrandom.h since some OSes have a system random.h
Matt Johnston <matt@ucc.asn.au>
parents: 814
diff changeset
35 #include "dbrandom.h"
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 #include "x11fwd.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 #include "agentfwd.h"
24
469950e86d0f switching to global vars
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
38 #include "runopts.h"
475
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
39 #include "auth.h"
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 /* Handles sessions (either shells or programs) requested by the client */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 int iscmd, int issubsys);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 static int sessionpty(struct ChanSess * chansess);
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
46 static int sessionsignal(const struct ChanSess *chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 static int noptycommand(struct Channel *channel, struct ChanSess *chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 static int ptycommand(struct Channel *channel, struct ChanSess *chansess);
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
49 static int sessionwinchange(const struct ChanSess *chansess);
1460
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
50 static void execchild(const void *user_data_chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 static void addchildpid(struct ChanSess *chansess, pid_t pid);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 static void sesssigchild_handler(int val);
1460
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
53 static void closechansess(const struct Channel *channel);
1625
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
54 static void cleanupchansess(const struct Channel *channel);
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
55 static int newchansess(struct Channel *channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 static void chansessionrequest(struct Channel *channel);
1835
90ac15aeac43 Bring back recently removed channel->flushing
Matt Johnston <matt@codeconstruct.com.au>
parents: 1830
diff changeset
57 static int sesscheckclose(struct Channel *channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
59 static void send_exitsignalstatus(const struct Channel *channel);
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
60 static void send_msg_chansess_exitstatus(const struct Channel * channel,
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
61 const struct ChanSess * chansess);
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
62 static void send_msg_chansess_exitsignal(const struct Channel * channel,
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
63 const struct ChanSess * chansess);
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
64 static void get_termmodes(const struct ChanSess *chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65
970
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
66 const struct ChanType svrchansess = {
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
67 "session", /* name */
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
68 newchansess, /* inithandler */
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
69 sesscheckclose, /* checkclosehandler */
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
70 chansessionrequest, /* reqhandler */
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
71 closechansess, /* closehandler */
1625
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
72 cleanupchansess /* cleanup */
970
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
73 };
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74
1828
3f0ac6bc58a1 - Remove "flushing" handling for exited processes, it should be
Matt Johnston <matt@ucc.asn.au>
parents: 1826
diff changeset
75 /* Returns whether the channel is ready to close. The child process
3f0ac6bc58a1 - Remove "flushing" handling for exited processes, it should be
Matt Johnston <matt@ucc.asn.au>
parents: 1826
diff changeset
76 must not be running (has never started, or has exited) */
1835
90ac15aeac43 Bring back recently removed channel->flushing
Matt Johnston <matt@codeconstruct.com.au>
parents: 1830
diff changeset
77 static int sesscheckclose(struct Channel *channel) {
364
90cb290836de Passes most test cases now
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
78 struct ChanSess *chansess = (struct ChanSess*)channel->typedata;
1828
3f0ac6bc58a1 - Remove "flushing" handling for exited processes, it should be
Matt Johnston <matt@ucc.asn.au>
parents: 1826
diff changeset
79 TRACE(("sesscheckclose, pid %d, exitpid %d", chansess->pid, chansess->exit.exitpid))
1835
90ac15aeac43 Bring back recently removed channel->flushing
Matt Johnston <matt@codeconstruct.com.au>
parents: 1830
diff changeset
80
90ac15aeac43 Bring back recently removed channel->flushing
Matt Johnston <matt@codeconstruct.com.au>
parents: 1830
diff changeset
81 if (chansess->exit.exitpid != -1) {
90ac15aeac43 Bring back recently removed channel->flushing
Matt Johnston <matt@codeconstruct.com.au>
parents: 1830
diff changeset
82 channel->flushing = 1;
90ac15aeac43 Bring back recently removed channel->flushing
Matt Johnston <matt@codeconstruct.com.au>
parents: 1830
diff changeset
83 }
1828
3f0ac6bc58a1 - Remove "flushing" handling for exited processes, it should be
Matt Johnston <matt@ucc.asn.au>
parents: 1826
diff changeset
84 return chansess->pid == 0 || chansess->exit.exitpid != -1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
1826
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
87 /* Handler for childs exiting, store the state for return to the client */
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
88
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
89 /* There's a particular race we have to watch out for: if the forked child
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
90 * executes, exits, and this signal-handler is called, all before the parent
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
91 * gets to run, then the childpids[] array won't have the pid in it. Hence we
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
92 * use the svr_ses.lastexit struct to hold the exit, which is then compared by
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
93 * the parent when it runs. This work correctly at least in the case of a
eaa2d7240a5d Move comment to svr_chansess_checksignal() where it belongs
Matt Johnston <matt@ucc.asn.au>
parents: 1804
diff changeset
94 * single shell spawned (ie the usual case) */
1495
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
95 void svr_chansess_checksignal(void) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
96 int status;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
97 pid_t pid;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
98
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
99 if (!ses.channel_signal_pending) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
100 return;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
101 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
102
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
103 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
104 unsigned int i;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
105 struct exitinfo *ex = NULL;
1625
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
106 TRACE(("svr_chansess_checksignal : pid %d", pid))
1495
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
107
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
108 ex = NULL;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
109 /* find the corresponding chansess */
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
110 for (i = 0; i < svr_ses.childpidsize; i++) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
111 if (svr_ses.childpids[i].pid == pid) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
112 TRACE(("found match session"));
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
113 ex = &svr_ses.childpids[i].chansess->exit;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
114 break;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
115 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
116 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
117
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
118 /* If the pid wasn't matched, then we might have hit the race mentioned
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
119 * above. So we just store the info for the parent to deal with */
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
120 if (ex == NULL) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
121 TRACE(("using lastexit"));
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
122 ex = &svr_ses.lastexit;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
123 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
124
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
125 ex->exitpid = pid;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
126 if (WIFEXITED(status)) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
127 ex->exitstatus = WEXITSTATUS(status);
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
128 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
129 if (WIFSIGNALED(status)) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
130 ex->exitsignal = WTERMSIG(status);
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
131 #if !defined(AIX) && defined(WCOREDUMP)
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
132 ex->exitcore = WCOREDUMP(status);
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
133 #else
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
134 ex->exitcore = 0;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
135 #endif
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
136 } else {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
137 /* we use this to determine how pid exited */
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
138 ex->exitsignal = -1;
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
139 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
140 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
141 }
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
142
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 96
diff changeset
143 static void sesssigchild_handler(int UNUSED(dummy)) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 struct sigaction sa_chld;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145
893
860e3522f8fc - Save errno in signal handlers
Matt Johnston <matt@ucc.asn.au>
parents: 871
diff changeset
146 const int saved_errno = errno;
860e3522f8fc - Save errno in signal handlers
Matt Johnston <matt@ucc.asn.au>
parents: 871
diff changeset
147
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
148 TRACE(("enter sigchld handler"))
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
149
1495
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
150 /* Make sure that the main select() loop wakes up */
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
151 while (1) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
152 /* isserver is just a random byte to write. We can't do anything
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
153 about an error so should just ignore it */
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
154 if (write(ses.signal_pipe[1], &ses.isserver, 1) == 1
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
155 || errno != EINTR) {
0c16b4ccbd54 make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
156 break;
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 402
diff changeset
157 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 }
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
159
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 sa_chld.sa_handler = sesssigchild_handler;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 sa_chld.sa_flags = SA_NOCLDSTOP;
658
d4d0279710b9 - Initialise sa_mask properly
Matt Johnston <matt@ucc.asn.au>
parents: 657
diff changeset
162 sigemptyset(&sa_chld.sa_mask);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 sigaction(SIGCHLD, &sa_chld, NULL);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
164 TRACE(("leave sigchld handler"))
893
860e3522f8fc - Save errno in signal handlers
Matt Johnston <matt@ucc.asn.au>
parents: 871
diff changeset
165
860e3522f8fc - Save errno in signal handlers
Matt Johnston <matt@ucc.asn.au>
parents: 871
diff changeset
166 errno = saved_errno;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 /* send the exit status or the signal causing termination for a session */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
170 static void send_exitsignalstatus(const struct Channel *channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 struct ChanSess *chansess = (struct ChanSess*)channel->typedata;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
174 if (chansess->exit.exitpid >= 0) {
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
175 if (chansess->exit.exitsignal > 0) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 send_msg_chansess_exitsignal(channel, chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 send_msg_chansess_exitstatus(channel, chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 /* send the exitstatus to the client */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
184 static void send_msg_chansess_exitstatus(const struct Channel * channel,
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
185 const struct ChanSess * chansess) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186
241
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 208
diff changeset
187 dropbear_assert(chansess->exit.exitpid != -1);
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 208
diff changeset
188 dropbear_assert(chansess->exit.exitsignal == -1);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 buf_putint(ses.writepayload, channel->remotechan);
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
194 buf_putstring(ses.writepayload, "exit-status", 11);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 buf_putbyte(ses.writepayload, 0); /* boolean FALSE */
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
196 buf_putint(ses.writepayload, chansess->exit.exitstatus);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 /* send the signal causing the exit to the client */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
203 static void send_msg_chansess_exitsignal(const struct Channel * channel,
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
204 const struct ChanSess * chansess) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206 int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207 char* signame = NULL;
241
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 208
diff changeset
208 dropbear_assert(chansess->exit.exitpid != -1);
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 208
diff changeset
209 dropbear_assert(chansess->exit.exitsignal > 0);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210
423
b2b67cfcd66e - Fix bug in child-exit handling where the wrong pid was being matched.
Matt Johnston <matt@ucc.asn.au>
parents: 416
diff changeset
211 TRACE(("send_msg_chansess_exitsignal %d", chansess->exit.exitsignal))
b2b67cfcd66e - Fix bug in child-exit handling where the wrong pid was being matched.
Matt Johnston <matt@ucc.asn.au>
parents: 416
diff changeset
212
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 /* we check that we can match a signal name, otherwise
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216 * don't send anything */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 for (i = 0; signames[i].name != NULL; i++) {
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
218 if (signames[i].signal == chansess->exit.exitsignal) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 signame = signames[i].name;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220 break;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224 if (signame == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
226 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 buf_putint(ses.writepayload, channel->remotechan);
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
230 buf_putstring(ses.writepayload, "exit-signal", 11);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 buf_putbyte(ses.writepayload, 0); /* boolean FALSE */
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
232 buf_putstring(ses.writepayload, signame, strlen(signame));
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
233 buf_putbyte(ses.writepayload, chansess->exit.exitcore);
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
234 buf_putstring(ses.writepayload, "", 0); /* error msg */
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
235 buf_putstring(ses.writepayload, "", 0); /* lang */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 /* set up a session channel */
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
241 static int newchansess(struct Channel *channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 struct ChanSess *chansess;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244
1038
d3925ed45a85 Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents: 974
diff changeset
245 TRACE(("new chansess %p", (void*)channel))
654
818108bf7749 - Fix use-after-free if multiple command requests were sent. Move
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
246
241
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 208
diff changeset
247 dropbear_assert(channel->typedata == NULL);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 chansess->cmd = NULL;
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
251 chansess->connection_string = NULL;
972
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
252 chansess->client_string = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 chansess->pid = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 /* pty details */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 chansess->master = -1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 chansess->slave = -1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 chansess->tty = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 chansess->term = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
261 chansess->exit.exitpid = -1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 channel->typedata = chansess;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
265 #if DROPBEAR_X11FWD
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
266 chansess->x11listener = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 chansess->x11authprot = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268 chansess->x11authcookie = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
271 #if DROPBEAR_SVR_AGENTFWD
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
272 chansess->agentlistener = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273 chansess->agentfile = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
274 chansess->agentdir = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276
1859
1d86a58fb52d Leave non-interactive at default QoS class
Matt Johnston <matt@ucc.asn.au>
parents: 1854
diff changeset
277 /* Will drop to DROPBEAR_PRIO_NORMAL if a non-tty command starts */
1d86a58fb52d Leave non-interactive at default QoS class
Matt Johnston <matt@ucc.asn.au>
parents: 1854
diff changeset
278 channel->prio = DROPBEAR_PRIO_LOWDELAY;
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 893
diff changeset
279
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
280 return 0;
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
281
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283
568
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
284 static struct logininfo*
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
285 chansess_login_alloc(const struct ChanSess *chansess) {
568
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
286 struct logininfo * li;
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
287 li = login_alloc_entry(chansess->pid, ses.authstate.username,
572
8fd0ac8c8cab Move remotehost into svr_ses structure since we can't look it up
Matt Johnston <matt@ucc.asn.au>
parents: 569
diff changeset
288 svr_ses.remotehost, chansess->tty);
568
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
289 return li;
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
290 }
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
291
1625
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
292 /* send exit status message before the channel is closed */
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
293 static void closechansess(const struct Channel *channel) {
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
294 struct ChanSess *chansess;
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
295
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
296 TRACE(("enter closechansess"))
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
297
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
298 chansess = (struct ChanSess*)channel->typedata;
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
299
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
300 if (chansess == NULL) {
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
301 TRACE(("leave closechansess: chansess == NULL"))
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
302 return;
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
303 }
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
304
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
305 send_exitsignalstatus(channel);
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
306 TRACE(("leave closechansess"))
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
307 }
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
308
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309 /* clean a session channel */
1625
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1508
diff changeset
310 static void cleanupchansess(const struct Channel *channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312 struct ChanSess *chansess;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 unsigned int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 struct logininfo *li;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 402
diff changeset
316 TRACE(("enter closechansess"))
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 402
diff changeset
317
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 chansess = (struct ChanSess*)channel->typedata;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320 if (chansess == NULL) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
321 TRACE(("leave closechansess: chansess == NULL"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 m_free(chansess->cmd);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 m_free(chansess->term);
654
818108bf7749 - Fix use-after-free if multiple command requests were sent. Move
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
327 m_free(chansess->original_command);
818108bf7749 - Fix use-after-free if multiple command requests were sent. Move
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
328
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
329 if (chansess->tty) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
330 /* write the utmp/wtmp login record */
568
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
331 li = chansess_login_alloc(chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
332 login_logout(li);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333 login_free_entry(li);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
334
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
335 pty_release(chansess->tty);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
336 m_free(chansess->tty);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
337 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
338
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
339 #if DROPBEAR_X11FWD
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
340 x11cleanup(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
341 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
342
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
343 #if DROPBEAR_SVR_AGENTFWD
560
52d7301e46bd Agent forwarding works
Matt Johnston <matt@ucc.asn.au>
parents: 508
diff changeset
344 svr_agentcleanup(chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
345 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
346
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
347 /* clear child pid entries */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
348 for (i = 0; i < svr_ses.childpidsize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
349 if (svr_ses.childpids[i].chansess == chansess) {
241
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 208
diff changeset
350 dropbear_assert(svr_ses.childpids[i].pid > 0);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
351 TRACE(("closing pid %d", svr_ses.childpids[i].pid))
423
b2b67cfcd66e - Fix bug in child-exit handling where the wrong pid was being matched.
Matt Johnston <matt@ucc.asn.au>
parents: 416
diff changeset
352 TRACE(("exitpid is %d", chansess->exit.exitpid))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
353 svr_ses.childpids[i].pid = -1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354 svr_ses.childpids[i].chansess = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
355 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
357
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
358 m_free(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
360 TRACE(("leave closechansess"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
361 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
362
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363 /* Handle requests for a channel. These can be execution requests,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
364 * or x11/authagent forwarding. These are passed to appropriate handlers */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
365 static void chansessionrequest(struct Channel *channel) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
366
1103
303e27a78d2e Turn type local variable into char *
Gaël PORTAY <gael.portay@gmail.com>
parents: 1102
diff changeset
367 char * type = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
368 unsigned int typelen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369 unsigned char wantreply;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
370 int ret = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
371 struct ChanSess *chansess;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
372
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
373 TRACE(("enter chansessionrequest"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
374
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
375 type = buf_getstring(ses.payload, &typelen);
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 171
diff changeset
376 wantreply = buf_getbool(ses.payload);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378 if (typelen > MAX_NAME_LEN) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
379 TRACE(("leave chansessionrequest: type too long")) /* XXX send error?*/
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380 goto out;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383 chansess = (struct ChanSess*)channel->typedata;
241
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 208
diff changeset
384 dropbear_assert(chansess != NULL);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
385 TRACE(("type is %s", type))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387 if (strcmp(type, "window-change") == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 ret = sessionwinchange(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389 } else if (strcmp(type, "shell") == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 ret = sessioncommand(channel, chansess, 0, 0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
391 } else if (strcmp(type, "pty-req") == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392 ret = sessionpty(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
393 } else if (strcmp(type, "exec") == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
394 ret = sessioncommand(channel, chansess, 1, 0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
395 } else if (strcmp(type, "subsystem") == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
396 ret = sessioncommand(channel, chansess, 1, 1);
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
397 #if DROPBEAR_X11FWD
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
398 } else if (strcmp(type, "x11-req") == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
399 ret = x11req(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
400 #endif
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
401 #if DROPBEAR_SVR_AGENTFWD
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 } else if (strcmp(type, "[email protected]") == 0) {
560
52d7301e46bd Agent forwarding works
Matt Johnston <matt@ucc.asn.au>
parents: 508
diff changeset
403 ret = svr_agentreq(chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405 } else if (strcmp(type, "signal") == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 ret = sessionsignal(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408 /* etc, todo "env", "subsystem" */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411 out:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413 if (wantreply) {
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
414 if (ret == DROPBEAR_SUCCESS) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415 send_msg_channel_success(channel);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417 send_msg_channel_failure(channel);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
420
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421 m_free(type);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
422 TRACE(("leave chansessionrequest"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426 /* Send a signal to a session's process as requested by the client*/
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
427 static int sessionsignal(const struct ChanSess *chansess) {
1791
685b47d8faf7 fuzz: wrap kill()
Matt Johnston <matt@ucc.asn.au>
parents: 1738
diff changeset
428 TRACE(("sessionsignal"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430 int sig = 0;
1113
367d3800555b Turn signame local variable into char *
Gaël PORTAY <gael.portay@gmail.com>
parents: 1112
diff changeset
431 char* signame = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432 int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
433
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434 if (chansess->pid == 0) {
1791
685b47d8faf7 fuzz: wrap kill()
Matt Johnston <matt@ucc.asn.au>
parents: 1738
diff changeset
435 TRACE(("sessionsignal: done no pid"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 /* haven't got a process pid yet */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
437 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
440 signame = buf_getstring(ses.payload, NULL);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441
1803
837cc354b388 small tidy of "signal" while loop
Matt Johnston <matt@ucc.asn.au>
parents: 1791
diff changeset
442 for (i = 0; signames[i].name != NULL; i++) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443 if (strcmp(signames[i].name, signame) == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
444 sig = signames[i].signal;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
445 break;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
446 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
447 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
448
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
449 m_free(signame);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
450
1791
685b47d8faf7 fuzz: wrap kill()
Matt Johnston <matt@ucc.asn.au>
parents: 1738
diff changeset
451 TRACE(("sessionsignal: pid %d signal %d", (int)chansess->pid, sig))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
452 if (sig == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453 /* failed */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
454 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
456
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
457 if (kill(chansess->pid, sig) < 0) {
1791
685b47d8faf7 fuzz: wrap kill()
Matt Johnston <matt@ucc.asn.au>
parents: 1738
diff changeset
458 TRACE(("sessionsignal: kill() errored"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
459 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
460 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
464
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465 /* Let the process know that the window size has changed, as notified from the
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466 * client. Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
467 static int sessionwinchange(const struct ChanSess *chansess) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
468
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
469 int termc, termr, termw, termh;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
470
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471 if (chansess->master < 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 /* haven't got a pty yet */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
476 termc = buf_getint(ses.payload);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
477 termr = buf_getint(ses.payload);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
478 termw = buf_getint(ses.payload);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
479 termh = buf_getint(ses.payload);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
480
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
481 pty_change_window_size(chansess->master, termr, termc, termw, termh);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
482
315
3eea61bd9993 send success message for successful window change request
Matt Johnston <matt@ucc.asn.au>
parents: 279
diff changeset
483 return DROPBEAR_SUCCESS;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
484 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
485
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1326
diff changeset
486 static void get_termmodes(const struct ChanSess *chansess) {
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
487
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
488 struct termios termio;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
489 unsigned char opcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
490 unsigned int value;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
491 const struct TermCode * termcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
492 unsigned int len;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
493
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
494 TRACE(("enter get_termmodes"))
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
495
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
496 /* Term modes */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
497 /* We'll ignore errors and continue if we can't set modes.
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
498 * We're ignoring baud rates since they seem evil */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
499 if (tcgetattr(chansess->master, &termio) == -1) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
500 return;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
501 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
502
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
503 len = buf_getint(ses.payload);
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
504 TRACE(("term mode str %d p->l %d p->p %d",
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
505 len, ses.payload->len , ses.payload->pos));
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
506 if (len != ses.payload->len - ses.payload->pos) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
507 dropbear_exit("Bad term mode string");
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
508 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
509
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
510 if (len == 0) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
511 TRACE(("leave get_termmodes: empty terminal modes string"))
171
8e68dbe8687b put back 'return;' on empty terminal mode strings which was erroneously
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
512 return;
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
513 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
514
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
515 while (((opcode = buf_getbyte(ses.payload)) != 0x00) && opcode <= 159) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
516
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
517 /* must be before checking type, so that value is consumed even if
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
518 * we don't use it */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
519 value = buf_getint(ses.payload);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
520
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
521 /* handle types of code */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
522 if (opcode > MAX_TERMCODE) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
523 continue;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
524 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
525 termcode = &termcodes[(unsigned int)opcode];
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
526
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
527
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
528 switch (termcode->type) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
529
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
530 case TERMCODE_NONE:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
531 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
532
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
533 case TERMCODE_CONTROLCHAR:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
534 termio.c_cc[termcode->mapcode] = value;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
535 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
536
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
537 case TERMCODE_INPUT:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
538 if (value) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
539 termio.c_iflag |= termcode->mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
540 } else {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
541 termio.c_iflag &= ~(termcode->mapcode);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
542 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
543 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
544
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
545 case TERMCODE_OUTPUT:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
546 if (value) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
547 termio.c_oflag |= termcode->mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
548 } else {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
549 termio.c_oflag &= ~(termcode->mapcode);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
550 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
551 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
552
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
553 case TERMCODE_LOCAL:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
554 if (value) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
555 termio.c_lflag |= termcode->mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
556 } else {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
557 termio.c_lflag &= ~(termcode->mapcode);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
558 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
559 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
560
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
561 case TERMCODE_CONTROL:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
562 if (value) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
563 termio.c_cflag |= termcode->mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
564 } else {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
565 termio.c_cflag &= ~(termcode->mapcode);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
566 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
567 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
568
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
569 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
570 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
571 if (tcsetattr(chansess->master, TCSANOW, &termio) < 0) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
572 dropbear_log(LOG_INFO, "Error setting terminal attributes");
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
573 }
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
574 TRACE(("leave get_termmodes"))
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
575 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
576
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
577 /* Set up a session pty which will be used to execute the shell or program.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
578 * The pty is allocated now, and kept for when the shell/program executes.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
579 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
580 static int sessionpty(struct ChanSess * chansess) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
581
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
582 unsigned int termlen;
1094
c45d65392c1a Fix pointer differ in signess warnings [-Werror=pointer-sign]
Gaël PORTAY <gael.portay@gmail.com>
parents: 1093
diff changeset
583 char namebuf[65];
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
584 struct passwd * pw = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
585
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
586 TRACE(("enter sessionpty"))
475
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
587
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
588 if (!svr_pubkey_allows_pty()) {
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
589 TRACE(("leave sessionpty : pty forbidden by public key option"))
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
590 return DROPBEAR_FAILURE;
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
591 }
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
592
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
593 chansess->term = buf_getstring(ses.payload, &termlen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
594 if (termlen > MAX_TERM_LEN) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
595 /* TODO send disconnect ? */
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
596 TRACE(("leave sessionpty: term len too long"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
597 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
598 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
599
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
600 /* allocate the pty */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 96
diff changeset
601 if (chansess->master != -1) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
602 dropbear_exit("Multiple pty requests");
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 96
diff changeset
603 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
604 if (pty_allocate(&chansess->master, &chansess->slave, namebuf, 64) == 0) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
605 TRACE(("leave sessionpty: failed to allocate pty"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
606 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
607 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
608
1102
ae63de5caf81 Turn ChanSess's tty and term attributes into char *
Gaël PORTAY <gael.portay@gmail.com>
parents: 1094
diff changeset
609 chansess->tty = m_strdup(namebuf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
610 if (!chansess->tty) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
611 dropbear_exit("Out of memory"); /* TODO disconnect */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
612 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
613
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
614 pw = getpwnam(ses.authstate.pw_name);
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
615 if (!pw)
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
616 dropbear_exit("getpwnam failed after succeeding previously");
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
617 pty_setowner(pw, chansess->tty);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
618
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
619 /* Set up the rows/col counts */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
620 sessionwinchange(chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
621
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
622 /* Read the terminal modes */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
623 get_termmodes(chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
624
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
625 TRACE(("leave sessionpty"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
626 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
627 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
628
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
629 #if !DROPBEAR_VFORK
974
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
630 static void make_connection_string(struct ChanSess *chansess) {
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
631 char *local_ip, *local_port, *remote_ip, *remote_port;
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
632 size_t len;
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
633 get_socket_address(ses.sock_in, &local_ip, &local_port, &remote_ip, &remote_port, 0);
974
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
634
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
635 /* "remoteip remoteport localip localport" */
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
636 len = strlen(local_ip) + strlen(remote_ip) + 20;
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
637 chansess->connection_string = m_malloc(len);
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
638 snprintf(chansess->connection_string, len, "%s %s %s %s", remote_ip, remote_port, local_ip, local_port);
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
639
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
640 /* deprecated but bash only loads .bashrc if SSH_CLIENT is set */
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
641 /* "remoteip remoteport localport" */
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
642 len = strlen(remote_ip) + 20;
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
643 chansess->client_string = m_malloc(len);
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
644 snprintf(chansess->client_string, len, "%s %s %s", remote_ip, remote_port, local_port);
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
645
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
646 m_free(local_ip);
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
647 m_free(local_port);
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
648 m_free(remote_ip);
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
649 m_free(remote_port);
972
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
650 }
1093
aae71c5f7d5b Fix unused make_connection_string() warning [-Werror=unused-function]
Gaël PORTAY <gael.portay@gmail.com>
parents: 1042
diff changeset
651 #endif
972
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
652
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
653 /* Handle a command request from the client. This is used for both shell
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
654 * and command-execution requests, and passes the command to
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
655 * noptycommand or ptycommand as appropriate.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
656 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
657 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
658 int iscmd, int issubsys) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
659
1326
79225928bf59 initialize variable
Francois Perrad <francois.perrad@gadz.org>
parents: 1295
diff changeset
660 unsigned int cmdlen = 0;
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
661 int ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
662
1804
f0cd000f3bca Prevent multiple shells being spawned
Matt Johnston <matt@ucc.asn.au>
parents: 1803
diff changeset
663 TRACE(("enter sessioncommand %d", channel->index))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
664
1804
f0cd000f3bca Prevent multiple shells being spawned
Matt Johnston <matt@ucc.asn.au>
parents: 1803
diff changeset
665 if (chansess->pid != 0) {
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
666 /* Note that only one command can _succeed_. The client might try
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
667 * one command (which fails), then try another. Ie fallback
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
668 * from sftp to scp */
1804
f0cd000f3bca Prevent multiple shells being spawned
Matt Johnston <matt@ucc.asn.au>
parents: 1803
diff changeset
669 TRACE(("leave sessioncommand, already have a command"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
670 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
671 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
672
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
673 if (iscmd) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
674 /* "exec" */
475
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
675 if (chansess->cmd == NULL) {
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1113
diff changeset
676 chansess->cmd = buf_getstring(ses.payload, &cmdlen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
677
475
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
678 if (cmdlen > MAX_CMD_LEN) {
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
679 m_free(chansess->cmd);
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
680 /* TODO - send error - too long ? */
1804
f0cd000f3bca Prevent multiple shells being spawned
Matt Johnston <matt@ucc.asn.au>
parents: 1803
diff changeset
681 TRACE(("leave sessioncommand, command too long %d", cmdlen))
475
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
682 return DROPBEAR_FAILURE;
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 466
diff changeset
683 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
684 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
685 if (issubsys) {
1499
2d450c1056e3 options: Complete the transition to numeric toggles (`#if')
Michael Witten <mfwitten@gmail.com>
parents: 1496
diff changeset
686 #if DROPBEAR_SFTPSERVER
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
687 if ((cmdlen == 4) && strncmp(chansess->cmd, "sftp", 4) == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
688 m_free(chansess->cmd);
11
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
689 chansess->cmd = m_strdup(SFTPSERVER_PATH);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
690 } else
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
691 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
692 {
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
693 m_free(chansess->cmd);
1804
f0cd000f3bca Prevent multiple shells being spawned
Matt Johnston <matt@ucc.asn.au>
parents: 1803
diff changeset
694 TRACE(("leave sessioncommand, unknown subsystem"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
695 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
696 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
697 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
698 }
566
b321aeb57c64 - set $SSH_ORIGINAL_COMMAND if a command is forced, and log it
Matt Johnston <matt@ucc.asn.au>
parents: 560
diff changeset
699
1289
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
700
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
701 /* take global command into account */
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
702 if (svr_opts.forced_command) {
1738
4f13df974cf4 Avoid gnu extension conditional operator
Matt Johnston <matt@ucc.asn.au>
parents: 1662
diff changeset
703 if (chansess->cmd) {
4f13df974cf4 Avoid gnu extension conditional operator
Matt Johnston <matt@ucc.asn.au>
parents: 1662
diff changeset
704 chansess->original_command = chansess->cmd;
4f13df974cf4 Avoid gnu extension conditional operator
Matt Johnston <matt@ucc.asn.au>
parents: 1662
diff changeset
705 } else {
4f13df974cf4 Avoid gnu extension conditional operator
Matt Johnston <matt@ucc.asn.au>
parents: 1662
diff changeset
706 chansess->original_command = m_strdup("");
4f13df974cf4 Avoid gnu extension conditional operator
Matt Johnston <matt@ucc.asn.au>
parents: 1662
diff changeset
707 }
1289
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
708 chansess->cmd = m_strdup(svr_opts.forced_command);
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
709 } else {
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
710 /* take public key option 'command' into account */
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
711 svr_pubkey_set_forced_command(chansess);
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
712 }
a23386821e9f Add -c <command> option to force a specific command
Jeremy Kerr <jk@ozlabs.org>
parents: 1154
diff changeset
713
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
714
1499
2d450c1056e3 options: Complete the transition to numeric toggles (`#if')
Michael Witten <mfwitten@gmail.com>
parents: 1496
diff changeset
715 #if LOG_COMMANDS
349
dba106bf6b34 Add (disabled by default) LOG_COMMANDS option to log the commands executed
Matt Johnston <matt@ucc.asn.au>
parents: 279
diff changeset
716 if (chansess->cmd) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
717 dropbear_log(LOG_INFO, "User %s executing '%s'",
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
718 ses.authstate.pw_name, chansess->cmd);
349
dba106bf6b34 Add (disabled by default) LOG_COMMANDS option to log the commands executed
Matt Johnston <matt@ucc.asn.au>
parents: 279
diff changeset
719 } else {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
720 dropbear_log(LOG_INFO, "User %s executing login shell",
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
721 ses.authstate.pw_name);
349
dba106bf6b34 Add (disabled by default) LOG_COMMANDS option to log the commands executed
Matt Johnston <matt@ucc.asn.au>
parents: 279
diff changeset
722 }
dba106bf6b34 Add (disabled by default) LOG_COMMANDS option to log the commands executed
Matt Johnston <matt@ucc.asn.au>
parents: 279
diff changeset
723 #endif
dba106bf6b34 Add (disabled by default) LOG_COMMANDS option to log the commands executed
Matt Johnston <matt@ucc.asn.au>
parents: 279
diff changeset
724
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
725 /* uClinux will vfork(), so there'll be a race as
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
726 connection_string is freed below. */
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
727 #if !DROPBEAR_VFORK
974
7c9377467934 Combine code for SSH_CONNECTION and SSH_CLIENT
Matt Johnston <matt@ucc.asn.au>
parents: 972
diff changeset
728 make_connection_string(chansess);
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
729 #endif
568
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
730
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
731 if (chansess->term == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
732 /* no pty */
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
733 ret = noptycommand(channel, chansess);
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 893
diff changeset
734 if (ret == DROPBEAR_SUCCESS) {
1859
1d86a58fb52d Leave non-interactive at default QoS class
Matt Johnston <matt@ucc.asn.au>
parents: 1854
diff changeset
735 channel->prio = DROPBEAR_PRIO_NORMAL;
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 893
diff changeset
736 update_channel_prio();
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 893
diff changeset
737 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
738 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
739 /* want pty */
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
740 ret = ptycommand(channel, chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
741 }
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
742
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
743 #if !DROPBEAR_VFORK
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
744 m_free(chansess->connection_string);
972
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
745 m_free(chansess->client_string);
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
746 #endif
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
747
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
748 if (ret == DROPBEAR_FAILURE) {
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
749 m_free(chansess->cmd);
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
750 }
1804
f0cd000f3bca Prevent multiple shells being spawned
Matt Johnston <matt@ucc.asn.au>
parents: 1803
diff changeset
751 TRACE(("leave sessioncommand, ret %d", ret))
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
752 return ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
753 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
754
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
755 /* Execute a command and set up redirection of stdin/stdout/stderr without a
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
756 * pty.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
757 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
758 static int noptycommand(struct Channel *channel, struct ChanSess *chansess) {
481
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
759 int ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
760
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
761 TRACE(("enter noptycommand"))
481
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
762 ret = spawn_command(execchild, chansess,
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
763 &channel->writefd, &channel->readfd, &channel->errfd,
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
764 &chansess->pid);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
765
481
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
766 if (ret == DROPBEAR_FAILURE) {
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
767 return ret;
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
768 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
769
481
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
770 ses.maxfd = MAX(ses.maxfd, channel->writefd);
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
771 ses.maxfd = MAX(ses.maxfd, channel->readfd);
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
772 ses.maxfd = MAX(ses.maxfd, channel->errfd);
1829
a7cc3332d8ab Replace ChanType.sepfds with Channel.bidir_fd
Matt Johnston <matt@ucc.asn.au>
parents: 1828
diff changeset
773 channel->bidir_fd = 0;
427
5df05d0a5366 Revert to default sigchld handler after forking, don't exit
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
774
481
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
775 addchildpid(chansess, chansess->pid);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
776
481
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
777 if (svr_ses.lastexit.exitpid != -1) {
502
43bbe17d6ba0 - Add Counter Mode support
Matt Johnston <matt@ucc.asn.au>
parents: 496
diff changeset
778 unsigned int i;
481
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
779 TRACE(("parent side: lastexitpid is %d", svr_ses.lastexit.exitpid))
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
780 /* The child probably exited and the signal handler triggered
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
781 * possibly before we got around to adding the childpid. So we fill
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
782 * out its data manually */
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
783 for (i = 0; i < svr_ses.childpidsize; i++) {
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
784 if (svr_ses.childpids[i].pid == svr_ses.lastexit.exitpid) {
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
785 TRACE(("found match for lastexitpid"))
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
786 svr_ses.childpids[i].chansess->exit = svr_ses.lastexit;
357a2e2e9bcc - Generalise spawn_command function
Matt Johnston <matt@ucc.asn.au>
parents: 480
diff changeset
787 svr_ses.lastexit.exitpid = -1;
609
306a907d23e7 Avoid segfault when handling childpid race
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
788 break;
130
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
789 }
154c8d5a6d1e propagate of 82bb923d0154750ef716b66b498561f882891946 and f51a272341ee12268fe7028bc2f2bad66c603069 from branch 'matt.dbclient.work' to 'matt.dbclient.rez'
Matt Johnston <matt@ucc.asn.au>
parents: 115
diff changeset
790 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
791 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
792
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
793 TRACE(("leave noptycommand"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
794 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
795 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
796
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
797 /* Execute a command or shell within a pty environment, and set up
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
798 * redirection as appropriate.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
799 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
800 static int ptycommand(struct Channel *channel, struct ChanSess *chansess) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
801
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
802 pid_t pid;
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
803 struct logininfo *li = NULL;
1499
2d450c1056e3 options: Complete the transition to numeric toggles (`#if')
Michael Witten <mfwitten@gmail.com>
parents: 1496
diff changeset
804 #if DO_MOTD
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
805 buffer * motdbuf = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
806 int len;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
807 struct stat sb;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
808 char *hushpath = NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
809 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
810
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
811 TRACE(("enter ptycommand"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
812
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
813 /* we need to have a pty allocated */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
814 if (chansess->master == -1 || chansess->tty == NULL) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
815 dropbear_log(LOG_WARNING, "No pty was allocated, couldn't execute");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
816 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
817 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
818
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
819 #if DROPBEAR_VFORK
273
02a80ce2ead4 Merge of the uClinux-dist patch, should work in inetd mode
Matt Johnston <matt@ucc.asn.au>
parents: 264
diff changeset
820 pid = vfork();
02a80ce2ead4 Merge of the uClinux-dist patch, should work in inetd mode
Matt Johnston <matt@ucc.asn.au>
parents: 264
diff changeset
821 #else
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
822 pid = fork();
273
02a80ce2ead4 Merge of the uClinux-dist patch, should work in inetd mode
Matt Johnston <matt@ucc.asn.au>
parents: 264
diff changeset
823 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
824 if (pid < 0)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
825 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
826
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
827 if (pid == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
828 /* child */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
829
427
5df05d0a5366 Revert to default sigchld handler after forking, don't exit
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
830 TRACE(("back to normal sigchld"))
5df05d0a5366 Revert to default sigchld handler after forking, don't exit
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
831 /* Revert to normal sigchld handling */
5df05d0a5366 Revert to default sigchld handler after forking, don't exit
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
832 if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
5df05d0a5366 Revert to default sigchld handler after forking, don't exit
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
833 dropbear_exit("signal() error");
5df05d0a5366 Revert to default sigchld handler after forking, don't exit
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
834 }
5df05d0a5366 Revert to default sigchld handler after forking, don't exit
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
835
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
836 /* redirect stdin/stdout/stderr */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
837 close(chansess->master);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
838
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
839 pty_make_controlling_tty(&chansess->slave, chansess->tty);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
840
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
841 if ((dup2(chansess->slave, STDIN_FILENO) < 0) ||
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
842 (dup2(chansess->slave, STDOUT_FILENO) < 0)) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
843 TRACE(("leave ptycommand: error redirecting filedesc"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
844 return DROPBEAR_FAILURE;
1662
8a7d26e86a56 Set SSH_ORIGINAL_COMMAND for "dropbear -c" too, fix build without
Matt Johnston <matt@ucc.asn.au>
parents: 1633
diff changeset
845 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
846
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
847 /* write the utmp/wtmp login record - must be after changing the
1840
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
848 * terminal used for stdout with the dup2 above, otherwise
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
849 * the wtmp login will not be recorded */
568
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
850 li = chansess_login_alloc(chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
851 login_login(li);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
852 login_free_entry(li);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
853
1840
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
854 /* Can now dup2 stderr. Messages from login_login() have gone
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
855 to the parent stderr */
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
856 if (dup2(chansess->slave, STDERR_FILENO) < 0) {
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
857 TRACE(("leave ptycommand: error redirecting filedesc"))
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
858 return DROPBEAR_FAILURE;
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
859 }
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
860
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
861 close(chansess->slave);
5c13e765ddbd Only redirect stderr after the session login. That lets errors
Matt Johnston <matt@ucc.asn.au>
parents: 1835
diff changeset
862
1499
2d450c1056e3 options: Complete the transition to numeric toggles (`#if')
Michael Witten <mfwitten@gmail.com>
parents: 1496
diff changeset
863 #if DO_MOTD
1154
b1fabf797bd3 Don't display the MOTD when an explicit command is run.
Guilhem Moulin <guilhem@fripost.org>
parents: 1122
diff changeset
864 if (svr_opts.domotd && !chansess->cmd) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
865 /* don't show the motd if ~/.hushlogin exists */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
866
462
1009980436c2 Actually use ~/.hushlogin rather than ~/hushlogin to ignore motd.
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
867 /* 12 == strlen("/.hushlogin\0") */
466
f11544d96354 fix up after merge
Matt Johnston <matt@ucc.asn.au>
parents: 465
diff changeset
868 len = strlen(ses.authstate.pw_dir) + 12;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
869
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
870 hushpath = m_malloc(len);
466
f11544d96354 fix up after merge
Matt Johnston <matt@ucc.asn.au>
parents: 465
diff changeset
871 snprintf(hushpath, len, "%s/.hushlogin", ses.authstate.pw_dir);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
872
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
873 if (stat(hushpath, &sb) < 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
874 /* more than a screenful is stupid IMHO */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
875 motdbuf = buf_new(80 * 25);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
876 if (buf_readfile(motdbuf, MOTD_FILENAME) == DROPBEAR_SUCCESS) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
877 buf_setpos(motdbuf, 0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
878 while (motdbuf->pos != motdbuf->len) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
879 len = motdbuf->len - motdbuf->pos;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
880 len = write(STDOUT_FILENO,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
881 buf_getptr(motdbuf, len), len);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
882 buf_incrpos(motdbuf, len);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
883 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
884 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
885 buf_free(motdbuf);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
886 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
887 m_free(hushpath);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
888 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
889 #endif /* DO_MOTD */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
890
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
891 execchild(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
892 /* not reached */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
893
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
894 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
895 /* parent */
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
896 TRACE(("continue ptycommand: parent"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
897 chansess->pid = pid;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
898
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
899 /* add a child pid */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
900 addchildpid(chansess, pid);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
901
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
902 close(chansess->slave);
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
903 channel->writefd = chansess->master;
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
904 channel->readfd = chansess->master;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
905 /* don't need to set stderr here */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
906 ses.maxfd = MAX(ses.maxfd, chansess->master);
1829
a7cc3332d8ab Replace ChanType.sepfds with Channel.bidir_fd
Matt Johnston <matt@ucc.asn.au>
parents: 1828
diff changeset
907 channel->bidir_fd = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
908
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
909 setnonblocking(chansess->master);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
910
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
911 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
912
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 133
diff changeset
913 TRACE(("leave ptycommand"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
914 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
915 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
916
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
917 /* Add the pid of a child to the list for exit-handling */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
918 static void addchildpid(struct ChanSess *chansess, pid_t pid) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
919
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
920 unsigned int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
921 for (i = 0; i < svr_ses.childpidsize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
922 if (svr_ses.childpids[i].pid == -1) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
923 break;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
924 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
925 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
926
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
927 /* need to increase size */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
928 if (i == svr_ses.childpidsize) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
929 svr_ses.childpids = (struct ChildPid*)m_realloc(svr_ses.childpids,
264
541b14504870 * fix incorrect array sizing
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
930 sizeof(struct ChildPid) * (svr_ses.childpidsize+1));
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
931 svr_ses.childpidsize++;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
932 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
933
1804
f0cd000f3bca Prevent multiple shells being spawned
Matt Johnston <matt@ucc.asn.au>
parents: 1803
diff changeset
934 TRACE(("addchildpid %d pid %d for chansess %p", i, pid, chansess))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
935 svr_ses.childpids[i].pid = pid;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
936 svr_ses.childpids[i].chansess = chansess;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
937
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
938 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
939
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
940 /* Clean up, drop to user privileges, set up the environment and execute
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
941 * the command/shell. This function does not return. */
1460
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
942 static void execchild(const void *user_data) {
1496
da3bed08607b fix compile warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1495
diff changeset
943 const struct ChanSess *chansess = user_data;
482
7ad49f34a122 - Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents: 481
diff changeset
944 char *usershell = NULL;
1824
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
945 char *cp = NULL;
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
946 char *envcp = getenv("LANG");
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
947 if (envcp != NULL) {
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
948 cp = m_strdup(envcp);
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
949 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
950
666
0ad95abf8d3c check for fork() and not __uClinux__
Mike Frysinger <vapier@gentoo.org>
parents: 658
diff changeset
951 /* with uClinux we'll have vfork()ed, so don't want to overwrite the
0ad95abf8d3c check for fork() and not __uClinux__
Mike Frysinger <vapier@gentoo.org>
parents: 658
diff changeset
952 * hostkey. can't think of a workaround to clear it */
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
953 #if !DROPBEAR_VFORK
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
954 /* wipe the hostkey */
24
469950e86d0f switching to global vars
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
955 sign_key_free(svr_opts.hostkey);
469950e86d0f switching to global vars
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
956 svr_opts.hostkey = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
957
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
958 /* overwrite the prng state */
687
167fdc091c05 Improve RNG seeding.
Matt Johnston <matt@ucc.asn.au>
parents: 668
diff changeset
959 seedrandom();
273
02a80ce2ead4 Merge of the uClinux-dist patch, should work in inetd mode
Matt Johnston <matt@ucc.asn.au>
parents: 264
diff changeset
960 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
961
1819
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
962 /* clear environment if -e was not set */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
963 /* if we're debugging using valgrind etc, we need to keep the LD_PRELOAD
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
964 * etc. This is hazardous, so should only be used for debugging. */
1819
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
965 if ( !svr_opts.pass_on_env) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
966 #ifndef DEBUG_VALGRIND
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
967 #ifdef HAVE_CLEARENV
1819
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
968 clearenv();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
969 #else /* don't HAVE_CLEARENV */
1819
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
970 /* Yay for posix. */
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
971 if (environ) {
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
972 environ[0] = NULL;
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
973 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
974 #endif /* HAVE_CLEARENV */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
975 #endif /* DEBUG_VALGRIND */
1819
5120e22882de pass on sever process environment to child processes (option -e) (#118)
Roland Vollgraf <30869947+rvollgraf@users.noreply.github.com>
parents: 1804
diff changeset
976 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
977
1633
592a18dac250 Support servers without multiple user support (#76)
Patrick Stewart <patstew@gmail.com>
parents: 1625
diff changeset
978 #if DROPBEAR_SVR_MULTIUSER
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
979 /* We can only change uid/gid as root ... */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
980 if (getuid() == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
981
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
982 if ((setgid(ses.authstate.pw_gid) < 0) ||
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
983 (initgroups(ses.authstate.pw_name,
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
984 ses.authstate.pw_gid) < 0)) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
985 dropbear_exit("Error changing user group");
204
675f7bf3c391 Seperate out exit errors from setgid()/initgroups(), and errors from setuid(),
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
986 }
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
987 if (setuid(ses.authstate.pw_uid) < 0) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
988 dropbear_exit("Error changing user");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
989 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
990 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
991 /* ... but if the daemon is the same uid as the requested uid, we don't
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
992 * need to */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
993
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
994 /* XXX - there is a minor issue here, in that if there are multiple
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
995 * usernames with the same uid, but differing groups, then the
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
996 * differing groups won't be set (as with initgroups()). The solution
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
997 * is for the sysadmin not to give out the UID twice */
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
998 if (getuid() != ses.authstate.pw_uid) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
999 dropbear_exit("Couldn't change user as non-root");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1000 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1001 }
1633
592a18dac250 Support servers without multiple user support (#76)
Patrick Stewart <patstew@gmail.com>
parents: 1625
diff changeset
1002 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1003
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1004 /* set env vars */
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
1005 addnewvar("USER", ses.authstate.pw_name);
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
1006 addnewvar("LOGNAME", ses.authstate.pw_name);
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
1007 addnewvar("HOME", ses.authstate.pw_dir);
482
7ad49f34a122 - Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents: 481
diff changeset
1008 addnewvar("SHELL", get_user_shell());
508
d4bbc0039008 - Set a default path, since bash won't export one otherwise (though it will set
Matt Johnston <matt@ucc.asn.au>
parents: 502
diff changeset
1009 addnewvar("PATH", DEFAULT_PATH);
1824
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
1010 if (cp != NULL) {
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
1011 addnewvar("LANG", cp);
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
1012 m_free(cp);
1edf4f143e12 keep LANG env variable for child process (#111)
fidomax <adobegitler@gmail.com>
parents: 1819
diff changeset
1013 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1014 if (chansess->term != NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1015 addnewvar("TERM", chansess->term);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1016 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1017
567
893a9dd0b9dd - set $SSH_TTY environment variable
Matt Johnston <matt@ucc.asn.au>
parents: 566
diff changeset
1018 if (chansess->tty) {
893a9dd0b9dd - set $SSH_TTY environment variable
Matt Johnston <matt@ucc.asn.au>
parents: 566
diff changeset
1019 addnewvar("SSH_TTY", chansess->tty);
893a9dd0b9dd - set $SSH_TTY environment variable
Matt Johnston <matt@ucc.asn.au>
parents: 566
diff changeset
1020 }
893a9dd0b9dd - set $SSH_TTY environment variable
Matt Johnston <matt@ucc.asn.au>
parents: 566
diff changeset
1021
569
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
1022 if (chansess->connection_string) {
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
1023 addnewvar("SSH_CONNECTION", chansess->connection_string);
6f472dc54da7 - Set $SSH_CONNECTION
Matt Johnston <matt@ucc.asn.au>
parents: 568
diff changeset
1024 }
972
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
1025
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
1026 if (chansess->client_string) {
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
1027 addnewvar("SSH_CLIENT", chansess->client_string);
eb5cb4f45cd6 Add SSH_CLIENT environment variable
Ryan Cleere <ryan.cleere@rackspace.com>
parents: 970
diff changeset
1028 }
568
005530560594 Rearrange getaddrstring() etc
Matt Johnston <matt@ucc.asn.au>
parents: 567
diff changeset
1029
654
818108bf7749 - Fix use-after-free if multiple command requests were sent. Move
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
1030 if (chansess->original_command) {
818108bf7749 - Fix use-after-free if multiple command requests were sent. Move
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
1031 addnewvar("SSH_ORIGINAL_COMMAND", chansess->original_command);
566
b321aeb57c64 - set $SSH_ORIGINAL_COMMAND if a command is forced, and log it
Matt Johnston <matt@ucc.asn.au>
parents: 560
diff changeset
1032 }
1882
2839daa507b3 set envvar SSH_PUBKEYINFO if authstate.pubkey_info contains information
HansH111 <hans@atbas.org>
parents: 1875
diff changeset
1033 if (ses.authstate.pubkey_info != NULL) {
2839daa507b3 set envvar SSH_PUBKEYINFO if authstate.pubkey_info contains information
HansH111 <hans@atbas.org>
parents: 1875
diff changeset
1034 addnewvar("SSH_PUBKEYINFO", ses.authstate.pubkey_info);
2839daa507b3 set envvar SSH_PUBKEYINFO if authstate.pubkey_info contains information
HansH111 <hans@atbas.org>
parents: 1875
diff changeset
1035 }
566
b321aeb57c64 - set $SSH_ORIGINAL_COMMAND if a command is forced, and log it
Matt Johnston <matt@ucc.asn.au>
parents: 560
diff changeset
1036
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1037 /* change directory */
464
4317be8b7cf9 Make a copy of passwd fields since getpwnam()'s retval isn't safe to keep
Matt Johnston <matt@ucc.asn.au>
parents: 427
diff changeset
1038 if (chdir(ses.authstate.pw_dir) < 0) {
1875
bfa92efd814b Make missing homedir non-fatal, instead use /
Matt Johnston <matt@ucc.asn.au>
parents: 1861
diff changeset
1039 int e = errno;
bfa92efd814b Make missing homedir non-fatal, instead use /
Matt Johnston <matt@ucc.asn.au>
parents: 1861
diff changeset
1040 if (chdir("/") < 0) {
bfa92efd814b Make missing homedir non-fatal, instead use /
Matt Johnston <matt@ucc.asn.au>
parents: 1861
diff changeset
1041 dropbear_exit("chdir(\"/\") failed");
bfa92efd814b Make missing homedir non-fatal, instead use /
Matt Johnston <matt@ucc.asn.au>
parents: 1861
diff changeset
1042 }
bfa92efd814b Make missing homedir non-fatal, instead use /
Matt Johnston <matt@ucc.asn.au>
parents: 1861
diff changeset
1043 fprintf(stderr, "Failed chdir '%s': %s\n", ses.authstate.pw_dir, strerror(e));
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1044 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1045
1875
bfa92efd814b Make missing homedir non-fatal, instead use /
Matt Johnston <matt@ucc.asn.au>
parents: 1861
diff changeset
1046
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
1047 #if DROPBEAR_X11FWD
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1048 /* set up X11 forwarding if enabled */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1049 x11setauth(chansess);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1050 #endif
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1289
diff changeset
1051 #if DROPBEAR_SVR_AGENTFWD
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1052 /* set up agent env variable */
560
52d7301e46bd Agent forwarding works
Matt Johnston <matt@ucc.asn.au>
parents: 508
diff changeset
1053 svr_agentset(chansess);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1054 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1055
482
7ad49f34a122 - Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents: 481
diff changeset
1056 usershell = m_strdup(get_user_shell());
7ad49f34a122 - Add run_shell_command() function to run a "sh -c" command, handling
Matt Johnston <matt@ucc.asn.au>
parents: 481
diff changeset
1057 run_shell_command(chansess->cmd, ses.maxfd, usershell);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1058
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1059 /* only reached on error */
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 581
diff changeset
1060 dropbear_exit("Child failed");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1061 }
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
1062
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1063 /* Set up the general chansession environment, in particular child-exit
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1064 * handling */
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1065 void svr_chansessinitialise() {
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1066
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1067 struct sigaction sa_chld;
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1068
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1069 /* single child process intially */
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1070 svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid));
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1071 svr_ses.childpids[0].pid = -1; /* unused */
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1072 svr_ses.childpids[0].chansess = NULL;
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1073 svr_ses.childpidsize = 1;
133
b4cfe976c8e1 Initialise the "lastexit" variable so that we don't get session channels
Matt Johnston <matt@ucc.asn.au>
parents: 130
diff changeset
1074 svr_ses.lastexit.exitpid = -1; /* Nothing has exited yet */
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1075 sa_chld.sa_handler = sesssigchild_handler;
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1076 sa_chld.sa_flags = SA_NOCLDSTOP;
658
d4d0279710b9 - Initialise sa_mask properly
Matt Johnston <matt@ucc.asn.au>
parents: 657
diff changeset
1077 sigemptyset(&sa_chld.sa_mask);
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1078 if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) {
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1079 dropbear_exit("signal() error");
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1080 }
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1081
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1082 }
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
1083
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1084 /* add a new environment variable, allocating space for the entry */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1085 void addnewvar(const char* param, const char* var) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1086
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
1087 char* newvar = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1088 int plen, vlen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1089
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1090 plen = strlen(param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1091 vlen = strlen(var);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1092
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1093 newvar = m_malloc(plen + vlen + 2); /* 2 is for '=' and '\0' */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1094 memcpy(newvar, param, plen);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1095 newvar[plen] = '=';
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1096 memcpy(&newvar[plen+1], var, vlen);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1097 newvar[plen+vlen+1] = '\0';
372
fbcc3b5b34f3 comment about putenv() leaking malloced variables
Matt Johnston <matt@ucc.asn.au>
parents: 369
diff changeset
1098 /* newvar is leaked here, but that's part of putenv()'s semantics */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1099 if (putenv(newvar) < 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1100 dropbear_exit("environ error");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1101 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1102 }