diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-01-19 21:37:13 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-01-20 09:02:37 +1100 |
commit | 8cc7a679d29cf6ecccfa08191e688c7f81ef95c2 (patch) | |
tree | d12cd9dc5339b57b2949132c2605525636cc6807 | |
parent | 06232038c794c7dfcb087be0ab0b3e65b09fd396 (diff) |
upstream: convert channels.c to new packet API
with & ok markus@
OpenBSD-Commit-ID: 0b8279b56113cbd4011fc91315c0796b63dc862c
-rw-r--r-- | channels.c | 68 |
1 files changed, 38 insertions, 30 deletions
diff --git a/channels.c b/channels.c index dcda44b07..19da16eb3 100644 --- a/channels.c +++ b/channels.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: channels.c,v 1.388 2019/01/19 21:31:32 djm Exp $ */ | 1 | /* $OpenBSD: channels.c,v 1.389 2019/01/19 21:37:13 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -84,9 +84,6 @@ | |||
84 | #include "pathnames.h" | 84 | #include "pathnames.h" |
85 | #include "match.h" | 85 | #include "match.h" |
86 | 86 | ||
87 | #include "opacket.h" /* XXX */ | ||
88 | extern struct ssh *active_state; /* XXX */ | ||
89 | |||
90 | /* -- agent forwarding */ | 87 | /* -- agent forwarding */ |
91 | #define NUM_SOCKS 10 | 88 | #define NUM_SOCKS 10 |
92 | 89 | ||
@@ -2994,10 +2991,10 @@ channel_input_data(int type, u_int32_t seq, struct ssh *ssh) | |||
2994 | return 0; | 2991 | return 0; |
2995 | 2992 | ||
2996 | /* Get the data. */ | 2993 | /* Get the data. */ |
2997 | if ((r = sshpkt_get_string_direct(ssh, &data, &data_len)) != 0) | 2994 | if ((r = sshpkt_get_string_direct(ssh, &data, &data_len)) != 0 || |
2995 | (r = sshpkt_get_end(ssh)) != 0) | ||
2998 | fatal("%s: channel %d: get data: %s", __func__, | 2996 | fatal("%s: channel %d: get data: %s", __func__, |
2999 | c->self, ssh_err(r)); | 2997 | c->self, ssh_err(r)); |
3000 | ssh_packet_check_eom(ssh); | ||
3001 | 2998 | ||
3002 | win_len = data_len; | 2999 | win_len = data_len; |
3003 | if (c->datagram) | 3000 | if (c->datagram) |
@@ -3071,11 +3068,11 @@ channel_input_extended_data(int type, u_int32_t seq, struct ssh *ssh) | |||
3071 | logit("channel %d: bad ext data", c->self); | 3068 | logit("channel %d: bad ext data", c->self); |
3072 | return 0; | 3069 | return 0; |
3073 | } | 3070 | } |
3074 | if ((r = sshpkt_get_string_direct(ssh, &data, &data_len)) != 0) { | 3071 | if ((r = sshpkt_get_string_direct(ssh, &data, &data_len)) != 0 || |
3072 | (r = sshpkt_get_end(ssh)) != 0) { | ||
3075 | error("%s: parse data: %s", __func__, ssh_err(r)); | 3073 | error("%s: parse data: %s", __func__, ssh_err(r)); |
3076 | ssh_packet_disconnect(ssh, "Invalid extended_data message"); | 3074 | ssh_packet_disconnect(ssh, "Invalid extended_data message"); |
3077 | } | 3075 | } |
3078 | ssh_packet_check_eom(ssh); | ||
3079 | 3076 | ||
3080 | if (data_len > c->local_window) { | 3077 | if (data_len > c->local_window) { |
3081 | logit("channel %d: rcvd too much extended_data %zu, win %u", | 3078 | logit("channel %d: rcvd too much extended_data %zu, win %u", |
@@ -3094,8 +3091,12 @@ int | |||
3094 | channel_input_ieof(int type, u_int32_t seq, struct ssh *ssh) | 3091 | channel_input_ieof(int type, u_int32_t seq, struct ssh *ssh) |
3095 | { | 3092 | { |
3096 | Channel *c = channel_from_packet_id(ssh, __func__, "ieof"); | 3093 | Channel *c = channel_from_packet_id(ssh, __func__, "ieof"); |
3094 | int r; | ||
3097 | 3095 | ||
3098 | ssh_packet_check_eom(ssh); | 3096 | if ((r = sshpkt_get_end(ssh)) != 0) { |
3097 | error("%s: parse data: %s", __func__, ssh_err(r)); | ||
3098 | ssh_packet_disconnect(ssh, "Invalid ieof message"); | ||
3099 | } | ||
3099 | 3100 | ||
3100 | if (channel_proxy_upstream(c, type, seq, ssh)) | 3101 | if (channel_proxy_upstream(c, type, seq, ssh)) |
3101 | return 0; | 3102 | return 0; |
@@ -3115,10 +3116,14 @@ int | |||
3115 | channel_input_oclose(int type, u_int32_t seq, struct ssh *ssh) | 3116 | channel_input_oclose(int type, u_int32_t seq, struct ssh *ssh) |
3116 | { | 3117 | { |
3117 | Channel *c = channel_from_packet_id(ssh, __func__, "oclose"); | 3118 | Channel *c = channel_from_packet_id(ssh, __func__, "oclose"); |
3119 | int r; | ||
3118 | 3120 | ||
3119 | if (channel_proxy_upstream(c, type, seq, ssh)) | 3121 | if (channel_proxy_upstream(c, type, seq, ssh)) |
3120 | return 0; | 3122 | return 0; |
3121 | ssh_packet_check_eom(ssh); | 3123 | if ((r = sshpkt_get_end(ssh)) != 0) { |
3124 | error("%s: parse data: %s", __func__, ssh_err(r)); | ||
3125 | ssh_packet_disconnect(ssh, "Invalid oclose message"); | ||
3126 | } | ||
3122 | chan_rcvd_oclose(ssh, c); | 3127 | chan_rcvd_oclose(ssh, c); |
3123 | return 0; | 3128 | return 0; |
3124 | } | 3129 | } |
@@ -3133,7 +3138,7 @@ channel_input_open_confirmation(int type, u_int32_t seq, struct ssh *ssh) | |||
3133 | if (channel_proxy_upstream(c, type, seq, ssh)) | 3138 | if (channel_proxy_upstream(c, type, seq, ssh)) |
3134 | return 0; | 3139 | return 0; |
3135 | if (c->type != SSH_CHANNEL_OPENING) | 3140 | if (c->type != SSH_CHANNEL_OPENING) |
3136 | packet_disconnect("Received open confirmation for " | 3141 | ssh_packet_disconnect(ssh, "Received open confirmation for " |
3137 | "non-opening channel %d.", c->self); | 3142 | "non-opening channel %d.", c->self); |
3138 | /* | 3143 | /* |
3139 | * Record the remote channel number and mark that the channel | 3144 | * Record the remote channel number and mark that the channel |
@@ -3141,11 +3146,11 @@ channel_input_open_confirmation(int type, u_int32_t seq, struct ssh *ssh) | |||
3141 | */ | 3146 | */ |
3142 | if ((r = sshpkt_get_u32(ssh, &c->remote_id)) != 0 || | 3147 | if ((r = sshpkt_get_u32(ssh, &c->remote_id)) != 0 || |
3143 | (r = sshpkt_get_u32(ssh, &remote_window)) != 0 || | 3148 | (r = sshpkt_get_u32(ssh, &remote_window)) != 0 || |
3144 | (r = sshpkt_get_u32(ssh, &remote_maxpacket)) != 0) { | 3149 | (r = sshpkt_get_u32(ssh, &remote_maxpacket)) != 0 || |
3150 | (r = sshpkt_get_end(ssh)) != 0) { | ||
3145 | error("%s: window/maxpacket: %s", __func__, ssh_err(r)); | 3151 | error("%s: window/maxpacket: %s", __func__, ssh_err(r)); |
3146 | packet_disconnect("Invalid open confirmation message"); | 3152 | ssh_packet_disconnect(ssh, "Invalid open confirmation message"); |
3147 | } | 3153 | } |
3148 | ssh_packet_check_eom(ssh); | ||
3149 | 3154 | ||
3150 | c->have_remote_id = 1; | 3155 | c->have_remote_id = 1; |
3151 | c->remote_window = remote_window; | 3156 | c->remote_window = remote_window; |
@@ -3188,19 +3193,19 @@ channel_input_open_failure(int type, u_int32_t seq, struct ssh *ssh) | |||
3188 | if (channel_proxy_upstream(c, type, seq, ssh)) | 3193 | if (channel_proxy_upstream(c, type, seq, ssh)) |
3189 | return 0; | 3194 | return 0; |
3190 | if (c->type != SSH_CHANNEL_OPENING) | 3195 | if (c->type != SSH_CHANNEL_OPENING) |
3191 | packet_disconnect("Received open failure for " | 3196 | ssh_packet_disconnect(ssh, "Received open failure for " |
3192 | "non-opening channel %d.", c->self); | 3197 | "non-opening channel %d.", c->self); |
3193 | if ((r = sshpkt_get_u32(ssh, &reason)) != 0) { | 3198 | if ((r = sshpkt_get_u32(ssh, &reason)) != 0) { |
3194 | error("%s: reason: %s", __func__, ssh_err(r)); | 3199 | error("%s: reason: %s", __func__, ssh_err(r)); |
3195 | packet_disconnect("Invalid open failure message"); | 3200 | ssh_packet_disconnect(ssh, "Invalid open failure message"); |
3196 | } | 3201 | } |
3197 | /* skip language */ | 3202 | /* skip language */ |
3198 | if ((r = sshpkt_get_cstring(ssh, &msg, NULL)) != 0 || | 3203 | if ((r = sshpkt_get_cstring(ssh, &msg, NULL)) != 0 || |
3199 | (r = sshpkt_get_string_direct(ssh, NULL, NULL)) != 0) { | 3204 | (r = sshpkt_get_string_direct(ssh, NULL, NULL)) != 0 || |
3205 | (r = sshpkt_get_end(ssh)) != 0) { | ||
3200 | error("%s: message/lang: %s", __func__, ssh_err(r)); | 3206 | error("%s: message/lang: %s", __func__, ssh_err(r)); |
3201 | packet_disconnect("Invalid open failure message"); | 3207 | ssh_packet_disconnect(ssh, "Invalid open failure message"); |
3202 | } | 3208 | } |
3203 | ssh_packet_check_eom(ssh); | ||
3204 | logit("channel %d: open failed: %s%s%s", c->self, | 3209 | logit("channel %d: open failed: %s%s%s", c->self, |
3205 | reason2txt(reason), msg ? ": ": "", msg ? msg : ""); | 3210 | reason2txt(reason), msg ? ": ": "", msg ? msg : ""); |
3206 | free(msg); | 3211 | free(msg); |
@@ -3230,11 +3235,11 @@ channel_input_window_adjust(int type, u_int32_t seq, struct ssh *ssh) | |||
3230 | 3235 | ||
3231 | if (channel_proxy_upstream(c, type, seq, ssh)) | 3236 | if (channel_proxy_upstream(c, type, seq, ssh)) |
3232 | return 0; | 3237 | return 0; |
3233 | if ((r = sshpkt_get_u32(ssh, &adjust)) != 0) { | 3238 | if ((r = sshpkt_get_u32(ssh, &adjust)) != 0 || |
3239 | (r = sshpkt_get_end(ssh)) != 0) { | ||
3234 | error("%s: adjust: %s", __func__, ssh_err(r)); | 3240 | error("%s: adjust: %s", __func__, ssh_err(r)); |
3235 | packet_disconnect("Invalid window adjust message"); | 3241 | ssh_packet_disconnect(ssh, "Invalid window adjust message"); |
3236 | } | 3242 | } |
3237 | ssh_packet_check_eom(ssh); | ||
3238 | debug2("channel %d: rcvd adjust %u", c->self, adjust); | 3243 | debug2("channel %d: rcvd adjust %u", c->self, adjust); |
3239 | if ((new_rwin = c->remote_window + adjust) < c->remote_window) { | 3244 | if ((new_rwin = c->remote_window + adjust) < c->remote_window) { |
3240 | fatal("channel %d: adjust %u overflows remote window %u", | 3245 | fatal("channel %d: adjust %u overflows remote window %u", |
@@ -3250,9 +3255,10 @@ channel_input_status_confirm(int type, u_int32_t seq, struct ssh *ssh) | |||
3250 | int id = channel_parse_id(ssh, __func__, "status confirm"); | 3255 | int id = channel_parse_id(ssh, __func__, "status confirm"); |
3251 | Channel *c; | 3256 | Channel *c; |
3252 | struct channel_confirm *cc; | 3257 | struct channel_confirm *cc; |
3258 | int r; | ||
3253 | 3259 | ||
3254 | /* Reset keepalive timeout */ | 3260 | /* Reset keepalive timeout */ |
3255 | packet_set_alive_timeouts(0); | 3261 | ssh_packet_set_alive_timeouts(ssh, 0); |
3256 | 3262 | ||
3257 | debug2("%s: type %d id %d", __func__, type, id); | 3263 | debug2("%s: type %d id %d", __func__, type, id); |
3258 | 3264 | ||
@@ -3262,7 +3268,8 @@ channel_input_status_confirm(int type, u_int32_t seq, struct ssh *ssh) | |||
3262 | } | 3268 | } |
3263 | if (channel_proxy_upstream(c, type, seq, ssh)) | 3269 | if (channel_proxy_upstream(c, type, seq, ssh)) |
3264 | return 0; | 3270 | return 0; |
3265 | ssh_packet_check_eom(ssh); | 3271 | if ((r = sshpkt_get_end(ssh)) != 0) |
3272 | ssh_packet_disconnect(ssh, "Invalid status confirm message"); | ||
3266 | if ((cc = TAILQ_FIRST(&c->status_confirms)) == NULL) | 3273 | if ((cc = TAILQ_FIRST(&c->status_confirms)) == NULL) |
3267 | return 0; | 3274 | return 0; |
3268 | cc->cb(ssh, type, c, cc->ctx); | 3275 | cc->cb(ssh, type, c, cc->ctx); |
@@ -3297,7 +3304,7 @@ channel_set_af(struct ssh *ssh, int af) | |||
3297 | * "127.0.0.1" / "::1" -> accepted even if gateway_ports isn't set | 3304 | * "127.0.0.1" / "::1" -> accepted even if gateway_ports isn't set |
3298 | */ | 3305 | */ |
3299 | static const char * | 3306 | static const char * |
3300 | channel_fwd_bind_addr(const char *listen_addr, int *wildcardp, | 3307 | channel_fwd_bind_addr(struct ssh *ssh, const char *listen_addr, int *wildcardp, |
3301 | int is_client, struct ForwardOptions *fwd_opts) | 3308 | int is_client, struct ForwardOptions *fwd_opts) |
3302 | { | 3309 | { |
3303 | const char *addr = NULL; | 3310 | const char *addr = NULL; |
@@ -3320,7 +3327,8 @@ channel_fwd_bind_addr(const char *listen_addr, int *wildcardp, | |||
3320 | if (*listen_addr != '\0' && | 3327 | if (*listen_addr != '\0' && |
3321 | strcmp(listen_addr, "0.0.0.0") != 0 && | 3328 | strcmp(listen_addr, "0.0.0.0") != 0 && |
3322 | strcmp(listen_addr, "*") != 0) { | 3329 | strcmp(listen_addr, "*") != 0) { |
3323 | packet_send_debug("Forwarding listen address " | 3330 | ssh_packet_send_debug(ssh, |
3331 | "Forwarding listen address " | ||
3324 | "\"%s\" overridden by server " | 3332 | "\"%s\" overridden by server " |
3325 | "GatewayPorts", listen_addr); | 3333 | "GatewayPorts", listen_addr); |
3326 | } | 3334 | } |
@@ -3374,7 +3382,7 @@ channel_setup_fwd_listener_tcpip(struct ssh *ssh, int type, | |||
3374 | } | 3382 | } |
3375 | 3383 | ||
3376 | /* Determine the bind address, cf. channel_fwd_bind_addr() comment */ | 3384 | /* Determine the bind address, cf. channel_fwd_bind_addr() comment */ |
3377 | addr = channel_fwd_bind_addr(fwd->listen_host, &wildcard, | 3385 | addr = channel_fwd_bind_addr(ssh, fwd->listen_host, &wildcard, |
3378 | is_client, fwd_opts); | 3386 | is_client, fwd_opts); |
3379 | debug3("%s: type %d wildcard %d addr %s", __func__, | 3387 | debug3("%s: type %d wildcard %d addr %s", __func__, |
3380 | type, wildcard, (addr == NULL) ? "NULL" : addr); | 3388 | type, wildcard, (addr == NULL) ? "NULL" : addr); |
@@ -3391,7 +3399,7 @@ channel_setup_fwd_listener_tcpip(struct ssh *ssh, int type, | |||
3391 | if ((r = getaddrinfo(addr, strport, &hints, &aitop)) != 0) { | 3399 | if ((r = getaddrinfo(addr, strport, &hints, &aitop)) != 0) { |
3392 | if (addr == NULL) { | 3400 | if (addr == NULL) { |
3393 | /* This really shouldn't happen */ | 3401 | /* This really shouldn't happen */ |
3394 | packet_disconnect("getaddrinfo: fatal error: %s", | 3402 | ssh_packet_disconnect(ssh, "getaddrinfo: fatal error: %s", |
3395 | ssh_gai_strerror(r)); | 3403 | ssh_gai_strerror(r)); |
3396 | } else { | 3404 | } else { |
3397 | error("%s: getaddrinfo(%.64s): %s", __func__, addr, | 3405 | error("%s: getaddrinfo(%.64s): %s", __func__, addr, |
@@ -3640,7 +3648,7 @@ channel_cancel_lport_listener_tcpip(struct ssh *ssh, | |||
3640 | { | 3648 | { |
3641 | u_int i; | 3649 | u_int i; |
3642 | int found = 0; | 3650 | int found = 0; |
3643 | const char *addr = channel_fwd_bind_addr(lhost, NULL, 1, fwd_opts); | 3651 | const char *addr = channel_fwd_bind_addr(ssh, lhost, NULL, 1, fwd_opts); |
3644 | 3652 | ||
3645 | for (i = 0; i < ssh->chanctxt->channels_alloc; i++) { | 3653 | for (i = 0; i < ssh->chanctxt->channels_alloc; i++) { |
3646 | Channel *c = ssh->chanctxt->channels[i]; | 3654 | Channel *c = ssh->chanctxt->channels[i]; |
@@ -3792,7 +3800,7 @@ channel_setup_remote_fwd_listener(struct ssh *ssh, struct Forward *fwd, | |||
3792 | int *allocated_listen_port, struct ForwardOptions *fwd_opts) | 3800 | int *allocated_listen_port, struct ForwardOptions *fwd_opts) |
3793 | { | 3801 | { |
3794 | if (!check_rfwd_permission(ssh, fwd)) { | 3802 | if (!check_rfwd_permission(ssh, fwd)) { |
3795 | packet_send_debug("port forwarding refused"); | 3803 | ssh_packet_send_debug(ssh, "port forwarding refused"); |
3796 | return 0; | 3804 | return 0; |
3797 | } | 3805 | } |
3798 | if (fwd->listen_path != NULL) { | 3806 | if (fwd->listen_path != NULL) { |