Mercurial > dropbear
annotate cli-main.c @ 1715:3974f087d9c0
Disallow leading lines before the ident for server (#102)
Per RFC4253 4.2 clients must be able to process other lines of data
before the version string, server behavior is not defined neither
with MUST/SHOULD nor with MAY.
If server process up to 50 lines too - it may cause too long hanging
session with invalid/evil client that consume host resources and
potentially may lead to DDoS on poor embedded boxes.
Let's require first line from client to be version string and fail
early if it's not - matches both RFC and real OpenSSH behavior.
author | Vladislav Grishenko <themiron@users.noreply.github.com> |
---|---|
date | Mon, 15 Jun 2020 18:22:18 +0500 |
parents | 789466c5956b |
children | d1b279aa5ed1 |
rev | line source |
---|---|
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
1 /* |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
2 * Dropbear - a SSH2 server |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
3 * SSH client implementation |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
4 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
5 * Copyright (c) 2002,2003 Matt Johnston |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
6 * Copyright (c) 2004 by Mihnea Stoenescu |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
7 * All rights reserved. |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
8 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
9 * Permission is hereby granted, free of charge, to any person obtaining a copy |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
10 * of this software and associated documentation files (the "Software"), to deal |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
11 * in the Software without restriction, including without limitation the rights |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
13 * copies of the Software, and to permit persons to whom the Software is |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
14 * furnished to do so, subject to the following conditions: |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
15 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
16 * The above copyright notice and this permission notice shall be included in |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
17 * all copies or substantial portions of the Software. |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
18 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
25 * SOFTWARE. */ |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
26 |
33 | 27 #include "includes.h" |
28 #include "dbutil.h" | |
29 #include "runopts.h" | |
30 #include "session.h" | |
858
220f55d540ae
rename random.h to dbrandom.h since some OSes have a system random.h
Matt Johnston <matt@ucc.asn.au>
parents:
857
diff
changeset
|
31 #include "dbrandom.h" |
795 | 32 #include "crypto_desc.h" |
1032
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
1027
diff
changeset
|
33 #include "netio.h" |
26 | 34 |
614
00eca37e47e8
Add noreturn and format attribute hints for some functions.
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
35 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) ATTRIB_NORETURN; |
33 | 36 static void cli_dropbear_log(int priority, const char* format, va_list param); |
37 | |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
38 #if DROPBEAR_CLI_PROXYCMD |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
39 static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out); |
1216
3daff2072bd0
rename killchild to kill_proxy_sighandler
Matt Johnston <matt@ucc.asn.au>
parents:
1215
diff
changeset
|
40 static void kill_proxy_sighandler(int signo); |
542
c9128994a2d6
Wrap proxycmd function in ENABLE_CLI_PROXYCMD #ifdef
Matt Johnston <matt@ucc.asn.au>
parents:
484
diff
changeset
|
41 #endif |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
42 |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
43 #if defined(DBMULTI_dbclient) || !DROPBEAR_MULTI |
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
44 #if defined(DBMULTI_dbclient) && DROPBEAR_MULTI |
33 | 45 int cli_main(int argc, char ** argv) { |
46 #else | |
26 | 47 int main(int argc, char ** argv) { |
33 | 48 #endif |
26 | 49 |
479
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
425
diff
changeset
|
50 int sock_in, sock_out; |
1027
daf21fd50abf
In theory TFO should work. Needs platform cleanup and testing
Matt Johnston <matt@ucc.asn.au>
parents:
1025
diff
changeset
|
51 struct dropbear_progress_connection *progress = NULL; |
26 | 52 |
53 _dropbear_exit = cli_dropbear_exit; | |
54 _dropbear_log = cli_dropbear_log; | |
55 | |
425 | 56 disallow_core(); |
57 | |
795 | 58 seedrandom(); |
59 crypto_init(); | |
60 | |
26 | 61 cli_getopts(argc, argv); |
62 | |
1212
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
63 #ifndef DISABLE_SYSLOG |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
64 if (opts.usingsyslog) { |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
65 startsyslog("dbclient"); |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
66 } |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
67 #endif |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
68 |
1466
f787f60f8e45
bind to port as well with -b
Matt Johnston <matt@ucc.asn.au>
parents:
1465
diff
changeset
|
69 TRACE(("user='%s' host='%s' port='%s' bind_address='%s' bind_port='%s'", cli_opts.username, |
f787f60f8e45
bind to port as well with -b
Matt Johnston <matt@ucc.asn.au>
parents:
1465
diff
changeset
|
70 cli_opts.remotehost, cli_opts.remoteport, cli_opts.bind_address, cli_opts.bind_port)) |
33 | 71 |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
72 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
73 dropbear_exit("signal() error"); |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
74 } |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
75 |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
76 pid_t proxy_cmd_pid = 0; |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
77 #if DROPBEAR_CLI_PROXYCMD |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
78 if (cli_opts.proxycmd) { |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
79 cli_proxy_cmd(&sock_in, &sock_out, &proxy_cmd_pid); |
544
9e51707cd6f2
- Make -i and -W pass through multihop arguments
Matt Johnston <matt@ucc.asn.au>
parents:
542
diff
changeset
|
80 m_free(cli_opts.proxycmd); |
1216
3daff2072bd0
rename killchild to kill_proxy_sighandler
Matt Johnston <matt@ucc.asn.au>
parents:
1215
diff
changeset
|
81 if (signal(SIGINT, kill_proxy_sighandler) == SIG_ERR || |
3daff2072bd0
rename killchild to kill_proxy_sighandler
Matt Johnston <matt@ucc.asn.au>
parents:
1215
diff
changeset
|
82 signal(SIGTERM, kill_proxy_sighandler) == SIG_ERR || |
3daff2072bd0
rename killchild to kill_proxy_sighandler
Matt Johnston <matt@ucc.asn.au>
parents:
1215
diff
changeset
|
83 signal(SIGHUP, kill_proxy_sighandler) == SIG_ERR) { |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
84 dropbear_exit("signal() error"); |
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
85 } |
479
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
425
diff
changeset
|
86 } else |
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
425
diff
changeset
|
87 #endif |
e3db1f7a2e43
- Split main socket var into ses.sock_in/ses.sock_out in preparation
Matt Johnston <matt@ucc.asn.au>
parents:
425
diff
changeset
|
88 { |
1466
f787f60f8e45
bind to port as well with -b
Matt Johnston <matt@ucc.asn.au>
parents:
1465
diff
changeset
|
89 progress = connect_remote(cli_opts.remotehost, cli_opts.remoteport, |
f787f60f8e45
bind to port as well with -b
Matt Johnston <matt@ucc.asn.au>
parents:
1465
diff
changeset
|
90 cli_connected, &ses, cli_opts.bind_address, cli_opts.bind_port); |
1025 | 91 sock_in = sock_out = -1; |
26 | 92 } |
93 | |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
94 cli_session(sock_in, sock_out, progress, proxy_cmd_pid); |
26 | 95 |
96 /* not reached */ | |
97 return -1; | |
98 } | |
33 | 99 #endif /* DBMULTI stuff */ |
100 | |
101 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { | |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
102 char exitmsg[150]; |
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
103 char fullmsg[300]; |
33 | 104 |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
105 /* Note that exit message must be rendered before session cleanup */ |
33 | 106 |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
107 /* Render the formatted exit message */ |
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
108 vsnprintf(exitmsg, sizeof(exitmsg), format, param); |
1676
d5cdc60db08e
ext-info handling for server-sig-algs
Matt Johnston <matt@ucc.asn.au>
parents:
1516
diff
changeset
|
109 TRACE(("Exited, cleaning up: %s", exitmsg)) |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
110 |
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
111 /* Add the prefix depending on session/auth state */ |
1495
0c16b4ccbd54
make signal flags volatile, simplify handling
Matt Johnston <matt@ucc.asn.au>
parents:
1466
diff
changeset
|
112 if (!ses.init_done) { |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
113 snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg); |
33 | 114 } else { |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
115 snprintf(fullmsg, sizeof(fullmsg), |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
568
diff
changeset
|
116 "Connection to %s@%s:%s exited: %s", |
33 | 117 cli_opts.username, cli_opts.remotehost, |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
118 cli_opts.remoteport, exitmsg); |
33 | 119 } |
120 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
121 /* Do the cleanup first, since then the terminal will be reset */ |
733
70811267715c
Run the cleanup handler also when we close due to TCP connection being closed
Matt Johnston <matt@ucc.asn.au>
parents:
614
diff
changeset
|
122 session_cleanup(); |
938
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
871
diff
changeset
|
123 /* Avoid printing onwards from terminal cruft */ |
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
871
diff
changeset
|
124 fprintf(stderr, "\n"); |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
125 |
1304
b66a483f3dcb
Improve exit message formatting
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
126 dropbear_log(LOG_INFO, "%s", fullmsg); |
33 | 127 exit(exitcode); |
128 } | |
129 | |
1212
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
130 static void cli_dropbear_log(int priority, |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
74
diff
changeset
|
131 const char* format, va_list param) { |
33 | 132 |
133 char printbuf[1024]; | |
1697 | 134 const char *name; |
135 | |
136 name = cli_opts.progname; | |
137 if (!name) { | |
138 name = "dbclient"; | |
139 } | |
33 | 140 |
141 vsnprintf(printbuf, sizeof(printbuf), format, param); | |
142 | |
1212
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
143 #ifndef DISABLE_SYSLOG |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
144 if (opts.usingsyslog) { |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
145 syslog(priority, "%s", printbuf); |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
146 } |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
147 #endif |
bf626d259eb1
Support syslog logging in dbclient.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1208
diff
changeset
|
148 |
1697 | 149 fprintf(stderr, "%s: %s\n", name, printbuf); |
938
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
871
diff
changeset
|
150 fflush(stderr); |
33 | 151 } |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
152 |
1460
58a74cb829b8
Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents:
1316
diff
changeset
|
153 static void exec_proxy_cmd(const void *user_data_cmd) { |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
154 const char *cmd = user_data_cmd; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
155 char *usershell; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
156 |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
157 usershell = m_strdup(get_user_shell()); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
158 run_shell_command(cmd, ses.maxfd, usershell); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
159 dropbear_exit("Failed to run '%s'\n", cmd); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
160 } |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
161 |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
162 #if DROPBEAR_CLI_PROXYCMD |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
163 static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) { |
1221 | 164 char * ex_cmd = NULL; |
165 size_t ex_cmdlen; | |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
166 int ret; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
167 |
1516
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
168 /* File descriptor "-j &3" */ |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
169 if (*cli_opts.proxycmd == '&') { |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
170 char *p = cli_opts.proxycmd + 1; |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
171 int sock = strtoul(p, &p, 10); |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
172 /* must be a single number, and not stdin/stdout/stderr */ |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
173 if (sock > 2 && sock < 1024 && *p == '\0') { |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
174 *sock_in = sock; |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
175 *sock_out = sock; |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
176 return; |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
177 } |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
178 } |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
179 |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
180 /* Normal proxycommand */ |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
181 |
33b872649eb7
Add dbclient '-J &fd' option for a file descriptor
Matt Johnston <matt@ucc.asn.au>
parents:
1495
diff
changeset
|
182 /* So that spawn_command knows which shell to run */ |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
183 fill_passwd(cli_opts.own_user); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
184 |
1221 | 185 ex_cmdlen = strlen(cli_opts.proxycmd) + 6; /* "exec " + command + '\0' */ |
186 ex_cmd = m_malloc(ex_cmdlen); | |
187 snprintf(ex_cmd, ex_cmdlen, "exec %s", cli_opts.proxycmd); | |
188 | |
189 ret = spawn_command(exec_proxy_cmd, ex_cmd, | |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
190 sock_out, sock_in, NULL, pid_out); |
1221 | 191 m_free(ex_cmd); |
483
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
192 if (ret == DROPBEAR_FAILURE) { |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
193 dropbear_exit("Failed running proxy command"); |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
194 *sock_in = *sock_out = -1; |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
195 } |
738313e73b1c
- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
Matt Johnston <matt@ucc.asn.au>
parents:
479
diff
changeset
|
196 } |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
197 |
1216
3daff2072bd0
rename killchild to kill_proxy_sighandler
Matt Johnston <matt@ucc.asn.au>
parents:
1215
diff
changeset
|
198 static void kill_proxy_sighandler(int UNUSED(signo)) { |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
199 kill_proxy_command(); |
1216
3daff2072bd0
rename killchild to kill_proxy_sighandler
Matt Johnston <matt@ucc.asn.au>
parents:
1215
diff
changeset
|
200 _exit(1); |
1208
fb58cf341951
Client: kill proxy command when exiting application.
Konstantin Tokarev <ktokarev@smartlabs.tv>
parents:
1065
diff
changeset
|
201 } |
1295
750ec4ec4cbe
Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents:
1221
diff
changeset
|
202 #endif /* DROPBEAR_CLI_PROXYCMD */ |