/src/dropbear/src/svr-forward.c
Line | Count | Source |
1 | | /* |
2 | | * Dropbear SSH |
3 | | * |
4 | | * Copyright (c) 2002,2003 Matt Johnston |
5 | | * Copyright (c) 2004 by Mihnea Stoenescu |
6 | | * All rights reserved. |
7 | | * |
8 | | * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | | * of this software and associated documentation files (the "Software"), to deal |
10 | | * in the Software without restriction, including without limitation the rights |
11 | | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12 | | * copies of the Software, and to permit persons to whom the Software is |
13 | | * furnished to do so, subject to the following conditions: |
14 | | * |
15 | | * The above copyright notice and this permission notice shall be included in |
16 | | * all copies or substantial portions of the Software. |
17 | | * |
18 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21 | | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 | | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
24 | | * SOFTWARE. */ |
25 | | |
26 | | #include "includes.h" |
27 | | #include "ssh.h" |
28 | | #include "forward.h" |
29 | | #include "dbutil.h" |
30 | | #include "session.h" |
31 | | #include "buffer.h" |
32 | | #include "packet.h" |
33 | | #include "listener.h" |
34 | | #include "runopts.h" |
35 | | #include "auth.h" |
36 | | |
37 | 0 | void svr_recv_msg_global_request(void) { |
38 | |
|
39 | 0 | char* reqname = NULL; |
40 | 0 | unsigned int namelen; |
41 | 0 | unsigned int wantreply = 0; |
42 | 0 | int ret = DROPBEAR_FAILURE; |
43 | |
|
44 | 0 | TRACE(("enter recv_msg_global_request_remote")) |
45 | |
|
46 | 0 | reqname = buf_getstring(ses.payload, &namelen); |
47 | 0 | wantreply = buf_getbool(ses.payload); |
48 | |
|
49 | 0 | #if DROPBEAR_SVR_REMOTEANYFWD |
50 | 0 | if (svr_opts.noremotefwd || !svr_pubkey_allows_tcpfwd()) { |
51 | 0 | TRACE(("remote forwarding is disabled")); |
52 | 0 | goto out; |
53 | 0 | } |
54 | | #else |
55 | | /* No request handlers */ |
56 | | goto out; |
57 | | #endif |
58 | | |
59 | 0 | if (namelen > MAX_NAME_LEN) { |
60 | 0 | TRACE(("name len is wrong: %d", namelen)) |
61 | 0 | goto out; |
62 | 0 | } |
63 | | |
64 | 0 | if (0) {} |
65 | 0 | #if DROPBEAR_SVR_REMOTETCPFWD |
66 | 0 | else if (strcmp("tcpip-forward", reqname) == 0) { |
67 | 0 | ret = svr_remotetcpreq(wantreply); |
68 | | /* svr_remotetcpreq sends its on reply if needed, |
69 | | * don't send another in out: below */ |
70 | 0 | wantreply = 0; |
71 | 0 | } else if (strcmp("cancel-tcpip-forward", reqname) == 0) { |
72 | 0 | ret = svr_cancelremotetcp(); |
73 | 0 | } |
74 | 0 | #endif |
75 | 0 | #if DROPBEAR_SVR_REMOTESTREAMFWD |
76 | 0 | else if (strcmp("streamlocal-forward@openssh.com", reqname) == 0) { |
77 | 0 | ret = svr_remotestreamlocalreq(); |
78 | 0 | } else if (strcmp("cancel-streamlocal-forward@openssh.com", reqname) == 0) { |
79 | 0 | ret = svr_cancelremotestreamlocal(); |
80 | 0 | } |
81 | 0 | #endif |
82 | 0 | else { |
83 | 0 | TRACE(("unhandled request '%s'", reqname)) |
84 | 0 | } |
85 | |
|
86 | 0 | out: |
87 | 0 | if (wantreply) { |
88 | 0 | if (ret == DROPBEAR_SUCCESS) { |
89 | 0 | send_msg_request_success(); |
90 | 0 | } else { |
91 | 0 | send_msg_request_failure(); |
92 | 0 | } |
93 | 0 | } |
94 | |
|
95 | 0 | m_free(reqname); |
96 | |
|
97 | 0 | TRACE(("leave recv_msg_global_request")) |
98 | 0 | } |