mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-24 05:31:03 +00:00
Added line-conversions for shells
This commit is contained in:
parent
6f60c7a5b7
commit
7e9597902f
@ -13,11 +13,6 @@ struct sLaika_shell {
|
|||||||
PROCESS_INFORMATION procInfo;
|
PROCESS_INFORMATION procInfo;
|
||||||
STARTUPINFOEX startupInfo;
|
STARTUPINFOEX startupInfo;
|
||||||
HPCON pseudoCon;
|
HPCON pseudoCon;
|
||||||
/* HANDLE watcherMutex;
|
|
||||||
char *outBuf;
|
|
||||||
int outCount, outCap;
|
|
||||||
char *inBuf;
|
|
||||||
int inCount, inCap; */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* edited from https://github.com/microsoft/terminal/blob/main/samples/ConPTY/EchoCon/EchoCon/EchoCon.cpp */
|
/* edited from https://github.com/microsoft/terminal/blob/main/samples/ConPTY/EchoCon/EchoCon/EchoCon.cpp */
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "lerror.h"
|
#include "lerror.h"
|
||||||
|
#include "lmem.h"
|
||||||
#include "cnc.h"
|
#include "cnc.h"
|
||||||
#include "cpanel.h"
|
#include "cpanel.h"
|
||||||
|
|
||||||
@ -143,8 +144,45 @@ void laikaC_handleAuthenticatedShellData(struct sLaika_peer *authPeer, LAIKAPKT_
|
|||||||
/* read data */
|
/* read data */
|
||||||
laikaS_read(&authPeer->sock, data, sz);
|
laikaS_read(&authPeer->sock, data, sz);
|
||||||
|
|
||||||
/* forward data to peer */
|
if (authPeer->osType == peer->osType) {
|
||||||
laikaS_startVarPacket(peer, LAIKAPKT_SHELL_DATA);
|
/* forward raw data to peer */
|
||||||
laikaS_write(&peer->sock, data, sz);
|
laikaS_startVarPacket(peer, LAIKAPKT_SHELL_DATA);
|
||||||
laikaS_endVarPacket(peer);
|
laikaS_write(&peer->sock, data, sz);
|
||||||
|
laikaS_endVarPacket(peer);
|
||||||
|
} else if (authPeer->osType == OS_LIN && peer->osType == OS_WIN) { /* convert data if its linux -> windows */
|
||||||
|
uint8_t *buf = NULL;
|
||||||
|
int i, count = 0, cap = 2;
|
||||||
|
|
||||||
|
/* convert line endings */
|
||||||
|
for (i = 0; i < sz; i++) {
|
||||||
|
laikaM_growarray(uint8_t, buf, 2, count, cap);
|
||||||
|
|
||||||
|
switch (data[i]) {
|
||||||
|
case '\n':
|
||||||
|
buf[count++] = '\r';
|
||||||
|
buf[count++] = '\n';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
buf[count++] = data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send buffer (99% of the time this isn't necessary, but the 1% can make
|
||||||
|
buffers > LAIKA_SHELL_DATA_MAX_LENGTH. so we send it in chunks) */
|
||||||
|
i = count;
|
||||||
|
while (i > LAIKA_SHELL_DATA_MAX_LENGTH) {
|
||||||
|
laikaS_startVarPacket(peer, LAIKAPKT_SHELL_DATA);
|
||||||
|
laikaS_write(&peer->sock, buf + (count - i), LAIKA_SHELL_DATA_MAX_LENGTH);
|
||||||
|
laikaS_endVarPacket(peer);
|
||||||
|
|
||||||
|
i -= LAIKA_SHELL_DATA_MAX_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send the leftovers */
|
||||||
|
laikaS_startVarPacket(peer, LAIKAPKT_SHELL_DATA);
|
||||||
|
laikaS_write(&peer->sock, buf + (count - i), i);
|
||||||
|
laikaS_endVarPacket(peer);
|
||||||
|
|
||||||
|
laikaM_free(buf);
|
||||||
|
}
|
||||||
}
|
}
|
@ -46,7 +46,7 @@ char *shellP_osTypeStr(tShell_peer *peer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void shellP_printInfo(tShell_peer *peer) {
|
void shellP_printInfo(tShell_peer *peer) {
|
||||||
char buf[128];
|
char buf[128]; /* i don't expect bin2hex to write outside this, but it's only user-info and doesn't break anything (ie doesn't write outside the buffer) */
|
||||||
|
|
||||||
sodium_bin2hex(buf, sizeof(buf), peer->pub, crypto_kx_PUBLICKEYBYTES);
|
sodium_bin2hex(buf, sizeof(buf), peer->pub, crypto_kx_PUBLICKEYBYTES);
|
||||||
shellT_printf("\t%s@%s\n\tTYPE: %s\n\tOS: %s\n\tPUBKEY: %s\n\tINET: %s\n", peer->hostname, peer->ipv4, shellP_typeStr(peer), shellP_osTypeStr(peer), buf, peer->inet);
|
shellT_printf("\t%s@%s\n\tTYPE: %s\n\tOS: %s\n\tPUBKEY: %s\n\tINET: %s\n", peer->hostname, peer->ipv4, shellP_typeStr(peer), shellP_osTypeStr(peer), buf, peer->inet);
|
||||||
|
Loading…
Reference in New Issue
Block a user