Lines Matching defs:ssh
12 * called by a name other than "ssh" or "Secure Shell".
89 static void server_init_dispatch(struct ssh *);
101 client_alive_check(struct ssh *ssh)
108 ssh_packet_inc_alive_timeouts(ssh) >
110 sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
119 if ((channel_id = channel_find_open(ssh)) == -1) {
120 if ((r = sshpkt_start(ssh, SSH2_MSG_GLOBAL_REQUEST)) != 0 ||
121 (r = sshpkt_put_cstring(ssh, "keepalive@openssh.com"))
123 (r = sshpkt_put_u8(ssh, 1)) != 0) /* boolean: want reply */
126 channel_request_start(ssh, channel_id,
129 if ((r = sshpkt_send(ssh)) != 0)
139 wait_until_can_do_something(struct ssh *ssh,
156 channel_prepare_poll(ssh, pfdp, npfd_allocp, npfd_activep, 2, &timeout);
160 if (options.rekey_interval > 0 && !ssh_packet_is_rekeying(ssh)) {
162 ssh_packet_get_rekey_timeout(ssh));
170 if (channel_still_open(ssh) || unused_connection_expiry == 0) {
202 (*pfdp)[1].events = ssh_packet_have_data_to_write(ssh) ? POLLOUT : 0;
208 if (child_terminated && ssh_packet_not_very_much_data_to_write(ssh))
231 client_alive_check(ssh);
241 now > unused_connection_expiry && !channel_still_open(ssh)) {
242 sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
253 process_input(struct ssh *ssh, int connection_in)
257 if ((r = ssh_packet_process_read(ssh, connection_in)) == 0)
264 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
268 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh),
279 process_output(struct ssh *ssh, int connection_out)
284 if ((r = ssh_packet_write_poll(ssh)) != 0) {
285 sshpkt_fatal(ssh, r, "%s: ssh_packet_write_poll",
291 process_buffered_input_packets(struct ssh *ssh)
293 ssh_dispatch_run_fatal(ssh, DISPATCH_NONBLOCK, NULL);
297 collect_children(struct ssh *ssh)
307 session_close_by_pid(ssh, pid, status);
313 server_loop2(struct ssh *ssh, Authctxt *authctxt)
327 connection_in = ssh_packet_get_connection_in(ssh);
328 connection_out = ssh_packet_get_connection_out(ssh);
330 server_init_dispatch(ssh);
333 process_buffered_input_packets(ssh);
335 if (!ssh_packet_is_rekeying(ssh) &&
336 ssh_packet_not_very_much_data_to_write(ssh))
337 channel_output_poll(ssh);
346 collect_children(ssh);
347 wait_until_can_do_something(ssh, connection_in, connection_out,
353 channel_after_poll(ssh, pfd, npfd_active);
355 process_input(ssh, connection_in) < 0)
358 if ((r = ssh_packet_check_rekey(ssh)) != 0)
361 process_output(ssh, connection_out);
363 collect_children(ssh);
367 channel_free_all(ssh);
370 session_destroy_all(ssh, NULL);
374 server_input_keep_alive(int type, u_int32_t seq, struct ssh *ssh)
382 ssh_packet_set_alive_timeouts(ssh, 0);
387 server_request_direct_tcpip(struct ssh *ssh, int *reason, const char **errmsg)
394 if ((r = sshpkt_get_cstring(ssh, &target, NULL)) != 0 ||
395 (r = sshpkt_get_u32(ssh, &target_port)) != 0 ||
396 (r = sshpkt_get_cstring(ssh, &originator, NULL)) != 0 ||
397 (r = sshpkt_get_u32(ssh, &originator_port)) != 0 ||
398 (r = sshpkt_get_end(ssh)) != 0)
399 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
418 c = channel_connect_to_port(ssh, target, target_port,
435 server_request_direct_streamlocal(struct ssh *ssh)
446 if ((r = sshpkt_get_cstring(ssh, &target, NULL)) != 0 ||
447 (r = sshpkt_get_cstring(ssh, &originator, NULL)) != 0 ||
448 (r = sshpkt_get_u32(ssh, &originator_port)) != 0 ||
449 (r = sshpkt_get_end(ssh)) != 0)
450 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
463 c = channel_connect_to_path(ssh, target,
478 server_request_tun(struct ssh *ssh)
485 if ((r = sshpkt_get_u32(ssh, &mode)) != 0)
486 sshpkt_fatal(ssh, r, "%s: parse mode", __func__);
492 ssh_packet_send_debug(ssh, "Unsupported tunnel device mode.");
496 ssh_packet_send_debug(ssh, "Server has rejected tunnel device "
501 if ((r = sshpkt_get_u32(ssh, &tun)) != 0)
502 sshpkt_fatal(ssh, r, "%s: parse device", __func__);
518 c = channel_new(ssh, "tun", SSH_CHANNEL_OPEN, sock, sock, -1,
537 ssh_packet_send_debug(ssh, "Failed to open the tunnel device.");
542 server_request_session(struct ssh *ssh)
548 if ((r = sshpkt_get_end(ssh)) != 0)
549 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
552 ssh_packet_disconnect(ssh, "Possible attack: attempt to open a "
562 c = channel_new(ssh, "session", SSH_CHANNEL_LARVAL,
567 channel_free(ssh, c);
570 channel_register_cleanup(ssh, c->self, session_close_by_channel, 0);
575 server_input_channel_open(int type, u_int32_t seq, struct ssh *ssh)
583 if ((r = sshpkt_get_cstring(ssh, &ctype, NULL)) != 0 ||
584 (r = sshpkt_get_u32(ssh, &rchan)) != 0 ||
585 (r = sshpkt_get_u32(ssh, &rwindow)) != 0 ||
586 (r = sshpkt_get_u32(ssh, &rmaxpack)) != 0)
587 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
592 c = server_request_session(ssh);
594 c = server_request_direct_tcpip(ssh, &reason, &errmsg);
596 c = server_request_direct_streamlocal(ssh);
598 c = server_request_tun(ssh);
607 if ((r = sshpkt_start(ssh, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION)) != 0 ||
608 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 ||
609 (r = sshpkt_put_u32(ssh, c->self)) != 0 ||
610 (r = sshpkt_put_u32(ssh, c->local_window)) != 0 ||
611 (r = sshpkt_put_u32(ssh, c->local_maxpacket)) != 0 ||
612 (r = sshpkt_send(ssh)) != 0) {
613 sshpkt_fatal(ssh, r,
619 if ((r = sshpkt_start(ssh, SSH2_MSG_CHANNEL_OPEN_FAILURE)) != 0 ||
620 (r = sshpkt_put_u32(ssh, rchan)) != 0 ||
621 (r = sshpkt_put_u32(ssh, reason)) != 0 ||
622 (r = sshpkt_put_cstring(ssh, errmsg ? errmsg : "open failed")) != 0 ||
623 (r = sshpkt_put_cstring(ssh, "")) != 0 ||
624 (r = sshpkt_send(ssh)) != 0) {
625 sshpkt_fatal(ssh, r,
634 server_input_hostkeys_prove(struct ssh *ssh, struct sshbuf **respp)
648 ssh->kex->hostkey_alg)) == KEY_RSA)
649 kex_rsa_sigalg = ssh->kex->hostkey_alg;
650 while (ssh_packet_remaining(ssh) > 0) {
653 if ((r = sshpkt_get_string_direct(ssh, &blob, &blen)) != 0 ||
662 if ((ndx = ssh->kex->host_key_index(key, 1, ssh)) == -1) {
671 (key_pub = get_hostkey_public_by_index(ndx, ssh)) == NULL) {
686 else if (ssh->kex->flags & KEX_RSA_SHA2_512_SUPPORTED)
688 else if (ssh->kex->flags & KEX_RSA_SHA2_256_SUPPORTED)
697 ssh->kex->session_id)) != 0 ||
699 (r = ssh->kex->sign(ssh, key_prv, key_pub, &sig, &slen,
719 server_input_global_request(int type, u_int32_t seq, struct ssh *ssh)
733 if ((r = sshpkt_get_cstring(ssh, &rtype, NULL)) != 0 ||
734 (r = sshpkt_get_u8(ssh, &want_reply)) != 0)
735 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
740 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_host, NULL)) != 0 ||
741 (r = sshpkt_get_u32(ssh, &port)) != 0)
742 sshpkt_fatal(ssh, r, "%s: parse tcpip-forward", __func__);
754 ssh_packet_send_debug(ssh, "Server has disabled port forwarding.");
757 success = channel_setup_remote_fwd_listener(ssh, &fwd,
766 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_host, NULL)) != 0 ||
767 (r = sshpkt_get_u32(ssh, &port)) != 0)
768 sshpkt_fatal(ssh, r, "%s: parse cancel-tcpip-forward", __func__);
774 success = channel_cancel_rport_listener(ssh, &fwd);
777 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_path, NULL)) != 0)
778 sshpkt_fatal(ssh, r, "%s: parse streamlocal-forward@openssh.com", __func__);
787 ssh_packet_send_debug(ssh, "Server has disabled "
791 success = channel_setup_remote_fwd_listener(ssh,
795 if ((r = sshpkt_get_cstring(ssh, &fwd.listen_path, NULL)) != 0)
796 sshpkt_fatal(ssh, r, "%s: parse cancel-streamlocal-forward@openssh.com", __func__);
800 success = channel_cancel_rport_listener(ssh, &fwd);
805 success = server_input_hostkeys_prove(ssh, &resp);
809 if ((r = sshpkt_start(ssh, success ?
811 (success && resp != NULL && (r = sshpkt_putb(ssh, resp)) != 0) ||
812 (r = sshpkt_send(ssh)) != 0 ||
813 (r = ssh_packet_write_wait(ssh)) != 0)
814 sshpkt_fatal(ssh, r, "%s: send reply", __func__);
824 server_input_channel_req(int type, u_int32_t seq, struct ssh *ssh)
832 if ((r = sshpkt_get_u32(ssh, &id)) != 0 ||
833 (r = sshpkt_get_cstring(ssh, &rtype, NULL)) != 0 ||
834 (r = sshpkt_get_u8(ssh, &want_reply)) != 0)
835 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
840 if (id >= INT_MAX || (c = channel_lookup(ssh, (int)id)) == NULL) {
841 ssh_packet_disconnect(ssh, "%s: unknown channel %d",
845 if ((r = sshpkt_get_end(ssh)) != 0)
846 sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
847 chan_rcvd_eow(ssh, c);
850 success = session_input_channel_req(ssh, c, rtype);
854 if ((r = sshpkt_start(ssh, success ?
856 (r = sshpkt_put_u32(ssh, c->remote_id)) != 0 ||
857 (r = sshpkt_send(ssh)) != 0)
858 sshpkt_fatal(ssh, r, "%s: send reply", __func__);
865 server_init_dispatch(struct ssh *ssh)
868 ssh_dispatch_init(ssh, &dispatch_protocol_error);
869 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose);
870 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_DATA, &channel_input_data);
871 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_EOF, &channel_input_ieof);
872 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_EXTENDED_DATA, &channel_input_extended_data);
873 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN, &server_input_channel_open);
874 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation);
875 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure);
876 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_REQUEST, &server_input_channel_req);
877 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust);
878 ssh_dispatch_set(ssh, SSH2_MSG_GLOBAL_REQUEST, &server_input_global_request);
880 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_SUCCESS, &server_input_keep_alive);
881 ssh_dispatch_set(ssh, SSH2_MSG_CHANNEL_FAILURE, &server_input_keep_alive);
882 ssh_dispatch_set(ssh, SSH2_MSG_REQUEST_SUCCESS, &server_input_keep_alive);
883 ssh_dispatch_set(ssh, SSH2_MSG_REQUEST_FAILURE, &server_input_keep_alive);
885 ssh_dispatch_set(ssh, SSH2_MSG_KEXINIT, &kex_input_kexinit);