--- ansh/src/daemon3.c 2011/10/04 22:37:46 1.1.1.1 +++ ansh/src/daemon3.c 2011/10/07 13:41:26 1.1.1.1.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: daemon3.c,v 1.1.1.1 2011/10/04 22:37:46 misho Exp $ + * $Id: daemon3.c,v 1.1.1.1.2.1 2011/10/07 13:41:26 misho Exp $ * *************************************************************************/ #include "global.h" @@ -15,6 +15,7 @@ icmpTx(sched_task_t *task) { struct tagProc *proc; int wlen; + u_char *str; FTRACE(3); @@ -22,7 +23,15 @@ icmpTx(sched_task_t *task) if (!(proc = TASK_ARG(task))) return (void*) -1; - if ((wlen = icmpSend(TASK_FD(task), proc->proc_id, proc->proc_flg, proc->proc_buf_[FD2NET], + if (Crypted) { + str = cryptBuffer(proc->proc_buf_[FD2NET], proc->proc_rlen_[FD2NET], Crypted); + if (str) { + memcpy(proc->proc_buf_[FD2NET], str, proc->proc_rlen_[FD2NET]); + free(str); + } + } + + if ((wlen = icmpSend(TASK_FD(task), proc->proc_id, proc->proc_flg, Crypted, proc->proc_buf_[FD2NET], proc->proc_rlen_[FD2NET], &proc->proc_cli, sizeof proc->proc_cli)) != ANSH_FLG_ERR) { proc->proc_flg = ANSH_FLG_OK; proc->proc_rlen_[FD2NET] = 0; @@ -35,7 +44,7 @@ icmpTx(sched_task_t *task) void * icmpRx(sched_task_t *task) { - u_char *buf; + u_char *buf, *str; struct sockaddr sa; int rlen, n = 0, salen = sizeof sa; struct tagProc *proc = NULL; @@ -48,7 +57,7 @@ icmpRx(sched_task_t *task) if (!(buf = malloc(rlen))) goto end; - if ((ret = icmpRecv(TASK_FD(task), &id, buf, &rlen, &sa, (socklen_t *) &salen)) == ANSH_FLG_ERR) + if ((ret = icmpRecv(TASK_FD(task), &id, &Crypted, buf, &rlen, &sa, (socklen_t *) &salen)) == ANSH_FLG_ERR) goto end; VERB(5) LOG("Received %d bytes", rlen); if (!(ret & ANSH_FLG_CPOUT)) @@ -64,6 +73,14 @@ icmpRx(sched_task_t *task) if (n != ANSH_CODE) { proc = NULL; goto end; + } + + if (Crypted) { + str = cryptBuffer(buf, rlen, Crypted); + if (str) { + memcpy(buf, str, rlen); + free(str); + } } switch (ret) {