int ssh_socket_connect_proxycommand(ssh_socket s, const char *command){ socket_t pair[2]; int pid; int rc; if (s->state != SSH_SOCKET_NONE) { return SSH_ERROR; } rc = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair); if (rc < 0) { return SSH_ERROR; } SSH_LOG(SSH_LOG_PROTOCOL,"Executing proxycommand '%s'",command); pid = fork(); if(pid == 0){ ssh_execute_command(command,pair[0],pair[0]); } close(pair[0]); SSH_LOG(SSH_LOG_PROTOCOL,"ProxyCommand connection pipe: [%d,%d]",pair[0],pair[1]); ssh_socket_set_fd(s, pair[1]); s->state=SSH_SOCKET_CONNECTED; s->fd_is_socket=0; /* POLLOUT is the event to wait for in a nonblocking connect */ ssh_poll_set_events(ssh_socket_get_poll_handle(s), POLLIN | POLLOUT); if(s->callbacks && s->callbacks->connected) { s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,0,s->callbacks->userdata); } return SSH_OK; }
int ssh_socket_connect_proxycommand(ssh_socket s, const char *command){ socket_t in_pipe[2]; socket_t out_pipe[2]; int pid; int rc; ssh_session session=s->session; enter_function(); if(s->state != SSH_SOCKET_NONE) return SSH_ERROR; rc = pipe(in_pipe); if (rc < 0) { return SSH_ERROR; } rc = pipe(out_pipe); if (rc < 0) { return SSH_ERROR; } ssh_log(session,SSH_LOG_PROTOCOL,"Executing proxycommand '%s'",command); pid = fork(); if(pid == 0){ ssh_execute_command(command,out_pipe[0],in_pipe[1]); } s->proxycommand_pid = pid; close(in_pipe[1]); close(out_pipe[0]); ssh_log(session,SSH_LOG_PROTOCOL,"ProxyCommand connection pipe: [%d,%d]",in_pipe[0],out_pipe[1]); ssh_socket_set_fd_in(s,in_pipe[0]); ssh_socket_set_fd_out(s,out_pipe[1]); s->state=SSH_SOCKET_CONNECTED; s->fd_is_socket=0; /* POLLOUT is the event to wait for in a nonblocking connect */ ssh_poll_set_events(ssh_socket_get_poll_handle_in(s),POLLIN | POLLERR); ssh_poll_set_events(ssh_socket_get_poll_handle_out(s),POLLOUT); if(s->callbacks && s->callbacks->connected) s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,0,s->callbacks->userdata); leave_function(); return SSH_OK; }