void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection *progress, pid_t proxy_cmd_pid) { common_session_init(sock_in, sock_out); if (progress) { connect_set_writequeue(progress, &ses.writequeue); } chaninitialise(cli_chantypes); /* Set up cli_ses vars */ cli_session_init(proxy_cmd_pid); /* Ready to go */ sessinitdone = 1; /* Exchange identification */ send_session_identification(); kexfirstinitialise(); /* initialise the kex state */ send_msg_kexinit(); session_loop(cli_sessionloop); /* Not reached */ }
void svr_session(int sock, int childpipe) { char *host, *port; size_t len; common_session_init(sock, sock); svr_ses.connect_time = monotonic_now();; /* Initialise server specific parts of the session */ svr_ses.childpipe = childpipe; #ifdef USE_VFORK svr_ses.server_pid = getpid(); #endif svr_authinitialise(); chaninitialise(svr_chantypes); svr_chansessinitialise(); /* for logging the remote address */ get_socket_address(ses.sock_in, NULL, NULL, &host, &port, 0); len = strlen(host) + strlen(port) + 2; svr_ses.addrstring = m_malloc(len); snprintf(svr_ses.addrstring, len, "%s:%s", host, port); m_free(host); m_free(port); get_socket_address(ses.sock_in, NULL, NULL, &svr_ses.remotehost, NULL, 1); /* set up messages etc */ ses.remoteclosed = svr_remoteclosed; ses.extra_session_cleanup = svr_session_cleanup; /* packet handlers */ ses.packettypes = svr_packettypes; ses.isserver = 1; /* We're ready to go now */ sessinitdone = 1; /* exchange identification, version etc */ send_session_identification(); kexfirstinitialise(); /* initialise the kex state */ /* start off with key exchange */ send_msg_kexinit(); /* Run the main for loop. NULL is for the dispatcher - only the client * code makes use of it */ session_loop(svr_sessionloop); /* Not reached */ }
/* called only at the start of a session, set up initial state */ void common_session_init(int sock_in, int sock_out) { TRACE(("enter session_init")) ses.sock_in = sock_in; ses.sock_out = sock_out; ses.maxfd = MAX(sock_in, sock_out); ses.connect_time = 0; ses.last_trx_packet_time = 0; ses.last_packet_time = 0; if (pipe(ses.signal_pipe) < 0) { dropbear_exit("Signal pipe failed"); } setnonblocking(ses.signal_pipe[0]); setnonblocking(ses.signal_pipe[1]); ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[0]); ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[1]); kexfirstinitialise(); /* initialise the kex state */ ses.writepayload = buf_new(TRANS_MAX_PAYLOAD_LEN); ses.transseq = 0; ses.readbuf = NULL; ses.payload = NULL; ses.recvseq = 0; initqueue(&ses.writequeue); ses.requirenext = SSH_MSG_KEXINIT; ses.dataallowed = 1; /* we can send data until we actually send the SSH_MSG_KEXINIT */ ses.ignorenext = 0; ses.lastpacket = 0; ses.reply_queue_head = NULL; ses.reply_queue_tail = NULL; /* set all the algos to none */ ses.keys = (struct key_context*)m_malloc(sizeof(struct key_context)); ses.newkeys = NULL; ses.keys->recv.algo_crypt = &dropbear_nocipher; ses.keys->trans.algo_crypt = &dropbear_nocipher; ses.keys->recv.crypt_mode = &dropbear_mode_none; ses.keys->trans.crypt_mode = &dropbear_mode_none; ses.keys->recv.algo_mac = &dropbear_nohash; ses.keys->trans.algo_mac = &dropbear_nohash; ses.keys->algo_kex = -1; ses.keys->algo_hostkey = -1; ses.keys->recv.algo_comp = DROPBEAR_COMP_NONE; ses.keys->trans.algo_comp = DROPBEAR_COMP_NONE; #ifndef DISABLE_ZLIB ses.keys->recv.zstream = NULL; ses.keys->trans.zstream = NULL; #endif /* key exchange buffers */ ses.session_id = NULL; ses.kexhashbuf = NULL; ses.transkexinit = NULL; ses.dh_K = NULL; ses.remoteident = NULL; ses.chantypes = NULL; ses.allowprivport = 0; TRACE(("leave session_init")) }
/* called only at the start of a session, set up initial state */ void common_session_init(int sock, char* remotehost) { TRACE(("enter session_init")) ses.remotehost = remotehost; ses.sock = sock; ses.maxfd = sock; ses.connecttimeout = 0; if (pipe(ses.signal_pipe) < 0) { dropbear_exit("signal pipe failed"); } setnonblocking(ses.signal_pipe[0]); setnonblocking(ses.signal_pipe[1]); kexfirstinitialise(); /* initialise the kex state */ ses.writepayload = buf_new(MAX_TRANS_PAYLOAD_LEN); ses.transseq = 0; ses.readbuf = NULL; ses.decryptreadbuf = NULL; ses.payload = NULL; ses.recvseq = 0; initqueue(&ses.writequeue); ses.requirenext = SSH_MSG_KEXINIT; ses.dataallowed = 0; /* don't send data yet, we'll wait until after kex */ ses.ignorenext = 0; ses.lastpacket = 0; /* set all the algos to none */ ses.keys = (struct key_context*)m_malloc(sizeof(struct key_context)); ses.newkeys = NULL; ses.keys->recv_algo_crypt = &dropbear_nocipher; ses.keys->trans_algo_crypt = &dropbear_nocipher; ses.keys->recv_algo_mac = &dropbear_nohash; ses.keys->trans_algo_mac = &dropbear_nohash; ses.keys->algo_kex = -1; ses.keys->algo_hostkey = -1; ses.keys->recv_algo_comp = DROPBEAR_COMP_NONE; ses.keys->trans_algo_comp = DROPBEAR_COMP_NONE; #ifndef DISABLE_ZLIB ses.keys->recv_zstream = NULL; ses.keys->trans_zstream = NULL; #endif /* key exchange buffers */ ses.session_id = NULL; ses.kexhashbuf = NULL; ses.transkexinit = NULL; ses.dh_K = NULL; ses.remoteident = NULL; ses.chantypes = NULL; ses.allowprivport = 0; TRACE(("leave session_init")) }