Mercurial > dropbear
diff svr-chansession.c @ 297:79bf1023cf11 agent-client
propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712)
to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 21 Mar 2006 16:20:59 +0000 |
parents | 1f5ec029dfe8 |
children | 5d5bbca82aba 3eea61bd9993 dba106bf6b34 8eaa6e3ca6eb |
line wrap: on
line diff
--- a/svr-chansession.c Mon Jul 18 14:32:52 2005 +0000 +++ b/svr-chansession.c Tue Mar 21 16:20:59 2006 +0000 @@ -148,8 +148,8 @@ static void send_msg_chansess_exitstatus(struct Channel * channel, struct ChanSess * chansess) { - assert(chansess->exit.exitpid != -1); - assert(chansess->exit.exitsignal == -1); + dropbear_assert(chansess->exit.exitpid != -1); + dropbear_assert(chansess->exit.exitsignal == -1); CHECKCLEARTOWRITE(); @@ -170,8 +170,8 @@ int i; char* signame = NULL; - assert(chansess->exit.exitpid != -1); - assert(chansess->exit.exitsignal > 0); + dropbear_assert(chansess->exit.exitpid != -1); + dropbear_assert(chansess->exit.exitsignal > 0); CHECKCLEARTOWRITE(); @@ -205,7 +205,7 @@ struct ChanSess *chansess; - assert(channel->typedata == NULL); + dropbear_assert(channel->typedata == NULL); chansess = (struct ChanSess*)m_malloc(sizeof(struct ChanSess)); chansess->cmd = NULL; @@ -279,7 +279,7 @@ /* clear child pid entries */ for (i = 0; i < svr_ses.childpidsize; i++) { if (svr_ses.childpids[i].chansess == chansess) { - assert(svr_ses.childpids[i].pid > 0); + dropbear_assert(svr_ses.childpids[i].pid > 0); TRACE(("closing pid %d", svr_ses.childpids[i].pid)) TRACE(("exitpid = %d", chansess->exit.exitpid)) svr_ses.childpids[i].pid = -1; @@ -313,7 +313,7 @@ } chansess = (struct ChanSess*)channel->typedata; - assert(chansess != NULL); + dropbear_assert(chansess != NULL); TRACE(("type is %s", type)) if (strcmp(type, "window-change") == 0) { @@ -623,7 +623,12 @@ if (pipe(errfds) != 0) return DROPBEAR_FAILURE; +#ifdef __uClinux__ + pid = vfork(); +#else pid = fork(); +#endif + if (pid < 0) return DROPBEAR_FAILURE; @@ -673,15 +678,15 @@ close(infds[FDIN]); close(outfds[FDOUT]); close(errfds[FDOUT]); - channel->infd = infds[FDOUT]; - channel->outfd = outfds[FDIN]; + channel->writefd = infds[FDOUT]; + channel->readfd = outfds[FDIN]; channel->errfd = errfds[FDIN]; - ses.maxfd = MAX(ses.maxfd, channel->infd); - ses.maxfd = MAX(ses.maxfd, channel->outfd); + ses.maxfd = MAX(ses.maxfd, channel->writefd); + ses.maxfd = MAX(ses.maxfd, channel->readfd); ses.maxfd = MAX(ses.maxfd, channel->errfd); - setnonblocking(channel->outfd); - setnonblocking(channel->infd); + setnonblocking(channel->readfd); + setnonblocking(channel->writefd); setnonblocking(channel->errfd); } @@ -714,7 +719,11 @@ return DROPBEAR_FAILURE; } +#ifdef __uClinux__ + pid = vfork(); +#else pid = fork(); +#endif if (pid < 0) return DROPBEAR_FAILURE; @@ -784,8 +793,8 @@ addchildpid(chansess, pid); close(chansess->slave); - channel->infd = chansess->master; - channel->outfd = chansess->master; + channel->writefd = chansess->master; + channel->readfd = chansess->master; /* don't need to set stderr here */ ses.maxfd = MAX(ses.maxfd, chansess->master); @@ -810,7 +819,7 @@ /* need to increase size */ if (i == svr_ses.childpidsize) { svr_ses.childpids = (struct ChildPid*)m_realloc(svr_ses.childpids, - sizeof(struct ChildPid) * svr_ses.childpidsize+1); + sizeof(struct ChildPid) * (svr_ses.childpidsize+1)); svr_ses.childpidsize++; } @@ -828,19 +837,21 @@ char * baseshell = NULL; unsigned int i; + /* with uClinux we'll have vfork()ed, so don't want to overwrite the + * hostkey. can't think of a workaround to clear it */ +#ifndef __uClinux__ /* wipe the hostkey */ sign_key_free(svr_opts.hostkey); svr_opts.hostkey = NULL; /* overwrite the prng state */ - seedrandom(); + reseedrandom(); +#endif /* close file descriptors except stdin/stdout/stderr * Need to be sure FDs are closed here to avoid reading files as root */ for (i = 3; i <= (unsigned int)ses.maxfd; i++) { - if (m_close(i) == DROPBEAR_FAILURE) { - dropbear_exit("Error closing file desc"); - } + m_close(i); } /* clear environment */