Lines Matching refs:chansess
43 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
45 static int sessionpty(struct ChanSess * chansess);
46 static int sessionsignal(struct ChanSess *chansess);
47 static int noptycommand(struct Channel *channel, struct ChanSess *chansess);
48 static int ptycommand(struct Channel *channel, struct ChanSess *chansess);
49 static int sessionwinchange(struct ChanSess *chansess);
50 static void execchild(struct ChanSess *chansess);
51 static void addchildpid(struct ChanSess *chansess, pid_t pid);
59 struct ChanSess * chansess);
61 struct ChanSess * chansess);
62 static void get_termmodes(struct ChanSess *chansess);
69 struct ChanSess *chansess = (struct ChanSess*)channel->typedata;
70 TRACE(("sesscheckclose, pid is %d", chansess->exit.exitpid))
71 return chansess->exit.exitpid != -1;
95 /* find the corresponding chansess */
99 exit = &svr_ses.childpids[i].chansess->exit;
147 struct ChanSess *chansess = (struct ChanSess*)channel->typedata;
149 if (chansess->exit.exitpid >= 0) {
150 if (chansess->exit.exitsignal > 0) {
151 send_msg_chansess_exitsignal(channel, chansess);
153 send_msg_chansess_exitstatus(channel, chansess);
160 struct ChanSess * chansess) {
162 dropbear_assert(chansess->exit.exitpid != -1);
163 dropbear_assert(chansess->exit.exitsignal == -1);
171 buf_putint(ses.writepayload, chansess->exit.exitstatus);
179 struct ChanSess * chansess) {
183 dropbear_assert(chansess->exit.exitpid != -1);
184 dropbear_assert(chansess->exit.exitsignal > 0);
186 TRACE(("send_msg_chansess_exitsignal %d", chansess->exit.exitsignal))
193 if (signames[i].signal == chansess->exit.exitsignal) {
208 buf_putbyte(ses.writepayload, chansess->exit.exitcore);
218 struct ChanSess *chansess;
222 chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess));
223 chansess->cmd = NULL;
224 chansess->pid = 0;
227 chansess->master = -1;
228 chansess->slave = -1;
229 chansess->tty = NULL;
230 chansess->term = NULL;
232 chansess->exit.exitpid = -1;
234 channel->typedata = chansess;
237 chansess->x11listener = NULL;
238 chansess->x11authprot = NULL;
239 chansess->x11authcookie = NULL;
243 chansess->agentlistener = NULL;
244 chansess->agentfile = NULL;
245 chansess->agentdir = NULL;
255 struct ChanSess *chansess;
261 chansess = (struct ChanSess*)channel->typedata;
263 if (chansess == NULL) {
264 TRACE(("leave closechansess: chansess == NULL"))
270 m_free(chansess->cmd);
271 m_free(chansess->term);
273 if (chansess->tty) {
275 li = login_alloc_entry(chansess->pid, ses.authstate.username,
276 ses.remotehost, chansess->tty);
280 pty_release(chansess->tty);
281 m_free(chansess->tty);
285 x11cleanup(chansess);
289 agentcleanup(chansess);
294 if (svr_ses.childpids[i].chansess == chansess) {
297 TRACE(("exitpid is %d", chansess->exit.exitpid))
299 svr_ses.childpids[i].chansess = NULL;
303 m_free(chansess);
316 struct ChanSess *chansess;
328 chansess = (struct ChanSess*)channel->typedata;
329 dropbear_assert(chansess != NULL);
333 ret = sessionwinchange(chansess);
335 ret = sessioncommand(channel, chansess, 0, 0);
337 ret = sessionpty(chansess);
339 ret = sessioncommand(channel, chansess, 1, 0);
341 ret = sessioncommand(channel, chansess, 1, 1);
344 ret = x11req(chansess);
348 ret = agentreq(chansess);
351 ret = sessionsignal(chansess);
372 static int sessionsignal(struct ChanSess *chansess) {
378 if (chansess->pid == 0) {
401 if (kill(chansess->pid, sig) < 0) {
410 static int sessionwinchange(struct ChanSess *chansess) {
414 if (chansess->master < 0) {
424 pty_change_window_size(chansess->master, termr, termc, termw, termh);
429 static void get_termmodes(struct ChanSess *chansess) {
442 if (tcgetattr(chansess->master, &termio) == -1) {
514 if (tcsetattr(chansess->master, TCSANOW, &termio) < 0) {
523 static int sessionpty(struct ChanSess * chansess) {
529 chansess->term = buf_getstring(ses.payload, &termlen);
537 if (chansess->master != -1) {
540 if (pty_allocate(&chansess->master, &chansess->slave, namebuf, 64) == 0) {
545 chansess->tty = (char*)m_strdup(namebuf);
546 if (!chansess->tty) {
550 pty_setowner(ses.authstate.pw, chansess->tty);
553 sessionwinchange(chansess);
556 get_termmodes(chansess);
566 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
574 if (chansess->cmd != NULL) {
583 chansess->cmd = buf_getstring(ses.payload, &cmdlen);
586 m_free(chansess->cmd);
592 if ((cmdlen == 4) && strncmp(chansess->cmd, "sftp", 4) == 0) {
593 m_free(chansess->cmd);
594 chansess->cmd = m_strdup(SFTPSERVER_PATH);
598 m_free(chansess->cmd);
605 if (chansess->cmd) {
607 ses.authstate.printableuser, chansess->cmd);
614 if (chansess->term == NULL) {
616 ret = noptycommand(channel, chansess);
619 ret = ptycommand(channel, chansess);
623 m_free(chansess->cmd);
631 static int noptycommand(struct Channel *channel, struct ChanSess *chansess) {
684 execchild(chansess);
690 chansess->pid = pid;
693 addchildpid(chansess, pid);
703 svr_ses.childpids[i].chansess->exit = svr_ses.lastexit;
734 static int ptycommand(struct Channel *channel, struct ChanSess *chansess) {
748 if (chansess->master == -1 || chansess->tty == NULL) {
771 close(chansess->master);
773 pty_make_controlling_tty(&chansess->slave, chansess->tty);
775 if ((dup2(chansess->slave, STDIN_FILENO) < 0) ||
776 (dup2(chansess->slave, STDERR_FILENO) < 0) ||
777 (dup2(chansess->slave, STDOUT_FILENO) < 0)) {
782 close(chansess->slave);
787 ses.remotehost, chansess->tty);
791 m_free(chansess->tty);
821 execchild(chansess);
827 chansess->pid = pid;
830 addchildpid(chansess, pid);
832 close(chansess->slave);
833 channel->writefd = chansess->master;
834 channel->readfd = chansess->master;
836 ses.maxfd = MAX(ses.maxfd, chansess->master);
838 setnonblocking(chansess->master);
847 static void addchildpid(struct ChanSess *chansess, pid_t pid) {
864 svr_ses.childpids[i].chansess = chansess;
870 static void execchild(struct ChanSess *chansess) {
944 if (chansess->term != NULL) {
945 addnewvar("TERM", chansess->term);
955 x11setauth(chansess);
959 agentset(chansess);
969 if (chansess->cmd != NULL) {
978 if (chansess->cmd != NULL) {
980 argv[2] = chansess->cmd;
1012 svr_ses.childpids[0].chansess = NULL;